glx-multithread-texture: Avoid front-buffer rendering.
[piglit.git] / tests / util / piglit-framework-gl / piglit_wgl_framework.c
blobb583df777d8f1592931a746c26b2ba99ea72b7bb
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 = GetMessage(&msg, NULL, 0, 0);
40 /* bRet will be negative on error, zero on WM_QUIT, positive for other messages */
41 if (bRet < 0) {
42 exit(EXIT_FAILURE);
45 if (0) {
46 fprintf(stderr, "message = 0x%04x, wParam = 0x%04x\n", msg.message, msg.wParam);
49 switch (msg.message) {
50 case WM_PAINT:
51 winsys_fw->need_redisplay = true;
52 break;
53 case WM_SIZE:
54 if (winsys_fw->user_reshape_func) {
55 RECT rect;
56 if (GetClientRect(msg.hwnd, &rect)) {
57 int width = rect.right - rect.left;
58 int height = rect.bottom - rect.top;
59 winsys_fw->user_reshape_func(width, height);
62 winsys_fw->need_redisplay = true;
63 break;
64 case WM_CHAR:
65 if (winsys_fw->user_keyboard_func) {
66 winsys_fw->user_keyboard_func(msg.wParam, 0, 0);
68 winsys_fw->need_redisplay = true;
69 break;
70 case WM_SYSCOMMAND:
71 if (msg.wParam == SC_CLOSE) {
72 PostQuitMessage(EXIT_SUCCESS);
74 break;
75 case WM_CLOSE:
76 /* XXX: we never see this message here in practice, only WM_SYSCOMMAND::SC_CLOSE above */
77 PostQuitMessage(EXIT_SUCCESS);
78 break;
79 case WM_QUIT:
80 /* TODO: cleanup/teardown things */
81 exit(msg.wParam);
82 default:
83 break;
86 TranslateMessage(&msg);
87 DispatchMessage(&msg);
89 if (winsys_fw->need_redisplay) {
90 enum piglit_result result = PIGLIT_PASS;
91 if (test_config->display)
92 result = test_config->display();
93 if (piglit_automatic)
94 piglit_report_result(result);
95 winsys_fw->need_redisplay = false;
99 static void
100 enter_event_loop(struct piglit_winsys_framework *winsys_fw)
102 while (true)
103 process_next_event(winsys_fw);
106 static void
107 show_window(struct piglit_winsys_framework *winsys_fw)
109 waffle_window_show(winsys_fw->wfl_fw.window);
112 static void
113 destroy(struct piglit_gl_framework *gl_fw)
115 struct piglit_winsys_framework *winsys_fw= piglit_winsys_framework(gl_fw);
117 if (winsys_fw == NULL)
118 return;
120 piglit_winsys_framework_teardown(winsys_fw);
121 free(winsys_fw);
124 struct piglit_gl_framework*
125 piglit_wgl_framework_create(const struct piglit_gl_test_config *test_config)
127 struct piglit_winsys_framework *winsys_fw = NULL;
128 struct piglit_gl_framework *gl_fw = NULL;
129 bool ok = true;
131 winsys_fw = calloc(1, sizeof(*winsys_fw));
132 gl_fw = &winsys_fw->wfl_fw.gl_fw;
134 ok = piglit_winsys_framework_init(winsys_fw, test_config,
135 WAFFLE_PLATFORM_WGL);
136 if (!ok)
137 goto fail;
139 winsys_fw->show_window = show_window;
140 winsys_fw->enter_event_loop = enter_event_loop;
141 gl_fw->destroy = destroy;
143 return gl_fw;
145 fail:
146 destroy(gl_fw);
147 return NULL;