Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xm_winsys.c 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /**************************************************************************
  2. *
  3. * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  18. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * The above copyright notice and this permission notice (including the
  23. * next paragraph) shall be included in all copies or substantial portions
  24. * of the Software.
  25. *
  26. *
  27. **************************************************************************/
  28. /*
  29. * Authors:
  30. * Keith Whitwell
  31. * Brian Paul
  32. */
  33. #include "glxheader.h"
  34. #include "xmesaP.h"
  35. #undef ASSERT
  36. #undef Elements
  37. #include "pipe/p_winsys.h"
  38. #include "pipe/p_format.h"
  39. #include "pipe/p_context.h"
  40. #include "pipe/p_inlines.h"
  41. #include "util/u_math.h"
  42. #include "util/u_memory.h"
  43. #include "softpipe/sp_winsys.h"
  44. #ifdef GALLIUM_CELL
  45. #include "cell/ppu/cell_context.h"
  46. #include "cell/ppu/cell_screen.h"
  47. #include "cell/ppu/cell_winsys.h"
  48. #else
  49. #define TILE_SIZE 32 /* avoid compilation errors */
  50. #endif
  51. #ifdef GALLIUM_TRACE
  52. #include "trace/tr_screen.h"
  53. #include "trace/tr_context.h"
  54. #endif
  55. #include "xm_winsys_aub.h"
  56. /**
  57. * Subclass of pipe_buffer for Xlib winsys.
  58. * Low-level OS/window system memory buffer
  59. */
  60. struct xm_buffer
  61. {
  62. struct pipe_buffer base;
  63. boolean userBuffer; /** Is this a user-space buffer? */
  64. void *data;
  65. void *mapped;
  66. XImage *tempImage;
  67. int shm;
  68. #if defined(USE_XSHM) && !defined(XFree86Server)
  69. XShmSegmentInfo shminfo;
  70. #endif
  71. };
  72. /**
  73. * Subclass of pipe_winsys for Xlib winsys
  74. */
  75. struct xmesa_pipe_winsys
  76. {
  77. struct pipe_winsys base;
  78. struct xmesa_visual *xm_visual;
  79. int shm;
  80. };
  81. /** Cast wrapper */
  82. static INLINE struct xm_buffer *
  83. xm_buffer( struct pipe_buffer *buf )
  84. {
  85. return (struct xm_buffer *)buf;
  86. }
  87. /**
  88. * X Shared Memory Image extension code
  89. */
  90. #if defined(USE_XSHM) && !defined(XFree86Server)
  91. #define XSHM_ENABLED(b) ((b)->shm)
  92. static volatile int mesaXErrorFlag = 0;
  93. /**
  94. * Catches potential Xlib errors.
  95. */
  96. static int
  97. mesaHandleXError(XMesaDisplay *dpy, XErrorEvent *event)
  98. {
  99. (void) dpy;
  100. (void) event;
  101. mesaXErrorFlag = 1;
  102. return 0;
  103. }
  104. static GLboolean alloc_shm(struct xm_buffer *buf, unsigned size)
  105. {
  106. XShmSegmentInfo *const shminfo = & buf->shminfo;
  107. shminfo->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT|0777);
  108. if (shminfo->shmid < 0) {
  109. return GL_FALSE;
  110. }
  111. shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
  112. if (shminfo->shmaddr == (char *) -1) {
  113. shmctl(shminfo->shmid, IPC_RMID, 0);
  114. return GL_FALSE;
  115. }
  116. shminfo->readOnly = False;
  117. return GL_TRUE;
  118. }
  119. /**
  120. * Allocate a shared memory XImage back buffer for the given XMesaBuffer.
  121. */
  122. static void
  123. alloc_shm_ximage(struct xm_buffer *b, struct xmesa_buffer *xmb,
  124. unsigned width, unsigned height)
  125. {
  126. /*
  127. * We have to do a _lot_ of error checking here to be sure we can
  128. * really use the XSHM extension. It seems different servers trigger
  129. * errors at different points if the extension won't work. Therefore
  130. * we have to be very careful...
  131. */
  132. #if 0
  133. GC gc;
  134. #endif
  135. int (*old_handler)(XMesaDisplay *, XErrorEvent *);
  136. b->tempImage = XShmCreateImage(xmb->xm_visual->display,
  137. xmb->xm_visual->visinfo->visual,
  138. xmb->xm_visual->visinfo->depth,
  139. ZPixmap,
  140. NULL,
  141. &b->shminfo,
  142. width, height);
  143. if (b->tempImage == NULL) {
  144. b->shm = 0;
  145. return;
  146. }
  147. mesaXErrorFlag = 0;
  148. old_handler = XSetErrorHandler(mesaHandleXError);
  149. /* This may trigger the X protocol error we're ready to catch: */
  150. XShmAttach(xmb->xm_visual->display, &b->shminfo);
  151. XSync(xmb->xm_visual->display, False);
  152. if (mesaXErrorFlag) {
  153. /* we are on a remote display, this error is normal, don't print it */
  154. XFlush(xmb->xm_visual->display);
  155. mesaXErrorFlag = 0;
  156. XDestroyImage(b->tempImage);
  157. b->tempImage = NULL;
  158. b->shm = 0;
  159. (void) XSetErrorHandler(old_handler);
  160. return;
  161. }
  162. /* Finally, try an XShmPutImage to be really sure the extension works */
  163. #if 0
  164. gc = XCreateGC(xmb->xm_visual->display, xmb->drawable, 0, NULL);
  165. XShmPutImage(xmb->xm_visual->display, xmb->drawable, gc,
  166. b->tempImage, 0, 0, 0, 0, 1, 1 /*one pixel*/, False);
  167. XSync(xmb->xm_visual->display, False);
  168. XFreeGC(xmb->xm_visual->display, gc);
  169. (void) XSetErrorHandler(old_handler);
  170. if (mesaXErrorFlag) {
  171. XFlush(xmb->xm_visual->display);
  172. mesaXErrorFlag = 0;
  173. XDestroyImage(b->tempImage);
  174. b->tempImage = NULL;
  175. b->shm = 0;
  176. return;
  177. }
  178. #endif
  179. }
  180. #else
  181. #define XSHM_ENABLED(b) 0
  182. static void
  183. alloc_shm_ximage(struct xm_buffer *b, struct xmesa_buffer *xmb,
  184. unsigned width, unsigned height)
  185. {
  186. b->shm = 0;
  187. }
  188. #endif /* USE_XSHM */
  189. /* Most callbacks map direcly onto dri_bufmgr operations:
  190. */
  191. static void *
  192. xm_buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf,
  193. unsigned flags)
  194. {
  195. struct xm_buffer *xm_buf = xm_buffer(buf);
  196. xm_buf->mapped = xm_buf->data;
  197. return xm_buf->mapped;
  198. }
  199. static void
  200. xm_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf)
  201. {
  202. struct xm_buffer *xm_buf = xm_buffer(buf);
  203. xm_buf->mapped = NULL;
  204. }
  205. static void
  206. xm_buffer_destroy(struct pipe_winsys *pws,
  207. struct pipe_buffer *buf)
  208. {
  209. struct xm_buffer *oldBuf = xm_buffer(buf);
  210. if (oldBuf->data) {
  211. #if defined(USE_XSHM) && !defined(XFree86Server)
  212. if (oldBuf->shminfo.shmid >= 0) {
  213. shmdt(oldBuf->shminfo.shmaddr);
  214. shmctl(oldBuf->shminfo.shmid, IPC_RMID, 0);
  215. oldBuf->shminfo.shmid = -1;
  216. oldBuf->shminfo.shmaddr = (char *) -1;
  217. }
  218. else
  219. #endif
  220. {
  221. if (!oldBuf->userBuffer) {
  222. align_free(oldBuf->data);
  223. }
  224. }
  225. oldBuf->data = NULL;
  226. }
  227. free(oldBuf);
  228. }
  229. /**
  230. * For Cell. Basically, rearrange the pixels/quads from this layout:
  231. * +--+--+--+--+
  232. * |p0|p1|p2|p3|....
  233. * +--+--+--+--+
  234. *
  235. * to this layout:
  236. * +--+--+
  237. * |p0|p1|....
  238. * +--+--+
  239. * |p2|p3|
  240. * +--+--+
  241. */
  242. static void
  243. twiddle_tile(const uint *tileIn, uint *tileOut)
  244. {
  245. int y, x;
  246. for (y = 0; y < TILE_SIZE; y+=2) {
  247. for (x = 0; x < TILE_SIZE; x+=2) {
  248. int k = 4 * (y/2 * TILE_SIZE/2 + x/2);
  249. tileOut[y * TILE_SIZE + (x + 0)] = tileIn[k];
  250. tileOut[y * TILE_SIZE + (x + 1)] = tileIn[k+1];
  251. tileOut[(y + 1) * TILE_SIZE + (x + 0)] = tileIn[k+2];
  252. tileOut[(y + 1) * TILE_SIZE + (x + 1)] = tileIn[k+3];
  253. }
  254. }
  255. }
  256. /**
  257. * Display a surface that's in a tiled configuration. That is, all the
  258. * pixels for a TILE_SIZExTILE_SIZE block are contiguous in memory.
  259. */
  260. static void
  261. xmesa_display_surface_tiled(XMesaBuffer b, const struct pipe_surface *surf)
  262. {
  263. XImage *ximage;
  264. struct xm_buffer *xm_buf = xm_buffer(surf->buffer);
  265. const uint tilesPerRow = (surf->width + TILE_SIZE - 1) / TILE_SIZE;
  266. uint x, y;
  267. if (XSHM_ENABLED(xm_buf) && (xm_buf->tempImage == NULL)) {
  268. alloc_shm_ximage(xm_buf, b, TILE_SIZE, TILE_SIZE);
  269. }
  270. ximage = (XSHM_ENABLED(xm_buf)) ? xm_buf->tempImage : b->tempImage;
  271. /* check that the XImage has been previously initialized */
  272. assert(ximage->format);
  273. assert(ximage->bitmap_unit);
  274. if (!XSHM_ENABLED(xm_buf)) {
  275. /* update XImage's fields */
  276. ximage->width = TILE_SIZE;
  277. ximage->height = TILE_SIZE;
  278. ximage->bytes_per_line = TILE_SIZE * 4;
  279. }
  280. for (y = 0; y < surf->height; y += TILE_SIZE) {
  281. for (x = 0; x < surf->width; x += TILE_SIZE) {
  282. uint tmpTile[TILE_SIZE * TILE_SIZE];
  283. int tx = x / TILE_SIZE;
  284. int ty = y / TILE_SIZE;
  285. int offset = ty * tilesPerRow + tx;
  286. int w = TILE_SIZE;
  287. int h = TILE_SIZE;
  288. if (y + h > surf->height)
  289. h = surf->height - y;
  290. if (x + w > surf->width)
  291. w = surf->width - x;
  292. offset *= 4 * TILE_SIZE * TILE_SIZE;
  293. twiddle_tile((uint *) ((char *) xm_buf->data + offset),
  294. tmpTile);
  295. ximage->data = (char*) tmpTile;
  296. if (XSHM_ENABLED(xm_buf)) {
  297. #if defined(USE_XSHM) && !defined(XFree86Server)
  298. XShmPutImage(b->xm_visual->display, b->drawable, b->gc,
  299. ximage, 0, 0, x, y, w, h, False);
  300. #endif
  301. }
  302. else {
  303. XPutImage(b->xm_visual->display, b->drawable, b->gc,
  304. ximage, 0, 0, x, y, w, h);
  305. }
  306. }
  307. }
  308. }
  309. /**
  310. * Display/copy the image in the surface into the X window specified
  311. * by the XMesaBuffer.
  312. */
  313. void
  314. xmesa_display_surface(XMesaBuffer b, const struct pipe_surface *surf)
  315. {
  316. XImage *ximage;
  317. struct xm_buffer *xm_buf = xm_buffer(surf->buffer);
  318. static boolean no_swap = 0;
  319. static boolean firsttime = 1;
  320. static int tileSize = 0;
  321. if (firsttime) {
  322. no_swap = getenv("SP_NO_RAST") != NULL;
  323. #ifdef GALLIUM_CELL
  324. if (!getenv("GALLIUM_NOCELL")) {
  325. tileSize = 32; /** probably temporary */
  326. }
  327. #endif
  328. firsttime = 0;
  329. }
  330. if (no_swap)
  331. return;
  332. if (tileSize) {
  333. xmesa_display_surface_tiled(b, surf);
  334. return;
  335. }
  336. if (XSHM_ENABLED(xm_buf) && (xm_buf->tempImage == NULL)) {
  337. assert(surf->block.width == 1);
  338. assert(surf->block.height == 1);
  339. alloc_shm_ximage(xm_buf, b, surf->stride/surf->block.size, surf->height);
  340. }
  341. ximage = (XSHM_ENABLED(xm_buf)) ? xm_buf->tempImage : b->tempImage;
  342. ximage->data = xm_buf->data;
  343. /* display image in Window */
  344. if (XSHM_ENABLED(xm_buf)) {
  345. #if defined(USE_XSHM) && !defined(XFree86Server)
  346. XShmPutImage(b->xm_visual->display, b->drawable, b->gc,
  347. ximage, 0, 0, 0, 0, surf->width, surf->height, False);
  348. #endif
  349. } else {
  350. /* check that the XImage has been previously initialized */
  351. assert(ximage->format);
  352. assert(ximage->bitmap_unit);
  353. /* update XImage's fields */
  354. ximage->width = surf->width;
  355. ximage->height = surf->height;
  356. ximage->bytes_per_line = surf->stride;
  357. XPutImage(b->xm_visual->display, b->drawable, b->gc,
  358. ximage, 0, 0, 0, 0, surf->width, surf->height);
  359. }
  360. }
  361. static void
  362. xm_flush_frontbuffer(struct pipe_winsys *pws,
  363. struct pipe_surface *surf,
  364. void *context_private)
  365. {
  366. /*
  367. * The front color buffer is actually just another XImage buffer.
  368. * This function copies that XImage to the actual X Window.
  369. */
  370. XMesaContext xmctx = (XMesaContext) context_private;
  371. xmesa_display_surface(xmctx->xm_buffer, surf);
  372. }
  373. static const char *
  374. xm_get_name(struct pipe_winsys *pws)
  375. {
  376. return "Xlib";
  377. }
  378. static struct pipe_buffer *
  379. xm_buffer_create(struct pipe_winsys *pws,
  380. unsigned alignment,
  381. unsigned usage,
  382. unsigned size)
  383. {
  384. struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer);
  385. #if defined(USE_XSHM) && !defined(XFree86Server)
  386. struct xmesa_pipe_winsys *xpws = (struct xmesa_pipe_winsys *) pws;
  387. #endif
  388. buffer->base.refcount = 1;
  389. buffer->base.alignment = alignment;
  390. buffer->base.usage = usage;
  391. buffer->base.size = size;
  392. #if defined(USE_XSHM) && !defined(XFree86Server)
  393. buffer->shminfo.shmid = -1;
  394. buffer->shminfo.shmaddr = (char *) -1;
  395. if (xpws->shm && (usage & PIPE_BUFFER_USAGE_PIXEL) != 0) {
  396. buffer->shm = xpws->shm;
  397. if (alloc_shm(buffer, size)) {
  398. buffer->data = buffer->shminfo.shmaddr;
  399. }
  400. }
  401. #endif
  402. if (buffer->data == NULL) {
  403. buffer->shm = 0;
  404. /* align to 16-byte multiple for Cell */
  405. buffer->data = align_malloc(size, max(alignment, 16));
  406. }
  407. return &buffer->base;
  408. }
  409. /**
  410. * Create buffer which wraps user-space data.
  411. */
  412. static struct pipe_buffer *
  413. xm_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes)
  414. {
  415. struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer);
  416. buffer->base.refcount = 1;
  417. buffer->base.size = bytes;
  418. buffer->userBuffer = TRUE;
  419. buffer->data = ptr;
  420. buffer->shm = 0;
  421. return &buffer->base;
  422. }
  423. /**
  424. * Round n up to next multiple.
  425. */
  426. static INLINE unsigned
  427. round_up(unsigned n, unsigned multiple)
  428. {
  429. return (n + multiple - 1) & ~(multiple - 1);
  430. }
  431. static int
  432. xm_surface_alloc_storage(struct pipe_winsys *winsys,
  433. struct pipe_surface *surf,
  434. unsigned width, unsigned height,
  435. enum pipe_format format,
  436. unsigned flags,
  437. unsigned tex_usage)
  438. {
  439. const unsigned alignment = 64;
  440. surf->width = width;
  441. surf->height = height;
  442. surf->format = format;
  443. pf_get_block(format, &surf->block);
  444. surf->nblocksx = pf_get_nblocksx(&surf->block, width);
  445. surf->nblocksy = pf_get_nblocksy(&surf->block, height);
  446. surf->stride = round_up(surf->nblocksx * surf->block.size, alignment);
  447. surf->usage = flags;
  448. assert(!surf->buffer);
  449. surf->buffer = winsys->buffer_create(winsys, alignment,
  450. PIPE_BUFFER_USAGE_PIXEL,
  451. #ifdef GALLIUM_CELL /* XXX a bit of a hack */
  452. surf->stride * round_up(surf->nblocksy, TILE_SIZE));
  453. #else
  454. surf->stride * surf->nblocksy);
  455. #endif
  456. if(!surf->buffer)
  457. return -1;
  458. return 0;
  459. }
  460. /**
  461. * Called via winsys->surface_alloc() to create new surfaces.
  462. */
  463. static struct pipe_surface *
  464. xm_surface_alloc(struct pipe_winsys *ws)
  465. {
  466. struct pipe_surface *surface = CALLOC_STRUCT(pipe_surface);
  467. assert(ws);
  468. surface->refcount = 1;
  469. surface->winsys = ws;
  470. return surface;
  471. }
  472. static void
  473. xm_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s)
  474. {
  475. struct pipe_surface *surf = *s;
  476. assert(!surf->texture);
  477. surf->refcount--;
  478. if (surf->refcount == 0) {
  479. if (surf->buffer)
  480. winsys_buffer_reference(winsys, &surf->buffer, NULL);
  481. free(surf);
  482. }
  483. *s = NULL;
  484. }
  485. /*
  486. * Fence functions - basically nothing to do, as we don't create any actual
  487. * fence objects.
  488. */
  489. static void
  490. xm_fence_reference(struct pipe_winsys *sws, struct pipe_fence_handle **ptr,
  491. struct pipe_fence_handle *fence)
  492. {
  493. }
  494. static int
  495. xm_fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
  496. unsigned flag)
  497. {
  498. return 0;
  499. }
  500. static int
  501. xm_fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
  502. unsigned flag)
  503. {
  504. return 0;
  505. }
  506. /**
  507. * Return pointer to a pipe_winsys object.
  508. * For Xlib, this is a singleton object.
  509. * Nothing special for the Xlib driver so no subclassing or anything.
  510. */
  511. struct pipe_winsys *
  512. xmesa_get_pipe_winsys_aub(struct xmesa_visual *xm_vis)
  513. {
  514. static struct xmesa_pipe_winsys *ws = NULL;
  515. if (!ws) {
  516. ws = (struct xmesa_pipe_winsys *) xmesa_create_pipe_winsys_aub();
  517. }
  518. return &ws->base;
  519. }
  520. static struct pipe_winsys *
  521. xmesa_get_pipe_winsys(struct xmesa_visual *xm_vis)
  522. {
  523. static struct xmesa_pipe_winsys *ws = NULL;
  524. if (!ws) {
  525. ws = CALLOC_STRUCT(xmesa_pipe_winsys);
  526. ws->xm_visual = xm_vis;
  527. ws->shm = xmesa_check_for_xshm(xm_vis->display);
  528. /* Fill in this struct with callbacks that pipe will need to
  529. * communicate with the window system, buffer manager, etc.
  530. */
  531. ws->base.buffer_create = xm_buffer_create;
  532. ws->base.user_buffer_create = xm_user_buffer_create;
  533. ws->base.buffer_map = xm_buffer_map;
  534. ws->base.buffer_unmap = xm_buffer_unmap;
  535. ws->base.buffer_destroy = xm_buffer_destroy;
  536. ws->base.surface_alloc = xm_surface_alloc;
  537. ws->base.surface_alloc_storage = xm_surface_alloc_storage;
  538. ws->base.surface_release = xm_surface_release;
  539. ws->base.fence_reference = xm_fence_reference;
  540. ws->base.fence_signalled = xm_fence_signalled;
  541. ws->base.fence_finish = xm_fence_finish;
  542. ws->base.flush_frontbuffer = xm_flush_frontbuffer;
  543. ws->base.get_name = xm_get_name;
  544. }
  545. return &ws->base;
  546. }
  547. struct pipe_context *
  548. xmesa_create_pipe_context(XMesaContext xmesa, uint pixelformat)
  549. {
  550. struct pipe_winsys *pws;
  551. struct pipe_context *pipe;
  552. if (getenv("XM_AUB")) {
  553. pws = xmesa_get_pipe_winsys_aub(xmesa->xm_visual);
  554. }
  555. else {
  556. pws = xmesa_get_pipe_winsys(xmesa->xm_visual);
  557. }
  558. #ifdef GALLIUM_CELL
  559. if (!getenv("GALLIUM_NOCELL")) {
  560. struct cell_winsys *cws = cell_get_winsys(pixelformat);
  561. struct pipe_screen *screen = cell_create_screen(pws);
  562. pipe = cell_create_context(screen, cws);
  563. }
  564. else
  565. #endif
  566. {
  567. struct pipe_screen *screen = softpipe_create_screen(pws);
  568. pipe = softpipe_create(screen, pws, NULL);
  569. #ifdef GALLIUM_TRACE
  570. screen = trace_screen_create(screen);
  571. pipe = trace_context_create(screen, pipe);
  572. #endif
  573. }
  574. if (pipe)
  575. pipe->priv = xmesa;
  576. return pipe;
  577. }