VirtualBox

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

Last change on this file since 42227 was 41971, checked in by vboxsync, 12 years ago

crOpenGL: report visual bits superset to avoid host context recreation misbehave

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.5 KB
Line 
1/* $Id: icd_drv.c 41971 2012-06-29 12:31:04Z 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
41/* Currently host part will misbehave re-creating context with proper visual bits
42 * if contexts with alternative visual bits is requested.
43 * For now we just report a superset of all visual bits to avoid that.
44 * Better to it on the host side as well?
45 * We could also implement properly multiple pixel formats,
46 * which should be done by implementing offscreen rendering or multiple host contexts.
47 * */
48#define VBOX_CROGL_USE_VBITS_SUPERSET
49
50#ifdef VBOX_CROGL_USE_VBITS_SUPERSET
51static GLuint desiredVisual = CR_RGB_BIT | CR_ALPHA_BIT | CR_DEPTH_BIT | CR_STENCIL_BIT | CR_ACCUM_BIT | CR_DOUBLE_BIT;
52#else
53static GLuint desiredVisual = CR_RGB_BIT;
54#endif
55
56#ifndef VBOX_CROGL_USE_VBITS_SUPERSET
57/**
58 * Compute a mask of CR_*_BIT flags which reflects the attributes of
59 * the pixel format of the given hdc.
60 */
61static GLuint ComputeVisBits( HDC hdc )
62{
63 PIXELFORMATDESCRIPTOR pfd;
64 int iPixelFormat;
65 GLuint b = 0;
66
67 iPixelFormat = GetPixelFormat( hdc );
68
69 DescribePixelFormat( hdc, iPixelFormat, sizeof(pfd), &pfd );
70
71 if (pfd.cDepthBits > 0)
72 b |= CR_DEPTH_BIT;
73 if (pfd.cAccumBits > 0)
74 b |= CR_ACCUM_BIT;
75 if (pfd.cColorBits > 8)
76 b |= CR_RGB_BIT;
77 if (pfd.cStencilBits > 0)
78 b |= CR_STENCIL_BIT;
79 if (pfd.cAlphaBits > 0)
80 b |= CR_ALPHA_BIT;
81 if (pfd.dwFlags & PFD_DOUBLEBUFFER)
82 b |= CR_DOUBLE_BIT;
83 if (pfd.dwFlags & PFD_STEREO)
84 b |= CR_STEREO_BIT;
85
86 return b;
87}
88#endif
89
90void APIENTRY DrvReleaseContext(HGLRC hglrc)
91{
92 CR_DDI_PROLOGUE();
93 /*crDebug( "DrvReleaseContext(0x%x) called", hglrc );*/
94 stubMakeCurrent( NULL, NULL );
95}
96
97BOOL APIENTRY DrvValidateVersion(DWORD version)
98{
99 CR_DDI_PROLOGUE();
100 if (stubInit()) {
101 crDebug("DrvValidateVersion %x -> TRUE\n", version);
102 return TRUE;
103 }
104
105 crDebug("DrvValidateVersion %x -> FALSE, going to use system default opengl32.dll\n", version);
106 return FALSE;
107}
108
109//we're not going to change icdTable at runtime, so callback is unused
110PICDTABLE APIENTRY DrvSetContext(HDC hdc, HGLRC hglrc, void *callback)
111{
112 ContextInfo *context;
113 WindowInfo *window;
114 BOOL ret;
115
116 CR_DDI_PROLOGUE();
117
118 /*crDebug( "DrvSetContext called(0x%x, 0x%x)", hdc, hglrc );*/
119 (void) (callback);
120
121 crHashtableLock(stub.windowTable);
122 crHashtableLock(stub.contextTable);
123
124 context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
125 window = stubGetWindowInfo(hdc);
126
127 ret = stubMakeCurrent(window, context);
128
129 crHashtableUnlock(stub.contextTable);
130 crHashtableUnlock(stub.windowTable);
131
132 return ret ? &icdTable:NULL;
133}
134
135BOOL APIENTRY DrvSetPixelFormat(HDC hdc, int iPixelFormat)
136{
137 CR_DDI_PROLOGUE();
138 crDebug( "DrvSetPixelFormat(0x%x, %i) called.", hdc, iPixelFormat );
139
140 if ( (iPixelFormat<1) || (iPixelFormat>2) ) {
141 crError( "wglSetPixelFormat: iPixelFormat=%d?", iPixelFormat );
142 }
143
144 return 1;
145}
146
147HGLRC APIENTRY DrvCreateContext(HDC hdc)
148{
149 char dpyName[MAX_DPY_NAME];
150 ContextInfo *context;
151
152 CR_DDI_PROLOGUE();
153
154 crDebug( "DrvCreateContext(0x%x) called.", hdc);
155
156 stubInit();
157
158 CRASSERT(stub.contextTable);
159
160 sprintf(dpyName, "%d", hdc);
161#ifndef VBOX_CROGL_USE_VBITS_SUPERSET
162 if (stub.haveNativeOpenGL)
163 desiredVisual |= ComputeVisBits( hdc );
164#endif
165
166 context = stubNewContext(dpyName, desiredVisual, UNDECIDED, 0);
167 if (!context)
168 return 0;
169
170 return (HGLRC) context->id;
171}
172
173HGLRC APIENTRY DrvCreateLayerContext(HDC hdc, int iLayerPlane)
174{
175 CR_DDI_PROLOGUE();
176 crDebug( "DrvCreateLayerContext(0x%x, %i) called.", hdc, iLayerPlane);
177 //We don't support more than 1 layers.
178 if (iLayerPlane == 0) {
179 return DrvCreateContext(hdc);
180 } else {
181 crError( "DrvCreateLayerContext (%x,%x): unsupported", hdc, iLayerPlane);
182 return NULL;
183 }
184
185}
186
187BOOL APIENTRY DrvDescribeLayerPlane(HDC hdc,int iPixelFormat,
188 int iLayerPlane, UINT nBytes,
189 LPLAYERPLANEDESCRIPTOR plpd)
190{
191 CR_DDI_PROLOGUE();
192 crWarning( "DrvDescribeLayerPlane: unimplemented" );
193 CRASSERT(false);
194 return 0;
195}
196
197int APIENTRY DrvGetLayerPaletteEntries(HDC hdc, int iLayerPlane,
198 int iStart, int cEntries,
199 COLORREF *pcr)
200{
201 CR_DDI_PROLOGUE();
202 crWarning( "DrvGetLayerPaletteEntries: unsupported" );
203 CRASSERT(false);
204 return 0;
205}
206
207int APIENTRY DrvDescribePixelFormat(HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR pfd)
208{
209 CR_DDI_PROLOGUE();
210 if ( !pfd ) {
211 return 2;
212 }
213
214 if ( nBytes != sizeof(*pfd) ) {
215 crWarning( "DrvDescribePixelFormat: nBytes=%u?", nBytes );
216 return 2;
217 }
218
219 if (iPixelFormat==1)
220 {
221 crMemZero(pfd, sizeof(*pfd));
222
223 pfd->nSize = sizeof(*pfd);
224 pfd->nVersion = 1;
225 pfd->dwFlags = (PFD_DRAW_TO_WINDOW |
226 PFD_SUPPORT_OPENGL |
227 PFD_DOUBLEBUFFER);
228
229 pfd->dwFlags |= 0x8000; /* <- Needed for VSG Open Inventor to be happy */
230
231 pfd->iPixelType = PFD_TYPE_RGBA;
232 pfd->cColorBits = 32;
233 pfd->cRedBits = 8;
234 pfd->cRedShift = 24;
235 pfd->cGreenBits = 8;
236 pfd->cGreenShift = 16;
237 pfd->cBlueBits = 8;
238 pfd->cBlueShift = 8;
239 pfd->cAlphaBits = 8;
240 pfd->cAlphaShift = 0;
241 pfd->cAccumBits = 0;
242 pfd->cAccumRedBits = 0;
243 pfd->cAccumGreenBits = 0;
244 pfd->cAccumBlueBits = 0;
245 pfd->cAccumAlphaBits = 0;
246 pfd->cDepthBits = 32;
247 pfd->cStencilBits = 8;
248 pfd->cAuxBuffers = 0;
249 pfd->iLayerType = PFD_MAIN_PLANE;
250 pfd->bReserved = 0;
251 pfd->dwLayerMask = 0;
252 pfd->dwVisibleMask = 0;
253 pfd->dwDamageMask = 0;
254 }
255 else
256 {
257 crMemZero(pfd, sizeof(*pfd));
258 pfd->nVersion = 1;
259 pfd->dwFlags = (PFD_DRAW_TO_WINDOW|
260 PFD_SUPPORT_OPENGL);
261
262 pfd->iPixelType = PFD_TYPE_RGBA;
263 pfd->cColorBits = 32;
264 pfd->cRedBits = 8;
265 pfd->cRedShift = 16;
266 pfd->cGreenBits = 8;
267 pfd->cGreenShift = 8;
268 pfd->cBlueBits = 8;
269 pfd->cBlueShift = 0;
270 pfd->cAlphaBits = 0;
271 pfd->cAlphaShift = 0;
272 pfd->cAccumBits = 64;
273 pfd->cAccumRedBits = 16;
274 pfd->cAccumGreenBits = 16;
275 pfd->cAccumBlueBits = 16;
276 pfd->cAccumAlphaBits = 0;
277 pfd->cDepthBits = 16;
278 pfd->cStencilBits = 8;
279 pfd->cAuxBuffers = 0;
280 pfd->iLayerType = PFD_MAIN_PLANE;
281 pfd->bReserved = 0;
282 pfd->dwLayerMask = 0;
283 pfd->dwVisibleMask = 0;
284 pfd->dwDamageMask = 0;
285 }
286
287 /* the max PFD index */
288 return 2;
289}
290
291BOOL APIENTRY DrvDeleteContext(HGLRC hglrc)
292{
293 CR_DDI_PROLOGUE();
294 /*crDebug( "DrvDeleteContext(0x%x) called", hglrc );*/
295 stubDestroyContext( (unsigned long) hglrc );
296 return 1;
297}
298
299BOOL APIENTRY DrvCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
300{
301 CR_DDI_PROLOGUE();
302 crWarning( "DrvCopyContext: unsupported" );
303 return 0;
304}
305
306BOOL APIENTRY DrvShareLists(HGLRC hglrc1, HGLRC hglrc2)
307{
308 CR_DDI_PROLOGUE();
309 crWarning( "DrvShareLists: unsupported" );
310 return 1;
311}
312
313int APIENTRY DrvSetLayerPaletteEntries(HDC hdc, int iLayerPlane,
314 int iStart, int cEntries,
315 CONST COLORREF *pcr)
316{
317 CR_DDI_PROLOGUE();
318 crWarning( "DrvSetLayerPaletteEntries: unsupported" );
319 return 0;
320}
321
322
323BOOL APIENTRY DrvRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize)
324{
325 CR_DDI_PROLOGUE();
326 crWarning( "DrvRealizeLayerPalette: unsupported" );
327 return 0;
328}
329
330BOOL APIENTRY DrvSwapLayerBuffers(HDC hdc, UINT fuPlanes)
331{
332 CR_DDI_PROLOGUE();
333 if (fuPlanes == 1)
334 {
335 return DrvSwapBuffers(hdc);
336 }
337 else
338 {
339 crWarning( "DrvSwapLayerBuffers: unsupported" );
340 CRASSERT(false);
341 return 0;
342 }
343}
344
345BOOL APIENTRY DrvSwapBuffers(HDC hdc)
346{
347 WindowInfo *window;
348
349 CR_DDI_PROLOGUE();
350 /*crDebug( "DrvSwapBuffers(0x%x) called", hdc );*/
351 window = stubGetWindowInfo(hdc);
352 stubSwapBuffers( window, 0 );
353 return 1;
354}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette