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.
44 #include "util/u_debug.h"
46 #include "stw_context.h"
47 #include "stw_pixelformat.h"
49 #include "stw_ext_context.h"
53 overrideOpenGL32EntryPoints(void);
55 WINGDIAPI BOOL APIENTRY
61 return DrvCopyContext( (DHGLRC
)(UINT_PTR
)hglrcSrc
,
62 (DHGLRC
)(UINT_PTR
)hglrcDst
,
66 WINGDIAPI HGLRC APIENTRY
70 overrideOpenGL32EntryPoints();
71 return (HGLRC
) DrvCreateContext(hdc
);
74 WINGDIAPI HGLRC APIENTRY
75 wglCreateLayerContext(
79 overrideOpenGL32EntryPoints();
80 return (HGLRC
) DrvCreateLayerContext( hdc
, iLayerPlane
);
83 WINGDIAPI BOOL APIENTRY
87 return DrvDeleteContext((DHGLRC
)(UINT_PTR
)hglrc
);
91 WINGDIAPI HGLRC APIENTRY
92 wglGetCurrentContext( VOID
)
94 return (HGLRC
)(UINT_PTR
)stw_get_current_context();
97 WINGDIAPI HDC APIENTRY
98 wglGetCurrentDC( VOID
)
100 return stw_get_current_dc();
103 WINGDIAPI HDC APIENTRY
104 wglGetCurrentReadDCARB( VOID
)
106 return stw_get_current_read_dc();
110 WINGDIAPI BOOL APIENTRY
115 return DrvSetContext( hdc
, (DHGLRC
)(UINT_PTR
)hglrc
, NULL
) ? TRUE
: FALSE
;
119 WINGDIAPI BOOL APIENTRY
123 return DrvSwapBuffers( hdc
);
127 WINGDIAPI DWORD WINAPI
128 wglSwapMultipleBuffers(UINT n
,
133 for (i
=0; i
< n
; ++i
)
134 wglSwapBuffers(ps
->hdc
);
140 WINGDIAPI BOOL APIENTRY
145 return DrvSwapLayerBuffers( hdc
, fuPlanes
);
148 WINGDIAPI PROC APIENTRY
152 return DrvGetProcAddress( lpszProc
);
156 WINGDIAPI
int APIENTRY
157 wglChoosePixelFormat(
159 CONST PIXELFORMATDESCRIPTOR
*ppfd
)
161 if (ppfd
->nSize
!= sizeof( PIXELFORMATDESCRIPTOR
) || ppfd
->nVersion
!= 1)
163 if (ppfd
->iPixelType
!= PFD_TYPE_RGBA
)
165 if (!(ppfd
->dwFlags
& PFD_DRAW_TO_WINDOW
))
167 if (!(ppfd
->dwFlags
& PFD_SUPPORT_OPENGL
))
169 if (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
)
171 if (ppfd
->dwFlags
& PFD_SUPPORT_GDI
)
173 if (!(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) && (ppfd
->dwFlags
& PFD_STEREO
))
176 return stw_pixelformat_choose( hdc
, ppfd
);
179 WINGDIAPI
int APIENTRY
180 wglDescribePixelFormat(
184 LPPIXELFORMATDESCRIPTOR ppfd
)
186 return DrvDescribePixelFormat( hdc
, iPixelFormat
, nBytes
, ppfd
);
189 WINGDIAPI
int APIENTRY
193 return stw_pixelformat_get( hdc
);
196 WINGDIAPI BOOL APIENTRY
200 const PIXELFORMATDESCRIPTOR
*ppfd
)
202 /* SetPixelFormat (hence wglSetPixelFormat) must not touch ppfd, per
203 * http://msdn.microsoft.com/en-us/library/dd369049(v=vs.85).aspx
207 return DrvSetPixelFormat( hdc
, iPixelFormat
);
211 WINGDIAPI BOOL APIENTRY
218 return wglUseFontBitmapsW(hdc
, first
, count
, listBase
);
221 WINGDIAPI BOOL APIENTRY
226 return DrvShareLists((DHGLRC
)(UINT_PTR
)hglrc1
,
227 (DHGLRC
)(UINT_PTR
)hglrc2
);
230 WINGDIAPI BOOL APIENTRY
239 FIXED one
, minus_one
, zero
;
245 minus_one
.value
= -1;
251 tra
.eM22
= minus_one
;
252 tra
.eM12
= tra
.eM21
= zero
;
254 for (int i
= 0; i
< count
; i
++) {
255 DWORD size
= GetGlyphOutline(hdc
, first
+ i
, GGO_BITMAP
, &gm
, 0,
258 glNewList(listBase
+ i
, GL_COMPILE
);
260 if (size
!= GDI_ERROR
) {
262 glBitmap(0, 0, (GLfloat
)-gm
.gmptGlyphOrigin
.x
,
263 (GLfloat
)gm
.gmptGlyphOrigin
.y
,
264 (GLfloat
)gm
.gmCellIncX
,
265 (GLfloat
)gm
.gmCellIncY
, NULL
);
268 buffer
= realloc(buffer
, size
);
269 size
= GetGlyphOutline(hdc
, first
+ i
, GGO_BITMAP
, &gm
,
272 glBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
273 -gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
,
274 gm
.gmCellIncX
, gm
.gmCellIncY
, buffer
);
289 WINGDIAPI BOOL APIENTRY
298 LPGLYPHMETRICSFLOAT lpgmf
)
314 WINGDIAPI BOOL APIENTRY
323 LPGLYPHMETRICSFLOAT lpgmf
)
339 WINGDIAPI BOOL APIENTRY
340 wglDescribeLayerPlane(
345 LPLAYERPLANEDESCRIPTOR plpd
)
347 return DrvDescribeLayerPlane(hdc
, iPixelFormat
, iLayerPlane
, nBytes
, plpd
);
350 WINGDIAPI
int APIENTRY
351 wglSetLayerPaletteEntries(
356 CONST COLORREF
*pcr
)
358 return DrvSetLayerPaletteEntries(hdc
, iLayerPlane
, iStart
, cEntries
, pcr
);
361 WINGDIAPI
int APIENTRY
362 wglGetLayerPaletteEntries(
369 return DrvGetLayerPaletteEntries(hdc
, iLayerPlane
, iStart
, cEntries
, pcr
);
372 WINGDIAPI BOOL APIENTRY
373 wglRealizeLayerPalette(
388 /* When this library is used as a opengl32.dll drop-in replacement, ensure we
389 * use the wglCreate/Destroy entrypoints above, and not the true opengl32.dll,
390 * which could happen if this library's name is not opengl32.dll exactly.
392 * For example, Qt 5.4 bundles this as opengl32sw.dll:
393 * https://blog.qt.io/blog/2014/11/27/qt-weekly-21-dynamic-opengl-implementation-loading-in-qt-5-4/
396 overrideOpenGL32EntryPoints(void)
398 wglCreateContext_func
= &wglCreateContext
;
399 wglDeleteContext_func
= &wglDeleteContext
;