1 #include "pipe/p_compiler.h"
2 #include "pipe/p_context.h"
3 #include "pipe/p_screen.h"
4 #include "util/u_debug.h"
5 #include "util/u_memory.h"
6 #include "target-helpers/wrap_screen.h"
7 #include "state_tracker/xlib_sw_winsys.h"
9 #ifdef GALLIUM_SOFTPIPE
10 #include "softpipe/sp_public.h"
13 #ifdef GALLIUM_LLVMPIPE
14 #include "llvmpipe/lp_public.h"
17 /* Haven't figured out a decent way to build the helper code yet -
18 * #include it here temporarily.
20 #include "sw/sw_public.h"
23 #include "state_tracker/graw.h"
26 #include <X11/Xlibint.h>
27 #include <X11/Xutil.h>
36 static struct pipe_screen
*
37 graw_create_screen( void )
39 const char *default_driver
;
41 struct pipe_screen
*screen
= NULL
;
42 struct sw_winsys
*winsys
= NULL
;
44 /* Create the underlying winsys, which performs presents to Xlib
47 winsys
= xlib_create_sw_winsys( graw
.display
);
51 #if defined(GALLIUM_LLVMPIPE)
52 default_driver
= "llvmpipe";
53 #elif defined(GALLIUM_SOFTPIPE)
54 default_driver
= "softpipe";
59 driver
= debug_get_option("GALLIUM_DRIVER", default_driver
);
61 #if defined(GALLIUM_LLVMPIPE)
62 if (screen
== NULL
&& strcmp(driver
, "llvmpipe") == 0)
63 screen
= llvmpipe_create_screen( winsys
);
66 #if defined(GALLIUM_SOFTPIPE)
68 screen
= softpipe_create_screen( winsys
);
71 /* Inject any wrapping layers we want to here:
73 return gallium_wrap_screen( screen
);
81 graw_create_window_and_screen( int x
,
85 enum pipe_format format
,
88 struct pipe_screen
*screen
= NULL
;
89 struct xlib_drawable
*xlib_handle
= NULL
;
90 XSetWindowAttributes attr
;
93 XVisualInfo templat
, *visinfo
= NULL
;
98 graw
.display
= XOpenDisplay(NULL
);
99 if (graw
.display
== NULL
)
102 scrnum
= DefaultScreen( graw
.display
);
103 root
= RootWindow( graw
.display
, scrnum
);
106 if (format
!= PIPE_FORMAT_R8G8B8A8_UNORM
)
109 if (graw
.display
== NULL
)
112 xlib_handle
= CALLOC_STRUCT(xlib_drawable
);
113 if (xlib_handle
== NULL
)
117 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
118 templat
.screen
= DefaultScreen(graw
.display
);
120 templat
.class = TrueColor
;
122 visinfo
= XGetVisualInfo(graw
.display
, mask
, &templat
, &n
);
124 printf("Error: couldn't get an RGB, Double-buffered visual\n");
128 /* window attributes */
129 attr
.background_pixel
= 0;
130 attr
.border_pixel
= 0;
131 attr
.colormap
= XCreateColormap( graw
.display
, root
, visinfo
->visual
, AllocNone
);
132 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
133 /* XXX this is a bad way to get a borderless window! */
134 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
136 win
= XCreateWindow( graw
.display
, root
, x
, y
, width
, height
,
137 0, visinfo
->depth
, InputOutput
,
138 visinfo
->visual
, mask
, &attr
);
141 /* set hints and properties */
144 XSizeHints sizehints
;
147 sizehints
.width
= width
;
148 sizehints
.height
= height
;
149 sizehints
.flags
= USSize
| USPosition
;
150 XSetNormalHints(graw
.display
, win
, &sizehints
);
151 XSetStandardProperties(graw
.display
, win
, name
, name
,
152 None
, (char **)NULL
, 0, &sizehints
);
155 XMapWindow(graw
.display
, win
);
158 XNextEvent( graw
.display
, &e
);
159 if (e
.type
== MapNotify
&& e
.xmap
.window
== win
) {
164 xlib_handle
->visual
= visinfo
->visual
;
165 xlib_handle
->drawable
= (Drawable
)win
;
166 xlib_handle
->depth
= visinfo
->depth
;
167 *handle
= (void *)xlib_handle
;
169 screen
= graw_create_screen();
178 screen
->destroy(screen
);
187 XDestroyWindow(graw
.display
, win
);
194 graw_set_display_func( void (*draw
)( void ) )
200 graw_main_loop( void )
203 for (i
= 0; i
< 10; i
++) {