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 gallium frontend.
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
)(UINT_PTR
)DrvCreateContext(hdc
);
74 WINGDIAPI HGLRC APIENTRY
75 wglCreateLayerContext(
79 overrideOpenGL32EntryPoints();
80 return (HGLRC
)(UINT_PTR
)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_STEREO_DONTCARE
) && (ppfd
->dwFlags
& PFD_STEREO
))
174 return stw_pixelformat_choose( hdc
, ppfd
);
177 WINGDIAPI
int APIENTRY
178 wglDescribePixelFormat(
182 LPPIXELFORMATDESCRIPTOR ppfd
)
184 return DrvDescribePixelFormat( hdc
, iPixelFormat
, nBytes
, ppfd
);
187 WINGDIAPI
int APIENTRY
191 return stw_pixelformat_get( hdc
);
194 WINGDIAPI BOOL APIENTRY
198 const PIXELFORMATDESCRIPTOR
*ppfd
)
200 /* SetPixelFormat (hence wglSetPixelFormat) must not touch ppfd, per
201 * http://msdn.microsoft.com/en-us/library/dd369049(v=vs.85).aspx
205 return DrvSetPixelFormat( hdc
, iPixelFormat
);
209 WINGDIAPI BOOL APIENTRY
216 return wglUseFontBitmapsW(hdc
, first
, count
, listBase
);
219 WINGDIAPI BOOL APIENTRY
224 return DrvShareLists((DHGLRC
)(UINT_PTR
)hglrc1
,
225 (DHGLRC
)(UINT_PTR
)hglrc2
);
228 WINGDIAPI BOOL APIENTRY
237 FIXED one
, minus_one
, zero
;
243 minus_one
.value
= -1;
249 tra
.eM22
= minus_one
;
250 tra
.eM12
= tra
.eM21
= zero
;
252 for (int i
= 0; i
< count
; i
++) {
253 DWORD size
= GetGlyphOutline(hdc
, first
+ i
, GGO_BITMAP
, &gm
, 0,
256 glNewList(listBase
+ i
, GL_COMPILE
);
258 if (size
!= GDI_ERROR
) {
260 glBitmap(0, 0, (GLfloat
)-gm
.gmptGlyphOrigin
.x
,
261 (GLfloat
)gm
.gmptGlyphOrigin
.y
,
262 (GLfloat
)gm
.gmCellIncX
,
263 (GLfloat
)gm
.gmCellIncY
, NULL
);
266 buffer
= realloc(buffer
, size
);
267 size
= GetGlyphOutline(hdc
, first
+ i
, GGO_BITMAP
, &gm
,
270 glBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
271 -gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
,
272 gm
.gmCellIncX
, gm
.gmCellIncY
, buffer
);
287 WINGDIAPI BOOL APIENTRY
296 LPGLYPHMETRICSFLOAT lpgmf
)
312 WINGDIAPI BOOL APIENTRY
321 LPGLYPHMETRICSFLOAT lpgmf
)
337 WINGDIAPI BOOL APIENTRY
338 wglDescribeLayerPlane(
343 LPLAYERPLANEDESCRIPTOR plpd
)
345 return DrvDescribeLayerPlane(hdc
, iPixelFormat
, iLayerPlane
, nBytes
, plpd
);
348 WINGDIAPI
int APIENTRY
349 wglSetLayerPaletteEntries(
354 CONST COLORREF
*pcr
)
356 return DrvSetLayerPaletteEntries(hdc
, iLayerPlane
, iStart
, cEntries
, pcr
);
359 WINGDIAPI
int APIENTRY
360 wglGetLayerPaletteEntries(
367 return DrvGetLayerPaletteEntries(hdc
, iLayerPlane
, iStart
, cEntries
, pcr
);
370 WINGDIAPI BOOL APIENTRY
371 wglRealizeLayerPalette(
386 /* When this library is used as a opengl32.dll drop-in replacement, ensure we
387 * use the wglCreate/Destroy entrypoints above, and not the true opengl32.dll,
388 * which could happen if this library's name is not opengl32.dll exactly.
390 * For example, Qt 5.4 bundles this as opengl32sw.dll:
391 * https://blog.qt.io/blog/2014/11/27/qt-weekly-21-dynamic-opengl-implementation-loading-in-qt-5-4/
394 overrideOpenGL32EntryPoints(void)
396 wglCreateContext_func
= &wglCreateContext
;
397 wglDeleteContext_func
= &wglDeleteContext
;