xm_winsys.c File Reference

Include dependency graph for xm_winsys.c:

Go to the source code of this file.

Data Structures

struct  xm_buffer
 Subclass of pipe_buffer for Xlib winsys. More...
struct  xmesa_pipe_winsys
 Subclass of pipe_winsys for Xlib winsys. More...

Defines

#define TILE_SIZE   32
#define XSHM_ENABLED(b)   0
 X Shared Memory Image extension code.

Functions

static struct xm_bufferxm_buffer (struct pipe_buffer *buf)
 Cast wrapper.
static void alloc_shm_ximage (struct xm_buffer *b, struct xmesa_buffer *xmb, unsigned width, unsigned height)
static void * xm_buffer_map (struct pipe_winsys *pws, struct pipe_buffer *buf, unsigned flags)
static void xm_buffer_unmap (struct pipe_winsys *pws, struct pipe_buffer *buf)
static void xm_buffer_destroy (struct pipe_winsys *pws, struct pipe_buffer *buf)
static void twiddle_tile (const uint *tileIn, uint *tileOut)
 For Cell.
static void xmesa_display_surface_tiled (XMesaBuffer b, const struct pipe_surface *surf)
 Display a surface that's in a tiled configuration.
void xmesa_display_surface (XMesaBuffer b, const struct pipe_surface *surf)
 Display/copy the image in the surface into the X window specified by the XMesaBuffer.
static void xm_flush_frontbuffer (struct pipe_winsys *pws, struct pipe_surface *surf, void *context_private)
static const char * xm_get_name (struct pipe_winsys *pws)
static struct pipe_bufferxm_buffer_create (struct pipe_winsys *pws, unsigned alignment, unsigned usage, unsigned size)
static struct pipe_bufferxm_user_buffer_create (struct pipe_winsys *pws, void *ptr, unsigned bytes)
 Create buffer which wraps user-space data.
static unsigned round_up (unsigned n, unsigned multiple)
 Round n up to next multiple.
static int xm_surface_alloc_storage (struct pipe_winsys *winsys, struct pipe_surface *surf, unsigned width, unsigned height, enum pipe_format format, unsigned flags, unsigned tex_usage)
static struct pipe_surfacexm_surface_alloc (struct pipe_winsys *ws)
 Called via winsys->surface_alloc() to create new surfaces.
static void xm_surface_release (struct pipe_winsys *winsys, struct pipe_surface **s)
static void xm_fence_reference (struct pipe_winsys *sws, struct pipe_fence_handle **ptr, struct pipe_fence_handle *fence)
static int xm_fence_signalled (struct pipe_winsys *sws, struct pipe_fence_handle *fence, unsigned flag)
static int xm_fence_finish (struct pipe_winsys *sws, struct pipe_fence_handle *fence, unsigned flag)
struct pipe_winsysxmesa_get_pipe_winsys_aub (struct xmesa_visual *xm_vis)
 Return pointer to a pipe_winsys object.
static struct pipe_winsysxmesa_get_pipe_winsys (struct xmesa_visual *xm_vis)
struct pipe_contextxmesa_create_pipe_context (XMesaContext xmesa, uint pixelformat)


Define Documentation

#define TILE_SIZE   32

Definition at line 55 of file xm_winsys.c.

#define XSHM_ENABLED (  )     0

X Shared Memory Image extension code.

Definition at line 215 of file xm_winsys.c.


Function Documentation

static void alloc_shm_ximage ( struct xm_buffer b,
struct xmesa_buffer xmb,
unsigned  width,
unsigned  height 
) [static]

Definition at line 218 of file xm_winsys.c.

References xm_buffer::shm.

00222 {

static unsigned round_up ( unsigned  n,
unsigned  multiple 
) [static]

Round n up to next multiple.

Definition at line 525 of file xm_winsys.c.

00528 {

static void twiddle_tile ( const uint tileIn,
uint tileOut 
) [static]

For Cell.

Basically, rearrange the pixels/quads from this layout: +--+--+--+--+ |p0|p1|p2|p3|.... +--+--+--+--+

to this layout: +--+--+ |p0|p1|.... +--+--+ |p2|p3| +--+--+

Definition at line 290 of file xm_winsys.c.

00293 {
00294    int y, x;
00295 
00296    for (y = 0; y < TILE_SIZE; y+=2) {
00297       for (x = 0; x < TILE_SIZE; x+=2) {
00298          int k = 4 * (y/2 * TILE_SIZE/2 + x/2);
00299          tileOut[y * TILE_SIZE + (x + 0)] = tileIn[k];
00300          tileOut[y * TILE_SIZE + (x + 1)] = tileIn[k+1];
00301          tileOut[(y + 1) * TILE_SIZE + (x + 0)] = tileIn[k+2];
00302          tileOut[(y + 1) * TILE_SIZE + (x + 1)] = tileIn[k+3];
00303       }

static struct xm_buffer* xm_buffer ( struct pipe_buffer buf  )  [static, read]

Cast wrapper.

Definition at line 99 of file xm_winsys.c.

00100 {
00101    return (struct xm_buffer *)buf;
00102 }

static struct pipe_buffer* xm_buffer_create ( struct pipe_winsys pws,
unsigned  alignment,
unsigned  usage,
unsigned  size 
) [static, read]

Definition at line 463 of file xm_winsys.c.

References align_malloc(), pipe_buffer::alignment, xm_buffer::base, CALLOC_STRUCT, xm_buffer::data, max(), PIPE_BUFFER_USAGE_PIXEL, pipe_buffer::refcount, xm_buffer::shm, xmesa_pipe_winsys::shm, pipe_buffer::size, and pipe_buffer::usage.

00469 {
00470    struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer);
00471 #if defined(USE_XSHM) && !defined(XFree86Server)
00472    struct xmesa_pipe_winsys *xpws = (struct xmesa_pipe_winsys *) pws;
00473 #endif
00474 
00475    buffer->base.refcount = 1;
00476    buffer->base.alignment = alignment;
00477    buffer->base.usage = usage;
00478    buffer->base.size = size;
00479 
00480 
00481 #if defined(USE_XSHM) && !defined(XFree86Server)
00482    buffer->shminfo.shmid = -1;
00483    buffer->shminfo.shmaddr = (char *) -1;
00484 
00485    if (xpws->shm && (usage & PIPE_BUFFER_USAGE_PIXEL) != 0) {
00486       buffer->shm = xpws->shm;
00487 
00488       if (alloc_shm(buffer, size)) {
00489          buffer->data = buffer->shminfo.shmaddr;
00490       }
00491    }
00492 #endif
00493 
00494    if (buffer->data == NULL) {
00495       buffer->shm = 0;
00496 
00497       /* align to 16-byte multiple for Cell */
00498       buffer->data = align_malloc(size, max(alignment, 16));
00499    }
00500 

static void xm_buffer_destroy ( struct pipe_winsys pws,
struct pipe_buffer buf 
) [static]

Definition at line 247 of file xm_winsys.c.

References align_free(), xm_buffer::data, xm_buffer::userBuffer, and xm_buffer().

00251 {
00252    struct xm_buffer *oldBuf = xm_buffer(buf);
00253 
00254    if (oldBuf->data) {
00255 #if defined(USE_XSHM) && !defined(XFree86Server)
00256       if (oldBuf->shminfo.shmid >= 0) {
00257          shmdt(oldBuf->shminfo.shmaddr);
00258          shmctl(oldBuf->shminfo.shmid, IPC_RMID, 0);
00259          
00260          oldBuf->shminfo.shmid = -1;
00261          oldBuf->shminfo.shmaddr = (char *) -1;
00262       }
00263       else
00264 #endif
00265       {
00266          if (!oldBuf->userBuffer) {
00267             align_free(oldBuf->data);
00268          }
00269       }
00270 
00271       oldBuf->data = NULL;
00272    }
00273 

static void* xm_buffer_map ( struct pipe_winsys pws,
struct pipe_buffer buf,
unsigned  flags 
) [static]

Definition at line 231 of file xm_winsys.c.

References xm_buffer::data, xm_buffer::mapped, and xm_buffer().

00235 {
00236    struct xm_buffer *xm_buf = xm_buffer(buf);
00237    xm_buf->mapped = xm_buf->data;

static void xm_buffer_unmap ( struct pipe_winsys pws,
struct pipe_buffer buf 
) [static]

Definition at line 240 of file xm_winsys.c.

References xm_buffer::mapped, and xm_buffer().

00243 {
00244    struct xm_buffer *xm_buf = xm_buffer(buf);

static int xm_fence_finish ( struct pipe_winsys sws,
struct pipe_fence_handle *  fence,
unsigned  flag 
) [static]

Definition at line 619 of file xm_winsys.c.

00623 {

static void xm_fence_reference ( struct pipe_winsys sws,
struct pipe_fence_handle **  ptr,
struct pipe_fence_handle *  fence 
) [static]

Definition at line 604 of file xm_winsys.c.

00608 {

static int xm_fence_signalled ( struct pipe_winsys sws,
struct pipe_fence_handle *  fence,
unsigned  flag 
) [static]

Definition at line 611 of file xm_winsys.c.

00615 {

static void xm_flush_frontbuffer ( struct pipe_winsys pws,
struct pipe_surface surf,
void *  context_private 
) [static]

Definition at line 441 of file xm_winsys.c.

References xmesa_display_surface().

00446 {
00447    /*
00448     * The front color buffer is actually just another XImage buffer.
00449     * This function copies that XImage to the actual X Window.
00450     */
00451    XMesaContext xmctx = (XMesaContext) context_private;

static const char* xm_get_name ( struct pipe_winsys pws  )  [static]

Definition at line 456 of file xm_winsys.c.

00459 {

static struct pipe_surface* xm_surface_alloc ( struct pipe_winsys ws  )  [static, read]

Called via winsys->surface_alloc() to create new surfaces.

Definition at line 569 of file xm_winsys.c.

00572 {
00573    struct pipe_surface *surface = CALLOC_STRUCT(pipe_surface);
00574 
00575    assert(ws);
00576 
00577    surface->refcount = 1;
00578    surface->winsys = ws;
00579 

static int xm_surface_alloc_storage ( struct pipe_winsys winsys,
struct pipe_surface surf,
unsigned  width,
unsigned  height,
enum pipe_format  format,
unsigned  flags,
unsigned  tex_usage 
) [static]

Definition at line 531 of file xm_winsys.c.

References assert, pipe_surface::block, pipe_surface::buffer, pipe_winsys::buffer_create, pipe_surface::format, pipe_surface::height, pipe_surface::nblocksx, pipe_surface::nblocksy, pf_get_block(), pf_get_nblocksx(), pf_get_nblocksy(), PIPE_BUFFER_USAGE_PIXEL, round_up(), pipe_format_block::size, pipe_surface::stride, pipe_surface::usage, and pipe_surface::width.

00539 {
00540    const unsigned alignment = 64;
00541 
00542    surf->width = width;
00543    surf->height = height;
00544    surf->format = format;
00545    pf_get_block(format, &surf->block);
00546    surf->nblocksx = pf_get_nblocksx(&surf->block, width);
00547    surf->nblocksy = pf_get_nblocksy(&surf->block, height);
00548    surf->stride = round_up(surf->nblocksx * surf->block.size, alignment);
00549    surf->usage = flags;
00550 
00551    assert(!surf->buffer);
00552    surf->buffer = winsys->buffer_create(winsys, alignment,
00553                                         PIPE_BUFFER_USAGE_PIXEL,
00554 #ifdef GALLIUM_CELL /* XXX a bit of a hack */
00555                                         surf->stride * round_up(surf->nblocksy, TILE_SIZE));
00556 #else
00557                                         surf->stride * surf->nblocksy);
00558 #endif
00559 
00560    if(!surf->buffer)
00561       return -1;
00562    

static void xm_surface_release ( struct pipe_winsys winsys,
struct pipe_surface **  s 
) [static]

Definition at line 584 of file xm_winsys.c.

References assert, pipe_surface::buffer, pipe_surface::refcount, pipe_surface::texture, and winsys_buffer_reference().

00587 {
00588    struct pipe_surface *surf = *s;
00589    assert(!surf->texture);
00590    surf->refcount--;
00591    if (surf->refcount == 0) {
00592       if (surf->buffer)
00593         winsys_buffer_reference(winsys, &surf->buffer, NULL);
00594       free(surf);
00595    }

static struct pipe_buffer* xm_user_buffer_create ( struct pipe_winsys pws,
void *  ptr,
unsigned  bytes 
) [static, read]

Create buffer which wraps user-space data.

Definition at line 507 of file xm_winsys.c.

00510 {
00511    struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer);
00512    buffer->base.refcount = 1;
00513    buffer->base.size = bytes;
00514    buffer->userBuffer = TRUE;
00515    buffer->data = ptr;
00516    buffer->shm = 0;
00517 

struct pipe_context* xmesa_create_pipe_context ( XMesaContext  xmesa,
uint  pixelformat 
) [read]

Definition at line 680 of file xm_winsys.c.

References cell_create_context(), cell_create_screen(), cell_get_winsys(), pipe_context::priv, softpipe_create(), softpipe_create_screen(), trace_context_create(), trace_screen_create(), xmesa_get_pipe_winsys(), and xmesa_get_pipe_winsys_aub().

00683 {
00684    struct pipe_winsys *pws;
00685    struct pipe_context *pipe;
00686    
00687    if (getenv("XM_AUB")) {
00688       pws = xmesa_get_pipe_winsys_aub(xmesa->xm_visual);
00689    }
00690    else {
00691       pws = xmesa_get_pipe_winsys(xmesa->xm_visual);
00692    }
00693 
00694 #ifdef GALLIUM_CELL
00695    if (!getenv("GALLIUM_NOCELL")) {
00696       struct cell_winsys *cws = cell_get_winsys(pixelformat);
00697       struct pipe_screen *screen = cell_create_screen(pws);
00698 
00699       pipe = cell_create_context(screen, cws);
00700    }
00701    else
00702 #endif
00703    {
00704       struct pipe_screen *screen = softpipe_create_screen(pws);
00705 
00706       pipe = softpipe_create(screen, pws, NULL);
00707 
00708 #ifdef GALLIUM_TRACE
00709       screen = trace_screen_create(screen);
00710       
00711       pipe = trace_context_create(screen, pipe);
00712 #endif
00713    }
00714 
00715    if (pipe)
00716       pipe->priv = xmesa;
00717 

void xmesa_display_surface ( XMesaBuffer  b,
const struct pipe_surface surf 
)

Display/copy the image in the surface into the X window specified by the XMesaBuffer.

Definition at line 383 of file xm_winsys.c.

00386 {
00387    XImage *ximage;
00388    struct xm_buffer *xm_buf = xm_buffer(surf->buffer);
00389    static boolean no_swap = 0;
00390    static boolean firsttime = 1;
00391    static int tileSize = 0;
00392 
00393    if (firsttime) {
00394       no_swap = getenv("SP_NO_RAST") != NULL;
00395 #ifdef GALLIUM_CELL
00396       if (!getenv("GALLIUM_NOCELL")) {
00397          tileSize = 32; 
00398       }
00399 #endif
00400       firsttime = 0;
00401    }
00402 
00403    if (no_swap)
00404       return;
00405 
00406    if (tileSize) {
00407       xmesa_display_surface_tiled(b, surf);
00408       return;
00409    }
00410 
00411    if (XSHM_ENABLED(xm_buf) && (xm_buf->tempImage == NULL)) {
00412       assert(surf->block.width == 1);
00413       assert(surf->block.height == 1);
00414       alloc_shm_ximage(xm_buf, b, surf->stride/surf->block.size, surf->height);
00415    }
00416 
00417    ximage = (XSHM_ENABLED(xm_buf)) ? xm_buf->tempImage : b->tempImage;
00418    ximage->data = xm_buf->data;
00419 
00420    /* display image in Window */
00421    if (XSHM_ENABLED(xm_buf)) {
00422 #if defined(USE_XSHM) && !defined(XFree86Server)
00423       XShmPutImage(b->xm_visual->display, b->drawable, b->gc,
00424                    ximage, 0, 0, 0, 0, surf->width, surf->height, False);
00425 #endif
00426    } else {
00427       /* check that the XImage has been previously initialized */
00428       assert(ximage->format);
00429       assert(ximage->bitmap_unit);
00430 
00431       /* update XImage's fields */
00432       ximage->width = surf->width;
00433       ximage->height = surf->height;
00434       ximage->bytes_per_line = surf->stride;
00435 
00436       XPutImage(b->xm_visual->display, b->drawable, b->gc,
00437                 ximage, 0, 0, 0, 0, surf->width, surf->height);

static void xmesa_display_surface_tiled ( XMesaBuffer  b,
const struct pipe_surface surf 
) [static]

Display a surface that's in a tiled configuration.

That is, all the pixels for a TILE_SIZExTILE_SIZE block are contiguous in memory.

Definition at line 312 of file xm_winsys.c.

00315 {
00316    XImage *ximage;
00317    struct xm_buffer *xm_buf = xm_buffer(surf->buffer);
00318    const uint tilesPerRow = (surf->width + TILE_SIZE - 1) / TILE_SIZE;
00319    uint x, y;
00320 
00321    if (XSHM_ENABLED(xm_buf) && (xm_buf->tempImage == NULL)) {
00322       alloc_shm_ximage(xm_buf, b, TILE_SIZE, TILE_SIZE);
00323    }
00324 
00325    ximage = (XSHM_ENABLED(xm_buf)) ? xm_buf->tempImage : b->tempImage;
00326 
00327    /* check that the XImage has been previously initialized */
00328    assert(ximage->format);
00329    assert(ximage->bitmap_unit);
00330 
00331    if (!XSHM_ENABLED(xm_buf)) {
00332       /* update XImage's fields */
00333       ximage->width = TILE_SIZE;
00334       ximage->height = TILE_SIZE;
00335       ximage->bytes_per_line = TILE_SIZE * 4;
00336    }
00337 
00338    for (y = 0; y < surf->height; y += TILE_SIZE) {
00339       for (x = 0; x < surf->width; x += TILE_SIZE) {
00340          uint tmpTile[TILE_SIZE * TILE_SIZE];
00341          int tx = x / TILE_SIZE;
00342          int ty = y / TILE_SIZE;
00343          int offset = ty * tilesPerRow + tx;
00344          int w = TILE_SIZE;
00345          int h = TILE_SIZE;
00346 
00347          if (y + h > surf->height)
00348             h = surf->height - y;
00349          if (x + w > surf->width)
00350             w = surf->width - x;
00351 
00352          /* offset in pixels */
00353          offset *= TILE_SIZE * TILE_SIZE;
00354 
00355          if (XSHM_ENABLED(xm_buf)) {
00356             ximage->data = (char *) xm_buf->data + 4 * offset;
00357             /* make copy of tile data */
00358             memcpy(tmpTile, (uint *) ximage->data, sizeof(tmpTile));
00359             /* twiddle from temp to ximage in shared memory */
00360             twiddle_tile(tmpTile, (uint *) ximage->data);
00361             /* display image in shared memory */
00362 #if defined(USE_XSHM) && !defined(XFree86Server)
00363             XShmPutImage(b->xm_visual->display, b->drawable, b->gc,
00364                          ximage, 0, 0, x, y, w, h, False);
00365 #endif
00366          }
00367          else {
00368             /* twiddel from ximage buffer to temp tile */
00369             twiddle_tile((uint *) xm_buf->data + offset, tmpTile);
00370             /* display temp tile data */
00371             ximage->data = (char *) tmpTile;
00372             XPutImage(b->xm_visual->display, b->drawable, b->gc,
00373                       ximage, 0, 0, x, y, w, h);
00374          }
00375       }

static struct pipe_winsys* xmesa_get_pipe_winsys ( struct xmesa_visual xm_vis  )  [static, read]

Definition at line 644 of file xm_winsys.c.

References xmesa_pipe_winsys::base, pipe_winsys::buffer_create, pipe_winsys::buffer_destroy, pipe_winsys::buffer_map, pipe_winsys::buffer_unmap, CALLOC_STRUCT, xmesa_visual::display, pipe_winsys::fence_finish, pipe_winsys::fence_reference, pipe_winsys::fence_signalled, pipe_winsys::flush_frontbuffer, pipe_winsys::get_name, xmesa_pipe_winsys::shm, pipe_winsys::surface_alloc, pipe_winsys::surface_alloc_storage, pipe_winsys::surface_release, pipe_winsys::user_buffer_create, xm_buffer_create(), xm_buffer_destroy(), xm_buffer_map(), xm_buffer_unmap(), xm_fence_finish(), xm_fence_reference(), xm_fence_signalled(), xm_flush_frontbuffer(), xm_get_name(), xm_surface_alloc(), xm_surface_alloc_storage(), xm_surface_release(), xm_user_buffer_create(), xmesa_pipe_winsys::xm_visual, and xmesa_check_for_xshm().

00647 {
00648    static struct xmesa_pipe_winsys *ws = NULL;
00649 
00650    if (!ws) {
00651       ws = CALLOC_STRUCT(xmesa_pipe_winsys);
00652 
00653       ws->xm_visual = xm_vis;
00654       ws->shm = xmesa_check_for_xshm(xm_vis->display);
00655 
00656       /* Fill in this struct with callbacks that pipe will need to
00657        * communicate with the window system, buffer manager, etc. 
00658        */
00659       ws->base.buffer_create = xm_buffer_create;
00660       ws->base.user_buffer_create = xm_user_buffer_create;
00661       ws->base.buffer_map = xm_buffer_map;
00662       ws->base.buffer_unmap = xm_buffer_unmap;
00663       ws->base.buffer_destroy = xm_buffer_destroy;
00664 
00665       ws->base.surface_alloc = xm_surface_alloc;
00666       ws->base.surface_alloc_storage = xm_surface_alloc_storage;
00667       ws->base.surface_release = xm_surface_release;
00668 
00669       ws->base.fence_reference = xm_fence_reference;
00670       ws->base.fence_signalled = xm_fence_signalled;
00671       ws->base.fence_finish = xm_fence_finish;
00672 
00673       ws->base.flush_frontbuffer = xm_flush_frontbuffer;
00674       ws->base.get_name = xm_get_name;
00675    }
00676 

struct pipe_winsys* xmesa_get_pipe_winsys_aub ( struct xmesa_visual xm_vis  )  [read]

Return pointer to a pipe_winsys object.

For Xlib, this is a singleton object. Nothing special for the Xlib driver so no subclassing or anything.

Definition at line 632 of file xm_winsys.c.

00635 {
00636    static struct xmesa_pipe_winsys *ws = NULL;
00637 
00638    if (!ws) {
00639       ws = (struct xmesa_pipe_winsys *) xmesa_create_pipe_winsys_aub();
00640    }


Generated on Tue Sep 29 06:25:50 2009 for Gallium3D by  doxygen 1.5.4