ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / util / piglit-framework-gl / piglit_wgl_framework.c
blob5a7273d794a7c1a8a0056d9e7bf5f261088a890d
1 /*
2 * Copyright © 2014 Emil Velikov
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
13 * Software.
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
21 * IN THE SOFTWARE.
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <windows.h>
28 #include "piglit-util-gl.h"
29 #include "piglit_wl_framework.h"
31 static void
32 process_next_event(struct piglit_winsys_framework *winsys_fw)
34 const struct piglit_gl_test_config *test_config = winsys_fw->wfl_fw.gl_fw.test_config;
36 BOOL bRet;
37 MSG msg;
39 bRet = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
41 if (bRet) {
42 if (0) {
43 fprintf(stderr, "message = 0x%04x, wParam = 0x%04x\n", msg.message, msg.wParam);
46 switch (msg.message) {
47 case WM_PAINT:
48 winsys_fw->need_redisplay = true;
49 break;
50 case WM_SIZE:
51 if (winsys_fw->user_reshape_func) {
52 RECT rect;
53 if (GetClientRect(msg.hwnd, &rect)) {
54 int width = rect.right - rect.left;
55 int height = rect.bottom - rect.top;
56 winsys_fw->user_reshape_func(width, height);
59 winsys_fw->need_redisplay = true;
60 break;
61 case WM_CHAR:
62 if (winsys_fw->user_keyboard_func) {
63 winsys_fw->user_keyboard_func(msg.wParam, 0, 0);
65 winsys_fw->need_redisplay = true;
66 break;
67 case WM_SYSCOMMAND:
68 if (msg.wParam == SC_CLOSE) {
69 PostQuitMessage(EXIT_SUCCESS);
71 break;
72 case WM_CLOSE:
73 /* XXX: we never see this message here in practice, only WM_SYSCOMMAND::SC_CLOSE above */
74 PostQuitMessage(EXIT_SUCCESS);
75 break;
76 case WM_QUIT:
77 /* TODO: cleanup/teardown things */
78 exit(msg.wParam);
79 default:
80 break;
83 TranslateMessage(&msg);
84 DispatchMessage(&msg);
87 if (winsys_fw->need_redisplay) {
88 enum piglit_result result = PIGLIT_PASS;
89 if (test_config->display)
90 result = test_config->display();
91 if (piglit_automatic)
92 piglit_report_result(result);
93 winsys_fw->need_redisplay = false;
97 static void
98 enter_event_loop(struct piglit_winsys_framework *winsys_fw)
100 while (true)
101 process_next_event(winsys_fw);
104 static void
105 show_window(struct piglit_winsys_framework *winsys_fw)
107 waffle_window_show(winsys_fw->wfl_fw.window);
110 static void
111 destroy(struct piglit_gl_framework *gl_fw)
113 struct piglit_winsys_framework *winsys_fw= piglit_winsys_framework(gl_fw);
115 if (winsys_fw == NULL)
116 return;
118 piglit_winsys_framework_teardown(winsys_fw);
119 free(winsys_fw);
122 struct piglit_gl_framework*
123 piglit_wgl_framework_create(const struct piglit_gl_test_config *test_config)
125 struct piglit_winsys_framework *winsys_fw = NULL;
126 struct piglit_gl_framework *gl_fw = NULL;
127 bool ok = true;
129 winsys_fw = calloc(1, sizeof(*winsys_fw));
130 gl_fw = &winsys_fw->wfl_fw.gl_fw;
132 ok = piglit_winsys_framework_init(winsys_fw, test_config,
133 WAFFLE_PLATFORM_WGL);
134 if (!ok)
135 goto fail;
137 winsys_fw->show_window = show_window;
138 winsys_fw->enter_event_loop = enter_event_loop;
139 gl_fw->destroy = destroy;
141 winsys_fw->need_redisplay = true;
143 return gl_fw;
145 fail:
146 destroy(gl_fw);
147 return NULL;