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
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
28 #include "piglit-util-gl.h"
29 #include "piglit_wl_framework.h"
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
;
39 bRet
= GetMessage(&msg
, NULL
, 0, 0);
40 /* bRet will be negative on error, zero on WM_QUIT, positive for other messages */
46 fprintf(stderr
, "message = 0x%04x, wParam = 0x%04x\n", msg
.message
, msg
.wParam
);
49 switch (msg
.message
) {
51 winsys_fw
->need_redisplay
= true;
54 if (winsys_fw
->user_reshape_func
) {
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;
65 if (winsys_fw
->user_keyboard_func
) {
66 winsys_fw
->user_keyboard_func(msg
.wParam
, 0, 0);
68 winsys_fw
->need_redisplay
= true;
71 if (msg
.wParam
== SC_CLOSE
) {
72 PostQuitMessage(EXIT_SUCCESS
);
76 /* XXX: we never see this message here in practice, only WM_SYSCOMMAND::SC_CLOSE above */
77 PostQuitMessage(EXIT_SUCCESS
);
80 /* TODO: cleanup/teardown things */
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();
94 piglit_report_result(result
);
95 winsys_fw
->need_redisplay
= false;
100 enter_event_loop(struct piglit_winsys_framework
*winsys_fw
)
103 process_next_event(winsys_fw
);
107 show_window(struct piglit_winsys_framework
*winsys_fw
)
109 waffle_window_show(winsys_fw
->wfl_fw
.window
);
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
)
120 piglit_winsys_framework_teardown(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
;
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
);
139 winsys_fw
->show_window
= show_window
;
140 winsys_fw
->enter_event_loop
= enter_event_loop
;
141 gl_fw
->destroy
= destroy
;