VirtualBox

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

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

bugref:8748: Additions/Graphics/Wayland: investigate EGLStreams support feasibility: remove glX code which has been commented out for a long time.

  • 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 XVisualInfo *visual;
145 Bool direct;
146 GLXContext glxContext;
147 CRHashTable *pGLXPixmapsHash;
148 Bool damageQueryFailed;
149 int damageEventsBase;
150#endif
151};
152
153#ifdef DARWIN
154enum {
155 VISBIT_SWAP_RECT,
156 VISBIT_SWAP_INTERVAL,
157 VISBIT_CLIENT_STORAGE
158};
159#endif
160
161struct window_info_t
162{
163 char dpyName[MAX_DPY_NAME];
164 int x, y;
165 unsigned int width, height;
166 ContextType type;
167 GLint spuWindow; /* returned by head SPU's WindowCreate() */
168 ContextInfo *pOwner; /* ctx which created this window */
169 GLboolean mapped;
170#ifdef WINDOWS
171 HDC drawable;
172 HRGN hVisibleRegion;
173 DWORD dmPelsWidth;
174 DWORD dmPelsHeight;
175 HWND hWnd;
176#elif defined(DARWIN)
177 CGSConnectionID connection;
178 CGSWindowID drawable;
179 CGSSurfaceID surface;
180#elif defined(GLX)
181 Display *dpy;
182# ifdef CR_NEWWINTRACK
183 Display *syncDpy;
184# endif
185 GLXDrawable drawable;
186 XRectangle *pVisibleRegions;
187 GLint cVisibleRegions;
188#endif
189#ifdef CR_NEWWINTRACK
190 uint32_t u32ClientID;
191#endif
192};
193
194/* "Global" variables for the stub library */
195typedef struct {
196 /* the first SPU in the SPU chain on this app node */
197 SPU *spu;
198
199 /* OpenGL/SPU dispatch tables */
200 crOpenGLInterface wsInterface;
201 SPUDispatchTable spuDispatch;
202 SPUDispatchTable nativeDispatch;
203 GLboolean haveNativeOpenGL;
204
205 /* config options */
206 int appDrawCursor;
207 GLuint minChromiumWindowWidth;
208 GLuint minChromiumWindowHeight;
209 GLuint maxChromiumWindowWidth;
210 GLuint maxChromiumWindowHeight;
211 GLuint matchChromiumWindowCount;
212 GLuint matchChromiumWindowCounter;
213 GLuint *matchChromiumWindowID;
214 GLuint numIgnoreWindowID;
215 char *matchWindowTitle;
216 int ignoreFreeglutMenus;
217 int trackWindowSize;
218 int trackWindowPos;
219 int trackWindowVisibility;
220 int trackWindowVisibleRgn;
221 char *spu_dir;
222 int force_pbuffers;
223
224 /* thread safety stuff */
225 GLboolean threadSafe;
226#ifdef CHROMIUM_THREADSAFE
227 CRtsd dispatchTSD;
228 CRmutex mutex;
229#endif
230
231 CRpid mothershipPID;
232
233 /* contexts */
234 int freeContextNumber;
235 CRHashTable *contextTable;
236#ifndef CHROMIUM_THREADSAFE
237 ContextInfo *currentContext; /* may be NULL */
238#endif
239
240 /* windows */
241 CRHashTable *windowTable;
242
243#ifdef GLX
244 /* Shared memory, used to transfer XServer pixmaps data into client memory */
245 XShmSegmentInfo xshmSI;
246 GLboolean bShmInitFailed;
247
248 CRHashTable *pGLXPixmapsHash;
249
250 GLboolean bXExtensionsChecked;
251 GLboolean bHaveXComposite;
252 GLboolean bHaveXFixes;
253#endif
254
255#ifdef WINDOWS
256# ifndef CR_NEWWINTRACK
257 HHOOK hMessageHook;
258# endif
259# ifdef VBOX_WITH_WDDM
260 bool bRunningUnderWDDM;
261# endif
262#endif
263
264#ifdef CR_NEWWINTRACK
265 RTTHREAD hSyncThread;
266 bool volatile bShutdownSyncThread;
267#endif
268
269} Stub;
270
271#ifdef CHROMIUM_THREADSAFE
272/* we place the g_stubCurrentContextTLS outside the Stub data because Stub data is inited by the client's call,
273 * while we need g_stubCurrentContextTLS the g_stubCurrentContextTLS to be valid at any time to be able to handle
274 * THREAD_DETACH cleanup on windows.
275 * Note that we can not do
276 * STUB_INIT_LOCK();
277 * if (stub_initialized) stubSetCurrentContext(NULL);
278 * STUB_INIT_UNLOCK();
279 * on THREAD_DETACH since it may cause deadlock, i.e. in this situation loader lock is acquired first and then the init lock,
280 * but since we use GetModuleFileName in crGetProcName called from stubInitLocked, the lock order might be the oposite.
281 * Note that GetModuleFileName acquires the loader lock.
282 * */
283extern CRtsd g_stubCurrentContextTSD;
284
285DECLINLINE(ContextInfo*) stubGetCurrentContext(void)
286{
287 ContextInfo* ctx;
288 VBoxTlsRefGetCurrentFunctional(ctx, ContextInfo, &g_stubCurrentContextTSD);
289 return ctx;
290}
291# define stubSetCurrentContext(_ctx) VBoxTlsRefSetCurrent(ContextInfo, &g_stubCurrentContextTSD, _ctx)
292#else
293# define stubGetCurrentContext() (stub.currentContext)
294# define stubSetCurrentContext(_ctx) do { stub.currentContext = (_ctx); } while (0)
295#endif
296
297extern Stub stub;
298
299extern DECLEXPORT(SPUDispatchTable) glim;
300extern SPUDispatchTable stubThreadsafeDispatch;
301extern DECLEXPORT(SPUDispatchTable) stubNULLDispatch;
302
303#if defined(GLX) || defined (WINDOWS)
304extern GLboolean stubUpdateWindowVisibileRegions(WindowInfo *pWindow);
305#endif
306
307#ifdef WINDOWS
308
309/* WGL versions */
310extern WindowInfo *stubGetWindowInfo( HDC drawable );
311
312extern void stubInstallWindowMessageHook();
313extern void stubUninstallWindowMessageHook();
314
315#elif defined(DARWIN)
316
317extern CGSConnectionID _CGSDefaultConnection(void);
318extern OSStatus CGSGetWindowLevel( CGSConnectionID cid, CGSWindowID wid, CGWindowLevel *level );
319extern OSStatus CGSSetWindowAlpha( const CGSConnectionID cid, CGSWindowID wid, float alpha );
320
321/* These don't seem to be included in the OSX glext.h ... */
322extern void glPointParameteri( GLenum pname, GLint param );
323extern void glPointParameteriv( GLenum pname, const GLint * param );
324
325extern WindowInfo *stubGetWindowInfo( CGSWindowID drawable );
326
327#elif defined(GLX)
328
329/* GLX versions */
330extern WindowInfo *stubGetWindowInfo( Display *dpy, GLXDrawable drawable );
331extern void stubUseXFont( Display *dpy, Font font, int first, int count, int listbase );
332extern Display* stubGetWindowDisplay(WindowInfo *pWindow);
333
334extern void stubCheckXExtensions(WindowInfo *pWindow);
335#endif
336
337
338extern ContextInfo *stubNewContext(char *dpyName, GLint visBits, ContextType type, unsigned long shareCtx
339#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
340 , struct VBOXUHGSMI *pHgsmi
341#endif
342 );
343extern void stubConChromiumParameteriCR(GLint con, GLenum param, GLint value);
344extern void stubConChromiumParametervCR(GLint con, GLenum target, GLenum type, GLsizei count, const GLvoid *values);
345extern GLboolean stubCtxCreate(ContextInfo *context);
346extern GLboolean stubCtxCheckCreate(ContextInfo *context);
347extern void stubDestroyContext( unsigned long contextId );
348extern GLboolean stubMakeCurrent( WindowInfo *window, ContextInfo *context );
349extern GLint stubNewWindow( const char *dpyName, GLint visBits );
350extern void stubDestroyWindow( GLint con, GLint window );
351extern void stubSwapBuffers(WindowInfo *window, GLint flags);
352extern void stubGetWindowGeometry(WindowInfo *win, int *x, int *y, unsigned int *w, unsigned int *h);
353extern GLboolean stubUpdateWindowGeometry(WindowInfo *pWindow, GLboolean bForceUpdate);
354extern GLboolean stubIsWindowVisible(WindowInfo *win);
355extern bool stubInit(void);
356
357extern void stubForcedFlush(GLint con);
358extern void stubConFlush(GLint con);
359extern void APIENTRY stub_GetChromiumParametervCR( GLenum target, GLuint index, GLenum type, GLsizei count, GLvoid *values );
360
361extern void APIENTRY glBoundsInfoCR(const CRrecti *, const GLbyte *, GLint, GLint);
362
363#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
364# define CR_CTX_CON(_pCtx) ((_pCtx)->spuConnection)
365#else
366# define CR_CTX_CON(_pCtx) (0)
367#endif
368
369#endif /* CR_STUB_H */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette