summaryrefslogtreecommitdiff
path: root/src/gallium/targets/graw-xlib/graw_xlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/targets/graw-xlib/graw_xlib.c')
-rw-r--r--src/gallium/targets/graw-xlib/graw_xlib.c72
1 files changed, 49 insertions, 23 deletions
diff --git a/src/gallium/targets/graw-xlib/graw_xlib.c b/src/gallium/targets/graw-xlib/graw_xlib.c
index 21715c26fd..41120ba3c7 100644
--- a/src/gallium/targets/graw-xlib/graw_xlib.c
+++ b/src/gallium/targets/graw-xlib/graw_xlib.c
@@ -1,4 +1,5 @@
#include "pipe/p_compiler.h"
+#include "pipe/p_context.h"
#include "util/u_debug.h"
#include "util/u_memory.h"
#include "target-helpers/wrap_screen.h"
@@ -27,21 +28,18 @@
static struct {
Display *display;
+ void (*draw)(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:
*/
@@ -78,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;
@@ -94,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 );
@@ -105,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;
@@ -148,7 +151,6 @@ graw_create_window( int x,
None, (char **)NULL, 0, &sizehints);
}
- XFree(visinfo);
XMapWindow(graw.display, win);
while (1) {
XEvent e;
@@ -158,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);
@@ -174,8 +189,19 @@ fail:
}
+void
+graw_set_display_func( void (*draw)( void ) )
+{
+ graw.draw = draw;
+}
+
void
-graw_destroy_window( void *xlib_drawable )
+graw_main_loop( void )
{
+ int i;
+ for (i = 0; i < 10; i++) {
+ graw.draw();
+ sleep(1);
+ }
}