1 #include "pipe/p_compiler.h"
2 #include "util/u_debug.h"
3 #include "util/u_memory.h"
4 #include "target-helpers/wrap_screen.h"
5 #include "state_tracker/xlib_sw_winsys.h"
7 #ifdef GALLIUM_SOFTPIPE
8 #include "softpipe/sp_public.h"
11 #ifdef GALLIUM_LLVMPIPE
12 #include "llvmpipe/lp_public.h"
15 /* Haven't figured out a decent way to build the helper code yet -
16 * #include it here temporarily.
18 #include "sw/sw_public.h"
24 #include <X11/Xlibint.h>
25 #include <X11/Xutil.h>
36 const char *default_driver
;
38 struct pipe_screen
*screen
= NULL
;
39 struct sw_winsys
*winsys
= NULL
;
41 graw
.display
= XOpenDisplay(NULL
);
42 if (graw
.display
== NULL
)
45 /* Create the underlying winsys, which performs presents to Xlib
48 winsys
= xlib_create_sw_winsys( graw
.display
);
52 #if defined(GALLIUM_LLVMPIPE)
53 default_driver
= "llvmpipe";
54 #elif defined(GALLIUM_SOFTPIPE)
55 default_driver
= "softpipe";
60 driver
= debug_get_option("GALLIUM_DRIVER", default_driver
);
62 #if defined(GALLIUM_LLVMPIPE)
63 if (screen
== NULL
&& strcmp(driver
, "llvmpipe") == 0)
64 screen
= llvmpipe_create_screen( winsys
);
67 #if defined(GALLIUM_SOFTPIPE)
69 screen
= softpipe_create_screen( winsys
);
72 /* Inject any wrapping layers we want to here:
74 return gallium_wrap_screen( screen
);
82 graw_create_window( int x
,
86 enum pipe_format format
)
88 struct xlib_drawable
*handle
= NULL
;
89 XSetWindowAttributes attr
;
92 XVisualInfo templat
, *visinfo
= NULL
;
98 scrnum
= DefaultScreen( graw
.display
);
99 root
= RootWindow( graw
.display
, scrnum
);
102 if (format
!= PIPE_FORMAT_R8G8B8A8_UNORM
)
105 if (graw
.display
== NULL
)
108 handle
= CALLOC_STRUCT(xlib_drawable
);
113 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
114 templat
.screen
= DefaultScreen(graw
.display
);
116 templat
.class = TrueColor
;
118 visinfo
= XGetVisualInfo(graw
.display
, mask
, &templat
, &n
);
120 printf("Error: couldn't get an RGB, Double-buffered visual\n");
124 /* window attributes */
125 attr
.background_pixel
= 0;
126 attr
.border_pixel
= 0;
127 attr
.colormap
= XCreateColormap( graw
.display
, root
, visinfo
->visual
, AllocNone
);
128 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
129 /* XXX this is a bad way to get a borderless window! */
130 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
132 win
= XCreateWindow( graw
.display
, root
, x
, y
, width
, height
,
133 0, visinfo
->depth
, InputOutput
,
134 visinfo
->visual
, mask
, &attr
);
137 /* set hints and properties */
140 XSizeHints sizehints
;
143 sizehints
.width
= width
;
144 sizehints
.height
= height
;
145 sizehints
.flags
= USSize
| USPosition
;
146 XSetNormalHints(graw
.display
, win
, &sizehints
);
147 XSetStandardProperties(graw
.display
, win
, name
, name
,
148 None
, (char **)NULL
, 0, &sizehints
);
152 XMapWindow(graw
.display
, win
);
155 XNextEvent( graw
.display
, &e
);
156 if (e
.type
== MapNotify
&& e
.xmap
.window
== win
) {
161 handle
->visual
= visinfo
->visual
;
162 handle
->drawable
= (Drawable
)win
;
163 handle
->depth
= visinfo
->depth
;
164 return (void *)handle
;
171 XDestroyWindow(graw
.display
, win
);
178 graw_destroy_window( void *xlib_drawable
)