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/inline_sw_helper.h"
7 #include "target-helpers/inline_debug_helper.h"
8 #include "state_tracker/xlib_sw_winsys.h"
9 #include "state_tracker/graw.h"
12 #include <X11/Xlibint.h>
13 #include <X11/Xutil.h>
22 static struct pipe_screen
*
23 graw_create_screen( void )
25 struct pipe_screen
*screen
= NULL
;
26 struct sw_winsys
*winsys
= NULL
;
28 /* Create the underlying winsys, which performs presents to Xlib
31 winsys
= xlib_create_sw_winsys( graw
.display
);
35 screen
= sw_screen_create( winsys
);
37 /* Inject any wrapping layers we want to here:
39 return debug_screen_wrap( screen
);
44 graw_create_window_and_screen( int x
,
48 enum pipe_format format
,
51 struct pipe_screen
*screen
= NULL
;
52 struct xlib_drawable
*xlib_handle
= NULL
;
53 XSetWindowAttributes attr
;
56 XVisualInfo templat
, *visinfo
= NULL
;
61 graw
.display
= XOpenDisplay(NULL
);
62 if (graw
.display
== NULL
)
65 scrnum
= DefaultScreen( graw
.display
);
66 root
= RootWindow( graw
.display
, scrnum
);
69 if (graw
.display
== NULL
)
72 xlib_handle
= CALLOC_STRUCT(xlib_drawable
);
73 if (xlib_handle
== NULL
)
77 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
78 templat
.screen
= DefaultScreen(graw
.display
);
80 templat
.class = TrueColor
;
82 visinfo
= XGetVisualInfo(graw
.display
, mask
, &templat
, &n
);
84 printf("Error: couldn't get an RGB, Double-buffered visual\n");
88 /* See if the requirested pixel format matches the visual */
89 if (visinfo
->red_mask
== 0xff0000 &&
90 visinfo
->green_mask
== 0xff00 &&
91 visinfo
->blue_mask
== 0xff) {
92 if (format
!= PIPE_FORMAT_B8G8R8A8_UNORM
)
95 else if (visinfo
->red_mask
== 0xff &&
96 visinfo
->green_mask
== 0xff00 &&
97 visinfo
->blue_mask
== 0xff0000) {
98 if (format
!= PIPE_FORMAT_R8G8B8A8_UNORM
)
105 /* window attributes */
106 attr
.background_pixel
= 0;
107 attr
.border_pixel
= 0;
108 attr
.colormap
= XCreateColormap( graw
.display
, root
, visinfo
->visual
, AllocNone
);
109 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
110 /* XXX this is a bad way to get a borderless window! */
111 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
113 win
= XCreateWindow( graw
.display
, root
, x
, y
, width
, height
,
114 0, visinfo
->depth
, InputOutput
,
115 visinfo
->visual
, mask
, &attr
);
118 /* set hints and properties */
121 XSizeHints sizehints
;
124 sizehints
.width
= width
;
125 sizehints
.height
= height
;
126 sizehints
.flags
= USSize
| USPosition
;
127 XSetNormalHints(graw
.display
, win
, &sizehints
);
128 XSetStandardProperties(graw
.display
, win
, name
, name
,
129 None
, (char **)NULL
, 0, &sizehints
);
132 XMapWindow(graw
.display
, win
);
135 XNextEvent( graw
.display
, &e
);
136 if (e
.type
== MapNotify
&& e
.xmap
.window
== win
) {
141 xlib_handle
->visual
= visinfo
->visual
;
142 xlib_handle
->drawable
= (Drawable
)win
;
143 xlib_handle
->depth
= visinfo
->depth
;
144 *handle
= (void *)xlib_handle
;
146 screen
= graw_create_screen();
155 screen
->destroy(screen
);
164 XDestroyWindow(graw
.display
, win
);
171 graw_set_display_func( void (*draw
)( void ) )
177 graw_main_loop( void )
180 for (i
= 0; i
< 10; i
++) {