diff options
author | Keith Whitwell <[email protected]> | 2010-05-14 12:12:54 +0100 |
---|---|---|
committer | Keith Whitwell <[email protected]> | 2010-05-14 12:19:57 +0100 |
commit | 15321a55e541c3209be6636ea467695a0bc6d55d (patch) | |
tree | 5fc82a59cd84668daa09861549e73145dfcdb54b /src/gallium/targets/graw-xlib/graw_xlib.c | |
parent | c26751447011a713924b9163a1e0b44fd39c6b1c (diff) |
graw: combine graw_init and graw_create_window functions
Different environments seem to want to create these in different
orders. Abstract over this by combining the calls.
Diffstat (limited to 'src/gallium/targets/graw-xlib/graw_xlib.c')
-rw-r--r-- | src/gallium/targets/graw-xlib/graw_xlib.c | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/src/gallium/targets/graw-xlib/graw_xlib.c b/src/gallium/targets/graw-xlib/graw_xlib.c index c9a850136a8..41120ba3c70 100644 --- a/src/gallium/targets/graw-xlib/graw_xlib.c +++ b/src/gallium/targets/graw-xlib/graw_xlib.c @@ -32,18 +32,14 @@ static struct { } graw; -struct pipe_screen * -graw_init( void ) +static struct pipe_screen * +graw_create_screen( void ) { const char *default_driver; const char *driver; struct pipe_screen *screen = NULL; struct sw_winsys *winsys = NULL; - graw.display = XOpenDisplay(NULL); - if (graw.display == NULL) - return NULL; - /* Create the underlying winsys, which performs presents to Xlib * drawables: */ @@ -80,14 +76,16 @@ graw_init( void ) -void * -graw_create_window( int x, - int y, - unsigned width, - unsigned height, - enum pipe_format format ) +struct pipe_screen * +graw_create_window_and_screen( int x, + int y, + unsigned width, + unsigned height, + enum pipe_format format, + void **handle) { - struct xlib_drawable *handle = NULL; + struct pipe_screen *screen = NULL; + struct xlib_drawable *xlib_handle = NULL; XSetWindowAttributes attr; Window root; Window win = 0; @@ -96,6 +94,9 @@ graw_create_window( int x, int n; int scrnum; + graw.display = XOpenDisplay(NULL); + if (graw.display == NULL) + return NULL; scrnum = DefaultScreen( graw.display ); root = RootWindow( graw.display, scrnum ); @@ -107,8 +108,8 @@ graw_create_window( int x, if (graw.display == NULL) goto fail; - handle = CALLOC_STRUCT(xlib_drawable); - if (handle == NULL) + xlib_handle = CALLOC_STRUCT(xlib_drawable); + if (xlib_handle == NULL) goto fail; @@ -150,7 +151,6 @@ graw_create_window( int x, None, (char **)NULL, 0, &sizehints); } - XFree(visinfo); XMapWindow(graw.display, win); while (1) { XEvent e; @@ -160,14 +160,27 @@ graw_create_window( int x, } } - handle->visual = visinfo->visual; - handle->drawable = (Drawable)win; - handle->depth = visinfo->depth; - return (void *)handle; + xlib_handle->visual = visinfo->visual; + xlib_handle->drawable = (Drawable)win; + xlib_handle->depth = visinfo->depth; + *handle = (void *)xlib_handle; + + screen = graw_create_screen(); + if (screen == NULL) + goto fail; -fail: - FREE(handle); XFree(visinfo); + return screen; + +fail: + if (screen) + screen->destroy(screen); + + if (xlib_handle) + FREE(xlib_handle); + + if (visinfo) + XFree(visinfo); if (win) XDestroyWindow(graw.display, win); @@ -176,11 +189,6 @@ fail: } -void -graw_destroy_window( void *xlib_drawable ) -{ -} - void graw_set_display_func( void (*draw)( void ) ) { |