diff options
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/include/state_tracker/graw.h | 14 | ||||
-rw-r--r-- | src/gallium/targets/graw-xlib/graw_xlib.c | 62 | ||||
-rw-r--r-- | src/gallium/tests/graw/clear.c | 17 |
3 files changed, 51 insertions, 42 deletions
diff --git a/src/gallium/include/state_tracker/graw.h b/src/gallium/include/state_tracker/graw.h index 87e7d97543..e5b298e03d 100644 --- a/src/gallium/include/state_tracker/graw.h +++ b/src/gallium/include/state_tracker/graw.h @@ -19,20 +19,18 @@ struct pipe_screen; struct pipe_context; -PUBLIC struct pipe_screen *graw_init( void ); - /* Returns a handle to be used with flush_frontbuffer()/present(). * * Query format support with screen::is_format_supported and usage * XXX. */ -PUBLIC void *graw_create_window( int x, - int y, - unsigned width, - unsigned height, - enum pipe_format format ); +PUBLIC struct pipe_screen *graw_create_window_and_screen( int x, + int y, + unsigned width, + unsigned height, + enum pipe_format format, + void **handle); -PUBLIC void graw_destroy_window( void *handle ); PUBLIC void graw_set_display_func( void (*func)( void ) ); PUBLIC void graw_main_loop( void ); diff --git a/src/gallium/targets/graw-xlib/graw_xlib.c b/src/gallium/targets/graw-xlib/graw_xlib.c index c9a850136a..41120ba3c7 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 ) ) { diff --git a/src/gallium/tests/graw/clear.c b/src/gallium/tests/graw/clear.c index adcbb08308..28c986eee6 100644 --- a/src/gallium/tests/graw/clear.c +++ b/src/gallium/tests/graw/clear.c @@ -53,13 +53,20 @@ static void init( void ) struct pipe_resource *tex, templat; int i; + /* It's hard to say whether window or screen should be created + * first. Different environments would prefer one or the other. + * + * Also, no easy way of querying supported formats if the screen + * cannot be created first. + */ for (i = 0; window == NULL && formats[i] != PIPE_FORMAT_NONE; i++) { - window = graw_create_window(0,0,300,300, formats[i]); + screen = graw_create_window_and_screen(0,0,300,300, + formats[i], + &window); } - if (window == NULL) exit(2); @@ -98,15 +105,11 @@ static void init( void ) } + int main( int argc, char *argv[] ) { - screen = graw_init(); - if (screen == NULL) - exit(1); - init(); - graw_set_display_func( draw ); graw_main_loop(); return 0; |