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 );
} 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:
*/
-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;
int n;
int scrnum;
+ graw.display = XOpenDisplay(NULL);
+ if (graw.display == NULL)
+ return NULL;
scrnum = DefaultScreen( graw.display );
root = RootWindow( graw.display, scrnum );
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;
None, (char **)NULL, 0, &sizehints);
}
- XFree(visinfo);
XMapWindow(graw.display, win);
while (1) {
XEvent e;
}
}
- 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);
}
-void
-graw_destroy_window( void *xlib_drawable )
-{
-}
-
void
graw_set_display_func( void (*draw)( 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);
}
+
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;