VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/icd_drv.c@ 35263

Last change on this file since 35263 was 34887, checked in by vboxsync, 13 years ago

crOpenGL/XPDM: fix explorer crashes on windows vista/win7 guests

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

© 2023 Oracle
ContactPrivacy policyTerms of Use