1 | /* $Id: icd_drv.c 15820 2009-01-06 15:37:59Z 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 |
|
---|
28 | #include <windows.h>
|
---|
29 |
|
---|
30 | //TODO: consider
|
---|
31 | /* We can modify chronium dispatch table functions order to match the one required by ICD,
|
---|
32 | * but it'd render us incompatible with other chromium SPUs and require more changes.
|
---|
33 | * In current state, we can use unmodified binary chromium SPUs. Question is do we need it?
|
---|
34 | */
|
---|
35 |
|
---|
36 | #define GL_FUNC(func) cr_gl##func
|
---|
37 |
|
---|
38 | static ICDTABLE icdTable = { 336, {
|
---|
39 | #define ICD_ENTRY(func) (PROC)GL_FUNC(func),
|
---|
40 | #include "VBoxICDList.h"
|
---|
41 | #undef ICD_ENTRY
|
---|
42 | } };
|
---|
43 |
|
---|
44 | static GLuint desiredVisual = CR_RGB_BIT;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Compute a mask of CR_*_BIT flags which reflects the attributes of
|
---|
48 | * the pixel format of the given hdc.
|
---|
49 | */
|
---|
50 | static GLuint ComputeVisBits( HDC hdc )
|
---|
51 | {
|
---|
52 | PIXELFORMATDESCRIPTOR pfd;
|
---|
53 | int iPixelFormat;
|
---|
54 | GLuint b = 0;
|
---|
55 |
|
---|
56 | iPixelFormat = GetPixelFormat( hdc );
|
---|
57 |
|
---|
58 | DescribePixelFormat( hdc, iPixelFormat, sizeof(pfd), &pfd );
|
---|
59 |
|
---|
60 | if (pfd.cDepthBits > 0)
|
---|
61 | b |= CR_DEPTH_BIT;
|
---|
62 | if (pfd.cAccumBits > 0)
|
---|
63 | b |= CR_ACCUM_BIT;
|
---|
64 | if (pfd.cColorBits > 8)
|
---|
65 | b |= CR_RGB_BIT;
|
---|
66 | if (pfd.cStencilBits > 0)
|
---|
67 | b |= CR_STENCIL_BIT;
|
---|
68 | if (pfd.cAlphaBits > 0)
|
---|
69 | b |= CR_ALPHA_BIT;
|
---|
70 | if (pfd.dwFlags & PFD_DOUBLEBUFFER)
|
---|
71 | b |= CR_DOUBLE_BIT;
|
---|
72 | if (pfd.dwFlags & PFD_STEREO)
|
---|
73 | b |= CR_STEREO_BIT;
|
---|
74 |
|
---|
75 | return b;
|
---|
76 | }
|
---|
77 |
|
---|
78 | void APIENTRY DrvReleaseContext(HGLRC hglrc)
|
---|
79 | {
|
---|
80 | /*crDebug( "DrvReleaseContext(%x) called", hglrc );*/
|
---|
81 | stubMakeCurrent( NULL, NULL );
|
---|
82 | }
|
---|
83 |
|
---|
84 | BOOL APIENTRY DrvValidateVersion(DWORD version)
|
---|
85 | {
|
---|
86 | if (stubInit()) {
|
---|
87 | crDebug("DrvValidateVersion %x -> TRUE\n", version);
|
---|
88 | return TRUE;
|
---|
89 | }
|
---|
90 |
|
---|
91 | crNetTearDown();
|
---|
92 | crDebug("DrvValidateVersion %x -> FALSE, going to use system default opengl32.dll\n", version);
|
---|
93 | return FALSE;
|
---|
94 | }
|
---|
95 |
|
---|
96 | //we're not going to change icdTable at runtime, so callback is unused
|
---|
97 | PICDTABLE APIENTRY DrvSetContext(HDC hdc, HGLRC hglrc, void *callback)
|
---|
98 | {
|
---|
99 | ContextInfo *context;
|
---|
100 | WindowInfo *window;
|
---|
101 |
|
---|
102 | /*crDebug( "DrvSetContext called(%x, %x)", hdc, hglrc );*/
|
---|
103 | (void) (callback);
|
---|
104 |
|
---|
105 | context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
|
---|
106 | window = stubGetWindowInfo(hdc);
|
---|
107 |
|
---|
108 | if (stubMakeCurrent( window, context )) {
|
---|
109 | return &icdTable;
|
---|
110 | }
|
---|
111 | else {
|
---|
112 | return NULL;
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | BOOL APIENTRY DrvSetPixelFormat(HDC hdc, int iPixelFormat)
|
---|
117 | {
|
---|
118 | crDebug( "DrvSetPixelFormat called.\n" );
|
---|
119 |
|
---|
120 | if ( iPixelFormat != 1 ) {
|
---|
121 | crError( "wglSetPixelFormat: iPixelFormat=%d?\n", iPixelFormat );
|
---|
122 | }
|
---|
123 |
|
---|
124 | return 1;
|
---|
125 | }
|
---|
126 |
|
---|
127 | HGLRC APIENTRY DrvCreateContext(HDC hdc)
|
---|
128 | {
|
---|
129 | char dpyName[MAX_DPY_NAME];
|
---|
130 | ContextInfo *context;
|
---|
131 |
|
---|
132 | crDebug( "DrvCreateContext called.\n" );
|
---|
133 |
|
---|
134 | stubInit();
|
---|
135 |
|
---|
136 | CRASSERT(stub.contextTable);
|
---|
137 |
|
---|
138 | sprintf(dpyName, "%d", hdc);
|
---|
139 | if (stub.haveNativeOpenGL)
|
---|
140 | desiredVisual |= ComputeVisBits( hdc );
|
---|
141 |
|
---|
142 | context = stubNewContext(dpyName, desiredVisual, UNDECIDED, 0);
|
---|
143 | if (!context)
|
---|
144 | return 0;
|
---|
145 |
|
---|
146 | return (HGLRC) context->id;
|
---|
147 | }
|
---|
148 |
|
---|
149 | HGLRC APIENTRY DrvCreateLayerContext(HDC hdc, int iLayerPlane)
|
---|
150 | {
|
---|
151 | //We don't support more than 1 layers.
|
---|
152 | if (iLayerPlane == 0) {
|
---|
153 | return DrvCreateContext(hdc);
|
---|
154 | } else {
|
---|
155 | crError( "DrvCreateLayerContext (%x,%x): unsupported", hdc, iLayerPlane);
|
---|
156 | return NULL;
|
---|
157 | }
|
---|
158 |
|
---|
159 | }
|
---|
160 |
|
---|
161 | BOOL APIENTRY DrvDescribeLayerPlane(HDC hdc,int iPixelFormat,
|
---|
162 | int iLayerPlane, UINT nBytes,
|
---|
163 | LPLAYERPLANEDESCRIPTOR plpd)
|
---|
164 | {
|
---|
165 | crWarning( "DrvDescribeLayerPlane: unimplemented" );
|
---|
166 | CRASSERT(false);
|
---|
167 | return 0;
|
---|
168 | }
|
---|
169 |
|
---|
170 | int APIENTRY DrvGetLayerPaletteEntries(HDC hdc, int iLayerPlane,
|
---|
171 | int iStart, int cEntries,
|
---|
172 | COLORREF *pcr)
|
---|
173 | {
|
---|
174 | crWarning( "DrvGetLayerPaletteEntries: unsupported" );
|
---|
175 | CRASSERT(false);
|
---|
176 | return 0;
|
---|
177 | }
|
---|
178 |
|
---|
179 | int APIENTRY DrvDescribePixelFormat(HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR pfd)
|
---|
180 | {
|
---|
181 | if ( !pfd ) {
|
---|
182 | return 1; /* There's only one, baby */
|
---|
183 | }
|
---|
184 |
|
---|
185 | if ( nBytes != sizeof(*pfd) ) {
|
---|
186 | crWarning( "DrvDescribePixelFormat: nBytes=%u?\n", nBytes );
|
---|
187 | return 1; /* There's only one, baby */
|
---|
188 | }
|
---|
189 |
|
---|
190 | pfd->nSize = sizeof(*pfd);
|
---|
191 | pfd->nVersion = 1;
|
---|
192 | pfd->dwFlags = ( PFD_DRAW_TO_WINDOW |
|
---|
193 | PFD_SUPPORT_GDI |
|
---|
194 | PFD_SUPPORT_OPENGL |
|
---|
195 | PFD_DOUBLEBUFFER );
|
---|
196 | pfd->iPixelType = PFD_TYPE_RGBA;
|
---|
197 | pfd->cColorBits = 32;
|
---|
198 | pfd->cRedBits = 8;
|
---|
199 | pfd->cRedShift = 24;
|
---|
200 | pfd->cGreenBits = 8;
|
---|
201 | pfd->cGreenShift = 16;
|
---|
202 | pfd->cBlueBits = 8;
|
---|
203 | pfd->cBlueShift = 8;
|
---|
204 | pfd->cAlphaBits = 8;
|
---|
205 | pfd->cAlphaShift = 0;
|
---|
206 | pfd->cAccumBits = 0;
|
---|
207 | pfd->cAccumRedBits = 0;
|
---|
208 | pfd->cAccumGreenBits = 0;
|
---|
209 | pfd->cAccumBlueBits = 0;
|
---|
210 | pfd->cAccumAlphaBits = 0;
|
---|
211 | pfd->cDepthBits = 32;
|
---|
212 | pfd->cStencilBits = 8;
|
---|
213 | pfd->cAuxBuffers = 0;
|
---|
214 | pfd->iLayerType = PFD_MAIN_PLANE;
|
---|
215 | pfd->bReserved = 0;
|
---|
216 | pfd->dwLayerMask = 0;
|
---|
217 | pfd->dwVisibleMask = 0;
|
---|
218 | pfd->dwDamageMask = 0;
|
---|
219 |
|
---|
220 | /* the max PFD index */
|
---|
221 | return 1;
|
---|
222 | }
|
---|
223 |
|
---|
224 | BOOL APIENTRY DrvDeleteContext(HGLRC hglrc)
|
---|
225 | {
|
---|
226 | stubDestroyContext( (unsigned long) hglrc );
|
---|
227 | return 1;
|
---|
228 | }
|
---|
229 |
|
---|
230 | BOOL APIENTRY DrvCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
|
---|
231 | {
|
---|
232 | crWarning( "DrvCopyContext: unsupported" );
|
---|
233 | return 0;
|
---|
234 | }
|
---|
235 |
|
---|
236 | BOOL APIENTRY DrvShareLists(HGLRC hglrc1, HGLRC hglrc2)
|
---|
237 | {
|
---|
238 | crWarning( "DrvShareLists: unsupported" );
|
---|
239 | return 0;
|
---|
240 | }
|
---|
241 |
|
---|
242 | int APIENTRY DrvSetLayerPaletteEntries(HDC hdc, int iLayerPlane,
|
---|
243 | int iStart, int cEntries,
|
---|
244 | CONST COLORREF *pcr)
|
---|
245 | {
|
---|
246 | crWarning( "DrvSetLayerPaletteEntries: unsupported" );
|
---|
247 | return 0;
|
---|
248 | }
|
---|
249 |
|
---|
250 |
|
---|
251 | BOOL APIENTRY DrvRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize)
|
---|
252 | {
|
---|
253 | crWarning( "DrvRealizeLayerPalette: unsupported" );
|
---|
254 | return 0;
|
---|
255 | }
|
---|
256 |
|
---|
257 | BOOL APIENTRY DrvSwapLayerBuffers(HDC hdc, UINT fuPlanes)
|
---|
258 | {
|
---|
259 | if (fuPlanes == 1)
|
---|
260 | {
|
---|
261 | DrvSwapBuffers(hdc);
|
---|
262 | return 1;
|
---|
263 | }
|
---|
264 | else
|
---|
265 | {
|
---|
266 | crWarning( "DrvSwapLayerBuffers: unsupported" );
|
---|
267 | CRASSERT(false);
|
---|
268 | return 0;
|
---|
269 | }
|
---|
270 | }
|
---|
271 |
|
---|
272 | BOOL APIENTRY DrvSwapBuffers(HDC hdc)
|
---|
273 | {
|
---|
274 | const WindowInfo *window;
|
---|
275 | //crDebug( "DrvSwapBuffers(%x) called", hdc );
|
---|
276 | window = stubGetWindowInfo(hdc);
|
---|
277 | stubSwapBuffers( window, 0 );
|
---|
278 | return 1;
|
---|
279 | }
|
---|