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