diff options
author | Keith Whitwell <keithw@vmware.com> | 2010-05-19 14:04:16 +0100 |
---|---|---|
committer | Keith Whitwell <keithw@vmware.com> | 2010-05-19 14:04:16 +0100 |
commit | 431a51b9af32980ae8a544d129bf567287887376 (patch) | |
tree | 91f1dad5509413524ea6330bba2de75d3c58ffe8 /src/gallium/targets/graw-xlib | |
parent | a536c204e289c46b0d493acfb4ebaf99f2b05189 (diff) | |
parent | c7ac03d3964400169ba0dd769e06796c9830aee1 (diff) |
Merge commit 'origin/graw-tests'
Diffstat (limited to 'src/gallium/targets/graw-xlib')
-rw-r--r-- | src/gallium/targets/graw-xlib/SConscript | 1 | ||||
-rw-r--r-- | src/gallium/targets/graw-xlib/graw_util.c | 36 | ||||
-rw-r--r-- | src/gallium/targets/graw-xlib/graw_xlib.c | 72 |
3 files changed, 86 insertions, 23 deletions
diff --git a/src/gallium/targets/graw-xlib/SConscript b/src/gallium/targets/graw-xlib/SConscript index ad84841922..40332fa4e1 100644 --- a/src/gallium/targets/graw-xlib/SConscript +++ b/src/gallium/targets/graw-xlib/SConscript @@ -25,6 +25,7 @@ env.Append(CPPPATH = [ sources = [ 'graw_xlib.c', + 'graw_util.c', ] if True: diff --git a/src/gallium/targets/graw-xlib/graw_util.c b/src/gallium/targets/graw-xlib/graw_util.c new file mode 100644 index 0000000000..147532cdee --- /dev/null +++ b/src/gallium/targets/graw-xlib/graw_util.c @@ -0,0 +1,36 @@ + +#include "pipe/p_compiler.h" +#include "pipe/p_context.h" +#include "tgsi/tgsi_text.h" +#include "util/u_memory.h" +#include "state_tracker/graw.h" + + +/* Helper functions. These are the same for all graw implementations. + */ +void *graw_parse_vertex_shader(struct pipe_context *pipe, + const char *text) +{ + struct tgsi_token tokens[1024]; + struct pipe_shader_state state; + + if (!tgsi_text_translate(text, tokens, Elements(tokens))) + return NULL; + + state.tokens = tokens; + return pipe->create_vs_state(pipe, &state); +} + +void *graw_parse_fragment_shader(struct pipe_context *pipe, + const char *text) +{ + struct tgsi_token tokens[1024]; + struct pipe_shader_state state; + + if (!tgsi_text_translate(text, tokens, Elements(tokens))) + return NULL; + + state.tokens = tokens; + return pipe->create_fs_state(pipe, &state); +} + 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); + } } |