VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/stub.h@ 65787

Last change on this file since 65787 was 65787, checked in by vboxsync, 8 years ago

bugref:8748: Additions/Graphics/Wayland: investigate EGLStreams support feasibility:

Removed more dependencies on native X11 visuals in the GLX code, with a view to stop using a visual ID as an fbconfig ID next. I tested the Mesa GLX demos before and after, and those which worked before to some extent still worked after, namely: glxcontexts, glxdemo, glxgears, glxgears_fbconfig, glxheads (one head of course), glxinfo, glxswapcontrol, manywin (with assertion), multictx, offset, pbinfo, shape, sharedtex (without the texture), texture_from_pixmap (without any animation), wincopy (without the copy), xfont and xrotfontdemo.

I did not test FBCONFIG_SGIX, as nothing I have available will use it if OpenGL 1.3 or later is available. I suspect that the code is broken from looking at it - the Mesa code it is presumably based on should work, but the Chromium code has diverged since then in ways which look incorrect.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.5 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7
8/*
9 * How this all works...
10 *
11 * This directory implements three different interfaces to Chromium:
12 *
13 * 1. the Chromium interface - this is defined by the functions that start
14 * with the "cr" prefix and are defined in chromium.h and implemented in
15 * stub.c. Typically, this is used by parallel apps (like psubmit).
16 *
17 * 2. GLX emulation interface - the glX*() functions are emulated here.
18 * When glXCreateContext() is called we may either create a real, native
19 * GLX context or a Chromium context (depending on match_window_title and
20 * minimum_window_size).
21 *
22 * 3. WGL emulation interface - the wgl*() functions are emulated here.
23 * When wglCreateContext() is called we may either create a real, native
24 * WGL context or a Chromium context (depending on match_window_title and
25 * minimum_window_size).
26 *
27 *
28 */
29
30
31#ifndef CR_STUB_H
32#define CR_STUB_H
33
34#include "chromium.h"
35#include "cr_version.h"
36#include "cr_hash.h"
37#include "cr_process.h"
38#include "cr_spu.h"
39#include "cr_threads.h"
40#include "spu_dispatch_table.h"
41
42#ifdef GLX
43#include <X11/extensions/XShm.h>
44#include <sys/shm.h>
45#include <X11/extensions/Xdamage.h>
46#include <X11/extensions/Xcomposite.h>
47#include <X11/extensions/Xfixes.h>
48#endif
49
50#if defined(WINDOWS) || defined(Linux) || defined(SunOS)
51# define CR_NEWWINTRACK
52#endif
53
54#if !defined(CHROMIUM_THREADSAFE) && defined(CR_NEWWINTRACK)
55# error CHROMIUM_THREADSAFE have to be defined
56#endif
57
58#ifdef CHROMIUM_THREADSAFE
59# include <cr_threads.h>
60#endif
61
62#if 0 && defined(CR_NEWWINTRACK) && !defined(WINDOWS)
63#define XLOCK(dpy) XLockDisplay(dpy)
64#define XUNLOCK(dpy) XUnlockDisplay(dpy)
65#else
66#define XLOCK(dpy)
67#define XUNLOCK(dpy)
68#endif
69
70/* When we first create a rendering context we can't be sure whether
71 * it'll be handled by Chromium or as a native GLX/WGL context. So in
72 * CreateContext() we'll mark the ContextInfo object as UNDECIDED then
73 * switch it to either NATIVE or CHROMIUM the first time MakeCurrent()
74 * is called. In MakeCurrent() we can use a criteria like window size
75 * or window title to decide between CHROMIUM and NATIVE.
76 */
77typedef enum
78{
79 UNDECIDED,
80 CHROMIUM,
81 NATIVE
82} ContextType;
83
84#define MAX_DPY_NAME 1000
85
86typedef struct context_info_t ContextInfo;
87typedef struct window_info_t WindowInfo;
88
89#ifdef GLX
90typedef struct glxpixmap_info_t GLX_Pixmap_t;
91
92struct glxpixmap_info_t
93{
94 int x, y;
95 unsigned int w, h, border, depth;
96 GLenum format;
97 Window root;
98 GLenum target;
99 GC gc;
100 Pixmap hShmPixmap; /* Shared memory pixmap object, if it's supported*/
101 Damage hDamage; /* damage xserver handle*/
102 Bool bPixmapImageDirty;
103 Region pDamageRegion;
104};
105#endif
106
107struct context_info_t
108{
109 char dpyName[MAX_DPY_NAME];
110 GLint spuContext; /* returned by head SPU's CreateContext() */
111 ContextType type; /* CHROMIUM, NATIVE or UNDECIDED */
112 unsigned long id; /* the client-visible handle */
113 GLint visBits;
114 WindowInfo *currentDrawable;
115
116#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
117 GLint spuConnection;
118 struct VBOXUHGSMI *pHgsmi;
119#endif
120
121#ifdef CHROMIUM_THREADSAFE
122 VBOXTLSREFDATA
123#endif
124
125#ifdef WINDOWS
126 HGLRC hglrc;
127#elif defined(DARWIN)
128 ContextInfo *share;
129 CGLContextObj cglc;
130
131 /* CGLContextEnable (CGLEnable, CGLDisable, and CGLIsEnabled) */
132 unsigned int options;
133
134 /* CGLContextParameter (CGLSetParameter and CGLGetParameter) */
135 GLint parambits;
136 long swap_rect[4], swap_interval;
137 unsigned long client_storage;
138 long surf_order, surf_opacy;
139
140 long disp_mask;
141#elif defined(GLX)
142 Display *dpy;
143 ContextInfo *share;
144 Bool direct;
145 GLXContext glxContext;
146 CRHashTable *pGLXPixmapsHash;
147 Bool damageQueryFailed;
148 int damageEventsBase;
149#endif
150};
151
152#ifdef DARWIN
153enum {
154 VISBIT_SWAP_RECT,
155 VISBIT_SWAP_INTERVAL,
156 VISBIT_CLIENT_STORAGE
157};
158#endif
159
160struct window_info_t
161{
162 char dpyName[MAX_DPY_NAME];
163 int x, y;
164 unsigned int width, height;
165 ContextType type;
166 GLint spuWindow; /* returned by head SPU's WindowCreate() */
167 ContextInfo *pOwner; /* ctx which created this window */
168 GLboolean mapped;
169#ifdef WINDOWS
170 HDC drawable;
171 HRGN hVisibleRegion;
172 DWORD dmPelsWidth;
173 DWORD dmPelsHeight;
174 HWND hWnd;
175#elif defined(DARWIN)
176 CGSConnectionID connection;
177 CGSWindowID drawable;
178 CGSSurfaceID surface;
179#elif defined(GLX)
180 Display *dpy;
181# ifdef CR_NEWWINTRACK
182 Display *syncDpy;
183# endif
184 GLXDrawable drawable;
185 XRectangle *pVisibleRegions;
186 GLint cVisibleRegions;
187#endif
188#ifdef CR_NEWWINTRACK
189 uint32_t u32ClientID;
190#endif
191};
192
193/* "Global" variables for the stub library */
194typedef struct {
195 /* the first SPU in the SPU chain on this app node */
196 SPU *spu;
197
198 /* OpenGL/SPU dispatch tables */
199 crOpenGLInterface wsInterface;
200 SPUDispatchTable spuDispatch;
201 SPUDispatchTable nativeDispatch;
202 GLboolean haveNativeOpenGL;
203
204 /* config options */
205 int appDrawCursor;
206 GLuint minChromiumWindowWidth;
207 GLuint minChromiumWindowHeight;
208 GLuint maxChromiumWindowWidth;
209 GLuint maxChromiumWindowHeight;
210 GLuint matchChromiumWindowCount;
211 GLuint matchChromiumWindowCounter;
212 GLuint *matchChromiumWindowID;
213 GLuint numIgnoreWindowID;
214 char *matchWindowTitle;
215 int ignoreFreeglutMenus;
216 int trackWindowSize;
217 int trackWindowPos;
218 int trackWindowVisibility;
219 int trackWindowVisibleRgn;
220 char *spu_dir;
221 int force_pbuffers;
222
223 /* thread safety stuff */
224 GLboolean threadSafe;
225#ifdef CHROMIUM_THREADSAFE
226 CRtsd dispatchTSD;
227 CRmutex mutex;
228#endif
229
230 CRpid mothershipPID;
231
232 /* contexts */
233 int freeContextNumber;
234 CRHashTable *contextTable;
235#ifndef CHROMIUM_THREADSAFE
236 ContextInfo *currentContext; /* may be NULL */
237#endif
238
239 /* windows */
240 CRHashTable *windowTable;
241
242#ifdef GLX
243 /* Shared memory, used to transfer XServer pixmaps data into client memory */
244 XShmSegmentInfo xshmSI;
245 GLboolean bShmInitFailed;
246
247 CRHashTable *pGLXPixmapsHash;
248
249 GLboolean bXExtensionsChecked;
250 GLboolean bHaveXComposite;
251 GLboolean bHaveXFixes;
252#endif
253
254#ifdef WINDOWS
255# ifndef CR_NEWWINTRACK
256 HHOOK hMessageHook;
257# endif
258# ifdef VBOX_WITH_WDDM
259 bool bRunningUnderWDDM;
260# endif
261#endif
262
263#ifdef CR_NEWWINTRACK
264 RTTHREAD hSyncThread;
265 bool volatile bShutdownSyncThread;
266#endif
267
268} Stub;
269
270#ifdef CHROMIUM_THREADSAFE
271/* we place the g_stubCurrentContextTLS outside the Stub data because Stub data is inited by the client's call,
272 * while we need g_stubCurrentContextTLS the g_stubCurrentContextTLS to be valid at any time to be able to handle
273 * THREAD_DETACH cleanup on windows.
274 * Note that we can not do
275 * STUB_INIT_LOCK();
276 * if (stub_initialized) stubSetCurrentContext(NULL);
277 * STUB_INIT_UNLOCK();
278 * on THREAD_DETACH since it may cause deadlock, i.e. in this situation loader lock is acquired first and then the init lock,
279 * but since we use GetModuleFileName in crGetProcName called from stubInitLocked, the lock order might be the oposite.
280 * Note that GetModuleFileName acquires the loader lock.
281 * */
282extern CRtsd g_stubCurrentContextTSD;
283
284DECLINLINE(ContextInfo*) stubGetCurrentContext(void)
285{
286 ContextInfo* ctx;
287 VBoxTlsRefGetCurrentFunctional(ctx, ContextInfo, &g_stubCurrentContextTSD);
288 return ctx;
289}
290# define stubSetCurrentContext(_ctx) VBoxTlsRefSetCurrent(ContextInfo, &g_stubCurrentContextTSD, _ctx)
291#else
292# define stubGetCurrentContext() (stub.currentContext)
293# define stubSetCurrentContext(_ctx) do { stub.currentContext = (_ctx); } while (0)
294#endif
295
296extern Stub stub;
297
298extern DECLEXPORT(SPUDispatchTable) glim;
299extern SPUDispatchTable stubThreadsafeDispatch;
300extern DECLEXPORT(SPUDispatchTable) stubNULLDispatch;
301
302#if defined(GLX) || defined (WINDOWS)
303extern GLboolean stubUpdateWindowVisibileRegions(WindowInfo *pWindow);
304#endif
305
306#ifdef WINDOWS
307
308/* WGL versions */
309extern WindowInfo *stubGetWindowInfo( HDC drawable );
310
311extern void stubInstallWindowMessageHook();
312extern void stubUninstallWindowMessageHook();
313
314#elif defined(DARWIN)
315
316extern CGSConnectionID _CGSDefaultConnection(void);
317extern OSStatus CGSGetWindowLevel( CGSConnectionID cid, CGSWindowID wid, CGWindowLevel *level );
318extern OSStatus CGSSetWindowAlpha( const CGSConnectionID cid, CGSWindowID wid, float alpha );
319
320/* These don't seem to be included in the OSX glext.h ... */
321extern void glPointParameteri( GLenum pname, GLint param );
322extern void glPointParameteriv( GLenum pname, const GLint * param );
323
324extern WindowInfo *stubGetWindowInfo( CGSWindowID drawable );
325
326#elif defined(GLX)
327
328/* GLX versions */
329extern WindowInfo *stubGetWindowInfo( Display *dpy, GLXDrawable drawable );
330extern void stubUseXFont( Display *dpy, Font font, int first, int count, int listbase );
331extern Display* stubGetWindowDisplay(WindowInfo *pWindow);
332
333extern void stubCheckXExtensions(WindowInfo *pWindow);
334#endif
335
336
337extern ContextInfo *stubNewContext(char *dpyName, GLint visBits, ContextType type, unsigned long shareCtx
338#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
339 , struct VBOXUHGSMI *pHgsmi
340#endif
341 );
342extern void stubConChromiumParameteriCR(GLint con, GLenum param, GLint value);
343extern void stubConChromiumParametervCR(GLint con, GLenum target, GLenum type, GLsizei count, const GLvoid *values);
344extern GLboolean stubCtxCreate(ContextInfo *context);
345extern GLboolean stubCtxCheckCreate(ContextInfo *context);
346extern void stubDestroyContext( unsigned long contextId );
347extern GLboolean stubMakeCurrent( WindowInfo *window, ContextInfo *context );
348extern GLint stubNewWindow( const char *dpyName, GLint visBits );
349extern void stubDestroyWindow( GLint con, GLint window );
350extern void stubSwapBuffers(WindowInfo *window, GLint flags);
351extern void stubGetWindowGeometry(WindowInfo *win, int *x, int *y, unsigned int *w, unsigned int *h);
352extern GLboolean stubUpdateWindowGeometry(WindowInfo *pWindow, GLboolean bForceUpdate);
353extern GLboolean stubIsWindowVisible(WindowInfo *win);
354extern bool stubInit(void);
355
356extern void stubForcedFlush(GLint con);
357extern void stubConFlush(GLint con);
358extern void APIENTRY stub_GetChromiumParametervCR( GLenum target, GLuint index, GLenum type, GLsizei count, GLvoid *values );
359
360extern void APIENTRY glBoundsInfoCR(const CRrecti *, const GLbyte *, GLint, GLint);
361
362#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
363# define CR_CTX_CON(_pCtx) ((_pCtx)->spuConnection)
364#else
365# define CR_CTX_CON(_pCtx) (0)
366#endif
367
368#endif /* CR_STUB_H */
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