1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /**
29 * @file
30 *
31 * Fake WGL gallium frontend.
32 *
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
35 * opengl32.dll.
36 *
37 * These functions never get called for ICD drivers, which use exclusively the
38 * ICD DDI, i.e., the Drv* entrypoints.
39 */
40
41 #include <windows.h>
42 #include <GL/gl.h>
43
44 #include "util/u_debug.h"
45 #include "stw_gdishim.h"
46 #include "gldrv.h"
47 #include "stw_context.h"
48 #include "stw_pixelformat.h"
49 #include "stw_wgl.h"
50 #include "stw_ext_context.h"
51
52 WINGDIAPI BOOL APIENTRY
wglCopyContext(HGLRC hglrcSrc,HGLRC hglrcDst,UINT mask)53 wglCopyContext(
54 HGLRC hglrcSrc,
55 HGLRC hglrcDst,
56 UINT mask )
57 {
58 return DrvCopyContext( (DHGLRC)(UINT_PTR)hglrcSrc,
59 (DHGLRC)(UINT_PTR)hglrcDst,
60 mask );
61 }
62
63 WINGDIAPI HGLRC APIENTRY
wglCreateContext(HDC hdc)64 wglCreateContext(
65 HDC hdc )
66 {
67 stw_override_opengl32_entry_points(&wglCreateContext, &wglDeleteContext);
68 return (HGLRC)(UINT_PTR)DrvCreateContext(hdc);
69 }
70
71 WINGDIAPI HGLRC APIENTRY
wglCreateLayerContext(HDC hdc,int iLayerPlane)72 wglCreateLayerContext(
73 HDC hdc,
74 int iLayerPlane )
75 {
76 stw_override_opengl32_entry_points(&wglCreateContext, &wglDeleteContext);
77 return (HGLRC)(UINT_PTR)DrvCreateLayerContext( hdc, iLayerPlane );
78 }
79
80 WINGDIAPI BOOL APIENTRY
wglDeleteContext(HGLRC hglrc)81 wglDeleteContext(
82 HGLRC hglrc )
83 {
84 DrvReleaseContext((DHGLRC)(UINT_PTR)hglrc);
85 return DrvDeleteContext((DHGLRC)(UINT_PTR)hglrc );
86 }
87
88
89 WINGDIAPI HGLRC APIENTRY
wglGetCurrentContext(VOID)90 wglGetCurrentContext( VOID )
91 {
92 return (HGLRC)(UINT_PTR)stw_get_current_context();
93 }
94
95 WINGDIAPI HDC APIENTRY
wglGetCurrentDC(VOID)96 wglGetCurrentDC( VOID )
97 {
98 return stw_get_current_dc();
99 }
100
101
102 WINGDIAPI BOOL APIENTRY
wglMakeCurrent(HDC hdc,HGLRC hglrc)103 wglMakeCurrent(
104 HDC hdc,
105 HGLRC hglrc )
106 {
107 return DrvSetContext( hdc, (DHGLRC)(UINT_PTR)hglrc, NULL ) ? true : false;
108 }
109
110
111 WINGDIAPI BOOL APIENTRY
wglSwapBuffers(HDC hdc)112 wglSwapBuffers(
113 HDC hdc )
114 {
115 return DrvSwapBuffers( hdc );
116 }
117
118
119 WINGDIAPI DWORD WINAPI
wglSwapMultipleBuffers(UINT n,CONST WGLSWAP * ps)120 wglSwapMultipleBuffers(UINT n,
121 CONST WGLSWAP *ps)
122 {
123 UINT i;
124
125 for (i =0; i < n; ++i)
126 wglSwapBuffers(ps->hdc);
127
128 return 0;
129 }
130
131
132 WINGDIAPI BOOL APIENTRY
wglSwapLayerBuffers(HDC hdc,UINT fuPlanes)133 wglSwapLayerBuffers(
134 HDC hdc,
135 UINT fuPlanes )
136 {
137 return DrvSwapLayerBuffers( hdc, fuPlanes );
138 }
139
140 WINGDIAPI PROC APIENTRY
wglGetProcAddress(LPCSTR lpszProc)141 wglGetProcAddress(
142 LPCSTR lpszProc )
143 {
144 return DrvGetProcAddress( lpszProc );
145 }
146
147
148 WINGDIAPI int APIENTRY
wglChoosePixelFormat(HDC hdc,CONST PIXELFORMATDESCRIPTOR * ppfd)149 wglChoosePixelFormat(
150 HDC hdc,
151 CONST PIXELFORMATDESCRIPTOR *ppfd )
152 {
153 if (ppfd->nSize != sizeof( PIXELFORMATDESCRIPTOR ) || ppfd->nVersion != 1)
154 return 0;
155 if (ppfd->iPixelType != PFD_TYPE_RGBA)
156 return 0;
157 if (!(ppfd->dwFlags & PFD_DRAW_TO_WINDOW))
158 return 0;
159 if (!(ppfd->dwFlags & PFD_SUPPORT_OPENGL))
160 return 0;
161 if (ppfd->dwFlags & PFD_DRAW_TO_BITMAP)
162 return 0;
163 if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO))
164 return 0;
165
166 return stw_pixelformat_choose( hdc, ppfd );
167 }
168
169 WINGDIAPI int APIENTRY
wglDescribePixelFormat(HDC hdc,int iPixelFormat,UINT nBytes,LPPIXELFORMATDESCRIPTOR ppfd)170 wglDescribePixelFormat(
171 HDC hdc,
172 int iPixelFormat,
173 UINT nBytes,
174 LPPIXELFORMATDESCRIPTOR ppfd )
175 {
176 return DrvDescribePixelFormat( hdc, iPixelFormat, nBytes, ppfd );
177 }
178
179 WINGDIAPI int APIENTRY
wglGetPixelFormat(HDC hdc)180 wglGetPixelFormat(
181 HDC hdc )
182 {
183 return stw_pixelformat_get( hdc );
184 }
185
186 WINGDIAPI BOOL APIENTRY
wglSetPixelFormat(HDC hdc,int iPixelFormat,const PIXELFORMATDESCRIPTOR * ppfd)187 wglSetPixelFormat(
188 HDC hdc,
189 int iPixelFormat,
190 const PIXELFORMATDESCRIPTOR *ppfd )
191 {
192 /* SetPixelFormat (hence wglSetPixelFormat) must not touch ppfd, per
193 * http://msdn.microsoft.com/en-us/library/dd369049(v=vs.85).aspx
194 */
195 (void) ppfd;
196
197 return DrvSetPixelFormat( hdc, iPixelFormat );
198 }
199
200
201 WINGDIAPI BOOL APIENTRY
wglUseFontBitmapsA(HDC hdc,DWORD first,DWORD count,DWORD listBase)202 wglUseFontBitmapsA(
203 HDC hdc,
204 DWORD first,
205 DWORD count,
206 DWORD listBase )
207 {
208 return wglUseFontBitmapsW(hdc, first, count, listBase);
209 }
210
211 WINGDIAPI BOOL APIENTRY
wglShareLists(HGLRC hglrc1,HGLRC hglrc2)212 wglShareLists(
213 HGLRC hglrc1,
214 HGLRC hglrc2 )
215 {
216 return DrvShareLists((DHGLRC)(UINT_PTR)hglrc1,
217 (DHGLRC)(UINT_PTR)hglrc2);
218 }
219
220 WINGDIAPI BOOL APIENTRY
wglUseFontBitmapsW(HDC hdc,DWORD first,DWORD count,DWORD listBase)221 wglUseFontBitmapsW(
222 HDC hdc,
223 DWORD first,
224 DWORD count,
225 DWORD listBase )
226 {
227 #ifndef _GAMING_XBOX
228 GLYPHMETRICS gm;
229 MAT2 tra;
230 FIXED one, minus_one, zero;
231 void *buffer = NULL;
232 BOOL result = true;
233
234 one.value = 1;
235 one.fract = 0;
236 minus_one.value = -1;
237 minus_one.fract = 0;
238 zero.value = 0;
239 zero.fract = 0;
240
241 tra.eM11 = one;
242 tra.eM22 = minus_one;
243 tra.eM12 = tra.eM21 = zero;
244
245 for (int i = 0; i < count; i++) {
246 DWORD size = GetGlyphOutline(hdc, first + i, GGO_BITMAP, &gm, 0,
247 NULL, &tra);
248
249 glNewList(listBase + i, GL_COMPILE);
250
251 if (size != GDI_ERROR) {
252 if (size == 0) {
253 glBitmap(0, 0, (GLfloat)-gm.gmptGlyphOrigin.x,
254 (GLfloat)gm.gmptGlyphOrigin.y,
255 (GLfloat)gm.gmCellIncX,
256 (GLfloat)gm.gmCellIncY, NULL);
257 }
258 else {
259 buffer = realloc(buffer, size);
260 size = GetGlyphOutline(hdc, first + i, GGO_BITMAP, &gm,
261 size, buffer, &tra);
262
263 glBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
264 -gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y,
265 gm.gmCellIncX, gm.gmCellIncY, buffer);
266 }
267 }
268 else {
269 result = false;
270 }
271
272 glEndList();
273 }
274
275 free(buffer);
276
277 return result;
278 #else
279 return false;
280 #endif /* _GAMING_XBOX */
281 }
282
283 WINGDIAPI BOOL APIENTRY
wglUseFontOutlinesA(HDC hdc,DWORD first,DWORD count,DWORD listBase,FLOAT deviation,FLOAT extrusion,int format,LPGLYPHMETRICSFLOAT lpgmf)284 wglUseFontOutlinesA(
285 HDC hdc,
286 DWORD first,
287 DWORD count,
288 DWORD listBase,
289 FLOAT deviation,
290 FLOAT extrusion,
291 int format,
292 LPGLYPHMETRICSFLOAT lpgmf )
293 {
294 (void) hdc;
295 (void) first;
296 (void) count;
297 (void) listBase;
298 (void) deviation;
299 (void) extrusion;
300 (void) format;
301 (void) lpgmf;
302
303 assert( 0 );
304
305 return false;
306 }
307
308 WINGDIAPI BOOL APIENTRY
wglUseFontOutlinesW(HDC hdc,DWORD first,DWORD count,DWORD listBase,FLOAT deviation,FLOAT extrusion,int format,LPGLYPHMETRICSFLOAT lpgmf)309 wglUseFontOutlinesW(
310 HDC hdc,
311 DWORD first,
312 DWORD count,
313 DWORD listBase,
314 FLOAT deviation,
315 FLOAT extrusion,
316 int format,
317 LPGLYPHMETRICSFLOAT lpgmf )
318 {
319 (void) hdc;
320 (void) first;
321 (void) count;
322 (void) listBase;
323 (void) deviation;
324 (void) extrusion;
325 (void) format;
326 (void) lpgmf;
327
328 assert( 0 );
329
330 return false;
331 }
332
333 WINGDIAPI BOOL APIENTRY
wglDescribeLayerPlane(HDC hdc,int iPixelFormat,int iLayerPlane,UINT nBytes,LPLAYERPLANEDESCRIPTOR plpd)334 wglDescribeLayerPlane(
335 HDC hdc,
336 int iPixelFormat,
337 int iLayerPlane,
338 UINT nBytes,
339 LPLAYERPLANEDESCRIPTOR plpd )
340 {
341 return DrvDescribeLayerPlane(hdc, iPixelFormat, iLayerPlane, nBytes, plpd);
342 }
343
344 WINGDIAPI int APIENTRY
wglSetLayerPaletteEntries(HDC hdc,int iLayerPlane,int iStart,int cEntries,CONST COLORREF * pcr)345 wglSetLayerPaletteEntries(
346 HDC hdc,
347 int iLayerPlane,
348 int iStart,
349 int cEntries,
350 CONST COLORREF *pcr )
351 {
352 return DrvSetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr);
353 }
354
355 WINGDIAPI int APIENTRY
wglGetLayerPaletteEntries(HDC hdc,int iLayerPlane,int iStart,int cEntries,COLORREF * pcr)356 wglGetLayerPaletteEntries(
357 HDC hdc,
358 int iLayerPlane,
359 int iStart,
360 int cEntries,
361 COLORREF *pcr )
362 {
363 return DrvGetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr);
364 }
365
366 WINGDIAPI BOOL APIENTRY
wglRealizeLayerPalette(HDC hdc,int iLayerPlane,BOOL bRealize)367 wglRealizeLayerPalette(
368 HDC hdc,
369 int iLayerPlane,
370 BOOL bRealize )
371 {
372 (void) hdc;
373 (void) iLayerPlane;
374 (void) bRealize;
375
376 assert( 0 );
377
378 return false;
379 }
380
381
382