2 * Copyright © 2009 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
31 #include "piglit-util-gl.h"
32 #include "piglit-framework-gl/piglit_gl_framework.h"
34 struct piglit_gl_framework
*gl_fw
;
36 const char *piglit_binary_name
;
37 bool piglit_dump_png
= false;
38 bool piglit_use_fbo
= false;
39 bool piglit_khr_no_error
= false;
40 int piglit_automatic
= 0;
41 unsigned piglit_winsys_fbo
= 0;
47 process_args(int *argc
, char *argv
[], unsigned *force_samples
,
48 struct piglit_gl_test_config
*config
);
51 piglit_gl_test_config_override_size(struct piglit_gl_test_config
*config
)
53 const char *default_size
;
57 default_size
= getenv("PIGLIT_DEFAULT_SIZE");
61 if (sscanf(default_size
, "%ux%u", &width
, &height
) != 2)
64 if (width
== 0 || height
== 0)
67 config
->window_width
= width
;
68 config
->window_height
= height
;
73 piglit_gl_test_config_init(struct piglit_gl_test_config
*config
)
75 memset(config
, 0, sizeof(*config
));
77 if (!piglit_gl_test_config_override_size(config
)) {
78 /* Default window size. Note: Win8's min window width */
79 /* seems to be 160 pixels. When the window size is */
80 /* unexpectedly resized, tests are marked as "WARN". */
81 /* Let's use a larger default to avoid that. */
82 config
->window_width
= 160;
83 config
->window_height
= 160;
86 config
->khr_no_error_support
= PIGLIT_UNKNOWN_ERROR_STATUS
;
90 delete_arg(char *argv
[], int *argc
, int arg
)
94 for (i
= arg
+ 1; i
< *argc
; i
++) {
95 argv
[i
- 1] = argv
[i
];
101 * Recognized arguments are removed from @a argv. The updated array
102 * length is returned in @a argc.
105 process_args(int *argc
, char *argv
[], unsigned *force_samples
,
106 struct piglit_gl_test_config
*config
)
110 piglit_binary_name
= argv
[0];
112 piglit_parse_subtest_args(argc
, argv
, config
->subtests
,
113 &config
->selected_subtests
,
114 &config
->num_selected_subtests
);
116 for (j
= 1; j
< *argc
; j
++) {
117 if (!strcmp(argv
[j
], "-auto")) {
118 piglit_automatic
= 1;
119 delete_arg(argv
, argc
, j
--);
120 } else if (!strcmp(argv
[j
], "-fbo")) {
121 piglit_use_fbo
= true;
122 delete_arg(argv
, argc
, j
--);
123 } else if (!strcmp(argv
[j
], "-png")) {
124 piglit_dump_png
= true;
125 delete_arg(argv
, argc
, j
--);
126 } else if (!strcmp(argv
[j
], "-rlimit")) {
134 "-rlimit requires an argument\n");
135 piglit_report_result(PIGLIT_FAIL
);
138 lim
= strtoul(argv
[j
], &ptr
, 0);
139 if (ptr
== argv
[j
]) {
141 "-rlimit requires an argument\n");
142 piglit_report_result(PIGLIT_FAIL
);
145 piglit_set_rlimit(lim
);
147 /* Remove 2 arguments (hence the 'i - 2') from the
150 for (i
= j
+ 1; i
< *argc
; i
++) {
151 argv
[i
- 2] = argv
[i
];
155 } else if (!strncmp(argv
[j
], "-samples=", 9)) {
156 *force_samples
= atoi(argv
[j
]+9);
157 delete_arg(argv
, argc
, j
--);
158 } else if (!strcmp(argv
[j
], "-khr_no_error")) {
159 piglit_khr_no_error
= true;
160 delete_arg(argv
, argc
, j
--);
161 if (config
->khr_no_error_support
==
162 PIGLIT_UNKNOWN_ERROR_STATUS
) {
164 "khr_no_error_support unknown "
166 piglit_report_result(PIGLIT_SKIP
);
167 } else if (config
->khr_no_error_support
==
169 piglit_report_result(PIGLIT_SKIP
);
171 assert(config
->khr_no_error_support
==
174 } else if (!strcmp(argv
[j
], "-compat")) {
175 if (config
->supports_gl_es_version
) {
177 "-compat isn't allowed with ES tests!\n");
178 piglit_report_result(PIGLIT_FAIL
);
180 config
->supports_gl_compat_version
= 10;
181 config
->supports_gl_core_version
= 0;
182 puts("The compatibility profile forced.");
183 delete_arg(argv
, argc
, j
--);
189 piglit_gl_process_args(int *argc
, char *argv
[],
190 struct piglit_gl_test_config
*config
)
192 unsigned force_samples
= 0;
194 process_args(argc
, argv
, &force_samples
, config
);
196 if (force_samples
> 1)
197 config
->window_samples
= force_samples
;
202 piglit_gl_test_run(int argc
, char *argv
[],
203 const struct piglit_gl_test_config
*config
)
205 piglit_width
= config
->window_width
;
206 piglit_height
= config
->window_height
;
208 gl_fw
= piglit_gl_framework_factory(config
);
210 printf("piglit: error: failed to create "
211 "piglit_gl_framework\n");
212 piglit_report_result(PIGLIT_FAIL
);
215 gl_fw
->run_test(&gl_fw
, argc
, argv
);
220 piglit_post_redisplay(void)
222 if (gl_fw
->post_redisplay
)
223 gl_fw
->post_redisplay(gl_fw
);
227 piglit_set_keyboard_func(void (*func
)(unsigned char key
, int x
, int y
))
229 if (gl_fw
->set_keyboard_func
)
230 gl_fw
->set_keyboard_func(gl_fw
, func
);
234 piglit_swap_buffers(void)
236 if (gl_fw
->swap_buffers
)
237 gl_fw
->swap_buffers(gl_fw
);
241 piglit_present_results(void)
243 if (piglit_dump_png
) {
244 static char *fileprefix
= NULL
;
245 static int frame
= 0;
247 GLenum base_format
= GL_RGBA
;
249 if (fileprefix
== NULL
) {
251 fileprefix
= strdup(piglit_binary_name
);
252 fileprefix
= basename(fileprefix
);
253 /* Strip potentially bad characters */
254 for (i
= 0; fileprefix
[i
]; i
++) {
255 if (!isalnum(fileprefix
[i
]) && fileprefix
[i
] != '-')
259 image
= malloc(4 * piglit_width
* piglit_height
);
260 glReadPixels(0, 0, piglit_width
, piglit_height
,
261 base_format
, GL_UNSIGNED_BYTE
, image
);
262 assert(glGetError() == GL_NO_ERROR
);
264 (void)!asprintf(&filename
, "%s%03d.png", fileprefix
, frame
++);
266 printf("Writing %s...\n", filename
);
267 piglit_write_png(filename
, base_format
, piglit_width
,
268 piglit_height
, image
, true);
273 if (!piglit_automatic
)
274 piglit_swap_buffers();
278 piglit_set_reshape_func(void (*func
)(int w
, int h
))
280 if (!gl_fw
->set_reshape_func
)
281 gl_fw
->set_reshape_func(gl_fw
, func
);
285 piglit_create_dma_buf(unsigned w
, unsigned h
, unsigned fourcc
,
286 const void *src_data
, struct piglit_dma_buf
**buf
)
288 if (!gl_fw
->create_dma_buf
)
291 return gl_fw
->create_dma_buf(w
, h
, fourcc
, src_data
, buf
);
295 piglit_destroy_dma_buf(struct piglit_dma_buf
*buf
)
297 if (gl_fw
->destroy_dma_buf
)
298 gl_fw
->destroy_dma_buf(buf
);
302 piglit_get_selected_tests(const char ***selected_subtests
)
304 *selected_subtests
= gl_fw
->test_config
->selected_subtests
;
305 return gl_fw
->test_config
->num_selected_subtests
;