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 d5006cc..b712acd 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 @@
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 82d125b..4811641 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 <GL/glx.h>
+
+/* 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 @@
/* 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 @@
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 b22d65a..8b6d164 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 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 xm_driver {
-struct pipe_screen *xmesa_create_pipe_screen( struct pipe_winsys * );
+ struct pipe_winsys *(*create_pipe_winsys)( void );
-/* 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 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 8d4d734..e5f8048 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 <stdlib.h>
@@ -50,7 +48,6 @@
MODE_SOFTPIPE
};
-static enum mode xlib_mode;
static enum mode get_mode()
{
@@ -68,80 +65,24 @@
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 @@
}
}
-
-
/***********************************************************************
*
* 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 0000000..9e47f23
--- /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 aad3f22..be2dd14 100644
--- a/src/gallium/winsys/xlib/xlib_brw.h
+++ b/src/gallium/winsys/xlib/xlib_brw.h
@@ -6,20 +6,6 @@
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 @@
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 9325bdc..1e4c2f6 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 @@
-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 @@
}
-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
+static void
xlib_brw_display_surface(struct xmesa_buffer *b,
struct pipe_surface *surf)
{
@@ -472,3 +469,12 @@
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 2a8bd46..7ad73be 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 @@
* 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 @@
* 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 @@
-struct pipe_winsys *
+static struct pipe_winsys *
xlib_create_softpipe_winsys( void )
{
static struct xmesa_pipe_winsys *ws = NULL;
@@ -655,7 +655,7 @@
}
-struct pipe_screen *
+static struct pipe_screen *
xlib_create_softpipe_screen( struct pipe_winsys *pws )
{
struct pipe_screen *screen;
@@ -671,7 +671,7 @@
}
-struct pipe_context *
+static struct pipe_context *
xlib_create_softpipe_context( struct pipe_screen *screen,
void *context_private )
{
@@ -689,6 +689,14 @@
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 @@
* 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 @@
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 0de96cc..0000000
--- 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 45afba7..1b8d3f8 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 @@
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 @@
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 c79c0fe..0000000
--- 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