1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 * Fake WGL API implementation.
33 * These functions implement the WGL API, on top of the ICD DDI, so that the
34 * resulting DLL can be used as a drop-in replacement for the system's
37 * These functions never get called for ICD drivers, which use exclusively the
38 * ICD DDI, i.e., the Drv* entrypoints.
43 #include "util/u_debug.h"
45 #include "stw_context.h"
46 #include "stw_pixelformat.h"
48 #include "stw_ext_context.h"
52 overrideOpenGL32EntryPoints(void);
54 WINGDIAPI BOOL APIENTRY
60 return DrvCopyContext( (DHGLRC
)(UINT_PTR
)hglrcSrc
,
61 (DHGLRC
)(UINT_PTR
)hglrcDst
,
65 WINGDIAPI HGLRC APIENTRY
69 overrideOpenGL32EntryPoints();
70 return (HGLRC
) DrvCreateContext(hdc
);
73 WINGDIAPI HGLRC APIENTRY
74 wglCreateLayerContext(
78 overrideOpenGL32EntryPoints();
79 return (HGLRC
) DrvCreateLayerContext( hdc
, iLayerPlane
);
82 WINGDIAPI BOOL APIENTRY
86 return DrvDeleteContext((DHGLRC
)(UINT_PTR
)hglrc
);
90 WINGDIAPI HGLRC APIENTRY
91 wglGetCurrentContext( VOID
)
93 return (HGLRC
)(UINT_PTR
)stw_get_current_context();
96 WINGDIAPI HDC APIENTRY
97 wglGetCurrentDC( VOID
)
99 return stw_get_current_dc();
102 WINGDIAPI HDC APIENTRY
103 wglGetCurrentReadDCARB( VOID
)
105 return stw_get_current_read_dc();
109 WINGDIAPI BOOL APIENTRY
114 return DrvSetContext( hdc
, (DHGLRC
)(UINT_PTR
)hglrc
, NULL
) ? TRUE
: FALSE
;
118 WINGDIAPI BOOL APIENTRY
122 return DrvSwapBuffers( hdc
);
126 WINGDIAPI DWORD WINAPI
127 wglSwapMultipleBuffers(UINT n
,
132 for (i
=0; i
< n
; ++i
)
133 wglSwapBuffers(ps
->hdc
);
139 WINGDIAPI BOOL APIENTRY
144 return DrvSwapLayerBuffers( hdc
, fuPlanes
);
147 WINGDIAPI PROC APIENTRY
151 return DrvGetProcAddress( lpszProc
);
155 WINGDIAPI
int APIENTRY
156 wglChoosePixelFormat(
158 CONST PIXELFORMATDESCRIPTOR
*ppfd
)
160 if (ppfd
->nSize
!= sizeof( PIXELFORMATDESCRIPTOR
) || ppfd
->nVersion
!= 1)
162 if (ppfd
->iPixelType
!= PFD_TYPE_RGBA
)
164 if (!(ppfd
->dwFlags
& PFD_DRAW_TO_WINDOW
))
166 if (!(ppfd
->dwFlags
& PFD_SUPPORT_OPENGL
))
168 if (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
)
170 if (ppfd
->dwFlags
& PFD_SUPPORT_GDI
)
172 if (!(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) && (ppfd
->dwFlags
& PFD_STEREO
))
175 return stw_pixelformat_choose( hdc
, ppfd
);
178 WINGDIAPI
int APIENTRY
179 wglDescribePixelFormat(
183 LPPIXELFORMATDESCRIPTOR ppfd
)
185 return DrvDescribePixelFormat( hdc
, iPixelFormat
, nBytes
, ppfd
);
188 WINGDIAPI
int APIENTRY
192 return stw_pixelformat_get( hdc
);
195 WINGDIAPI BOOL APIENTRY
199 const PIXELFORMATDESCRIPTOR
*ppfd
)
201 /* SetPixelFormat (hence wglSetPixelFormat) must not touch ppfd, per
202 * http://msdn.microsoft.com/en-us/library/dd369049(v=vs.85).aspx
206 return DrvSetPixelFormat( hdc
, iPixelFormat
);
210 WINGDIAPI BOOL APIENTRY
217 return wglUseFontBitmapsW(hdc
, first
, count
, listBase
);
220 WINGDIAPI BOOL APIENTRY
225 return DrvShareLists((DHGLRC
)(UINT_PTR
)hglrc1
,
226 (DHGLRC
)(UINT_PTR
)hglrc2
);
229 WINGDIAPI BOOL APIENTRY
238 FIXED one
, minus_one
, zero
;
244 minus_one
.value
= -1;
250 tra
.eM22
= minus_one
;
251 tra
.eM12
= tra
.eM21
= zero
;
253 for (int i
= 0; i
< count
; i
++) {
254 DWORD size
= GetGlyphOutline(hdc
, first
+ i
, GGO_BITMAP
, &gm
, 0,
257 glNewList(listBase
+ i
, GL_COMPILE
);
259 if (size
!= GDI_ERROR
) {
261 glBitmap(0, 0, (GLfloat
)-gm
.gmptGlyphOrigin
.x
,
262 (GLfloat
)gm
.gmptGlyphOrigin
.y
,
263 (GLfloat
)gm
.gmCellIncX
,
264 (GLfloat
)gm
.gmCellIncY
, NULL
);
267 buffer
= realloc(buffer
, size
);
268 size
= GetGlyphOutline(hdc
, first
+ i
, GGO_BITMAP
, &gm
,
271 glBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
272 -gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
,
273 gm
.gmCellIncX
, gm
.gmCellIncY
, buffer
);
288 WINGDIAPI BOOL APIENTRY
297 LPGLYPHMETRICSFLOAT lpgmf
)
313 WINGDIAPI BOOL APIENTRY
322 LPGLYPHMETRICSFLOAT lpgmf
)
338 WINGDIAPI BOOL APIENTRY
339 wglDescribeLayerPlane(
344 LPLAYERPLANEDESCRIPTOR plpd
)
346 return DrvDescribeLayerPlane(hdc
, iPixelFormat
, iLayerPlane
, nBytes
, plpd
);
349 WINGDIAPI
int APIENTRY
350 wglSetLayerPaletteEntries(
355 CONST COLORREF
*pcr
)
357 return DrvSetLayerPaletteEntries(hdc
, iLayerPlane
, iStart
, cEntries
, pcr
);
360 WINGDIAPI
int APIENTRY
361 wglGetLayerPaletteEntries(
368 return DrvGetLayerPaletteEntries(hdc
, iLayerPlane
, iStart
, cEntries
, pcr
);
371 WINGDIAPI BOOL APIENTRY
372 wglRealizeLayerPalette(
387 /* When this library is used as a opengl32.dll drop-in replacement, ensure we
388 * use the wglCreate/Destroy entrypoints above, and not the true opengl32.dll,
389 * which could happen if this library's name is not opengl32.dll exactly.
391 * For example, Qt 5.4 bundles this as opengl32sw.dll:
392 * https://blog.qt.io/blog/2014/11/27/qt-weekly-21-dynamic-opengl-implementation-loading-in-qt-5-4/
395 overrideOpenGL32EntryPoints(void)
397 wglCreateContext_func
= &wglCreateContext
;
398 wglDeleteContext_func
= &wglDeleteContext
;