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 /* Find/remove "-auto" and "-fbo" from the argument vector.
118 for (j
= 1; j
< *argc
; j
++) {
119 if (!strcmp(argv
[j
], "-auto")) {
120 piglit_automatic
= 1;
121 delete_arg(argv
, argc
, j
--);
122 } else if (!strcmp(argv
[j
], "-fbo")) {
123 piglit_use_fbo
= true;
124 delete_arg(argv
, argc
, j
--);
125 } else if (!strcmp(argv
[j
], "-png")) {
126 piglit_dump_png
= true;
127 delete_arg(argv
, argc
, j
--);
128 } else if (!strcmp(argv
[j
], "-rlimit")) {
136 "-rlimit requires an argument\n");
137 piglit_report_result(PIGLIT_FAIL
);
140 lim
= strtoul(argv
[j
], &ptr
, 0);
141 if (ptr
== argv
[j
]) {
143 "-rlimit requires an argument\n");
144 piglit_report_result(PIGLIT_FAIL
);
147 piglit_set_rlimit(lim
);
149 /* Remove 2 arguments (hence the 'i - 2') from the
152 for (i
= j
+ 1; i
< *argc
; i
++) {
153 argv
[i
- 2] = argv
[i
];
157 } else if (!strncmp(argv
[j
], "-samples=", 9)) {
158 *force_samples
= atoi(argv
[j
]+9);
159 delete_arg(argv
, argc
, j
--);
160 } else if (!strcmp(argv
[j
], "-khr_no_error")) {
161 piglit_khr_no_error
= true;
162 delete_arg(argv
, argc
, j
--);
163 if (config
->khr_no_error_support
==
164 PIGLIT_UNKNOWN_ERROR_STATUS
) {
166 "khr_no_error_support unknown "
168 piglit_report_result(PIGLIT_SKIP
);
169 } else if (config
->khr_no_error_support
==
171 piglit_report_result(PIGLIT_SKIP
);
173 assert(config
->khr_no_error_support
==
176 } else if (!strcmp(argv
[j
], "-compat")) {
177 if (config
->supports_gl_es_version
) {
179 "-compat isn't allowed with ES tests!\n");
180 piglit_report_result(PIGLIT_FAIL
);
182 config
->supports_gl_compat_version
= 10;
183 config
->supports_gl_core_version
= 0;
184 puts("The compatibility profile forced.");
185 delete_arg(argv
, argc
, j
--);
191 piglit_gl_process_args(int *argc
, char *argv
[],
192 struct piglit_gl_test_config
*config
)
194 unsigned force_samples
= 0;
196 process_args(argc
, argv
, &force_samples
, config
);
198 if (force_samples
> 1)
199 config
->window_samples
= force_samples
;
210 gl_fw
->destroy(gl_fw
);
215 piglit_gl_test_run(int argc
, char *argv
[],
216 const struct piglit_gl_test_config
*config
)
218 piglit_width
= config
->window_width
;
219 piglit_height
= config
->window_height
;
221 gl_fw
= piglit_gl_framework_factory(config
);
223 printf("piglit: error: failed to create "
224 "piglit_gl_framework\n");
225 piglit_report_result(PIGLIT_FAIL
);
229 gl_fw
->run_test(gl_fw
, argc
, argv
);
234 piglit_post_redisplay(void)
236 if (gl_fw
->post_redisplay
)
237 gl_fw
->post_redisplay(gl_fw
);
241 piglit_set_keyboard_func(void (*func
)(unsigned char key
, int x
, int y
))
243 if (gl_fw
->set_keyboard_func
)
244 gl_fw
->set_keyboard_func(gl_fw
, func
);
248 piglit_swap_buffers(void)
250 if (gl_fw
->swap_buffers
)
251 gl_fw
->swap_buffers(gl_fw
);
255 piglit_present_results(void)
257 if (piglit_dump_png
) {
258 static char *fileprefix
= NULL
;
259 static int frame
= 0;
261 GLenum base_format
= GL_RGBA
;
263 if (fileprefix
== NULL
) {
265 fileprefix
= strdup(piglit_binary_name
);
266 fileprefix
= basename(fileprefix
);
267 /* Strip potentially bad characters */
268 for (i
= 0; fileprefix
[i
]; i
++) {
269 if (!isalnum(fileprefix
[i
]) && fileprefix
[i
] != '-')
273 image
= malloc(4 * piglit_width
* piglit_height
);
274 glReadPixels(0, 0, piglit_width
, piglit_height
,
275 base_format
, GL_UNSIGNED_BYTE
, image
);
276 assert(glGetError() == GL_NO_ERROR
);
278 (void)!asprintf(&filename
, "%s%03d.png", fileprefix
, frame
++);
280 printf("Writing %s...\n", filename
);
281 piglit_write_png(filename
, base_format
, piglit_width
,
282 piglit_height
, image
, true);
287 if (!piglit_automatic
)
288 piglit_swap_buffers();
292 piglit_set_reshape_func(void (*func
)(int w
, int h
))
294 if (!gl_fw
->set_reshape_func
)
295 gl_fw
->set_reshape_func(gl_fw
, func
);
299 piglit_create_dma_buf(unsigned w
, unsigned h
, unsigned fourcc
,
300 const void *src_data
, struct piglit_dma_buf
**buf
)
302 if (!gl_fw
->create_dma_buf
)
305 return gl_fw
->create_dma_buf(w
, h
, fourcc
, src_data
, buf
);
309 piglit_destroy_dma_buf(struct piglit_dma_buf
*buf
)
311 if (gl_fw
->destroy_dma_buf
)
312 gl_fw
->destroy_dma_buf(buf
);
316 piglit_get_selected_tests(const char ***selected_subtests
)
318 *selected_subtests
= gl_fw
->test_config
->selected_subtests
;
319 return gl_fw
->test_config
->num_selected_subtests
;