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