summaryrefslogtreecommitdiff
path: root/tests/util/piglit-framework-gl/piglit_winsys_framework.c
blob: 2564f81be2b1293bb78df81a3f3caa4d5df8a618 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
 * Copyright © 2012 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#include <assert.h>
#include <unistd.h>

#include "piglit-util-gl-common.h"
#include "piglit-util-waffle.h"

#include "piglit_gbm_framework.h"
#include "piglit_gl_framework.h"
#include "piglit_winsys_framework.h"
#include "piglit_wl_framework.h"
#include "piglit_x11_framework.h"

struct piglit_winsys_framework*
piglit_winsys_framework(struct piglit_gl_framework *gl_fw)
{
	return (struct piglit_winsys_framework*) gl_fw;
}

static void
swap_buffers(struct piglit_gl_framework *gl_fw)
{
	waffle_window_swap_buffers(piglit_wfl_framework(gl_fw)->window);
}

static void
run_test(struct piglit_gl_framework *gl_fw,
         int argc, char *argv[])
{
	struct piglit_winsys_framework *winsys_fw = piglit_winsys_framework(gl_fw);
	enum piglit_result result = PIGLIT_PASS;

	if (gl_fw->test_config->requires_displayed_window) {
		/* Display the window before running the actual test. */
		winsys_fw->show_window(winsys_fw);
	}

	if (gl_fw->test_config->init)
		gl_fw->test_config->init(argc, argv);
	if (gl_fw->test_config->display)
		result = gl_fw->test_config->display();

	if (piglit_automatic)
		piglit_report_result(result);

	/* In non-auto mode, the user wishes to see the window regardless
	 * of the value of piglit_gl_test_config::require_displayed_window.
	 */
	winsys_fw->show_window(winsys_fw);
	winsys_fw->enter_event_loop(winsys_fw);
	abort();
}

static void
set_keyboard_func(struct piglit_gl_framework *gl_fw,
                  void (*func)(unsigned char key, int x, int y))
{
	piglit_winsys_framework(gl_fw)->user_keyboard_func = func;
}

static void
post_redisplay(struct piglit_gl_framework *gl_fw)
{
	piglit_winsys_framework(gl_fw)->need_redisplay = true;
}

static const int32_t*
choose_config_attribs(const struct piglit_gl_test_config *test_config)
{
	static int32_t attrib_list[64];
	int i = 0;

	attrib_list[i++] = WAFFLE_RED_SIZE;
	attrib_list[i++] = 1;
	attrib_list[i++] = WAFFLE_GREEN_SIZE;
	attrib_list[i++] = 1;
	attrib_list[i++] = WAFFLE_BLUE_SIZE;
	attrib_list[i++] = 1;

	if (test_config->window_visual & PIGLIT_GL_VISUAL_ALPHA) {
		attrib_list[i++] = WAFFLE_ALPHA_SIZE;
		attrib_list[i++] = 1;
	}

	if (test_config->window_visual & PIGLIT_GL_VISUAL_DEPTH) {
		attrib_list[i++] = WAFFLE_DEPTH_SIZE;
		attrib_list[i++] = 1;
	}

	if (test_config->window_visual & PIGLIT_GL_VISUAL_STENCIL) {
		attrib_list[i++] = WAFFLE_STENCIL_SIZE;
		attrib_list[i++] = 1;
	}

	if (!(test_config->window_visual & PIGLIT_GL_VISUAL_DOUBLE)) {
		attrib_list[i++] = WAFFLE_DOUBLE_BUFFERED;
		attrib_list[i++] = false;
	}

	if (test_config->window_visual & PIGLIT_GL_VISUAL_ACCUM) {
		attrib_list[i++] = WAFFLE_ACCUM_BUFFER;
		attrib_list[i++] = true;
	}

	attrib_list[i++] = WAFFLE_NONE;

	return attrib_list;
}

struct piglit_gl_framework*
piglit_winsys_framework_factory(const struct piglit_gl_test_config *test_config)
{
	int32_t platform = piglit_wfl_framework_choose_platform();

	switch (platform) {
#ifdef PIGLIT_HAS_X11
	case WAFFLE_PLATFORM_GLX:
	case WAFFLE_PLATFORM_X11_EGL:
		return piglit_x11_framework_create(test_config, platform);
#endif

#ifdef PIGLIT_HAS_GBM
	case WAFFLE_PLATFORM_GBM:
		return piglit_gbm_framework_create(test_config);
#endif

/* There is no need to #ifdef out Piglit support for Wayland yet
 * because Piglit calls no Wayland functions.
 */
	case WAFFLE_PLATFORM_WAYLAND:
		return piglit_wl_framework_create(test_config);
	default:
		assert(0);
		return NULL;
	}
}

bool
piglit_winsys_framework_init(struct piglit_winsys_framework *winsys_fw,
                             const struct piglit_gl_test_config *test_config,
                             int32_t platform)
{
	struct piglit_wfl_framework *wfl_fw = &winsys_fw->wfl_fw;
	struct piglit_gl_framework *gl_fw = &wfl_fw->gl_fw;
	bool ok = true;

	ok = piglit_wfl_framework_init(wfl_fw, test_config, platform,
	                               choose_config_attribs(test_config));
	if (!ok)
		goto fail;

	winsys_fw->user_keyboard_func = piglit_escape_exit_key;

	wfl_fw->gl_fw.post_redisplay = post_redisplay;
	wfl_fw->gl_fw.set_keyboard_func = set_keyboard_func;

	gl_fw->run_test = run_test;
	gl_fw->swap_buffers = swap_buffers;

	return true;

fail:
	piglit_winsys_framework_teardown(winsys_fw);
	return false;
}

void
piglit_winsys_framework_teardown(struct piglit_winsys_framework *winsys_fw)
{
	piglit_wfl_framework_teardown(&winsys_fw->wfl_fw);
}