Commit e9ae0fb4 authored by Brian Paul's avatar Brian Paul

wgl: initial check-in of wgl utility code and wgl sanity check program

Like the glx tests/utility code, but for wgl.

Note, one must set the PIGLIT_PLATFORM env var to "wgl" before running
Piglit.  It looks like there's some Waffle work to look at before this
can be made automatic.
parent b50af79d
......@@ -179,6 +179,13 @@ ELSE()
option(PIGLIT_BUILD_GLX_TESTS "Build tests that require GLX" OFF)
ENDIF()
IF(PIGLIT_HAS_WGL)
option(PIGLIT_BUILD_WGL_TESTS "Build tests that require WGL" ON)
ELSE()
option(PIGLIT_BUILD_WGL_TESTS "Build tests that require WGL" OFF)
ENDIF()
# Choose to build tests that use dma_buf.
#
# Piglit's dma_buf utilities require xcb-dri2 to gain DRM authentication.
......
......@@ -44,7 +44,7 @@ __all__ = [
'parse_listfile',
]
PLATFORMS = ["glx", "x11_egl", "wayland", "gbm", "mixed_glx_egl"]
PLATFORMS = ["glx", "x11_egl", "wayland", "gbm", "mixed_glx_egl", "wgl"]
class PiglitConfig(configparser.SafeConfigParser):
......
......@@ -17,6 +17,7 @@ add_subdirectory (texturing)
add_subdirectory (spec)
add_subdirectory (fast_color_clear)
add_subdirectory (perf)
add_subdirectory (wgl)
if (NOT APPLE)
# glean relies on AGL which is deprecated/broken on recent Mac OS X
......
......@@ -835,6 +835,11 @@ with profile.test_list.group_manager(
require_platforms=['glx', 'mixed_glx_egl']) as g:
g(['glx-query-renderer-coverage'], 'coverage')
with profile.test_list.group_manager(
PiglitGLTest, 'wgl',
require_platforms=['wgl']) as g:
g(['wgl-sanity'])
with profile.test_list.group_manager(
PiglitGLTest,
grouptools.join('spec', '!opengl 1.1')) as g:
......
......@@ -33,6 +33,31 @@ IF(PIGLIT_BUILD_GLX_TESTS)
)
ENDIF(PIGLIT_BUILD_GLX_TESTS)
IF(PIGLIT_BUILD_WGL_TESTS)
# XXX: This is currently duplicated wherever tests
# include "piglit-wgl-util.h". Is it possible to refactor it?
include_directories(
${GLPROTO_INCLUDE_DIRS}
)
add_definitions ( -DPIGLIT_USE_WGL )
piglit_add_library (piglitwglutil
piglit-shader.c
piglit-util-gl.c
piglit-wgl-util.c
piglit-dispatch.c
piglit-dispatch-init.c
${piglit_dispatch_gen_output_dir}/piglit-util-gl-enum-gen.c
)
target_link_libraries(piglitwglutil
piglitutil_${piglit_target_api}
)
set (UTIL_GL_SOURCES
${UTIL_GL_SOURCES}
piglit-wgl-util.c
)
ENDIF(PIGLIT_BUILD_WGL_TESTS)
piglit_add_library (piglitutil_${piglit_target_api}
${UTIL_GL_SOURCES}
)
......
/*
* Copyright © 2017 VMware, Inc.
*
* 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.
*
* WGL utility functions, based on GLX utility functions by Eric Anholt.
*
* Authors:
* Brian Paul
*
*/
#include <stdio.h>
#include "piglit-util-gl.h"
#include "piglit-wgl-util.h"
int piglit_width = 100;
int piglit_height = 100;
static LRESULT CALLBACK
WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_SIZE:
//reshape(LOWORD(lParam), HIWORD(lParam));
return 0;
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
HWND
piglit_get_wgl_window(void)
{
int pixelFormat;
WNDCLASS wc;
DWORD dwExStyle, dwStyle;
HDC hDC;
RECT winrect;
HINSTANCE hInst;
HWND hWnd;
char *name = "wgl";
static const PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
winrect.left = 0;
winrect.right = piglit_width;
winrect.top = 0;
winrect.bottom = piglit_height;
hInst = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = name;
if (!RegisterClass(&wc)) {
/* This fails for second and subsequent calls */
/*
fprintf(stderr, "failed to register class\n");
fflush(stderr);
return 0;
*/
}
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW;
AdjustWindowRectEx(&winrect, dwStyle, FALSE, dwExStyle);
if (!(hWnd = CreateWindowEx(dwExStyle, name, name,
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle,
0, 0,
winrect.right - winrect.left,
winrect.bottom - winrect.top,
NULL, NULL, hInst, NULL))) {
fprintf(stderr, "failed to create window\n");
fflush(stderr);
return 0;
}
if (!(hDC = GetDC(hWnd))) {
fprintf(stderr, "GetDC failed\n");
fflush(stderr);
return 0;
}
if (!(pixelFormat = ChoosePixelFormat(hDC, &pfd))) {
fprintf(stderr, "ChoosePixelFormat failed\n");
fflush(stderr);
return 0;
}
if (!(SetPixelFormat(hDC, pixelFormat, &pfd))) {
fprintf(stderr, "SetPixelFormat failed\n");
fflush(stderr);
return 0;
}
ShowWindow(hWnd, SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
return hWnd;
}
HGLRC
piglit_get_wgl_context(HWND hWnd)
{
HDC hDC;
HGLRC hRC;
if (!(hDC = GetDC(hWnd))) {
fprintf(stderr, "GetDC failed\n");
fflush(stderr);
return 0;
}
if (!(hRC = wglCreateContext(hDC))) {
fprintf(stderr, "wglCreateContext failed\n");
fflush(stderr);
return 0;
}
return hRC;
}
void
piglit_wgl_event_loop(enum piglit_result (*draw)(void))
{
MSG msg;
enum piglit_result result = PIGLIT_SKIP;
while(1) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
result = draw();
if (piglit_automatic) {
break;
}
}
piglit_report_result(result);
}
/*
* Copyright © 2017 VMware, Inc.
*
* 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.
*/
#ifndef PIGLIT_WGL_UTIL_H
#define PIGLIT_WGL_UTIL_H
#include <windows.h>
#include "piglit-framework-gl.h"
HWND
piglit_get_wgl_window(void);
HGLRC
piglit_get_wgl_context(HWND hWnd);
void
piglit_wgl_event_loop(enum piglit_result (*draw)(void));
#endif
include_directories(
${GLEXT_INCLUDE_DIR}
${OPENGL_INCLUDE_PATH}
)
if(PIGLIT_BUILD_WGL_TESTS)
link_libraries (
piglitwglutil
)
endif(PIGLIT_BUILD_WGL_TESTS)
link_libraries (
${OPENGL_gl_LIBRARY}
)
IF(PIGLIT_BUILD_WGL_TESTS)
include_directories(
${GLPROTO_INCLUDE_DIRS}
)
link_libraries (
${X11_X11_LIB}
)
piglit_add_executable (wgl-sanity wgl-sanity.c)
ENDIF(PIGLIT_BUILD_WGL_TESTS)
# vim: ft=cmake:
piglit_include_target_api()
/*
* Copyright © 2017 VMware, Inc.
*
* 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.
*/
/*
* Basic WGL sanity check: create a window, context, clear window to green.
*
* Authors:
* Brian Paul
*/
#include <assert.h>
#include <stdio.h>
#include "piglit-util-gl.h"
#include "piglit-wgl-util.h"
HWND hWnd;
HGLRC ctx;
enum piglit_result
draw(void)
{
static const float green[4] = { 0, 1, 0, 1 };
bool pass = true;
glClearColor(0, 1, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
if (!piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
green)) {
pass = false;
}
SwapBuffers(GetDC(hWnd));
return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
int
main(int argc, char **argv)
{
int i;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-auto") == 0) {
piglit_automatic = 1;
break;
}
}
hWnd = piglit_get_wgl_window();
assert(hWnd);
ctx = piglit_get_wgl_context(hWnd);
assert(ctx);
if (!wglMakeCurrent(GetDC(hWnd), ctx)) {
fprintf(stderr, "wglMakeCurrent failed\n");
return 0;
}
piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
piglit_wgl_event_loop(draw);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment