On 11/07/17 17:06, Brian Paul wrote:
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.
---
  CMakeLists.txt               |   7 ++
  framework/core.py            |   2 +-
  tests/CMakeLists.txt         |   1 +
  tests/all.py                 |   5 ++
  tests/util/CMakeLists.gl.txt |  25 ++++++
  tests/util/piglit-wgl-util.c | 190 +++++++++++++++++++++++++++++++++++++++++++
  tests/util/piglit-wgl-util.h |  41 ++++++++++
  tests/wgl/CMakeLists.gl.txt  |  27 ++++++
  tests/wgl/CMakeLists.txt     |   1 +
  tests/wgl/wgl-sanity.c       |  88 ++++++++++++++++++++
  10 files changed, 386 insertions(+), 1 deletion(-)
  create mode 100644 tests/util/piglit-wgl-util.c
  create mode 100644 tests/util/piglit-wgl-util.h
  create mode 100644 tests/wgl/CMakeLists.gl.txt
  create mode 100644 tests/wgl/CMakeLists.txt
  create mode 100644 tests/wgl/wgl-sanity.c

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cc26fa8..d560bcc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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.
diff --git a/framework/core.py b/framework/core.py
index c2de5d0..9abc128 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -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):
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 7aab33f..ae50d0a 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -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
diff --git a/tests/all.py b/tests/all.py
index 4959789..f98b703 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -835,6 +835,11 @@ with profile.test_list.group_manager(
      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:
      g(['copyteximage', '1D'], run_concurrent=False)
diff --git a/tests/util/CMakeLists.gl.txt b/tests/util/CMakeLists.gl.txt
index a01fce3..e11213a 100644
--- a/tests/util/CMakeLists.gl.txt
+++ b/tests/util/CMakeLists.gl.txt
@@ -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}
+       )

There are two possible solutions: -

- add GLPROTO_INCLUDE_DIRS include dir globally, assuming it doesn't cause interference

- use target_include_directories(piglitwglutil ${GLPROTO_INCLUDE_DIRS}) instead of include_directories(), which in theory should make any dependent target that links against piglitwglutil automatically include this include.

But is this really needed for WGL?  Aren't these X11 proto headers?


+
+       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}
  )
diff --git a/tests/util/piglit-wgl-util.c b/tests/util/piglit-wgl-util.c
new file mode 100644
index 0000000..80f0f52
--- /dev/null
+++ b/tests/util/piglit-wgl-util.c
@@ -0,0 +1,190 @@
+/*
+ * 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)) {
+               fprintf(stderr, "failed to register class\n");
+               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");
+               return 0;
+       }
+
+       if (!(hDC = GetDC(hWnd))) {
+               fprintf(stderr, "GetDC failed\n");
+               return 0;
+       }
+
+       if (!(pixelFormat = ChoosePixelFormat(hDC, &pfd))) {
+               fprintf(stderr, "ChoosePixelFormat failed\n");
+               return 0;
+       }
+
+       if (!(SetPixelFormat(hDC, pixelFormat, &pfd))) {
+               fprintf(stderr, "SetPixelFormat failed\n");
+               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");
+               return 0;
+       }
+
+       if (!(hRC = wglCreateContext(hDC))) {
+               fprintf(stderr, "wglCreateContext failed\n");
+               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);
+}
diff --git a/tests/util/piglit-wgl-util.h b/tests/util/piglit-wgl-util.h
new file mode 100644
index 0000000..dce11b9
--- /dev/null
+++ b/tests/util/piglit-wgl-util.h
@@ -0,0 +1,41 @@
+/*
+ * 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
diff --git a/tests/wgl/CMakeLists.gl.txt b/tests/wgl/CMakeLists.gl.txt
new file mode 100644
index 0000000..c631f85
--- /dev/null
+++ b/tests/wgl/CMakeLists.gl.txt
@@ -0,0 +1,27 @@
+
+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:
diff --git a/tests/wgl/CMakeLists.txt b/tests/wgl/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/wgl/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/wgl/wgl-sanity.c b/tests/wgl/wgl-sanity.c
new file mode 100644
index 0000000..133501d
--- /dev/null
+++ b/tests/wgl/wgl-sanity.c
@@ -0,0 +1,88 @@
+/*
+ * 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;
+}


Otherwise looks great AFAICT -- WGL specific tests have indeed been long standing omission.

Jose
_______________________________________________
Piglit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to