wgl: Move wgl* non-extension definitions to libgl-gdi
authorJesse Natalie <jenatali@microsoft.com>
Wed, 1 Sep 2021 14:06:49 +0000 (07:06 -0700)
committerJesse Natalie <jenatali@microsoft.com>
Wed, 8 Sep 2021 14:22:24 +0000 (07:22 -0700)
Reviewed By: Bill Kristiansen <billkris@microsoft.com>

Reviewed-by: Charmaine Lee >charmainel@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12677>

src/gallium/frontends/wgl/meson.build
src/gallium/frontends/wgl/stw_ext_context.c
src/gallium/frontends/wgl/stw_wgl.c [deleted file]
src/gallium/frontends/wgl/stw_wgl.h [deleted file]
src/gallium/targets/libgl-gdi/meson.build
src/gallium/targets/libgl-gdi/stw_wgl.c [new file with mode: 0644]
src/gallium/targets/libgl-gdi/stw_wgl.h [new file with mode: 0644]

index f8e775774dce31debf75d7e5f6ad1410d21cce52..0fae0c05a6fc646a561d1e983e13e98d4167be75 100644 (file)
@@ -43,7 +43,6 @@ libwgl = static_library(
     'stw_pixelformat.c',
     'stw_st.c',
     'stw_tls.c',
-    'stw_wgl.c',
   ),
   c_args : [
     '-D_GDI32_',             # prevent wgl* being declared __declspec(dllimport)
index 4171987f89c182f577970bd7a3b162ef915b64fb..fee498bf80066144a72c92d35fedfccff82a13ef 100644 (file)
@@ -210,3 +210,9 @@ wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc)
 
    return stw_make_current(hDrawDC, hReadDC, dhglrc);
 }
+
+HDC APIENTRY
+wglGetCurrentReadDCARB(VOID)
+{
+   return stw_get_current_read_dc();
+}
diff --git a/src/gallium/frontends/wgl/stw_wgl.c b/src/gallium/frontends/wgl/stw_wgl.c
deleted file mode 100644 (file)
index fc0796f..0000000
+++ /dev/null
@@ -1,398 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2008 VMware, Inc.
- * All Rights Reserved.
- *
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
- *
- **************************************************************************/
-
-/**
- * @file
- *
- * Fake WGL gallium frontend.
- *
- * These functions implement the WGL API, on top of the ICD DDI, so that the
- * resulting DLL can be used as a drop-in replacement for the system's
- * opengl32.dll.
- *
- * These functions never get called for ICD drivers, which use exclusively the
- * ICD DDI, i.e., the Drv* entrypoints.
- */
-
-#include <windows.h>
-#include <GL/gl.h>
-
-#include "util/u_debug.h"
-#include "gldrv.h"
-#include "stw_context.h"
-#include "stw_pixelformat.h"
-#include "stw_wgl.h"
-#include "stw_ext_context.h"
-
-
-static void
-overrideOpenGL32EntryPoints(void);
-
-WINGDIAPI BOOL APIENTRY
-wglCopyContext(
-   HGLRC hglrcSrc,
-   HGLRC hglrcDst,
-   UINT mask )
-{
-   return DrvCopyContext( (DHGLRC)(UINT_PTR)hglrcSrc,
-                          (DHGLRC)(UINT_PTR)hglrcDst,
-                          mask );
-}
-
-WINGDIAPI HGLRC APIENTRY
-wglCreateContext(
-   HDC hdc )
-{
-   overrideOpenGL32EntryPoints();
-   return (HGLRC)(UINT_PTR)DrvCreateContext(hdc);
-}
-
-WINGDIAPI HGLRC APIENTRY
-wglCreateLayerContext(
-   HDC hdc,
-   int iLayerPlane )
-{
-   overrideOpenGL32EntryPoints();
-   return (HGLRC)(UINT_PTR)DrvCreateLayerContext( hdc, iLayerPlane );
-}
-
-WINGDIAPI BOOL APIENTRY
-wglDeleteContext(
-   HGLRC hglrc )
-{
-   return DrvDeleteContext((DHGLRC)(UINT_PTR)hglrc );
-}
-
-
-WINGDIAPI HGLRC APIENTRY
-wglGetCurrentContext( VOID )
-{
-   return (HGLRC)(UINT_PTR)stw_get_current_context();
-}
-
-WINGDIAPI HDC APIENTRY
-wglGetCurrentDC( VOID )
-{
-   return stw_get_current_dc();
-}
-
-WINGDIAPI HDC APIENTRY
-wglGetCurrentReadDCARB( VOID )
-{
-   return stw_get_current_read_dc();
-}
-
-
-WINGDIAPI BOOL APIENTRY
-wglMakeCurrent(
-   HDC hdc,
-   HGLRC hglrc )
-{
-   return DrvSetContext( hdc, (DHGLRC)(UINT_PTR)hglrc, NULL ) ? TRUE : FALSE;
-}
-
-
-WINGDIAPI BOOL APIENTRY
-wglSwapBuffers(
-   HDC hdc )
-{
-   return DrvSwapBuffers( hdc );
-}
-
-
-WINGDIAPI DWORD WINAPI
-wglSwapMultipleBuffers(UINT n,
-                       CONST WGLSWAP *ps)
-{
-   UINT i;
-
-   for (i =0; i < n; ++i)
-      wglSwapBuffers(ps->hdc);
-
-   return 0;
-}
-
-
-WINGDIAPI BOOL APIENTRY
-wglSwapLayerBuffers(
-   HDC hdc,
-   UINT fuPlanes )
-{
-   return DrvSwapLayerBuffers( hdc, fuPlanes );
-}
-
-WINGDIAPI PROC APIENTRY
-wglGetProcAddress(
-    LPCSTR lpszProc )
-{
-   return DrvGetProcAddress( lpszProc );
-}
-
-
-WINGDIAPI int APIENTRY
-wglChoosePixelFormat(
-   HDC hdc,
-   CONST PIXELFORMATDESCRIPTOR *ppfd )
-{
-   if (ppfd->nSize != sizeof( PIXELFORMATDESCRIPTOR ) || ppfd->nVersion != 1)
-      return 0;
-   if (ppfd->iPixelType != PFD_TYPE_RGBA)
-      return 0;
-   if (!(ppfd->dwFlags & PFD_DRAW_TO_WINDOW))
-      return 0;
-   if (!(ppfd->dwFlags & PFD_SUPPORT_OPENGL))
-      return 0;
-   if (ppfd->dwFlags & PFD_DRAW_TO_BITMAP)
-      return 0;
-   if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO))
-      return 0;
-
-   return stw_pixelformat_choose( hdc, ppfd );
-}
-
-WINGDIAPI int APIENTRY
-wglDescribePixelFormat(
-   HDC hdc,
-   int iPixelFormat,
-   UINT nBytes,
-   LPPIXELFORMATDESCRIPTOR ppfd )
-{
-   return DrvDescribePixelFormat( hdc, iPixelFormat, nBytes, ppfd );
-}
-
-WINGDIAPI int APIENTRY
-wglGetPixelFormat(
-   HDC hdc )
-{
-   return stw_pixelformat_get( hdc );
-}
-
-WINGDIAPI BOOL APIENTRY
-wglSetPixelFormat(
-   HDC hdc,
-   int iPixelFormat,
-   const PIXELFORMATDESCRIPTOR *ppfd )
-{
-    /* SetPixelFormat (hence wglSetPixelFormat) must not touch ppfd, per
-     * http://msdn.microsoft.com/en-us/library/dd369049(v=vs.85).aspx
-     */
-   (void) ppfd;
-
-   return DrvSetPixelFormat( hdc, iPixelFormat );
-}
-
-
-WINGDIAPI BOOL APIENTRY
-wglUseFontBitmapsA(
-   HDC hdc,
-   DWORD first,
-   DWORD count,
-   DWORD listBase )
-{
-   return wglUseFontBitmapsW(hdc, first, count, listBase);
-}
-
-WINGDIAPI BOOL APIENTRY
-wglShareLists(
-   HGLRC hglrc1,
-   HGLRC hglrc2 )
-{
-   return DrvShareLists((DHGLRC)(UINT_PTR)hglrc1,
-                        (DHGLRC)(UINT_PTR)hglrc2);
-}
-
-WINGDIAPI BOOL APIENTRY
-wglUseFontBitmapsW(
-   HDC hdc,
-   DWORD first,
-   DWORD count,
-   DWORD listBase )
-{
-   GLYPHMETRICS gm;
-   MAT2 tra;
-   FIXED one, minus_one, zero;
-   void *buffer = NULL;
-   BOOL result = TRUE;
-
-   one.value = 1;
-   one.fract = 0;
-   minus_one.value = -1;
-   minus_one.fract = 0;
-   zero.value = 0;
-   zero.fract = 0;
-
-   tra.eM11 = one;
-   tra.eM22 = minus_one;
-   tra.eM12 = tra.eM21 = zero;
-
-   for (int i = 0; i < count; i++) {
-      DWORD size = GetGlyphOutline(hdc, first + i, GGO_BITMAP, &gm, 0,
-                                   NULL, &tra);
-
-      glNewList(listBase + i, GL_COMPILE);
-
-      if (size != GDI_ERROR) {
-         if (size == 0) {
-            glBitmap(0, 0, (GLfloat)-gm.gmptGlyphOrigin.x,
-                     (GLfloat)gm.gmptGlyphOrigin.y,
-                     (GLfloat)gm.gmCellIncX,
-                     (GLfloat)gm.gmCellIncY, NULL);
-         }
-         else {
-            buffer = realloc(buffer, size);
-            size = GetGlyphOutline(hdc, first + i, GGO_BITMAP, &gm,
-                                   size, buffer, &tra);
-
-            glBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
-                     -gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y,
-                     gm.gmCellIncX, gm.gmCellIncY, buffer);
-         }
-      }
-      else {
-         result = FALSE;
-      }
-
-      glEndList();
-   }
-
-   free(buffer);
-
-   return result;
-}
-
-WINGDIAPI BOOL APIENTRY
-wglUseFontOutlinesA(
-   HDC hdc,
-   DWORD first,
-   DWORD count,
-   DWORD listBase,
-   FLOAT deviation,
-   FLOAT extrusion,
-   int format,
-   LPGLYPHMETRICSFLOAT lpgmf )
-{
-   (void) hdc;
-   (void) first;
-   (void) count;
-   (void) listBase;
-   (void) deviation;
-   (void) extrusion;
-   (void) format;
-   (void) lpgmf;
-
-   assert( 0 );
-
-   return FALSE;
-}
-
-WINGDIAPI BOOL APIENTRY
-wglUseFontOutlinesW(
-   HDC hdc,
-   DWORD first,
-   DWORD count,
-   DWORD listBase,
-   FLOAT deviation,
-   FLOAT extrusion,
-   int format,
-   LPGLYPHMETRICSFLOAT lpgmf )
-{
-   (void) hdc;
-   (void) first;
-   (void) count;
-   (void) listBase;
-   (void) deviation;
-   (void) extrusion;
-   (void) format;
-   (void) lpgmf;
-
-   assert( 0 );
-
-   return FALSE;
-}
-
-WINGDIAPI BOOL APIENTRY
-wglDescribeLayerPlane(
-   HDC hdc,
-   int iPixelFormat,
-   int iLayerPlane,
-   UINT nBytes,
-   LPLAYERPLANEDESCRIPTOR plpd )
-{
-   return DrvDescribeLayerPlane(hdc, iPixelFormat, iLayerPlane, nBytes, plpd);
-}
-
-WINGDIAPI int APIENTRY
-wglSetLayerPaletteEntries(
-   HDC hdc,
-   int iLayerPlane,
-   int iStart,
-   int cEntries,
-   CONST COLORREF *pcr )
-{
-   return DrvSetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr);
-}
-
-WINGDIAPI int APIENTRY
-wglGetLayerPaletteEntries(
-   HDC hdc,
-   int iLayerPlane,
-   int iStart,
-   int cEntries,
-   COLORREF *pcr )
-{
-   return DrvGetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr);
-}
-
-WINGDIAPI BOOL APIENTRY
-wglRealizeLayerPalette(
-   HDC hdc,
-   int iLayerPlane,
-   BOOL bRealize )
-{
-   (void) hdc;
-   (void) iLayerPlane;
-   (void) bRealize;
-
-   assert( 0 );
-
-   return FALSE;
-}
-
-
-/* When this library is used as a opengl32.dll drop-in replacement, ensure we
- * use the wglCreate/Destroy entrypoints above, and not the true opengl32.dll,
- * which could happen if this library's name is not opengl32.dll exactly.
- *
- * For example, Qt 5.4 bundles this as opengl32sw.dll:
- * https://blog.qt.io/blog/2014/11/27/qt-weekly-21-dynamic-opengl-implementation-loading-in-qt-5-4/
- */
-static void
-overrideOpenGL32EntryPoints(void)
-{
-   wglCreateContext_func = &wglCreateContext;
-   wglDeleteContext_func = &wglDeleteContext;
-}
diff --git a/src/gallium/frontends/wgl/stw_wgl.h b/src/gallium/frontends/wgl/stw_wgl.h
deleted file mode 100644 (file)
index 92d70b5..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * All Rights Reserved.
- *
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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 STW_WGL_H_
-#define STW_WGL_H_
-
-
-#include <windows.h>
-
-#include <GL/gl.h>
-
-
-/*
- * Undeclared APIs exported by opengl32.dll
- */
-
-WINGDIAPI BOOL WINAPI
-wglSwapBuffers(HDC hdc);
-
-WINGDIAPI int WINAPI
-wglChoosePixelFormat(HDC hdc,
-                     CONST PIXELFORMATDESCRIPTOR *ppfd);
-
-WINGDIAPI int WINAPI
-wglDescribePixelFormat(HDC hdc,
-                       int iPixelFormat,
-                       UINT nBytes,
-                       LPPIXELFORMATDESCRIPTOR ppfd);
-
-WINGDIAPI int WINAPI
-wglGetPixelFormat(HDC hdc);
-
-WINGDIAPI BOOL WINAPI
-wglSetPixelFormat(HDC hdc,
-                  int iPixelFormat,
-                  CONST PIXELFORMATDESCRIPTOR *ppfd);
-
-WINGDIAPI HDC APIENTRY
-wglGetCurrentReadDCARB( VOID );
-
-WINGDIAPI BOOL APIENTRY
-wglMakeContextCurrentARB(
-   HDC hDrawDC,
-   HDC hReadDC,
-   HGLRC hglrc );
-
-
-#ifndef WGL_SWAPMULTIPLE_MAX
-
-typedef struct _WGLSWAP
-{
-   HDC hdc;
-   UINT uiFlags;
-} WGLSWAP;
-
-#define WGL_SWAPMULTIPLE_MAX 16
-
-WINGDIAPI DWORD WINAPI
-wglSwapMultipleBuffers(UINT n,
-                       CONST WGLSWAP *ps);
-
-#endif /* !WGL_SWAPMULTIPLE_MAX */
-
-
-#endif /* STW_WGL_H_ */
index 734bbe5786cf601a58a79dd36b046126bd0151a7..588749aa639e62ace967f76a2e38f0f575740957 100644 (file)
@@ -28,7 +28,7 @@ ogldef = files('opengl32.def')[0]
 
 libopengl32 = shared_library(
   'opengl32',
-  ['libgl_gdi.c'],
+  ['libgl_gdi.c', 'stw_wgl.c'],
   vs_module_defs : ogldef,
   include_directories : [
     inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_wgl, inc_gallium_winsys, inc_gallium_winsys_sw, inc_gallium_drivers,
@@ -41,6 +41,7 @@ libopengl32 = shared_library(
     dep_ws2_32, idep_nir, idep_mesautil, driver_swrast, driver_swr,
     driver_d3d12, driver_zink, winsys_d3d12_wgl
   ],
+  c_args : ['-D_GDI32_'],
   link_args : opengl32_link_args,
   name_prefix : '',  # otherwise mingw will create libopengl32.dll
   install : true,
diff --git a/src/gallium/targets/libgl-gdi/stw_wgl.c b/src/gallium/targets/libgl-gdi/stw_wgl.c
new file mode 100644 (file)
index 0000000..5f4cb72
--- /dev/null
@@ -0,0 +1,392 @@
+/**************************************************************************
+ *
+ * Copyright 2008 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/**
+ * @file
+ *
+ * Fake WGL gallium frontend.
+ *
+ * These functions implement the WGL API, on top of the ICD DDI, so that the
+ * resulting DLL can be used as a drop-in replacement for the system's
+ * opengl32.dll.
+ *
+ * These functions never get called for ICD drivers, which use exclusively the
+ * ICD DDI, i.e., the Drv* entrypoints.
+ */
+
+#include <windows.h>
+#include <GL/gl.h>
+
+#include "util/u_debug.h"
+#include "gldrv.h"
+#include "stw_context.h"
+#include "stw_pixelformat.h"
+#include "stw_wgl.h"
+#include "stw_ext_context.h"
+
+
+static void
+overrideOpenGL32EntryPoints(void);
+
+WINGDIAPI BOOL APIENTRY
+wglCopyContext(
+   HGLRC hglrcSrc,
+   HGLRC hglrcDst,
+   UINT mask )
+{
+   return DrvCopyContext( (DHGLRC)(UINT_PTR)hglrcSrc,
+                          (DHGLRC)(UINT_PTR)hglrcDst,
+                          mask );
+}
+
+WINGDIAPI HGLRC APIENTRY
+wglCreateContext(
+   HDC hdc )
+{
+   overrideOpenGL32EntryPoints();
+   return (HGLRC)(UINT_PTR)DrvCreateContext(hdc);
+}
+
+WINGDIAPI HGLRC APIENTRY
+wglCreateLayerContext(
+   HDC hdc,
+   int iLayerPlane )
+{
+   overrideOpenGL32EntryPoints();
+   return (HGLRC)(UINT_PTR)DrvCreateLayerContext( hdc, iLayerPlane );
+}
+
+WINGDIAPI BOOL APIENTRY
+wglDeleteContext(
+   HGLRC hglrc )
+{
+   return DrvDeleteContext((DHGLRC)(UINT_PTR)hglrc );
+}
+
+
+WINGDIAPI HGLRC APIENTRY
+wglGetCurrentContext( VOID )
+{
+   return (HGLRC)(UINT_PTR)stw_get_current_context();
+}
+
+WINGDIAPI HDC APIENTRY
+wglGetCurrentDC( VOID )
+{
+   return stw_get_current_dc();
+}
+
+
+WINGDIAPI BOOL APIENTRY
+wglMakeCurrent(
+   HDC hdc,
+   HGLRC hglrc )
+{
+   return DrvSetContext( hdc, (DHGLRC)(UINT_PTR)hglrc, NULL ) ? TRUE : FALSE;
+}
+
+
+WINGDIAPI BOOL APIENTRY
+wglSwapBuffers(
+   HDC hdc )
+{
+   return DrvSwapBuffers( hdc );
+}
+
+
+WINGDIAPI DWORD WINAPI
+wglSwapMultipleBuffers(UINT n,
+                       CONST WGLSWAP *ps)
+{
+   UINT i;
+
+   for (i =0; i < n; ++i)
+      wglSwapBuffers(ps->hdc);
+
+   return 0;
+}
+
+
+WINGDIAPI BOOL APIENTRY
+wglSwapLayerBuffers(
+   HDC hdc,
+   UINT fuPlanes )
+{
+   return DrvSwapLayerBuffers( hdc, fuPlanes );
+}
+
+WINGDIAPI PROC APIENTRY
+wglGetProcAddress(
+    LPCSTR lpszProc )
+{
+   return DrvGetProcAddress( lpszProc );
+}
+
+
+WINGDIAPI int APIENTRY
+wglChoosePixelFormat(
+   HDC hdc,
+   CONST PIXELFORMATDESCRIPTOR *ppfd )
+{
+   if (ppfd->nSize != sizeof( PIXELFORMATDESCRIPTOR ) || ppfd->nVersion != 1)
+      return 0;
+   if (ppfd->iPixelType != PFD_TYPE_RGBA)
+      return 0;
+   if (!(ppfd->dwFlags & PFD_DRAW_TO_WINDOW))
+      return 0;
+   if (!(ppfd->dwFlags & PFD_SUPPORT_OPENGL))
+      return 0;
+   if (ppfd->dwFlags & PFD_DRAW_TO_BITMAP)
+      return 0;
+   if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO))
+      return 0;
+
+   return stw_pixelformat_choose( hdc, ppfd );
+}
+
+WINGDIAPI int APIENTRY
+wglDescribePixelFormat(
+   HDC hdc,
+   int iPixelFormat,
+   UINT nBytes,
+   LPPIXELFORMATDESCRIPTOR ppfd )
+{
+   return DrvDescribePixelFormat( hdc, iPixelFormat, nBytes, ppfd );
+}
+
+WINGDIAPI int APIENTRY
+wglGetPixelFormat(
+   HDC hdc )
+{
+   return stw_pixelformat_get( hdc );
+}
+
+WINGDIAPI BOOL APIENTRY
+wglSetPixelFormat(
+   HDC hdc,
+   int iPixelFormat,
+   const PIXELFORMATDESCRIPTOR *ppfd )
+{
+    /* SetPixelFormat (hence wglSetPixelFormat) must not touch ppfd, per
+     * http://msdn.microsoft.com/en-us/library/dd369049(v=vs.85).aspx
+     */
+   (void) ppfd;
+
+   return DrvSetPixelFormat( hdc, iPixelFormat );
+}
+
+
+WINGDIAPI BOOL APIENTRY
+wglUseFontBitmapsA(
+   HDC hdc,
+   DWORD first,
+   DWORD count,
+   DWORD listBase )
+{
+   return wglUseFontBitmapsW(hdc, first, count, listBase);
+}
+
+WINGDIAPI BOOL APIENTRY
+wglShareLists(
+   HGLRC hglrc1,
+   HGLRC hglrc2 )
+{
+   return DrvShareLists((DHGLRC)(UINT_PTR)hglrc1,
+                        (DHGLRC)(UINT_PTR)hglrc2);
+}
+
+WINGDIAPI BOOL APIENTRY
+wglUseFontBitmapsW(
+   HDC hdc,
+   DWORD first,
+   DWORD count,
+   DWORD listBase )
+{
+   GLYPHMETRICS gm;
+   MAT2 tra;
+   FIXED one, minus_one, zero;
+   void *buffer = NULL;
+   BOOL result = TRUE;
+
+   one.value = 1;
+   one.fract = 0;
+   minus_one.value = -1;
+   minus_one.fract = 0;
+   zero.value = 0;
+   zero.fract = 0;
+
+   tra.eM11 = one;
+   tra.eM22 = minus_one;
+   tra.eM12 = tra.eM21 = zero;
+
+   for (int i = 0; i < count; i++) {
+      DWORD size = GetGlyphOutline(hdc, first + i, GGO_BITMAP, &gm, 0,
+                                   NULL, &tra);
+
+      glNewList(listBase + i, GL_COMPILE);
+
+      if (size != GDI_ERROR) {
+         if (size == 0) {
+            glBitmap(0, 0, (GLfloat)-gm.gmptGlyphOrigin.x,
+                     (GLfloat)gm.gmptGlyphOrigin.y,
+                     (GLfloat)gm.gmCellIncX,
+                     (GLfloat)gm.gmCellIncY, NULL);
+         }
+         else {
+            buffer = realloc(buffer, size);
+            size = GetGlyphOutline(hdc, first + i, GGO_BITMAP, &gm,
+                                   size, buffer, &tra);
+
+            glBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
+                     -gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y,
+                     gm.gmCellIncX, gm.gmCellIncY, buffer);
+         }
+      }
+      else {
+         result = FALSE;
+      }
+
+      glEndList();
+   }
+
+   free(buffer);
+
+   return result;
+}
+
+WINGDIAPI BOOL APIENTRY
+wglUseFontOutlinesA(
+   HDC hdc,
+   DWORD first,
+   DWORD count,
+   DWORD listBase,
+   FLOAT deviation,
+   FLOAT extrusion,
+   int format,
+   LPGLYPHMETRICSFLOAT lpgmf )
+{
+   (void) hdc;
+   (void) first;
+   (void) count;
+   (void) listBase;
+   (void) deviation;
+   (void) extrusion;
+   (void) format;
+   (void) lpgmf;
+
+   assert( 0 );
+
+   return FALSE;
+}
+
+WINGDIAPI BOOL APIENTRY
+wglUseFontOutlinesW(
+   HDC hdc,
+   DWORD first,
+   DWORD count,
+   DWORD listBase,
+   FLOAT deviation,
+   FLOAT extrusion,
+   int format,
+   LPGLYPHMETRICSFLOAT lpgmf )
+{
+   (void) hdc;
+   (void) first;
+   (void) count;
+   (void) listBase;
+   (void) deviation;
+   (void) extrusion;
+   (void) format;
+   (void) lpgmf;
+
+   assert( 0 );
+
+   return FALSE;
+}
+
+WINGDIAPI BOOL APIENTRY
+wglDescribeLayerPlane(
+   HDC hdc,
+   int iPixelFormat,
+   int iLayerPlane,
+   UINT nBytes,
+   LPLAYERPLANEDESCRIPTOR plpd )
+{
+   return DrvDescribeLayerPlane(hdc, iPixelFormat, iLayerPlane, nBytes, plpd);
+}
+
+WINGDIAPI int APIENTRY
+wglSetLayerPaletteEntries(
+   HDC hdc,
+   int iLayerPlane,
+   int iStart,
+   int cEntries,
+   CONST COLORREF *pcr )
+{
+   return DrvSetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr);
+}
+
+WINGDIAPI int APIENTRY
+wglGetLayerPaletteEntries(
+   HDC hdc,
+   int iLayerPlane,
+   int iStart,
+   int cEntries,
+   COLORREF *pcr )
+{
+   return DrvGetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr);
+}
+
+WINGDIAPI BOOL APIENTRY
+wglRealizeLayerPalette(
+   HDC hdc,
+   int iLayerPlane,
+   BOOL bRealize )
+{
+   (void) hdc;
+   (void) iLayerPlane;
+   (void) bRealize;
+
+   assert( 0 );
+
+   return FALSE;
+}
+
+
+/* When this library is used as a opengl32.dll drop-in replacement, ensure we
+ * use the wglCreate/Destroy entrypoints above, and not the true opengl32.dll,
+ * which could happen if this library's name is not opengl32.dll exactly.
+ *
+ * For example, Qt 5.4 bundles this as opengl32sw.dll:
+ * https://blog.qt.io/blog/2014/11/27/qt-weekly-21-dynamic-opengl-implementation-loading-in-qt-5-4/
+ */
+static void
+overrideOpenGL32EntryPoints(void)
+{
+   wglCreateContext_func = &wglCreateContext;
+   wglDeleteContext_func = &wglDeleteContext;
+}
diff --git a/src/gallium/targets/libgl-gdi/stw_wgl.h b/src/gallium/targets/libgl-gdi/stw_wgl.h
new file mode 100644 (file)
index 0000000..92d70b5
--- /dev/null
@@ -0,0 +1,89 @@
+/**************************************************************************
+ *
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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 STW_WGL_H_
+#define STW_WGL_H_
+
+
+#include <windows.h>
+
+#include <GL/gl.h>
+
+
+/*
+ * Undeclared APIs exported by opengl32.dll
+ */
+
+WINGDIAPI BOOL WINAPI
+wglSwapBuffers(HDC hdc);
+
+WINGDIAPI int WINAPI
+wglChoosePixelFormat(HDC hdc,
+                     CONST PIXELFORMATDESCRIPTOR *ppfd);
+
+WINGDIAPI int WINAPI
+wglDescribePixelFormat(HDC hdc,
+                       int iPixelFormat,
+                       UINT nBytes,
+                       LPPIXELFORMATDESCRIPTOR ppfd);
+
+WINGDIAPI int WINAPI
+wglGetPixelFormat(HDC hdc);
+
+WINGDIAPI BOOL WINAPI
+wglSetPixelFormat(HDC hdc,
+                  int iPixelFormat,
+                  CONST PIXELFORMATDESCRIPTOR *ppfd);
+
+WINGDIAPI HDC APIENTRY
+wglGetCurrentReadDCARB( VOID );
+
+WINGDIAPI BOOL APIENTRY
+wglMakeContextCurrentARB(
+   HDC hDrawDC,
+   HDC hReadDC,
+   HGLRC hglrc );
+
+
+#ifndef WGL_SWAPMULTIPLE_MAX
+
+typedef struct _WGLSWAP
+{
+   HDC hdc;
+   UINT uiFlags;
+} WGLSWAP;
+
+#define WGL_SWAPMULTIPLE_MAX 16
+
+WINGDIAPI DWORD WINAPI
+wglSwapMultipleBuffers(UINT n,
+                       CONST WGLSWAP *ps);
+
+#endif /* !WGL_SWAPMULTIPLE_MAX */
+
+
+#endif /* STW_WGL_H_ */