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