VirtualBox

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

Last change on this file since 39587 was 39568, checked in by vboxsync, 13 years ago

crOpenGL: more threading fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.7 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/*#define VBOX_TEST_MEGOO*/
59
60#if 0 && defined(CR_NEWWINTRACK) && !defined(WINDOWS)
61#define XLOCK(dpy) XLockDisplay(dpy)
62#define XUNLOCK(dpy) XUnlockDisplay(dpy)
63#else
64#define XLOCK(dpy)
65#define XUNLOCK(dpy)
66#endif
67
68/* When we first create a rendering context we can't be sure whether
69 * it'll be handled by Chromium or as a native GLX/WGL context. So in
70 * CreateContext() we'll mark the ContextInfo object as UNDECIDED then
71 * switch it to either NATIVE or CHROMIUM the first time MakeCurrent()
72 * is called. In MakeCurrent() we can use a criteria like window size
73 * or window title to decide between CHROMIUM and NATIVE.
74 */
75typedef enum
76{
77 UNDECIDED,
78 CHROMIUM,
79 NATIVE
80} ContextType;
81
82#define MAX_DPY_NAME 1000
83
84typedef struct context_info_t ContextInfo;
85typedef struct window_info_t WindowInfo;
86
87#ifdef GLX
88typedef struct glxpixmap_info_t GLX_Pixmap_t;
89
90struct glxpixmap_info_t
91{
92 int x, y;
93 unsigned int w, h, border, depth;
94 GLenum format;
95 Window root;
96 GLenum target;
97 GC gc;
98 Pixmap hShmPixmap; /* Shared memory pixmap object, if it's supported*/
99 Damage hDamage; /* damage xserver handle*/
100 Bool bPixmapImageDirty;
101 Region pDamageRegion;
102};
103#endif
104
105struct context_info_t
106{
107 char dpyName[MAX_DPY_NAME];
108 GLint spuContext; /* returned by head SPU's CreateContext() */
109 ContextType type; /* CHROMIUM, NATIVE or UNDECIDED */
110 unsigned long id; /* the client-visible handle */
111 GLint visBits;
112 WindowInfo *currentDrawable;
113
114#ifdef CHROMIUM_THREADSAFE
115 CRTSDREFDATA
116#endif
117
118#ifdef WINDOWS
119 HGLRC hglrc;
120#elif defined(DARWIN)
121 ContextInfo *share;
122 CGLContextObj cglc;
123
124 /* CGLContextEnable (CGLEnable, CGLDisable, and CGLIsEnabled) */
125 unsigned int options;
126
127 /* CGLContextParameter (CGLSetParameter and CGLGetParameter) */
128 GLint parambits;
129 long swap_rect[4], swap_interval;
130 unsigned long client_storage;
131 long surf_order, surf_opacy;
132
133 long disp_mask;
134#elif defined(GLX)
135 Display *dpy;
136 ContextInfo *share;
137 XVisualInfo *visual;
138 Bool direct;
139 GLXContext glxContext;
140 CRHashTable *pGLXPixmapsHash;
141 Bool damageInitFailed;
142 Display *damageDpy; /* second display connection to read xdamage extension data */
143 int damageEventsBase;
144#endif
145};
146
147#ifdef DARWIN
148enum {
149 VISBIT_SWAP_RECT,
150 VISBIT_SWAP_INTERVAL,
151 VISBIT_CLIENT_STORAGE
152};
153#endif
154
155struct window_info_t
156{
157 char dpyName[MAX_DPY_NAME];
158 int x, y;
159 unsigned int width, height;
160 ContextType type;
161 GLint spuWindow; /* returned by head SPU's WindowCreate() */
162 ContextInfo *pOwner; /* ctx which created this window */
163 GLboolean mapped;
164#ifdef WINDOWS
165 HDC drawable;
166 HRGN hVisibleRegion;
167 DWORD dmPelsWidth;
168 DWORD dmPelsHeight;
169 HWND hWnd;
170#elif defined(DARWIN)
171 CGSConnectionID connection;
172 CGSWindowID drawable;
173 CGSSurfaceID surface;
174#elif defined(GLX)
175 Display *dpy;
176# ifdef CR_NEWWINTRACK
177 Display *syncDpy;
178# endif
179 GLXDrawable drawable;
180 XRectangle *pVisibleRegions;
181 GLint cVisibleRegions;
182#endif
183#ifdef CR_NEWWINTRACK
184 uint32_t u32ClientID;
185#endif
186};
187
188/* "Global" variables for the stub library */
189typedef struct {
190 /* the first SPU in the SPU chain on this app node */
191 SPU *spu;
192
193 /* OpenGL/SPU dispatch tables */
194 crOpenGLInterface wsInterface;
195 SPUDispatchTable spuDispatch;
196 SPUDispatchTable nativeDispatch;
197 GLboolean haveNativeOpenGL;
198
199 /* config options */
200 int appDrawCursor;
201 GLuint minChromiumWindowWidth;
202 GLuint minChromiumWindowHeight;
203 GLuint maxChromiumWindowWidth;
204 GLuint maxChromiumWindowHeight;
205 GLuint matchChromiumWindowCount;
206 GLuint matchChromiumWindowCounter;
207 GLuint *matchChromiumWindowID;
208 GLuint numIgnoreWindowID;
209 char *matchWindowTitle;
210 int ignoreFreeglutMenus;
211 int trackWindowSize;
212 int trackWindowPos;
213 int trackWindowVisibility;
214 int trackWindowVisibleRgn;
215 char *spu_dir;
216 int force_pbuffers;
217 int viewportHack;
218
219 /* thread safety stuff */
220 GLboolean threadSafe;
221#ifdef CHROMIUM_THREADSAFE
222 CRtsd dispatchTSD;
223 CRmutex mutex;
224#endif
225
226 CRpid mothershipPID;
227
228 /* contexts */
229 int freeContextNumber;
230 CRHashTable *contextTable;
231#ifndef CHROMIUM_THREADSAFE
232 ContextInfo *currentContext; /* may be NULL */
233#endif
234
235 /* windows */
236 CRHashTable *windowTable;
237
238#ifdef GLX
239 /* Shared memory, used to transfer XServer pixmaps data into client memory */
240 XShmSegmentInfo xshmSI;
241 GLboolean bShmInitFailed;
242
243 CRHashTable *pGLXPixmapsHash;
244
245 GLboolean bXExtensionsChecked;
246 GLboolean bHaveXComposite;
247 GLboolean bHaveXFixes;
248#endif
249
250#ifdef WINDOWS
251# ifndef CR_NEWWINTRACK
252 HHOOK hMessageHook;
253# endif
254# ifdef VBOX_WITH_WDDM
255 bool bRunningUnderWDDM;
256# endif
257#endif
258
259#ifdef CR_NEWWINTRACK
260 RTTHREAD hSyncThread;
261 bool volatile bShutdownSyncThread;
262#endif
263
264} Stub;
265
266#ifdef CHROMIUM_THREADSAFE
267# define stubGetCurrentContext() crTSDRefGetCurrent(ContextInfo, &g_stubCurrentContextTSD)
268# define stubSetCurrentContext(_ctx) crTSDRefSetCurrent(ContextInfo, &g_stubCurrentContextTSD, _ctx)
269#else
270# define stubGetCurrentContext() (stub.currentContext)
271# define stubSetCurrentContext(_ctx) do { stub.currentContext = (_ctx); } while (0)
272#endif
273
274extern Stub stub;
275/* we place the __currentContextTSD outside the Stub data because Stub data is inited by the client's call,
276 * while we need __currentContextTSD the __currentContextTSD to be valid at any time to be able to handle
277 * THREAD_DETACH cleanup on windows.
278 * Note that we can not do
279 * STUB_INIT_LOCK();
280 * if (stub_initialized) stubSetCurrentContext(NULL);
281 * STUB_INIT_UNLOCK();
282 * on THREAD_DETACH since it may cause deadlock, i.e. in this situation loader lock is acquired first and then the init lock,
283 * but since we use GetModuleFileName in crGetProcName called from stubInitLocked, the lock order might be the oposite.
284 * Note that GetModuleFileName acquires the loader lock.
285 * */
286#ifdef CHROMIUM_THREADSAFE
287extern CRtsd g_stubCurrentContextTSD;
288#endif
289extern DECLEXPORT(SPUDispatchTable) glim;
290extern SPUDispatchTable stubThreadsafeDispatch;
291extern DECLEXPORT(SPUDispatchTable) stubNULLDispatch;
292
293#if defined(GLX) || defined (WINDOWS)
294extern GLboolean stubUpdateWindowVisibileRegions(WindowInfo *pWindow);
295#endif
296
297#ifdef WINDOWS
298
299/* WGL versions */
300extern WindowInfo *stubGetWindowInfo( HDC drawable );
301
302extern void stubInstallWindowMessageHook();
303extern void stubUninstallWindowMessageHook();
304
305#elif defined(DARWIN)
306
307extern CGSConnectionID _CGSDefaultConnection(void);
308extern OSStatus CGSGetWindowLevel( CGSConnectionID cid, CGSWindowID wid, CGWindowLevel *level );
309extern OSStatus CGSSetWindowAlpha( const CGSConnectionID cid, CGSWindowID wid, float alpha );
310
311/* These don't seem to be included in the OSX glext.h ... */
312extern void glPointParameteri( GLenum pname, GLint param );
313extern void glPointParameteriv( GLenum pname, const GLint * param );
314
315extern WindowInfo *stubGetWindowInfo( CGSWindowID drawable );
316
317#elif defined(GLX)
318
319/* GLX versions */
320extern WindowInfo *stubGetWindowInfo( Display *dpy, GLXDrawable drawable );
321extern void stubUseXFont( Display *dpy, Font font, int first, int count, int listbase );
322extern Display* stubGetWindowDisplay(WindowInfo *pWindow);
323
324extern void stubCheckXExtensions(WindowInfo *pWindow);
325#endif
326
327
328extern ContextInfo *stubNewContext( const char *dpyName, GLint visBits, ContextType type, unsigned long shareCtx );
329extern void stubDestroyContext( unsigned long contextId );
330extern GLboolean stubMakeCurrent( WindowInfo *window, ContextInfo *context );
331extern GLint stubNewWindow( const char *dpyName, GLint visBits );
332extern void stubSwapBuffers(WindowInfo *window, GLint flags);
333extern void stubGetWindowGeometry(WindowInfo *win, int *x, int *y, unsigned int *w, unsigned int *h);
334extern GLboolean stubUpdateWindowGeometry(WindowInfo *pWindow, GLboolean bForceUpdate);
335extern GLboolean stubIsWindowVisible(WindowInfo *win);
336extern bool stubInit(void);
337
338extern void APIENTRY stub_GetChromiumParametervCR( GLenum target, GLuint index, GLenum type, GLsizei count, GLvoid *values );
339
340extern void APIENTRY glBoundsInfoCR(const CRrecti *, const GLbyte *, GLint, GLint);
341
342#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