VirtualBox

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

Last change on this file since 41465 was 39602, checked in by vboxsync, 13 years ago

wine/XPDM: 1. Additional swapchain creation fixes 2. De-libwine'ize wined3d 3. Single context per swapchain 4. wine & crOgl current context sync fixes 5. Proper Get/ReleaseDC handling

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