VirtualBox

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

Last change on this file since 51559 was 51559, checked in by vboxsync, 11 years ago

crOpenGL: wglShareLists support

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.6 KB
Line 
1/* $Id: icd_drv.c 51559 2014-06-05 21:18:41Z vboxsync $ */
2
3/** @file
4 * VBox OpenGL windows ICD driver functions
5 */
6
7/*
8 * Copyright (C) 2006-2012 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 defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
168 , NULL
169#endif
170 );
171 if (!context)
172 return 0;
173
174 return (HGLRC) context->id;
175}
176
177HGLRC APIENTRY DrvCreateLayerContext(HDC hdc, int iLayerPlane)
178{
179 CR_DDI_PROLOGUE();
180 crDebug( "DrvCreateLayerContext(0x%x, %i) called.", hdc, iLayerPlane);
181 //We don't support more than 1 layers.
182 if (iLayerPlane == 0) {
183 return DrvCreateContext(hdc);
184 } else {
185 crError( "DrvCreateLayerContext (%x,%x): unsupported", hdc, iLayerPlane);
186 return NULL;
187 }
188
189}
190
191BOOL APIENTRY DrvDescribeLayerPlane(HDC hdc,int iPixelFormat,
192 int iLayerPlane, UINT nBytes,
193 LPLAYERPLANEDESCRIPTOR plpd)
194{
195 CR_DDI_PROLOGUE();
196 crWarning( "DrvDescribeLayerPlane: unimplemented" );
197 CRASSERT(false);
198 return 0;
199}
200
201int APIENTRY DrvGetLayerPaletteEntries(HDC hdc, int iLayerPlane,
202 int iStart, int cEntries,
203 COLORREF *pcr)
204{
205 CR_DDI_PROLOGUE();
206 crWarning( "DrvGetLayerPaletteEntries: unsupported" );
207 CRASSERT(false);
208 return 0;
209}
210
211int APIENTRY DrvDescribePixelFormat(HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR pfd)
212{
213 CR_DDI_PROLOGUE();
214 if ( !pfd ) {
215 return 2;
216 }
217
218 if ( nBytes != sizeof(*pfd) ) {
219 crWarning( "DrvDescribePixelFormat: nBytes=%u?", nBytes );
220 return 2;
221 }
222
223 if (iPixelFormat==1)
224 {
225 crMemZero(pfd, sizeof(*pfd));
226
227 pfd->nSize = sizeof(*pfd);
228 pfd->nVersion = 1;
229 pfd->dwFlags = (PFD_DRAW_TO_WINDOW |
230 PFD_SUPPORT_OPENGL |
231 PFD_DOUBLEBUFFER);
232
233 pfd->dwFlags |= 0x8000; /* <- Needed for VSG Open Inventor to be happy */
234
235 pfd->iPixelType = PFD_TYPE_RGBA;
236 pfd->cColorBits = 32;
237 pfd->cRedBits = 8;
238 pfd->cRedShift = 24;
239 pfd->cGreenBits = 8;
240 pfd->cGreenShift = 16;
241 pfd->cBlueBits = 8;
242 pfd->cBlueShift = 8;
243 pfd->cAlphaBits = 8;
244 pfd->cAlphaShift = 0;
245 pfd->cAccumBits = 0;
246 pfd->cAccumRedBits = 0;
247 pfd->cAccumGreenBits = 0;
248 pfd->cAccumBlueBits = 0;
249 pfd->cAccumAlphaBits = 0;
250 pfd->cDepthBits = 32;
251 pfd->cStencilBits = 8;
252 pfd->cAuxBuffers = 0;
253 pfd->iLayerType = PFD_MAIN_PLANE;
254 pfd->bReserved = 0;
255 pfd->dwLayerMask = 0;
256 pfd->dwVisibleMask = 0;
257 pfd->dwDamageMask = 0;
258 }
259 else
260 {
261 crMemZero(pfd, sizeof(*pfd));
262 pfd->nVersion = 1;
263 pfd->dwFlags = (PFD_DRAW_TO_WINDOW|
264 PFD_SUPPORT_OPENGL);
265
266 pfd->iPixelType = PFD_TYPE_RGBA;
267 pfd->cColorBits = 32;
268 pfd->cRedBits = 8;
269 pfd->cRedShift = 16;
270 pfd->cGreenBits = 8;
271 pfd->cGreenShift = 8;
272 pfd->cBlueBits = 8;
273 pfd->cBlueShift = 0;
274 pfd->cAlphaBits = 0;
275 pfd->cAlphaShift = 0;
276 pfd->cAccumBits = 64;
277 pfd->cAccumRedBits = 16;
278 pfd->cAccumGreenBits = 16;
279 pfd->cAccumBlueBits = 16;
280 pfd->cAccumAlphaBits = 0;
281 pfd->cDepthBits = 16;
282 pfd->cStencilBits = 8;
283 pfd->cAuxBuffers = 0;
284 pfd->iLayerType = PFD_MAIN_PLANE;
285 pfd->bReserved = 0;
286 pfd->dwLayerMask = 0;
287 pfd->dwVisibleMask = 0;
288 pfd->dwDamageMask = 0;
289 }
290
291 /* the max PFD index */
292 return 2;
293}
294
295BOOL APIENTRY DrvDeleteContext(HGLRC hglrc)
296{
297 CR_DDI_PROLOGUE();
298 /*crDebug( "DrvDeleteContext(0x%x) called", hglrc );*/
299 stubDestroyContext( (unsigned long) hglrc );
300 return 1;
301}
302
303BOOL APIENTRY DrvCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
304{
305 CR_DDI_PROLOGUE();
306 crWarning( "DrvCopyContext: unsupported" );
307 return 0;
308}
309
310DECLEXPORT(BOOL) WINAPI wglShareLists_prox( HGLRC hglrc1, HGLRC hglrc2 );
311
312BOOL APIENTRY DrvShareLists(HGLRC hglrc1, HGLRC hglrc2)
313{
314 return wglShareLists_prox(hglrc1, hglrc2);
315}
316
317int APIENTRY DrvSetLayerPaletteEntries(HDC hdc, int iLayerPlane,
318 int iStart, int cEntries,
319 CONST COLORREF *pcr)
320{
321 CR_DDI_PROLOGUE();
322 crWarning( "DrvSetLayerPaletteEntries: unsupported" );
323 return 0;
324}
325
326
327BOOL APIENTRY DrvRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize)
328{
329 CR_DDI_PROLOGUE();
330 crWarning( "DrvRealizeLayerPalette: unsupported" );
331 return 0;
332}
333
334BOOL APIENTRY DrvSwapLayerBuffers(HDC hdc, UINT fuPlanes)
335{
336 CR_DDI_PROLOGUE();
337 if (fuPlanes == 1)
338 {
339 return DrvSwapBuffers(hdc);
340 }
341 else
342 {
343 crWarning( "DrvSwapLayerBuffers: unsupported" );
344 CRASSERT(false);
345 return 0;
346 }
347}
348
349BOOL APIENTRY DrvSwapBuffers(HDC hdc)
350{
351 WindowInfo *window;
352
353 CR_DDI_PROLOGUE();
354 /*crDebug( "DrvSwapBuffers(0x%x) called", hdc );*/
355 window = stubGetWindowInfo(hdc);
356 stubSwapBuffers( window, 0 );
357 return 1;
358}
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