2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #ifndef PIGLIT_HAS_X11
25 #error "Cannot build piglit_x11_framework.c without PIGLIT_HAS_X11"
28 #include <piglit/gl_wrap.h>
30 /* If building for a GLES API, <piglit/gl_wrap.h> may include the GLES
31 * headers, such as <GLES2/gl2.h>. Below, <waffle_glx.h> transitively includes
32 * <GL/gl.h>, which defines some of the same symbols found in <GLES2/gl2.h>.
33 * We define the include guards below in order to prevent <GL/gl.h> and
34 * related headers from being included and causing compilation failure due to
35 * symbol redefinitions.
45 #include <X11/Xutil.h>
46 #include <X11/keysym.h>
49 # include <waffle_glx.h>
53 # include <waffle_x11_egl.h>
56 #include "piglit-util-gl.h"
58 #include "piglit_gl_framework.h"
59 #include "piglit_x11_framework.h"
61 struct piglit_x11_framework
{
62 struct piglit_winsys_framework winsys_fw
;
68 struct piglit_x11_framework
*
69 piglit_x11_framework(struct piglit_gl_framework
*gl_fw
)
71 return (struct piglit_x11_framework
*) gl_fw
;
75 get_window_size(struct piglit_x11_framework
*x11_fw
)
77 unsigned width
, height
;
83 XGetGeometry(x11_fw
->display
, x11_fw
->window
,
84 &wjunk
, &ijunk
, &ijunk
,
85 &width
, &height
, &ujunk
, &ujunk
);
88 piglit_height
= height
;
92 process_next_event(struct piglit_x11_framework
*x11_fw
)
94 struct piglit_winsys_framework
*winsys_fw
= &x11_fw
->winsys_fw
;
95 const struct piglit_gl_test_config
*test_config
= winsys_fw
->wfl_fw
.gl_fw
.test_config
;
97 Display
*dpy
= x11_fw
->display
;
100 XNextEvent(dpy
, &event
);
102 switch (event
.type
) {
104 get_window_size(x11_fw
);
105 winsys_fw
->need_redisplay
= true;
107 case ConfigureNotify
:
108 get_window_size(x11_fw
);
109 if (winsys_fw
->user_reshape_func
)
110 winsys_fw
->user_reshape_func(event
.xconfigure
.width
,
111 event
.xconfigure
.height
);
112 winsys_fw
->need_redisplay
= true;
119 n
= XLookupString(&event
.xkey
,
121 sizeof(buffer
), &sym
, NULL
);
123 if (n
> 0 && winsys_fw
->user_keyboard_func
)
124 winsys_fw
->user_keyboard_func(buffer
[0],
127 winsys_fw
->need_redisplay
= true;
134 if (winsys_fw
->need_redisplay
) {
135 enum piglit_result result
= PIGLIT_PASS
;
136 if (test_config
->display
)
137 result
= test_config
->display();
138 if (piglit_automatic
)
139 piglit_report_result(result
);
140 winsys_fw
->need_redisplay
= false;
145 enter_event_loop(struct piglit_winsys_framework
*winsys_fw
)
147 struct piglit_x11_framework
*x11_fw
= (void*) winsys_fw
;
149 assert(x11_fw
->display
!= NULL
);
150 assert(x11_fw
->window
!= 0);
153 process_next_event(x11_fw
);
157 get_native(struct piglit_x11_framework
*x11_fw
)
159 struct piglit_wfl_framework
*wfl_fw
= &x11_fw
->winsys_fw
.wfl_fw
;
160 union waffle_native_window
*n_window
= waffle_window_get_native(wfl_fw
->window
);
162 switch (wfl_fw
->platform
) {
163 #ifdef PIGLIT_HAS_GLX
164 case WAFFLE_PLATFORM_GLX
:
165 x11_fw
->display
= n_window
->glx
->xlib_display
;
166 x11_fw
->window
= n_window
->glx
->xlib_window
;
169 #ifdef PIGLIT_HAS_EGL
170 case WAFFLE_PLATFORM_X11_EGL
:
171 x11_fw
->display
= n_window
->x11_egl
->display
.xlib_display
;
172 x11_fw
->window
= n_window
->x11_egl
->xlib_window
;
184 show_window(struct piglit_winsys_framework
*winsys_fw
)
186 struct piglit_x11_framework
*x11_fw
= piglit_x11_framework(&winsys_fw
->wfl_fw
.gl_fw
);
187 struct piglit_wfl_framework
*wfl_fw
= &winsys_fw
->wfl_fw
;
192 if (piglit_automatic
) {
193 /* Prevent the window from grabbing input. */
194 wm_hints
= XAllocWMHints();
195 wm_hints
->flags
|= InputHint
;
196 wm_hints
->input
= False
;
197 XSetWMHints(x11_fw
->display
, x11_fw
->window
, wm_hints
);
201 waffle_window_show(wfl_fw
->window
);
205 destroy(struct piglit_gl_framework
*gl_fw
)
207 struct piglit_x11_framework
*x11_fw
= piglit_x11_framework(gl_fw
);
212 piglit_winsys_framework_teardown(&x11_fw
->winsys_fw
);
216 struct piglit_gl_framework
*
217 piglit_x11_framework_create(const struct piglit_gl_test_config
*test_config
,
220 struct piglit_x11_framework
*x11_fw
= NULL
;
221 struct piglit_winsys_framework
*winsys_fw
= NULL
;
222 struct piglit_gl_framework
*gl_fw
= NULL
;
225 x11_fw
= calloc(1, sizeof(*x11_fw
));
226 winsys_fw
= &x11_fw
->winsys_fw
;
227 gl_fw
= &x11_fw
->winsys_fw
.wfl_fw
.gl_fw
;
229 ok
= piglit_winsys_framework_init(&x11_fw
->winsys_fw
,
230 test_config
, platform
);
234 winsys_fw
->show_window
= show_window
;
235 winsys_fw
->enter_event_loop
= enter_event_loop
;
236 gl_fw
->destroy
= destroy
;