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 "target-helpers/inline_sw_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 gallium_wrap_screen( 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 (format
!= PIPE_FORMAT_R8G8B8A8_UNORM
)
72 if (graw
.display
== NULL
)
75 xlib_handle
= CALLOC_STRUCT(xlib_drawable
);
76 if (xlib_handle
== NULL
)
80 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
81 templat
.screen
= DefaultScreen(graw
.display
);
83 templat
.class = TrueColor
;
85 visinfo
= XGetVisualInfo(graw
.display
, mask
, &templat
, &n
);
87 printf("Error: couldn't get an RGB, Double-buffered visual\n");
91 /* window attributes */
92 attr
.background_pixel
= 0;
93 attr
.border_pixel
= 0;
94 attr
.colormap
= XCreateColormap( graw
.display
, root
, visinfo
->visual
, AllocNone
);
95 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
96 /* XXX this is a bad way to get a borderless window! */
97 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
99 win
= XCreateWindow( graw
.display
, root
, x
, y
, width
, height
,
100 0, visinfo
->depth
, InputOutput
,
101 visinfo
->visual
, mask
, &attr
);
104 /* set hints and properties */
107 XSizeHints sizehints
;
110 sizehints
.width
= width
;
111 sizehints
.height
= height
;
112 sizehints
.flags
= USSize
| USPosition
;
113 XSetNormalHints(graw
.display
, win
, &sizehints
);
114 XSetStandardProperties(graw
.display
, win
, name
, name
,
115 None
, (char **)NULL
, 0, &sizehints
);
118 XMapWindow(graw
.display
, win
);
121 XNextEvent( graw
.display
, &e
);
122 if (e
.type
== MapNotify
&& e
.xmap
.window
== win
) {
127 xlib_handle
->visual
= visinfo
->visual
;
128 xlib_handle
->drawable
= (Drawable
)win
;
129 xlib_handle
->depth
= visinfo
->depth
;
130 *handle
= (void *)xlib_handle
;
132 screen
= graw_create_screen();
141 screen
->destroy(screen
);
150 XDestroyWindow(graw
.display
, win
);
157 graw_set_display_func( void (*draw
)( void ) )
163 graw_main_loop( void )
166 for (i
= 0; i
< 10; i
++) {