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
29 #include "piglit-util-gl.h"
30 #include "piglit-util-waffle.h"
32 #include "piglit_gbm_framework.h"
33 #include "piglit_gl_framework.h"
34 #include "piglit_wgl_framework.h"
35 #include "piglit_winsys_framework.h"
36 #include "piglit_wl_framework.h"
37 #include "piglit_x11_framework.h"
38 #include "piglit_sl_framework.h"
40 struct piglit_winsys_framework
*
41 piglit_winsys_framework(struct piglit_gl_framework
*gl_fw
)
43 return (struct piglit_winsys_framework
*) gl_fw
;
47 swap_buffers(struct piglit_gl_framework
*gl_fw
)
49 waffle_window_swap_buffers(piglit_wfl_framework(gl_fw
)->window
);
53 run_test(struct piglit_gl_framework
*gl_fw
,
54 int argc
, char *argv
[])
56 struct piglit_winsys_framework
*winsys_fw
= piglit_winsys_framework(gl_fw
);
57 bool no_window
= false;
58 const char *env_no_window
= getenv("PIGLIT_NO_WINDOW");
61 if (env_no_window
!= NULL
) {
62 if (strcmp(env_no_window
, "0") == 0) {
64 } else if (strcmp(env_no_window
, "1") == 0) {
67 fprintf(stderr
, "PIGLIT_NO_WINDOW has invalid"
68 " value: %s\n", env_no_window
);
73 if (gl_fw
->test_config
->init
)
74 gl_fw
->test_config
->init(argc
, argv
);
76 if (!gl_fw
->test_config
->requires_displayed_window
&&
77 piglit_automatic
&& no_window
) {
78 enum piglit_result result
= PIGLIT_PASS
;
79 if (gl_fw
->test_config
->display
)
80 result
= gl_fw
->test_config
->display();
82 piglit_report_result(result
);
85 /* In non-auto mode, the user wishes to see the window regardless
86 * of the value of piglit_gl_test_config::require_displayed_window.
88 winsys_fw
->show_window(winsys_fw
);
89 winsys_fw
->enter_event_loop(winsys_fw
);
94 set_keyboard_func(struct piglit_gl_framework
*gl_fw
,
95 void (*func
)(unsigned char key
, int x
, int y
))
97 piglit_winsys_framework(gl_fw
)->user_keyboard_func
= func
;
101 post_redisplay(struct piglit_gl_framework
*gl_fw
)
103 piglit_winsys_framework(gl_fw
)->need_redisplay
= true;
107 * Create a integer array of WAFFLE_x attribute/value pairs from
108 * the given test_config (which specifies color, depth, samples, etc.
109 * \param min_color minimum bits per channel for color components.
110 * \param min_z minimum bits for depth/Z buffer.
112 static const int32_t*
113 choose_config_attribs(const struct piglit_gl_test_config
*test_config
,
114 int min_color
, int min_z
)
116 static int32_t attrib_list
[64];
120 if (test_config
->window_visual
&
121 (PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_RGBA
)) {
122 attrib_list
[i
++] = WAFFLE_RED_SIZE
;
123 attrib_list
[i
++] = min_color
;
124 attrib_list
[i
++] = WAFFLE_GREEN_SIZE
;
125 attrib_list
[i
++] = min_color
;
126 attrib_list
[i
++] = WAFFLE_BLUE_SIZE
;
127 attrib_list
[i
++] = min_color
;
130 if (test_config
->window_visual
& PIGLIT_GL_VISUAL_RGBA
) {
131 attrib_list
[i
++] = WAFFLE_ALPHA_SIZE
;
132 attrib_list
[i
++] = min_color
;
135 if (test_config
->window_visual
& PIGLIT_GL_VISUAL_DEPTH
) {
136 attrib_list
[i
++] = WAFFLE_DEPTH_SIZE
;
137 attrib_list
[i
++] = min_z
;
140 if (test_config
->window_visual
& PIGLIT_GL_VISUAL_STENCIL
) {
141 attrib_list
[i
++] = WAFFLE_STENCIL_SIZE
;
142 attrib_list
[i
++] = 1;
145 if (!(test_config
->window_visual
& PIGLIT_GL_VISUAL_DOUBLE
)) {
146 attrib_list
[i
++] = WAFFLE_DOUBLE_BUFFERED
;
147 attrib_list
[i
++] = false;
150 if (test_config
->window_visual
& PIGLIT_GL_VISUAL_ACCUM
) {
151 attrib_list
[i
++] = WAFFLE_ACCUM_BUFFER
;
152 attrib_list
[i
++] = true;
155 if (test_config
->window_samples
> 1) {
156 attrib_list
[i
++] = WAFFLE_SAMPLE_BUFFERS
;
157 attrib_list
[i
++] = 1;
158 attrib_list
[i
++] = WAFFLE_SAMPLES
;
159 attrib_list
[i
++] = test_config
->window_samples
;
162 attrib_list
[i
++] = WAFFLE_NONE
;
167 struct piglit_gl_framework
*
168 piglit_winsys_framework_factory(const struct piglit_gl_test_config
*test_config
)
170 int32_t platform
= piglit_wfl_framework_choose_platform(test_config
);
173 #ifdef PIGLIT_HAS_X11
174 case WAFFLE_PLATFORM_GLX
:
175 case WAFFLE_PLATFORM_X11_EGL
:
176 return piglit_x11_framework_create(test_config
, platform
);
179 #ifdef PIGLIT_HAS_GBM
180 case WAFFLE_PLATFORM_GBM
:
181 return piglit_gbm_framework_create(test_config
);
184 #ifdef PIGLIT_HAS_WAYLAND
185 case WAFFLE_PLATFORM_WAYLAND
:
186 return piglit_wl_framework_create(test_config
);
189 #ifdef PIGLIT_HAS_WGL
190 case WAFFLE_PLATFORM_WGL
:
191 return piglit_wgl_framework_create(test_config
);
194 #if WAFFLE_MAJOR_VERSION > 1 || (WAFFLE_MAJOR_VERSION == 1 && WAFFLE_MINOR_VERSION >= 6)
195 case WAFFLE_PLATFORM_SURFACELESS_EGL
:
196 return piglit_sl_framework_create(test_config
);
206 piglit_winsys_framework_init(struct piglit_winsys_framework
*winsys_fw
,
207 const struct piglit_gl_test_config
*test_config
,
210 struct piglit_wfl_framework
*wfl_fw
= &winsys_fw
->wfl_fw
;
211 struct piglit_gl_framework
*gl_fw
= &wfl_fw
->gl_fw
;
214 // First try to get 8-bit color channels, 24-bit Z
215 ok
= piglit_wfl_framework_init(wfl_fw
, test_config
, platform
,
216 choose_config_attribs(test_config
, 8, 24));
218 // Try shallower color/Z. We may get 565 color and 16-bit Z.
219 ok
= piglit_wfl_framework_init(wfl_fw
, test_config
, platform
,
220 choose_config_attribs(test_config
, 1, 1));
226 winsys_fw
->user_keyboard_func
= piglit_escape_exit_key
;
228 wfl_fw
->gl_fw
.post_redisplay
= post_redisplay
;
229 wfl_fw
->gl_fw
.set_keyboard_func
= set_keyboard_func
;
231 gl_fw
->run_test
= run_test
;
232 gl_fw
->swap_buffers
= swap_buffers
;
237 piglit_winsys_framework_teardown(winsys_fw
);
242 piglit_winsys_framework_teardown(struct piglit_winsys_framework
*winsys_fw
)
244 piglit_wfl_framework_teardown(&winsys_fw
->wfl_fw
);