VirtualBox

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

Last change on this file since 55620 was 55620, checked in by vboxsync, 10 years ago

3D: addition: treat a little bit more carefully with pointers (Win GAs).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.8 KB
Line 
1/* $Id: icd_drv.c 55620 2015-05-03 15:21:53Z 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 *pContext;
113 WindowInfo *pWindowInfo;
114 BOOL ret = false;
115
116 CR_DDI_PROLOGUE();
117
118 (void) (callback);
119
120 crHashtableLock(stub.windowTable);
121 crHashtableLock(stub.contextTable);
122
123 pContext = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
124 if (pContext)
125 {
126 pWindowInfo = stubGetWindowInfo(hdc);
127 if (pWindowInfo)
128 ret = stubMakeCurrent(pWindowInfo, pContext);
129 else
130 crError("no window info available.");
131 }
132 else
133 crError("No context found.");
134
135 crHashtableUnlock(stub.contextTable);
136 crHashtableUnlock(stub.windowTable);
137
138 return ret ? &icdTable : NULL;
139}
140
141BOOL APIENTRY DrvSetPixelFormat(HDC hdc, int iPixelFormat)
142{
143 CR_DDI_PROLOGUE();
144 crDebug( "DrvSetPixelFormat(0x%x, %i) called.", hdc, iPixelFormat );
145
146 if ( (iPixelFormat<1) || (iPixelFormat>2) ) {
147 crError( "wglSetPixelFormat: iPixelFormat=%d?", iPixelFormat );
148 }
149
150 return 1;
151}
152
153HGLRC APIENTRY DrvCreateContext(HDC hdc)
154{
155 char dpyName[MAX_DPY_NAME];
156 ContextInfo *context;
157
158 CR_DDI_PROLOGUE();
159
160 crDebug( "DrvCreateContext(0x%x) called.", hdc);
161
162 stubInit();
163
164 CRASSERT(stub.contextTable);
165
166 sprintf(dpyName, "%d", hdc);
167#ifndef VBOX_CROGL_USE_VBITS_SUPERSET
168 if (stub.haveNativeOpenGL)
169 desiredVisual |= ComputeVisBits( hdc );
170#endif
171
172 context = stubNewContext(dpyName, desiredVisual, UNDECIDED, 0
173#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
174 , NULL
175#endif
176 );
177 if (!context)
178 return 0;
179
180 return (HGLRC) context->id;
181}
182
183HGLRC APIENTRY DrvCreateLayerContext(HDC hdc, int iLayerPlane)
184{
185 CR_DDI_PROLOGUE();
186 crDebug( "DrvCreateLayerContext(0x%x, %i) called.", hdc, iLayerPlane);
187 //We don't support more than 1 layers.
188 if (iLayerPlane == 0) {
189 return DrvCreateContext(hdc);
190 } else {
191 crError( "DrvCreateLayerContext (%x,%x): unsupported", hdc, iLayerPlane);
192 return NULL;
193 }
194
195}
196
197BOOL APIENTRY DrvDescribeLayerPlane(HDC hdc,int iPixelFormat,
198 int iLayerPlane, UINT nBytes,
199 LPLAYERPLANEDESCRIPTOR plpd)
200{
201 CR_DDI_PROLOGUE();
202 crWarning( "DrvDescribeLayerPlane: unimplemented" );
203 CRASSERT(false);
204 return 0;
205}
206
207int APIENTRY DrvGetLayerPaletteEntries(HDC hdc, int iLayerPlane,
208 int iStart, int cEntries,
209 COLORREF *pcr)
210{
211 CR_DDI_PROLOGUE();
212 crWarning( "DrvGetLayerPaletteEntries: unsupported" );
213 CRASSERT(false);
214 return 0;
215}
216
217int APIENTRY DrvDescribePixelFormat(HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR pfd)
218{
219 CR_DDI_PROLOGUE();
220 if ( !pfd ) {
221 return 2;
222 }
223
224 if ( nBytes != sizeof(*pfd) ) {
225 crWarning( "DrvDescribePixelFormat: nBytes=%u?", nBytes );
226 return 2;
227 }
228
229 if (iPixelFormat==1)
230 {
231 crMemZero(pfd, sizeof(*pfd));
232
233 pfd->nSize = sizeof(*pfd);
234 pfd->nVersion = 1;
235 pfd->dwFlags = (PFD_DRAW_TO_WINDOW |
236 PFD_SUPPORT_OPENGL |
237 PFD_DOUBLEBUFFER);
238
239 pfd->dwFlags |= 0x8000; /* <- Needed for VSG Open Inventor to be happy */
240
241 pfd->iPixelType = PFD_TYPE_RGBA;
242 pfd->cColorBits = 32;
243 pfd->cRedBits = 8;
244 pfd->cRedShift = 24;
245 pfd->cGreenBits = 8;
246 pfd->cGreenShift = 16;
247 pfd->cBlueBits = 8;
248 pfd->cBlueShift = 8;
249 pfd->cAlphaBits = 8;
250 pfd->cAlphaShift = 0;
251 pfd->cAccumBits = 0;
252 pfd->cAccumRedBits = 0;
253 pfd->cAccumGreenBits = 0;
254 pfd->cAccumBlueBits = 0;
255 pfd->cAccumAlphaBits = 0;
256 pfd->cDepthBits = 32;
257 pfd->cStencilBits = 8;
258 pfd->cAuxBuffers = 0;
259 pfd->iLayerType = PFD_MAIN_PLANE;
260 pfd->bReserved = 0;
261 pfd->dwLayerMask = 0;
262 pfd->dwVisibleMask = 0;
263 pfd->dwDamageMask = 0;
264 }
265 else
266 {
267 crMemZero(pfd, sizeof(*pfd));
268 pfd->nVersion = 1;
269 pfd->dwFlags = (PFD_DRAW_TO_WINDOW|
270 PFD_SUPPORT_OPENGL);
271
272 pfd->iPixelType = PFD_TYPE_RGBA;
273 pfd->cColorBits = 32;
274 pfd->cRedBits = 8;
275 pfd->cRedShift = 16;
276 pfd->cGreenBits = 8;
277 pfd->cGreenShift = 8;
278 pfd->cBlueBits = 8;
279 pfd->cBlueShift = 0;
280 pfd->cAlphaBits = 0;
281 pfd->cAlphaShift = 0;
282 pfd->cAccumBits = 64;
283 pfd->cAccumRedBits = 16;
284 pfd->cAccumGreenBits = 16;
285 pfd->cAccumBlueBits = 16;
286 pfd->cAccumAlphaBits = 0;
287 pfd->cDepthBits = 16;
288 pfd->cStencilBits = 8;
289 pfd->cAuxBuffers = 0;
290 pfd->iLayerType = PFD_MAIN_PLANE;
291 pfd->bReserved = 0;
292 pfd->dwLayerMask = 0;
293 pfd->dwVisibleMask = 0;
294 pfd->dwDamageMask = 0;
295 }
296
297 /* the max PFD index */
298 return 2;
299}
300
301BOOL APIENTRY DrvDeleteContext(HGLRC hglrc)
302{
303 CR_DDI_PROLOGUE();
304 /*crDebug( "DrvDeleteContext(0x%x) called", hglrc );*/
305 stubDestroyContext( (unsigned long) hglrc );
306 return 1;
307}
308
309BOOL APIENTRY DrvCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
310{
311 CR_DDI_PROLOGUE();
312 crWarning( "DrvCopyContext: unsupported" );
313 return 0;
314}
315
316DECLEXPORT(BOOL) WINAPI wglShareLists_prox( HGLRC hglrc1, HGLRC hglrc2 );
317
318BOOL APIENTRY DrvShareLists(HGLRC hglrc1, HGLRC hglrc2)
319{
320 return wglShareLists_prox(hglrc1, hglrc2);
321}
322
323int APIENTRY DrvSetLayerPaletteEntries(HDC hdc, int iLayerPlane,
324 int iStart, int cEntries,
325 CONST COLORREF *pcr)
326{
327 CR_DDI_PROLOGUE();
328 crWarning( "DrvSetLayerPaletteEntries: unsupported" );
329 return 0;
330}
331
332
333BOOL APIENTRY DrvRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize)
334{
335 CR_DDI_PROLOGUE();
336 crWarning( "DrvRealizeLayerPalette: unsupported" );
337 return 0;
338}
339
340BOOL APIENTRY DrvSwapLayerBuffers(HDC hdc, UINT fuPlanes)
341{
342 CR_DDI_PROLOGUE();
343 if (fuPlanes == 1)
344 {
345 return DrvSwapBuffers(hdc);
346 }
347 else
348 {
349 crWarning( "DrvSwapLayerBuffers: unsupported" );
350 CRASSERT(false);
351 return 0;
352 }
353}
354
355BOOL APIENTRY DrvSwapBuffers(HDC hdc)
356{
357 WindowInfo *window;
358
359 CR_DDI_PROLOGUE();
360 /*crDebug( "DrvSwapBuffers(0x%x) called", hdc );*/
361 window = stubGetWindowInfo(hdc);
362 stubSwapBuffers( window, 0 );
363 return 1;
364}
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