1 #include "pipe/p_compiler.h"
2 #include "pipe/p_context.h"
3 #include "util/u_debug.h"
4 #include "util/u_memory.h"
5 #include "target-helpers/wrap_screen.h"
6 #include "state_tracker/xlib_sw_winsys.h"
8 #ifdef GALLIUM_SOFTPIPE
9 #include "softpipe/sp_public.h"
12 #ifdef GALLIUM_LLVMPIPE
13 #include "llvmpipe/lp_public.h"
16 /* Haven't figured out a decent way to build the helper code yet -
17 * #include it here temporarily.
19 #include "sw/sw_public.h"
22 #include "state_tracker/graw.h"
25 #include <X11/Xlibint.h>
26 #include <X11/Xutil.h>
35 static struct pipe_screen
*
36 graw_create_screen( void )
38 const char *default_driver
;
40 struct pipe_screen
*screen
= NULL
;
41 struct sw_winsys
*winsys
= NULL
;
43 /* Create the underlying winsys, which performs presents to Xlib
46 winsys
= xlib_create_sw_winsys( graw
.display
);
50 #if defined(GALLIUM_LLVMPIPE)
51 default_driver
= "llvmpipe";
52 #elif defined(GALLIUM_SOFTPIPE)
53 default_driver
= "softpipe";
58 driver
= debug_get_option("GALLIUM_DRIVER", default_driver
);
60 #if defined(GALLIUM_LLVMPIPE)
61 if (screen
== NULL
&& strcmp(driver
, "llvmpipe") == 0)
62 screen
= llvmpipe_create_screen( winsys
);
65 #if defined(GALLIUM_SOFTPIPE)
67 screen
= softpipe_create_screen( winsys
);
70 /* Inject any wrapping layers we want to here:
72 return gallium_wrap_screen( screen
);
80 graw_create_window_and_screen( int x
,
84 enum pipe_format format
,
87 struct pipe_screen
*screen
= NULL
;
88 struct xlib_drawable
*xlib_handle
= NULL
;
89 XSetWindowAttributes attr
;
92 XVisualInfo templat
, *visinfo
= NULL
;
97 graw
.display
= XOpenDisplay(NULL
);
98 if (graw
.display
== NULL
)
101 scrnum
= DefaultScreen( graw
.display
);
102 root
= RootWindow( graw
.display
, scrnum
);
105 if (format
!= PIPE_FORMAT_R8G8B8A8_UNORM
)
108 if (graw
.display
== NULL
)
111 xlib_handle
= CALLOC_STRUCT(xlib_drawable
);
112 if (xlib_handle
== NULL
)
116 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
117 templat
.screen
= DefaultScreen(graw
.display
);
119 templat
.class = TrueColor
;
121 visinfo
= XGetVisualInfo(graw
.display
, mask
, &templat
, &n
);
123 printf("Error: couldn't get an RGB, Double-buffered visual\n");
127 /* window attributes */
128 attr
.background_pixel
= 0;
129 attr
.border_pixel
= 0;
130 attr
.colormap
= XCreateColormap( graw
.display
, root
, visinfo
->visual
, AllocNone
);
131 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
132 /* XXX this is a bad way to get a borderless window! */
133 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
135 win
= XCreateWindow( graw
.display
, root
, x
, y
, width
, height
,
136 0, visinfo
->depth
, InputOutput
,
137 visinfo
->visual
, mask
, &attr
);
140 /* set hints and properties */
143 XSizeHints sizehints
;
146 sizehints
.width
= width
;
147 sizehints
.height
= height
;
148 sizehints
.flags
= USSize
| USPosition
;
149 XSetNormalHints(graw
.display
, win
, &sizehints
);
150 XSetStandardProperties(graw
.display
, win
, name
, name
,
151 None
, (char **)NULL
, 0, &sizehints
);
154 XMapWindow(graw
.display
, win
);
157 XNextEvent( graw
.display
, &e
);
158 if (e
.type
== MapNotify
&& e
.xmap
.window
== win
) {
163 xlib_handle
->visual
= visinfo
->visual
;
164 xlib_handle
->drawable
= (Drawable
)win
;
165 xlib_handle
->depth
= visinfo
->depth
;
166 *handle
= (void *)xlib_handle
;
168 screen
= graw_create_screen();
177 screen
->destroy(screen
);
186 XDestroyWindow(graw
.display
, win
);
193 graw_set_display_func( void (*draw
)( void ) )
199 graw_main_loop( void )
202 for (i
= 0; i
< 10; i
++) {