VirtualBox

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

Last change on this file since 78384 was 78341, checked in by vboxsync, 6 years ago

Config.kmk,Additions/common/crOpenGL,VBox/GuestHost/OpenGL,HostServices/SharedOpenGL: Remove CHROMIUM_THREADSAFE define and apply the current default

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