VirtualBox

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

Last change on this file since 78581 was 78190, checked in by vboxsync, 6 years ago

Merge first stage of the Chromium cleanup from the branch:

  • r129818 (Remove VBOX_WITH_CR_DISPLAY_LISTS and accompanying code as it was disabled since r108676 and was never brought back (see ​bugref:3456 and ​bugref:8485))
  • r129819 (HostServices/SharedOpenGL: Remove unused main entry point from upstream server process based implementation)
  • r129820 (HostServices/SharedOpenGL: Started eliminating all backends other than HGCM. They are not used and probably wouldn't work anymore anyway)
  • r129821 (HostServices/SharedOpenGL,GuestHost/OpenGLAdditions/common/crOpenGL: Kill crTimer* API as it is not used anywhere)
  • r129822 (HostServices/SharedOpenGL,GuestHost/OpenGLAdditions/common/crOpenGL: Kill most from cr_process.h apart from two used methods)
  • r129823 (HostServices/SharedOpenGL,GuestHost/OpenGLAdditions/common/crOpenGL: Kill crList* API as it is unused)
  • r129824 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill crHullInteriorBox API as it is unused)
  • r129825 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill crWarpPoint API as it is unused)
  • r129826 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill CrSa* API as it is unused and not even compiled in)
  • r129827 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill cr_bbox.h as it is unused)
  • r129828 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove a few crParseUrl() two uses)
  • r129829 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove last crParseURL() use)
  • r129830 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove crParseURL())
  • r129831 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove VBOX_WITH_COCOA_QT and related code when not set as it is the default for years now and we don't support anything else anymore)
  • r129832 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused cr_logo.h)
  • r129833 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused crut_api.h and crut_clientapi.h)
  • r129834 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused cr_dmx.h)
  • r129835 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused cr_perf.h)
  • r129836 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove cr_rand.h and friends as it is not actively used anywhere)
  • r129837 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of all the swapped versions in the packer SPU, we never change endianess from guest to host and don't need it)
  • r129838 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove more swapper versions in the packer related code)
  • r129839 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove more swapper versions in the packer related code)
  • r129840 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused pack_pica.c)
  • r129841 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove more swapper versions in the packer related code)
  • r129842 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of cr_endianess.h and friends)
  • r129843 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused lowercase.py)
  • r129844 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused cr_calllists.h and friends)
  • r129845 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of completely unused idpool.c, not even compiled in)
  • r129846 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused cr_debugopcodes.h and friends)
  • r129847 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Make the cr_mem.h API inline and get rid of the implementation in the util library)
  • r129848 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of SPUOptions and related code as it is of no use for us)
  • r129849 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of cr_environment.h and friends and convert usage to RTEnv* APIs)
  • r129850 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused renderspu_agl.c)
  • r129851 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused code in cr_htable.h)
  • r129853 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Introduce a state paremeter for the unpacker workers instead of reyling on global variables, work in progress)
  • r129854 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Let the caller of crUnpack set up the initial state. This allows to get rid of the global return_ptr and writeback_ptr as they get supplied in the unpacker state by the server)
  • r129855 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of the cr_lastDispatch and cr_unpackDispatch as they are of no use now)
  • r129856 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of the global cr_unpackData and cr_unpackDataEnd symbols by indtroducing another hack to make it possible for certail server dispatch callbacks to access the data buffer)
  • r129857 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: build fix for release builds)
  • r129858 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Make the pointer to the unpacker state non const (is required for the access verification))
  • r129859 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: First iteration of the buffer size validation to prevent out of bound read access + added todos for places where additional checks are needed)
  • r129860 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129861 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129871 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129872 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Stop as soon as the unpacker encountered an error)
  • r129876 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129880 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129882 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Fixed some offsets in unpack_texture.c, 3DMark03 renders correctly again)
  • r130013 (HostServices/SharedOpenGL: Convert files to C++ so we can use C99 featuers on Windows with cl.exe)
  • r130014 (HostServices/SharedOpenGL,GuestHost/OpenGL: WIndows build fixes)
  • r130015 (HostServices/SharedOpenGL,GuestHost/OpenGL: More Windows build fixes)
  • r130036 (Config.kmk: Fix linker error on Windows by temporarily disabling the use of VBoxGuestR3DllMinW2K)
  • r130094 (src/VBox/GuestHost/OpenGL: Revert inlining the allocation/free functions in R3 completely as it doesn't work on Windows if memory is allocated and freed across different DLLs which don't share a common CRT, causes crashes in RtlValidtaeHeap())
  • r130095 (src/VBox/GuestHost/OpenGL,src/VBox/Additions/common/crOpenGL/pack: Don't use floating point specifiers in packspu_GetString() to avoid R6002 errors (couldn't fully understand why they occur suddenly after the rework but this gets rid of it))
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 10.6 KB
Line 
1/* $Id: icd_drv.c 78190 2019-04-18 00:07:07Z vboxsync $ */
2/** @file
3 * VBox OpenGL windows ICD driver functions
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "cr_error.h"
19#include "icd_drv.h"
20#include "cr_gl.h"
21#include "stub.h"
22#include "cr_mem.h"
23
24#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
25# include <VBoxCrHgsmi.h>
26# include <VBoxUhgsmi.h>
27#endif
28
29#include <iprt/win/windows.h>
30
31#include <stdio.h> /*sprintf*/
32
33/// @todo consider
34/* We can modify chronium dispatch table functions order to match the one required by ICD,
35 * but it'd render us incompatible with other chromium SPUs and require more changes.
36 * In current state, we can use unmodified binary chromium SPUs. Question is do we need it?
37*/
38
39#define GL_FUNC(func) cr_gl##func
40
41static ICDTABLE icdTable = { 336, {
42#define ICD_ENTRY(func) (PROC)GL_FUNC(func),
43#include "VBoxICDList.h"
44#undef ICD_ENTRY
45} };
46
47/* Currently host part will misbehave re-creating context with proper visual bits
48 * if contexts with alternative visual bits is requested.
49 * For now we just report a superset of all visual bits to avoid that.
50 * Better to it on the host side as well?
51 * We could also implement properly multiple pixel formats,
52 * which should be done by implementing offscreen rendering or multiple host contexts.
53 * */
54#define VBOX_CROGL_USE_VBITS_SUPERSET
55
56#ifdef VBOX_CROGL_USE_VBITS_SUPERSET
57static GLuint desiredVisual = CR_RGB_BIT | CR_ALPHA_BIT | CR_DEPTH_BIT | CR_STENCIL_BIT | CR_ACCUM_BIT | CR_DOUBLE_BIT;
58#else
59static GLuint desiredVisual = CR_RGB_BIT;
60#endif
61
62#ifndef VBOX_CROGL_USE_VBITS_SUPERSET
63/**
64 * Compute a mask of CR_*_BIT flags which reflects the attributes of
65 * the pixel format of the given hdc.
66 */
67static GLuint ComputeVisBits( HDC hdc )
68{
69 PIXELFORMATDESCRIPTOR pfd;
70 int iPixelFormat;
71 GLuint b = 0;
72
73 iPixelFormat = GetPixelFormat( hdc );
74
75 DescribePixelFormat( hdc, iPixelFormat, sizeof(pfd), &pfd );
76
77 if (pfd.cDepthBits > 0)
78 b |= CR_DEPTH_BIT;
79 if (pfd.cAccumBits > 0)
80 b |= CR_ACCUM_BIT;
81 if (pfd.cColorBits > 8)
82 b |= CR_RGB_BIT;
83 if (pfd.cStencilBits > 0)
84 b |= CR_STENCIL_BIT;
85 if (pfd.cAlphaBits > 0)
86 b |= CR_ALPHA_BIT;
87 if (pfd.dwFlags & PFD_DOUBLEBUFFER)
88 b |= CR_DOUBLE_BIT;
89 if (pfd.dwFlags & PFD_STEREO)
90 b |= CR_STEREO_BIT;
91
92 return b;
93}
94#endif
95
96void APIENTRY DrvReleaseContext(HGLRC hglrc)
97{
98 CR_DDI_PROLOGUE();
99 /*crDebug( "DrvReleaseContext(0x%x) called", hglrc );*/
100 stubMakeCurrent( NULL, NULL );
101}
102
103BOOL APIENTRY DrvValidateVersion(DWORD version)
104{
105 CR_DDI_PROLOGUE();
106 if (stubInit()) {
107 crDebug("DrvValidateVersion %x -> TRUE\n", version);
108 return TRUE;
109 }
110
111 crDebug("DrvValidateVersion %x -> FALSE, going to use system default opengl32.dll\n", version);
112 return FALSE;
113}
114
115//we're not going to change icdTable at runtime, so callback is unused
116PICDTABLE APIENTRY DrvSetContext(HDC hdc, HGLRC hglrc, void *callback)
117{
118 ContextInfo *pContext;
119 WindowInfo *pWindowInfo;
120 BOOL ret = false;
121
122 CR_DDI_PROLOGUE();
123
124 (void) (callback);
125
126 crHashtableLock(stub.windowTable);
127 crHashtableLock(stub.contextTable);
128
129 pContext = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
130 if (pContext)
131 {
132 pWindowInfo = stubGetWindowInfo(hdc);
133 if (pWindowInfo)
134 ret = stubMakeCurrent(pWindowInfo, pContext);
135 else
136 crError("no window info available.");
137 }
138 else
139 crError("No context found.");
140
141 crHashtableUnlock(stub.contextTable);
142 crHashtableUnlock(stub.windowTable);
143
144 return ret ? &icdTable : NULL;
145}
146
147BOOL APIENTRY DrvSetPixelFormat(HDC hdc, int iPixelFormat)
148{
149 CR_DDI_PROLOGUE();
150 crDebug( "DrvSetPixelFormat(0x%x, %i) called.", hdc, iPixelFormat );
151
152 if ( (iPixelFormat<1) || (iPixelFormat>2) ) {
153 crError( "wglSetPixelFormat: iPixelFormat=%d?", iPixelFormat );
154 }
155
156 return 1;
157}
158
159HGLRC APIENTRY DrvCreateContext(HDC hdc)
160{
161 char dpyName[MAX_DPY_NAME];
162 ContextInfo *context;
163#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
164 PVBOXUHGSMI pHgsmi = NULL;
165#endif
166
167 CR_DDI_PROLOGUE();
168
169 crDebug( "DrvCreateContext(0x%x) called.", hdc);
170
171 stubInit();
172
173 CRASSERT(stub.contextTable);
174
175 sprintf(dpyName, "%p", hdc);
176#ifndef VBOX_CROGL_USE_VBITS_SUPERSET
177 if (stub.haveNativeOpenGL)
178 desiredVisual |= ComputeVisBits( hdc );
179#endif
180
181#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
182 pHgsmi = VBoxCrHgsmiCreate();
183#endif
184
185 context = stubNewContext(dpyName, desiredVisual, UNDECIDED, 0
186#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
187 , pHgsmi
188#endif
189 );
190 if (!context)
191 return 0;
192
193 return (HGLRC) context->id;
194}
195
196HGLRC APIENTRY DrvCreateLayerContext(HDC hdc, int iLayerPlane)
197{
198 CR_DDI_PROLOGUE();
199 crDebug( "DrvCreateLayerContext(0x%x, %i) called.", hdc, iLayerPlane);
200 //We don't support more than 1 layers.
201 if (iLayerPlane == 0) {
202 return DrvCreateContext(hdc);
203 } else {
204 crError( "DrvCreateLayerContext (%x,%x): unsupported", hdc, iLayerPlane);
205 return NULL;
206 }
207
208}
209
210BOOL APIENTRY DrvDescribeLayerPlane(HDC hdc,int iPixelFormat,
211 int iLayerPlane, UINT nBytes,
212 LPLAYERPLANEDESCRIPTOR plpd)
213{
214 CR_DDI_PROLOGUE();
215 crWarning( "DrvDescribeLayerPlane: unimplemented" );
216 CRASSERT(false);
217 return 0;
218}
219
220int APIENTRY DrvGetLayerPaletteEntries(HDC hdc, int iLayerPlane,
221 int iStart, int cEntries,
222 COLORREF *pcr)
223{
224 CR_DDI_PROLOGUE();
225 crWarning( "DrvGetLayerPaletteEntries: unsupported" );
226 CRASSERT(false);
227 return 0;
228}
229
230int APIENTRY DrvDescribePixelFormat(HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR pfd)
231{
232 CR_DDI_PROLOGUE();
233 if ( !pfd ) {
234 return 2;
235 }
236
237 if ( nBytes != sizeof(*pfd) ) {
238 crWarning( "DrvDescribePixelFormat: nBytes=%u?", nBytes );
239 return 2;
240 }
241
242 if (iPixelFormat==1)
243 {
244 crMemZero(pfd, sizeof(*pfd));
245
246 pfd->nSize = sizeof(*pfd);
247 pfd->nVersion = 1;
248 pfd->dwFlags = (PFD_DRAW_TO_WINDOW |
249 PFD_SUPPORT_OPENGL |
250 PFD_DOUBLEBUFFER);
251
252 pfd->dwFlags |= 0x8000; /* <- Needed for VSG Open Inventor to be happy */
253
254 pfd->iPixelType = PFD_TYPE_RGBA;
255 pfd->cColorBits = 32;
256 pfd->cRedBits = 8;
257 pfd->cRedShift = 24;
258 pfd->cGreenBits = 8;
259 pfd->cGreenShift = 16;
260 pfd->cBlueBits = 8;
261 pfd->cBlueShift = 8;
262 pfd->cAlphaBits = 8;
263 pfd->cAlphaShift = 0;
264 pfd->cAccumBits = 0;
265 pfd->cAccumRedBits = 0;
266 pfd->cAccumGreenBits = 0;
267 pfd->cAccumBlueBits = 0;
268 pfd->cAccumAlphaBits = 0;
269 pfd->cDepthBits = 32;
270 pfd->cStencilBits = 8;
271 pfd->cAuxBuffers = 0;
272 pfd->iLayerType = PFD_MAIN_PLANE;
273 pfd->bReserved = 0;
274 pfd->dwLayerMask = 0;
275 pfd->dwVisibleMask = 0;
276 pfd->dwDamageMask = 0;
277 }
278 else
279 {
280 crMemZero(pfd, sizeof(*pfd));
281 pfd->nVersion = 1;
282 pfd->dwFlags = (PFD_DRAW_TO_WINDOW|
283 PFD_SUPPORT_OPENGL);
284
285 pfd->iPixelType = PFD_TYPE_RGBA;
286 pfd->cColorBits = 32;
287 pfd->cRedBits = 8;
288 pfd->cRedShift = 16;
289 pfd->cGreenBits = 8;
290 pfd->cGreenShift = 8;
291 pfd->cBlueBits = 8;
292 pfd->cBlueShift = 0;
293 pfd->cAlphaBits = 0;
294 pfd->cAlphaShift = 0;
295 pfd->cAccumBits = 64;
296 pfd->cAccumRedBits = 16;
297 pfd->cAccumGreenBits = 16;
298 pfd->cAccumBlueBits = 16;
299 pfd->cAccumAlphaBits = 0;
300 pfd->cDepthBits = 16;
301 pfd->cStencilBits = 8;
302 pfd->cAuxBuffers = 0;
303 pfd->iLayerType = PFD_MAIN_PLANE;
304 pfd->bReserved = 0;
305 pfd->dwLayerMask = 0;
306 pfd->dwVisibleMask = 0;
307 pfd->dwDamageMask = 0;
308 }
309
310 /* the max PFD index */
311 return 2;
312}
313
314BOOL APIENTRY DrvDeleteContext(HGLRC hglrc)
315{
316#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
317 ContextInfo *pContext;
318 PVBOXUHGSMI pHgsmi = NULL;
319#endif
320
321 CR_DDI_PROLOGUE();
322 crDebug( "DrvDeleteContext(0x%x) called", hglrc );
323
324#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
325 crHashtableLock(stub.contextTable);
326
327 pContext = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
328 if (pContext)
329 pHgsmi = pContext->pHgsmi;
330
331 crHashtableUnlock(stub.contextTable);
332#endif
333
334 stubDestroyContext( (unsigned long) hglrc );
335
336#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
337 if (pHgsmi)
338 VBoxCrHgsmiDestroy(pHgsmi);
339#endif
340
341 return true;
342}
343
344BOOL APIENTRY DrvCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
345{
346 CR_DDI_PROLOGUE();
347 crWarning( "DrvCopyContext: unsupported" );
348 return 0;
349}
350
351DECLEXPORT(BOOL) WINAPI wglShareLists_prox( HGLRC hglrc1, HGLRC hglrc2 );
352
353BOOL APIENTRY DrvShareLists(HGLRC hglrc1, HGLRC hglrc2)
354{
355 return wglShareLists_prox(hglrc1, hglrc2);
356}
357
358int APIENTRY DrvSetLayerPaletteEntries(HDC hdc, int iLayerPlane,
359 int iStart, int cEntries,
360 CONST COLORREF *pcr)
361{
362 CR_DDI_PROLOGUE();
363 crWarning( "DrvSetLayerPaletteEntries: unsupported" );
364 return 0;
365}
366
367
368BOOL APIENTRY DrvRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize)
369{
370 CR_DDI_PROLOGUE();
371 crWarning( "DrvRealizeLayerPalette: unsupported" );
372 return 0;
373}
374
375BOOL APIENTRY DrvSwapLayerBuffers(HDC hdc, UINT fuPlanes)
376{
377 CR_DDI_PROLOGUE();
378 if (fuPlanes == 1)
379 {
380 return DrvSwapBuffers(hdc);
381 }
382 else
383 {
384 crWarning( "DrvSwapLayerBuffers: unsupported" );
385 CRASSERT(false);
386 return 0;
387 }
388}
389
390BOOL APIENTRY DrvSwapBuffers(HDC hdc)
391{
392 WindowInfo *window;
393
394 CR_DDI_PROLOGUE();
395 /*crDebug( "DrvSwapBuffers(0x%x) called", hdc );*/
396 window = stubGetWindowInfo(hdc);
397 stubSwapBuffers( window, 0 );
398 return 1;
399}
400
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