VirtualBox

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

Last change on this file since 30440 was 30440, checked in by vboxsync, 15 years ago

crOpenGL: wddm friendly windows info tracking + more consistent updates (disabled except windows yet)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.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 * mimimum_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 * mimimum_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#endif
47
48#ifdef WINDOWS
49#define CR_NEWWINTRACK
50#endif
51
52#if !defined(CHROMIUM_THREADSAFE) && defined(CR_NEWWINTRACK)
53# error CHROMIUM_THREADSAFE have to be defined
54#endif
55
56#if defined(CR_NEWWINTRACK) && !defined(WINDOWS)
57#define XLOCK(dpy) XLockDisplay(dpy)
58#define XUNLOCK(dpy) XUnlockDisplay(dpy)
59#else
60#define XLOCK(dpy)
61#define XUNLOCK(dpy)
62#endif
63
64/* When we first create a rendering context we can't be sure whether
65 * it'll be handled by Chromium or as a native GLX/WGL context. So in
66 * CreateContext() we'll mark the ContextInfo object as UNDECIDED then
67 * switch it to either NATIVE or CHROMIUM the first time MakeCurrent()
68 * is called. In MakeCurrent() we can use a criteria like window size
69 * or window title to decide between CHROMIUM and NATIVE.
70 */
71typedef enum
72{
73 UNDECIDED,
74 CHROMIUM,
75 NATIVE
76} ContextType;
77
78#define MAX_DPY_NAME 1000
79
80typedef struct context_info_t ContextInfo;
81typedef struct window_info_t WindowInfo;
82
83#ifdef GLX
84typedef struct glxpixmap_info_t GLX_Pixmap_t;
85
86struct glxpixmap_info_t
87{
88 int x, y;
89 unsigned int w, h, border, depth;
90 GLenum format;
91 Window root;
92 GLenum target;
93 GC gc;
94 Pixmap hShmPixmap; /* Shared memory pixmap object, if it's supported*/
95 Damage hDamage; /* damage xserver handle*/
96 Bool bPixmapImageDirty;
97 Region pDamageRegion;
98};
99#endif
100
101struct context_info_t
102{
103 char dpyName[MAX_DPY_NAME];
104 GLint spuContext; /* returned by head SPU's CreateContext() */
105 ContextType type; /* CHROMIUM, NATIVE or UNDECIDED */
106 unsigned long id; /* the client-visible handle */
107 GLint visBits;
108 WindowInfo *currentDrawable;
109
110#ifdef WINDOWS
111 HGLRC hglrc;
112#elif defined(DARWIN)
113 ContextInfo *share;
114 CGLContextObj cglc;
115
116 /* CGLContextEnable (CGLEnable, CGLDisable, and CGLIsEnabled) */
117 unsigned int options;
118
119 /* CGLContextParameter (CGLSetParameter and CGLGetParameter) */
120 GLint parambits;
121 long swap_rect[4], swap_interval;
122 unsigned long client_storage;
123 long surf_order, surf_opacy;
124
125 long disp_mask;
126#elif defined(GLX)
127 Display *dpy;
128 ContextInfo *share;
129 XVisualInfo *visual;
130 Bool direct;
131 GLXContext glxContext;
132 CRHashTable *pGLXPixmapsHash;
133 Bool damageInitFailed;
134 Display *damageDpy; /* second display connection to read xdamage extension data */
135 int damageEventsBase;
136#endif
137};
138
139#ifdef DARWIN
140enum {
141 VISBIT_SWAP_RECT,
142 VISBIT_SWAP_INTERVAL,
143 VISBIT_CLIENT_STORAGE
144};
145#endif
146
147struct window_info_t
148{
149 char dpyName[MAX_DPY_NAME];
150 int x, y;
151 unsigned int width, height;
152 ContextType type;
153 GLint spuWindow; /* returned by head SPU's WindowCreate() */
154 ContextInfo *pOwner; /* ctx which created this window */
155 GLboolean mapped;
156#ifdef WINDOWS
157 HDC drawable;
158 HRGN hVisibleRegion;
159 DWORD dmPelsWidth;
160 DWORD dmPelsHeight;
161 HWND hWnd;
162#elif defined(DARWIN)
163 CGSConnectionID connection;
164 CGSWindowID drawable;
165 CGSSurfaceID surface;
166#elif defined(GLX)
167 Display *dpy;
168 GLXDrawable drawable;
169 XRectangle *pVisibleRegions;
170 GLint cVisibleRegions;
171#endif
172#ifdef CR_NEWWINTRACK
173 uint32_t u32ClientID;
174#endif
175};
176
177/* "Global" variables for the stub library */
178typedef struct {
179 /* the first SPU in the SPU chain on this app node */
180 SPU *spu;
181
182 /* OpenGL/SPU dispatch tables */
183 crOpenGLInterface wsInterface;
184 SPUDispatchTable spuDispatch;
185 SPUDispatchTable nativeDispatch;
186 GLboolean haveNativeOpenGL;
187
188 /* config options */
189 int appDrawCursor;
190 GLuint minChromiumWindowWidth;
191 GLuint minChromiumWindowHeight;
192 GLuint maxChromiumWindowWidth;
193 GLuint maxChromiumWindowHeight;
194 GLuint matchChromiumWindowCount;
195 GLuint matchChromiumWindowCounter;
196 GLuint *matchChromiumWindowID;
197 GLuint numIgnoreWindowID;
198 char *matchWindowTitle;
199 int ignoreFreeglutMenus;
200 int trackWindowSize;
201 int trackWindowPos;
202 int trackWindowVisibility;
203 int trackWindowVisibleRgn;
204 char *spu_dir;
205 int force_pbuffers;
206 int viewportHack;
207
208 /* thread safety stuff */
209 GLboolean threadSafe;
210#ifdef CHROMIUM_THREADSAFE
211 CRtsd dispatchTSD;
212 CRmutex mutex;
213#endif
214
215 CRpid mothershipPID;
216
217 /* contexts */
218 int freeContextNumber;
219 CRHashTable *contextTable;
220 ContextInfo *currentContext; /* may be NULL */
221
222 /* windows */
223 CRHashTable *windowTable;
224
225#ifdef GLX
226 /* Shared memory, used to transfer XServer pixmaps data into client memory */
227 XShmSegmentInfo xshmSI;
228 GLboolean bShmInitFailed;
229
230 CRHashTable *pGLXPixmapsHash;
231#endif
232
233#ifdef WINDOWS
234# ifndef CR_NEWWINTRACK
235 HHOOK hMessageHook;
236# endif
237#endif
238
239#ifdef CR_NEWWINTRACK
240 RTTHREAD hSyncThread;
241 bool volatile bShutdownSyncThread;
242#endif
243
244} Stub;
245
246
247extern Stub stub;
248extern DECLEXPORT(SPUDispatchTable) glim;
249extern SPUDispatchTable stubThreadsafeDispatch;
250extern DECLEXPORT(SPUDispatchTable) stubNULLDispatch;
251
252#if defined(GLX) || defined (WINDOWS)
253extern GLboolean stubUpdateWindowVisibileRegions(WindowInfo *pWindow);
254#endif
255
256#ifdef WINDOWS
257
258/* WGL versions */
259extern WindowInfo *stubGetWindowInfo( HDC drawable );
260
261extern void stubInstallWindowMessageHook();
262extern void stubUninstallWindowMessageHook();
263
264#elif defined(DARWIN)
265
266extern CGSConnectionID _CGSDefaultConnection(void);
267extern OSStatus CGSGetWindowLevel( CGSConnectionID cid, CGSWindowID wid, CGWindowLevel *level );
268extern OSStatus CGSSetWindowAlpha( const CGSConnectionID cid, CGSWindowID wid, float alpha );
269
270/* These don't seem to be included in the OSX glext.h ... */
271extern void glPointParameteri( GLenum pname, GLint param );
272extern void glPointParameteriv( GLenum pname, const GLint * param );
273
274extern WindowInfo *stubGetWindowInfo( CGSWindowID drawable );
275
276#elif defined(GLX)
277
278/* GLX versions */
279extern WindowInfo *stubGetWindowInfo( Display *dpy, GLXDrawable drawable );
280extern void stubUseXFont( Display *dpy, Font font, int first, int count, int listbase );
281
282#endif
283
284
285extern ContextInfo *stubNewContext( const char *dpyName, GLint visBits, ContextType type, unsigned long shareCtx );
286extern void stubDestroyContext( unsigned long contextId );
287extern GLboolean stubMakeCurrent( WindowInfo *window, ContextInfo *context );
288extern GLint stubNewWindow( const char *dpyName, GLint visBits );
289extern void stubSwapBuffers( const WindowInfo *window, GLint flags );
290extern void stubGetWindowGeometry( const WindowInfo *win, int *x, int *y, unsigned int *w, unsigned int *h );
291extern GLboolean stubUpdateWindowGeometry(WindowInfo *pWindow, GLboolean bForceUpdate);
292extern GLboolean stubIsWindowVisible( const WindowInfo *win );
293extern bool stubInit(void);
294
295extern void APIENTRY stub_GetChromiumParametervCR( GLenum target, GLuint index, GLenum type, GLsizei count, GLvoid *values );
296
297extern void APIENTRY glBoundsInfoCR(const CRrecti *, const GLbyte *, GLint, GLint);
298
299#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