1 | /* $Id: icd_drv.c 23274 2009-09-24 09:31:32Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox OpenGL windows ICD driver functions
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2008 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include "cr_error.h"
|
---|
24 | #include "icd_drv.h"
|
---|
25 | #include "cr_gl.h"
|
---|
26 | #include "stub.h"
|
---|
27 | #include "cr_mem.h"
|
---|
28 |
|
---|
29 | #include <windows.h>
|
---|
30 |
|
---|
31 | //TODO: consider
|
---|
32 | /* We can modify chronium dispatch table functions order to match the one required by ICD,
|
---|
33 | * but it'd render us incompatible with other chromium SPUs and require more changes.
|
---|
34 | * In current state, we can use unmodified binary chromium SPUs. Question is do we need it?
|
---|
35 | */
|
---|
36 |
|
---|
37 | #define GL_FUNC(func) cr_gl##func
|
---|
38 |
|
---|
39 | static ICDTABLE icdTable = { 336, {
|
---|
40 | #define ICD_ENTRY(func) (PROC)GL_FUNC(func),
|
---|
41 | #include "VBoxICDList.h"
|
---|
42 | #undef ICD_ENTRY
|
---|
43 | } };
|
---|
44 |
|
---|
45 | static GLuint desiredVisual = CR_RGB_BIT;
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Compute a mask of CR_*_BIT flags which reflects the attributes of
|
---|
49 | * the pixel format of the given hdc.
|
---|
50 | */
|
---|
51 | static GLuint ComputeVisBits( HDC hdc )
|
---|
52 | {
|
---|
53 | PIXELFORMATDESCRIPTOR pfd;
|
---|
54 | int iPixelFormat;
|
---|
55 | GLuint b = 0;
|
---|
56 |
|
---|
57 | iPixelFormat = GetPixelFormat( hdc );
|
---|
58 |
|
---|
59 | DescribePixelFormat( hdc, iPixelFormat, sizeof(pfd), &pfd );
|
---|
60 |
|
---|
61 | if (pfd.cDepthBits > 0)
|
---|
62 | b |= CR_DEPTH_BIT;
|
---|
63 | if (pfd.cAccumBits > 0)
|
---|
64 | b |= CR_ACCUM_BIT;
|
---|
65 | if (pfd.cColorBits > 8)
|
---|
66 | b |= CR_RGB_BIT;
|
---|
67 | if (pfd.cStencilBits > 0)
|
---|
68 | b |= CR_STENCIL_BIT;
|
---|
69 | if (pfd.cAlphaBits > 0)
|
---|
70 | b |= CR_ALPHA_BIT;
|
---|
71 | if (pfd.dwFlags & PFD_DOUBLEBUFFER)
|
---|
72 | b |= CR_DOUBLE_BIT;
|
---|
73 | if (pfd.dwFlags & PFD_STEREO)
|
---|
74 | b |= CR_STEREO_BIT;
|
---|
75 |
|
---|
76 | return b;
|
---|
77 | }
|
---|
78 |
|
---|
79 | void APIENTRY DrvReleaseContext(HGLRC hglrc)
|
---|
80 | {
|
---|
81 | /*crDebug( "DrvReleaseContext(0x%x) called", hglrc );*/
|
---|
82 | stubMakeCurrent( NULL, NULL );
|
---|
83 | }
|
---|
84 |
|
---|
85 | BOOL APIENTRY DrvValidateVersion(DWORD version)
|
---|
86 | {
|
---|
87 | if (stubInit()) {
|
---|
88 | crDebug("DrvValidateVersion %x -> TRUE\n", version);
|
---|
89 | return TRUE;
|
---|
90 | }
|
---|
91 |
|
---|
92 | crNetTearDown();
|
---|
93 | crDebug("DrvValidateVersion %x -> FALSE, going to use system default opengl32.dll\n", version);
|
---|
94 | return FALSE;
|
---|
95 | }
|
---|
96 |
|
---|
97 | //we're not going to change icdTable at runtime, so callback is unused
|
---|
98 | PICDTABLE APIENTRY DrvSetContext(HDC hdc, HGLRC hglrc, void *callback)
|
---|
99 | {
|
---|
100 | ContextInfo *context;
|
---|
101 | WindowInfo *window;
|
---|
102 |
|
---|
103 | /*crDebug( "DrvSetContext called(0x%x, 0x%x)", hdc, hglrc );*/
|
---|
104 | (void) (callback);
|
---|
105 |
|
---|
106 | context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
|
---|
107 | window = stubGetWindowInfo(hdc);
|
---|
108 |
|
---|
109 | if (stubMakeCurrent( window, context )) {
|
---|
110 | return &icdTable;
|
---|
111 | }
|
---|
112 | else {
|
---|
113 | return NULL;
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | BOOL APIENTRY DrvSetPixelFormat(HDC hdc, int iPixelFormat)
|
---|
118 | {
|
---|
119 | crDebug( "DrvSetPixelFormat(0x%x, %i) called.", hdc, iPixelFormat );
|
---|
120 |
|
---|
121 | if ( (iPixelFormat<1) || (iPixelFormat>2) ) {
|
---|
122 | crError( "wglSetPixelFormat: iPixelFormat=%d?", iPixelFormat );
|
---|
123 | }
|
---|
124 |
|
---|
125 | return 1;
|
---|
126 | }
|
---|
127 |
|
---|
128 | HGLRC APIENTRY DrvCreateContext(HDC hdc)
|
---|
129 | {
|
---|
130 | char dpyName[MAX_DPY_NAME];
|
---|
131 | ContextInfo *context;
|
---|
132 |
|
---|
133 | crDebug( "DrvCreateContext(0x%x) called.", hdc);
|
---|
134 |
|
---|
135 | stubInit();
|
---|
136 |
|
---|
137 | CRASSERT(stub.contextTable);
|
---|
138 |
|
---|
139 | sprintf(dpyName, "%d", hdc);
|
---|
140 | if (stub.haveNativeOpenGL)
|
---|
141 | desiredVisual |= ComputeVisBits( hdc );
|
---|
142 |
|
---|
143 | context = stubNewContext(dpyName, desiredVisual, UNDECIDED, 0);
|
---|
144 | if (!context)
|
---|
145 | return 0;
|
---|
146 |
|
---|
147 | return (HGLRC) context->id;
|
---|
148 | }
|
---|
149 |
|
---|
150 | HGLRC APIENTRY DrvCreateLayerContext(HDC hdc, int iLayerPlane)
|
---|
151 | {
|
---|
152 | crDebug( "DrvCreateLayerContext(0x%x, %i) called.", hdc, iLayerPlane);
|
---|
153 | //We don't support more than 1 layers.
|
---|
154 | if (iLayerPlane == 0) {
|
---|
155 | return DrvCreateContext(hdc);
|
---|
156 | } else {
|
---|
157 | crError( "DrvCreateLayerContext (%x,%x): unsupported", hdc, iLayerPlane);
|
---|
158 | return NULL;
|
---|
159 | }
|
---|
160 |
|
---|
161 | }
|
---|
162 |
|
---|
163 | BOOL APIENTRY DrvDescribeLayerPlane(HDC hdc,int iPixelFormat,
|
---|
164 | int iLayerPlane, UINT nBytes,
|
---|
165 | LPLAYERPLANEDESCRIPTOR plpd)
|
---|
166 | {
|
---|
167 | crWarning( "DrvDescribeLayerPlane: unimplemented" );
|
---|
168 | CRASSERT(false);
|
---|
169 | return 0;
|
---|
170 | }
|
---|
171 |
|
---|
172 | int APIENTRY DrvGetLayerPaletteEntries(HDC hdc, int iLayerPlane,
|
---|
173 | int iStart, int cEntries,
|
---|
174 | COLORREF *pcr)
|
---|
175 | {
|
---|
176 | crWarning( "DrvGetLayerPaletteEntries: unsupported" );
|
---|
177 | CRASSERT(false);
|
---|
178 | return 0;
|
---|
179 | }
|
---|
180 |
|
---|
181 | int APIENTRY DrvDescribePixelFormat(HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR pfd)
|
---|
182 | {
|
---|
183 | if ( !pfd ) {
|
---|
184 | return 2;
|
---|
185 | }
|
---|
186 |
|
---|
187 | if ( nBytes != sizeof(*pfd) ) {
|
---|
188 | crWarning( "DrvDescribePixelFormat: nBytes=%u?", nBytes );
|
---|
189 | return 2;
|
---|
190 | }
|
---|
191 |
|
---|
192 | if (iPixelFormat==1)
|
---|
193 | {
|
---|
194 | crMemZero(pfd, sizeof(*pfd));
|
---|
195 |
|
---|
196 | pfd->nSize = sizeof(*pfd);
|
---|
197 | pfd->nVersion = 1;
|
---|
198 | pfd->dwFlags = (PFD_DRAW_TO_WINDOW |
|
---|
199 | PFD_SUPPORT_OPENGL |
|
---|
200 | PFD_DOUBLEBUFFER);
|
---|
201 | pfd->iPixelType = PFD_TYPE_RGBA;
|
---|
202 | pfd->cColorBits = 32;
|
---|
203 | pfd->cRedBits = 8;
|
---|
204 | pfd->cRedShift = 24;
|
---|
205 | pfd->cGreenBits = 8;
|
---|
206 | pfd->cGreenShift = 16;
|
---|
207 | pfd->cBlueBits = 8;
|
---|
208 | pfd->cBlueShift = 8;
|
---|
209 | pfd->cAlphaBits = 8;
|
---|
210 | pfd->cAlphaShift = 0;
|
---|
211 | pfd->cAccumBits = 0;
|
---|
212 | pfd->cAccumRedBits = 0;
|
---|
213 | pfd->cAccumGreenBits = 0;
|
---|
214 | pfd->cAccumBlueBits = 0;
|
---|
215 | pfd->cAccumAlphaBits = 0;
|
---|
216 | pfd->cDepthBits = 32;
|
---|
217 | pfd->cStencilBits = 8;
|
---|
218 | pfd->cAuxBuffers = 0;
|
---|
219 | pfd->iLayerType = PFD_MAIN_PLANE;
|
---|
220 | pfd->bReserved = 0;
|
---|
221 | pfd->dwLayerMask = 0;
|
---|
222 | pfd->dwVisibleMask = 0;
|
---|
223 | pfd->dwDamageMask = 0;
|
---|
224 | }
|
---|
225 | else
|
---|
226 | {
|
---|
227 | crMemZero(pfd, sizeof(*pfd));
|
---|
228 | pfd->nVersion = 1;
|
---|
229 | pfd->dwFlags = (PFD_DRAW_TO_WINDOW|
|
---|
230 | PFD_SUPPORT_OPENGL);
|
---|
231 |
|
---|
232 | pfd->iPixelType = PFD_TYPE_RGBA;
|
---|
233 | pfd->cColorBits = 32;
|
---|
234 | pfd->cRedBits = 8;
|
---|
235 | pfd->cRedShift = 16;
|
---|
236 | pfd->cGreenBits = 8;
|
---|
237 | pfd->cGreenShift = 8;
|
---|
238 | pfd->cBlueBits = 8;
|
---|
239 | pfd->cBlueShift = 0;
|
---|
240 | pfd->cAlphaBits = 0;
|
---|
241 | pfd->cAlphaShift = 0;
|
---|
242 | pfd->cAccumBits = 64;
|
---|
243 | pfd->cAccumRedBits = 16;
|
---|
244 | pfd->cAccumGreenBits = 16;
|
---|
245 | pfd->cAccumBlueBits = 16;
|
---|
246 | pfd->cAccumAlphaBits = 0;
|
---|
247 | pfd->cDepthBits = 16;
|
---|
248 | pfd->cStencilBits = 8;
|
---|
249 | pfd->cAuxBuffers = 0;
|
---|
250 | pfd->iLayerType = PFD_MAIN_PLANE;
|
---|
251 | pfd->bReserved = 0;
|
---|
252 | pfd->dwLayerMask = 0;
|
---|
253 | pfd->dwVisibleMask = 0;
|
---|
254 | pfd->dwDamageMask = 0;
|
---|
255 | }
|
---|
256 |
|
---|
257 | /* the max PFD index */
|
---|
258 | return 2;
|
---|
259 | }
|
---|
260 |
|
---|
261 | BOOL APIENTRY DrvDeleteContext(HGLRC hglrc)
|
---|
262 | {
|
---|
263 | /*crDebug( "DrvDeleteContext(0x%x) called", hglrc );*/
|
---|
264 | stubDestroyContext( (unsigned long) hglrc );
|
---|
265 | return 1;
|
---|
266 | }
|
---|
267 |
|
---|
268 | BOOL APIENTRY DrvCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
|
---|
269 | {
|
---|
270 | crWarning( "DrvCopyContext: unsupported" );
|
---|
271 | return 0;
|
---|
272 | }
|
---|
273 |
|
---|
274 | BOOL APIENTRY DrvShareLists(HGLRC hglrc1, HGLRC hglrc2)
|
---|
275 | {
|
---|
276 | crWarning( "DrvShareLists: unsupported" );
|
---|
277 | return 1;
|
---|
278 | }
|
---|
279 |
|
---|
280 | int APIENTRY DrvSetLayerPaletteEntries(HDC hdc, int iLayerPlane,
|
---|
281 | int iStart, int cEntries,
|
---|
282 | CONST COLORREF *pcr)
|
---|
283 | {
|
---|
284 | crWarning( "DrvSetLayerPaletteEntries: unsupported" );
|
---|
285 | return 0;
|
---|
286 | }
|
---|
287 |
|
---|
288 |
|
---|
289 | BOOL APIENTRY DrvRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize)
|
---|
290 | {
|
---|
291 | crWarning( "DrvRealizeLayerPalette: unsupported" );
|
---|
292 | return 0;
|
---|
293 | }
|
---|
294 |
|
---|
295 | BOOL APIENTRY DrvSwapLayerBuffers(HDC hdc, UINT fuPlanes)
|
---|
296 | {
|
---|
297 | if (fuPlanes == 1)
|
---|
298 | {
|
---|
299 | DrvSwapBuffers(hdc);
|
---|
300 | return 1;
|
---|
301 | }
|
---|
302 | else
|
---|
303 | {
|
---|
304 | crWarning( "DrvSwapLayerBuffers: unsupported" );
|
---|
305 | CRASSERT(false);
|
---|
306 | return 0;
|
---|
307 | }
|
---|
308 | }
|
---|
309 |
|
---|
310 | BOOL APIENTRY DrvSwapBuffers(HDC hdc)
|
---|
311 | {
|
---|
312 | const WindowInfo *window;
|
---|
313 | /*crDebug( "DrvSwapBuffers(0x%x) called", hdc );*/
|
---|
314 | window = stubGetWindowInfo(hdc);
|
---|
315 | stubSwapBuffers( window, 0 );
|
---|
316 | return 1;
|
---|
317 | }
|
---|