From: Keith Whitwell Date: Tue, 13 Jan 2009 18:08:24 +0000 (+0000) Subject: xlib: allow winsys's to register themselves with glx/xlib state tracker X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2f19fecd583a4406385708de6362b3bdef23811e;p=mesa.git xlib: allow winsys's to register themselves with glx/xlib state tracker --- diff --git a/src/gallium/state_trackers/glx/dri/dri_drawable.c b/src/gallium/state_trackers/glx/dri/dri_drawable.c index d5006cc0164..b712acda88e 100644 --- a/src/gallium/state_trackers/glx/dri/dri_drawable.c +++ b/src/gallium/state_trackers/glx/dri/dri_drawable.c @@ -142,8 +142,7 @@ dri_display_surface(__DRIdrawablePrivate *dPriv, drawable->last_swap_fence = drawable->first_swap_fence; drawable->first_swap_fence = NULL; - /* The lock_hardware is required for the cliprects. Buffer offsets - * should work regardless. + /* Call lock_hardware to update dPriv cliprects. */ dri_lock_hardware(context, drawable); { diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index 82d125b5f31..48116415590 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -71,6 +71,18 @@ #include "xm_winsys.h" #include + +/* Driver interface routines, set up by xlib backend on library + * _init(). These are global in the same way that function names are + * global. + */ +static struct xm_driver driver; + +void xmesa_set_driver( const struct xm_driver *templ ) +{ + driver = *templ; +} + /** * Global X driver lock */ @@ -756,17 +768,17 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) /* XXX: create once per Xlib Display. */ - winsys = xmesa_create_pipe_winsys(); + winsys = driver.create_pipe_winsys(); if (winsys == NULL) goto fail; /* XXX: create once per Xlib Display. */ - screen = xmesa_create_pipe_screen( winsys ); + screen = driver.create_pipe_screen( winsys ); if (screen == NULL) goto fail; - pipe = xmesa_create_pipe_context( screen, + pipe = driver.create_pipe_context( screen, (void *)c ); if (pipe == NULL) goto fail; @@ -1118,8 +1130,7 @@ void XMesaSwapBuffers( XMesaBuffer b ) surf = st_get_framebuffer_surface(b->stfb, ST_SURFACE_BACK_LEFT); if (surf) { - xmesa_display_surface(b, surf); -// xmesa_display_surface(b, surf); + driver.display_surface(b, surf); } xmesa_check_and_update_buffer_size(NULL, b); diff --git a/src/gallium/state_trackers/glx/xlib/xm_winsys.h b/src/gallium/state_trackers/glx/xlib/xm_winsys.h index b22d65a5699..8b6d1644e8f 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_winsys.h +++ b/src/gallium/state_trackers/glx/xlib/xm_winsys.h @@ -36,22 +36,27 @@ struct pipe_surface; struct xmesa_buffer; -/* Will turn this into a callback-style interface. For now, these - * have fixed names, and are implemented in the winsys/xlib directory. - */ -struct pipe_winsys *xmesa_create_pipe_winsys( void ); - -struct pipe_screen *xmesa_create_pipe_screen( struct pipe_winsys * ); - -/* The context_private argument needs to go away. Is currently used - * in a round-about way to associate a display-target surface with its - * Xlib window. - */ -struct pipe_context *xmesa_create_pipe_context( struct pipe_screen *, +struct xm_driver { + + struct pipe_winsys *(*create_pipe_winsys)( void ); + + struct pipe_screen *(*create_pipe_screen)( struct pipe_winsys * ); + + /* The context_private argument needs to go away. Is currently used + * in a round-about way to associate a display-target surface with its + * Xlib window. + */ + struct pipe_context *(*create_pipe_context)( struct pipe_screen *, void *context_private ); -void xmesa_display_surface( struct xmesa_buffer *, + void (*display_surface)( struct xmesa_buffer *, struct pipe_surface * ); +}; + + +extern void +xmesa_set_driver( const struct xm_driver *driver ); + #endif diff --git a/src/gallium/winsys/xlib/xlib.c b/src/gallium/winsys/xlib/xlib.c index 8d4d734b036..e5f8048b6a8 100644 --- a/src/gallium/winsys/xlib/xlib.c +++ b/src/gallium/winsys/xlib/xlib.c @@ -31,9 +31,7 @@ * Keith Whitwell */ -#include "xlib_trace.h" -#include "xlib_softpipe.h" -#include "xlib_brw.h" +#include "xlib.h" #include "xm_winsys.h" #include @@ -50,7 +48,6 @@ enum mode { MODE_SOFTPIPE }; -static enum mode xlib_mode; static enum mode get_mode() { @@ -68,80 +65,24 @@ static enum mode get_mode() return MODE_SOFTPIPE; } +static void _init( void ) __attribute__((constructor)); -struct pipe_winsys * -xmesa_create_pipe_winsys( void ) +static void _init( void ) { - xlib_mode = get_mode(); + enum mode xlib_mode = get_mode(); switch (xlib_mode) { case MODE_TRACE: - return xlib_create_trace_winsys(); - case MODE_BRW: - return xlib_create_brw_winsys(); - case MODE_CELL: - return xlib_create_cell_winsys(); - case MODE_SOFTPIPE: - return xlib_create_softpipe_winsys(); - default: - assert(0); - return NULL; - } -} - -struct pipe_screen * -xmesa_create_pipe_screen( struct pipe_winsys *winsys ) -{ - switch (xlib_mode) { - case MODE_TRACE: - return xlib_create_trace_screen( winsys ); - case MODE_BRW: - return xlib_create_brw_screen( winsys ); - case MODE_CELL: - return xlib_create_cell_screen( winsys ); - case MODE_SOFTPIPE: - return xlib_create_softpipe_screen( winsys ); - default: - assert(0); - return NULL; - } -} - -struct pipe_context * -xmesa_create_pipe_context( struct pipe_screen *screen, - void *priv ) -{ - switch (xlib_mode) { - case MODE_TRACE: - return xlib_create_trace_context( screen, priv ); - case MODE_BRW: - return xlib_create_brw_context( screen, priv ); - case MODE_CELL: - return xlib_create_cell_context( screen, priv ); - case MODE_SOFTPIPE: - return xlib_create_softpipe_context( screen, priv ); - default: - assert(0); - return NULL; - } -} - -void -xmesa_display_surface( struct xmesa_buffer *buffer, - struct pipe_surface *surf ) -{ - switch (xlib_mode) { - case MODE_TRACE: - xlib_trace_display_surface( buffer, surf ); + xmesa_set_driver( &xlib_trace_driver ); break; case MODE_BRW: - xlib_brw_display_surface( buffer, surf ); + xmesa_set_driver( &xlib_brw_driver ); break; case MODE_CELL: - xlib_cell_display_surface( buffer, surf ); + xmesa_set_driver( &xlib_cell_driver ); break; case MODE_SOFTPIPE: - xlib_softpipe_display_surface( buffer, surf ); + xmesa_set_driver( &xlib_softpipe_driver ); break; default: assert(0); @@ -149,8 +90,6 @@ xmesa_display_surface( struct xmesa_buffer *buffer, } } - - /*********************************************************************** * * Butt-ugly hack to convince the linker not to throw away public GL diff --git a/src/gallium/winsys/xlib/xlib.h b/src/gallium/winsys/xlib/xlib.h new file mode 100644 index 00000000000..9e47f23be50 --- /dev/null +++ b/src/gallium/winsys/xlib/xlib.h @@ -0,0 +1,13 @@ + +#ifndef XLIB_H +#define XLIB_H + +#include "xm_winsys.h" + +extern struct xm_driver xlib_trace_driver; +extern struct xm_driver xlib_softpipe_driver; +extern struct xm_driver xlib_cell_driver; +extern struct xm_driver xlib_brw_driver; + + +#endif diff --git a/src/gallium/winsys/xlib/xlib_brw.h b/src/gallium/winsys/xlib/xlib_brw.h index aad3f229bf6..be2dd147dbe 100644 --- a/src/gallium/winsys/xlib/xlib_brw.h +++ b/src/gallium/winsys/xlib/xlib_brw.h @@ -6,20 +6,6 @@ struct pipe_buffer; struct pipe_surface; struct xmesa_buffer; -struct pipe_winsys *xlib_create_brw_winsys( void ); - -struct pipe_screen *xlib_create_brw_screen( struct pipe_winsys * ); - -struct pipe_context *xlib_create_brw_context( struct pipe_screen *, - void *priv ); - -void xlib_brw_display_surface(struct xmesa_buffer *b, - struct pipe_surface *surf); - -/*********************************************************************** - * Internal functions - */ - unsigned xlib_brw_get_buffer_offset( struct pipe_winsys *pws, struct pipe_buffer *buf, unsigned access_flags ); @@ -37,4 +23,8 @@ void xlib_brw_commands_aub(struct pipe_winsys *winsys, unsigned *cmds, unsigned nr_dwords); +struct pipe_context * +xlib_create_brw_context( struct pipe_screen *screen, + void *unused ); + #endif diff --git a/src/gallium/winsys/xlib/xlib_brw_screen.c b/src/gallium/winsys/xlib/xlib_brw_screen.c index 9325bdc7a68..1e4c2f6c411 100644 --- a/src/gallium/winsys/xlib/xlib_brw_screen.c +++ b/src/gallium/winsys/xlib/xlib_brw_screen.c @@ -45,6 +45,7 @@ #include "xlib_brw_aub.h" #include "xlib_brw.h" +#include "xlib.h" @@ -311,7 +312,7 @@ xlib_brw_destroy_pipe_winsys_aub( struct pipe_winsys *winsys ) -struct pipe_winsys * +static struct pipe_winsys * xlib_create_brw_winsys( void ) { struct aub_pipe_winsys *iws = CALLOC_STRUCT( aub_pipe_winsys ); @@ -349,14 +350,10 @@ xlib_create_brw_winsys( void ) } -struct pipe_screen * +static struct pipe_screen * xlib_create_brw_screen( struct pipe_winsys *winsys ) { -#ifdef GALLIUM_CELL - return NULL; -#else return brw_create_screen(winsys, 0/* XXX pci_id */); -#endif } @@ -464,7 +461,7 @@ void xlib_brw_buffer_subdata_typed( struct pipe_winsys *pws, } -void +static void xlib_brw_display_surface(struct xmesa_buffer *b, struct pipe_surface *surf) { @@ -472,3 +469,12 @@ xlib_brw_display_surface(struct xmesa_buffer *b, surf, aub_bo(surf->buffer)->offset ); } + + +struct xm_driver xlib_brw_driver = +{ + .create_pipe_winsys = xlib_create_brw_winsys, + .create_pipe_screen = xlib_create_brw_screen, + .create_pipe_context = xlib_create_brw_context, + .display_surface = xlib_brw_display_surface, +}; diff --git a/src/gallium/winsys/xlib/xlib_softpipe.c b/src/gallium/winsys/xlib/xlib_softpipe.c index 2a8bd4681e6..7ad73be2608 100644 --- a/src/gallium/winsys/xlib/xlib_softpipe.c +++ b/src/gallium/winsys/xlib/xlib_softpipe.c @@ -54,7 +54,7 @@ #define TILE_SIZE 32 /* avoid compilation errors */ #endif -#include "xlib_softpipe.h" +#include "xlib.h" /** * Subclass of pipe_buffer for Xlib winsys. @@ -303,7 +303,7 @@ twiddle_tile(const uint *tileIn, uint *tileOut) * Display a surface that's in a tiled configuration. That is, all the * pixels for a TILE_SIZExTILE_SIZE block are contiguous in memory. */ -void +static void xlib_cell_display_surface(struct xmesa_buffer *b, struct pipe_surface *surf) { XImage *ximage; @@ -374,7 +374,7 @@ xlib_cell_display_surface(struct xmesa_buffer *b, struct pipe_surface *surf) * Display/copy the image in the surface into the X window specified * by the XMesaBuffer. */ -void +static void xlib_softpipe_display_surface(struct xmesa_buffer *b, struct pipe_surface *surf) { @@ -620,7 +620,7 @@ xm_fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence, -struct pipe_winsys * +static struct pipe_winsys * xlib_create_softpipe_winsys( void ) { static struct xmesa_pipe_winsys *ws = NULL; @@ -655,7 +655,7 @@ xlib_create_softpipe_winsys( void ) } -struct pipe_screen * +static struct pipe_screen * xlib_create_softpipe_screen( struct pipe_winsys *pws ) { struct pipe_screen *screen; @@ -671,7 +671,7 @@ fail: } -struct pipe_context * +static struct pipe_context * xlib_create_softpipe_context( struct pipe_screen *screen, void *context_private ) { @@ -689,6 +689,14 @@ fail: return NULL; } +struct xm_driver xlib_softpipe_driver = +{ + .create_pipe_winsys = xlib_create_softpipe_winsys, + .create_pipe_screen = xlib_create_softpipe_screen, + .create_pipe_context = xlib_create_softpipe_context, + .display_surface = xlib_softpipe_display_surface +}; + /*********************************************************************** * Cell piggybacks on softpipe code still. @@ -698,28 +706,25 @@ fail: * and creating cell-specific versions of either those functions or * the entire file. */ -struct pipe_winsys * +#ifdef GALLIUM_CELL + +static struct pipe_winsys * xlib_create_cell_winsys( void ) { return xlib_create_softpipe_winsys(); } -struct pipe_screen * +static struct pipe_screen * xlib_create_cell_screen( struct pipe_winsys *pws ) { -#ifdef GALLIUM_CELL return cell_create_screen( pws ); -#else - return NULL; -#endif } -struct pipe_context * +static struct pipe_context * xlib_create_cell_context( struct pipe_screen *screen, void *priv ) { -#ifdef GALLIUM_CELL struct cell_winsys *cws; struct pipe_context *pipe; @@ -742,6 +747,26 @@ xlib_create_cell_context( struct pipe_screen *screen, return pipe; fail: -#endif return NULL; } +#endif + +#if defined(GALLIUM_CELL) +struct xm_driver xlib_cell_driver = +{ + .create_pipe_winsys = xlib_create_cell_winsys, + .create_pipe_screen = xlib_create_cell_screen, + .create_pipe_context = xlib_create_cell_context, + .display_surface = xlib_cell_display_surface, +}; +#else +struct xm_driver xlib_cell_driver = +{ + .create_pipe_winsys = xlib_create_softpipe_winsys, + .create_pipe_screen = xlib_create_softpipe_screen, + .create_pipe_context = xlib_create_softpipe_context, + .display_surface = xlib_softpipe_display_surface, +}; +#endif + + diff --git a/src/gallium/winsys/xlib/xlib_softpipe.h b/src/gallium/winsys/xlib/xlib_softpipe.h deleted file mode 100644 index 0de96cc4c6b..00000000000 --- a/src/gallium/winsys/xlib/xlib_softpipe.h +++ /dev/null @@ -1,50 +0,0 @@ - -#ifndef XLIB_SOFTPIPE_H -#define XLIB_SOFTPIPE_H - -struct pipe_winsys; -struct pipe_screen; -struct pipe_context; -struct pipe_surface; -struct xmesa_buffer; - - -struct pipe_winsys * -xlib_create_softpipe_winsys( void ); - -struct pipe_screen * -xlib_create_softpipe_screen( struct pipe_winsys *pws ); - -struct pipe_context * -xlib_create_softpipe_context( struct pipe_screen *screen, - void *context_priv ); - -void -xlib_softpipe_display_surface( struct xmesa_buffer *, - struct pipe_surface * ); - -/*********************************************************************** - * Cell piggybacks on softpipe code still. - * - * Should be untangled sufficiently to live in a separate file, at - * least. That would mean removing #ifdef GALLIUM_CELL's from above - * and creating cell-specific versions of either those functions or - * the entire file. - */ -struct pipe_winsys * -xlib_create_cell_winsys( void ); - -struct pipe_screen * -xlib_create_cell_screen( struct pipe_winsys *pws ); - - -struct pipe_context * -xlib_create_cell_context( struct pipe_screen *screen, - void *priv ); - -void -xlib_cell_display_surface( struct xmesa_buffer *, - struct pipe_surface * ); - - -#endif diff --git a/src/gallium/winsys/xlib/xlib_trace.c b/src/gallium/winsys/xlib/xlib_trace.c index 45afba7a474..1b8d3f8a115 100644 --- a/src/gallium/winsys/xlib/xlib_trace.c +++ b/src/gallium/winsys/xlib/xlib_trace.c @@ -33,25 +33,24 @@ */ -#include "xlib_softpipe.h" -#include "xlib_trace.h" +#include "xlib.h" #include "trace/tr_screen.h" #include "trace/tr_context.h" -struct pipe_winsys * +static struct pipe_winsys * xlib_create_trace_winsys( void ) { - return xlib_create_softpipe_winsys(); + return xlib_softpipe_driver.create_pipe_winsys(); } -struct pipe_screen * +static struct pipe_screen * xlib_create_trace_screen( struct pipe_winsys *winsys ) { struct pipe_screen *screen, *trace_screen; - screen = xlib_create_softpipe_screen( winsys ); + screen = xlib_softpipe_driver.create_pipe_screen( winsys ); if (screen == NULL) goto fail; @@ -68,13 +67,13 @@ fail: return NULL; } -struct pipe_context * +static struct pipe_context * xlib_create_trace_context( struct pipe_screen *screen, void *priv ) { struct pipe_context *pipe, *trace_pipe; - pipe = xlib_create_softpipe_context( screen, priv ); + pipe = xlib_softpipe_driver.create_pipe_context( screen, priv ); if (pipe == NULL) goto fail; @@ -92,11 +91,20 @@ fail: return NULL; } -void +static void xlib_trace_display_surface( struct xmesa_buffer *buffer, struct pipe_surface *surf ) { /* ?? */ - xlib_softpipe_display_surface( buffer, surf ); + xlib_softpipe_driver.display_surface( buffer, surf ); } + + +struct xm_driver xlib_trace_driver = +{ + .create_pipe_winsys = xlib_create_trace_winsys, + .create_pipe_screen = xlib_create_trace_screen, + .create_pipe_context = xlib_create_trace_context, + .display_surface = xlib_trace_display_surface, +}; diff --git a/src/gallium/winsys/xlib/xlib_trace.h b/src/gallium/winsys/xlib/xlib_trace.h deleted file mode 100644 index c79c0fe34de..00000000000 --- a/src/gallium/winsys/xlib/xlib_trace.h +++ /dev/null @@ -1,26 +0,0 @@ - -#ifndef XLIB_TRACE_H -#define XLIB_TRACE_H - -struct pipe_winsys; -struct pipe_screen; -struct pipe_context; -struct pipe_surface; -struct xmesa_buffer; - -struct pipe_winsys * -xlib_create_trace_winsys( void ); - -struct pipe_screen * -xlib_create_trace_screen( struct pipe_winsys *winsys ); - -struct pipe_context * -xlib_create_trace_context( struct pipe_screen *screen, - void *priv ); - -void -xlib_trace_display_surface( struct xmesa_buffer *buffer, - struct pipe_surface *surf ); - - -#endif