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 "frontend/xlibsw_api.h"
9 #include "frontend/graw.h"
10 #include "sw/xlib/xlib_sw_winsys.h"
13 #include <X11/Xlibint.h>
14 #include <X11/Xutil.h>
23 static struct pipe_screen
*
24 graw_create_screen( void )
26 struct pipe_screen
*screen
= NULL
;
27 struct sw_winsys
*winsys
= NULL
;
29 /* Create the underlying winsys, which performs presents to Xlib
32 winsys
= xlib_create_sw_winsys( graw
.display
);
36 screen
= sw_screen_create( winsys
);
38 /* Inject any wrapping layers we want to here:
40 return debug_screen_wrap( screen
);
45 graw_create_window_and_screen( int x
,
49 enum pipe_format format
,
52 struct pipe_screen
*screen
= NULL
;
53 struct xlib_drawable
*xlib_handle
= NULL
;
54 XSetWindowAttributes attr
;
57 XVisualInfo templat
, *visinfo
= NULL
;
62 graw
.display
= XOpenDisplay(NULL
);
63 if (graw
.display
== NULL
)
66 scrnum
= DefaultScreen( graw
.display
);
67 root
= RootWindow( graw
.display
, scrnum
);
70 if (graw
.display
== NULL
)
73 xlib_handle
= CALLOC_STRUCT(xlib_drawable
);
74 if (xlib_handle
== NULL
)
78 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
79 templat
.screen
= DefaultScreen(graw
.display
);
81 templat
.class = TrueColor
;
83 visinfo
= XGetVisualInfo(graw
.display
, mask
, &templat
, &n
);
85 printf("Error: couldn't get an RGB, Double-buffered visual\n");
89 /* See if the requirested pixel format matches the visual */
90 if (visinfo
->red_mask
== 0xff0000 &&
91 visinfo
->green_mask
== 0xff00 &&
92 visinfo
->blue_mask
== 0xff) {
93 if (format
!= PIPE_FORMAT_BGRA8888_UNORM
)
96 else if (visinfo
->red_mask
== 0xff &&
97 visinfo
->green_mask
== 0xff00 &&
98 visinfo
->blue_mask
== 0xff0000) {
99 if (format
!= PIPE_FORMAT_RGBA8888_UNORM
)
106 /* window attributes */
107 attr
.background_pixel
= 0;
108 attr
.border_pixel
= 0;
109 attr
.colormap
= XCreateColormap( graw
.display
, root
, visinfo
->visual
, AllocNone
);
110 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
111 /* XXX this is a bad way to get a borderless window! */
112 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
114 win
= XCreateWindow( graw
.display
, root
, x
, y
, width
, height
,
115 0, visinfo
->depth
, InputOutput
,
116 visinfo
->visual
, mask
, &attr
);
119 /* set hints and properties */
122 XSizeHints sizehints
;
125 sizehints
.width
= width
;
126 sizehints
.height
= height
;
127 sizehints
.flags
= USSize
| USPosition
;
128 XSetNormalHints(graw
.display
, win
, &sizehints
);
129 XSetStandardProperties(graw
.display
, win
, name
, name
,
130 None
, (char **)NULL
, 0, &sizehints
);
133 XMapWindow(graw
.display
, win
);
136 XNextEvent( graw
.display
, &e
);
137 if (e
.type
== MapNotify
&& e
.xmap
.window
== win
) {
142 xlib_handle
->visual
= visinfo
->visual
;
143 xlib_handle
->drawable
= (Drawable
)win
;
144 xlib_handle
->depth
= visinfo
->depth
;
145 *handle
= (void *)xlib_handle
;
147 screen
= graw_create_screen();
156 screen
->destroy(screen
);
163 XDestroyWindow(graw
.display
, win
);
170 graw_set_display_func( void (*draw
)( void ) )
176 graw_main_loop( void )
179 for (i
= 0; i
< 10; i
++) {