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 | #ifndef CR_RENDERSPU_H
|
---|
8 | #define CR_RENDERSPU_H
|
---|
9 |
|
---|
10 | #ifdef WINDOWS
|
---|
11 | #define WIN32_LEAN_AND_MEAN
|
---|
12 | #include <windows.h>
|
---|
13 | #define RENDER_APIENTRY __stdcall
|
---|
14 | #elif defined(DARWIN)
|
---|
15 | # ifndef VBOX_WITH_COCOA_QT
|
---|
16 | # include <AGL/AGL.h>
|
---|
17 | # else
|
---|
18 | # include "renderspu_cocoa_helper.h"
|
---|
19 | # endif
|
---|
20 | #define RENDER_APIENTRY
|
---|
21 | #else
|
---|
22 | #include <GL/glx.h>
|
---|
23 | #define RENDER_APIENTRY
|
---|
24 | #endif
|
---|
25 | #include "cr_threads.h"
|
---|
26 | #include "cr_spu.h"
|
---|
27 | #include "cr_hash.h"
|
---|
28 | #include "cr_server.h"
|
---|
29 |
|
---|
30 | #include <iprt/cdefs.h>
|
---|
31 |
|
---|
32 | #define MAX_VISUALS 32
|
---|
33 |
|
---|
34 | #ifdef RT_OS_DARWIN
|
---|
35 | # ifndef VBOX_WITH_COCOA_QT
|
---|
36 | enum
|
---|
37 | {
|
---|
38 | /* Event classes */
|
---|
39 | kEventClassVBox = 'vbox',
|
---|
40 | /* Event kinds */
|
---|
41 | kEventVBoxShowWindow = 'swin',
|
---|
42 | kEventVBoxHideWindow = 'hwin',
|
---|
43 | kEventVBoxMoveWindow = 'mwin',
|
---|
44 | kEventVBoxResizeWindow = 'rwin',
|
---|
45 | kEventVBoxDisposeWindow = 'dwin',
|
---|
46 | kEventVBoxUpdateDock = 'udck',
|
---|
47 | kEventVBoxUpdateContext = 'uctx',
|
---|
48 | kEventVBoxBoundsChanged = 'bchg'
|
---|
49 | };
|
---|
50 | pascal OSStatus windowEvtHndlr(EventHandlerCallRef myHandler, EventRef event, void* userData);
|
---|
51 | # endif
|
---|
52 | #endif /* RT_OS_DARWIN */
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Visual info
|
---|
56 | */
|
---|
57 | typedef struct {
|
---|
58 | GLbitfield visAttribs;
|
---|
59 | const char *displayName;
|
---|
60 | #if defined(WINDOWS)
|
---|
61 | HDC device_context;
|
---|
62 | #elif defined(DARWIN)
|
---|
63 | # ifndef VBOX_WITH_COCOA_QT
|
---|
64 | WindowRef window;
|
---|
65 | # endif
|
---|
66 | #elif defined(GLX)
|
---|
67 | Display *dpy;
|
---|
68 | XVisualInfo *visual;
|
---|
69 | #ifdef GLX_VERSION_1_3
|
---|
70 | GLXFBConfig fbconfig;
|
---|
71 | #endif /* GLX_VERSION_1_3 */
|
---|
72 | #endif
|
---|
73 | } VisualInfo;
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Window info
|
---|
77 | */
|
---|
78 | typedef struct {
|
---|
79 | int x, y;
|
---|
80 | int width, height;
|
---|
81 | int id; /**< integer window ID */
|
---|
82 | VisualInfo *visual;
|
---|
83 | GLboolean mapPending;
|
---|
84 | GLboolean visible;
|
---|
85 | GLboolean everCurrent; /**< has this window ever been bound? */
|
---|
86 | char *title;
|
---|
87 | #if defined(WINDOWS)
|
---|
88 | HDC nativeWindow; /**< for render_to_app_window */
|
---|
89 | HWND hWnd;
|
---|
90 | HDC device_context;
|
---|
91 | #elif defined(DARWIN)
|
---|
92 | # ifndef VBOX_WITH_COCOA_QT
|
---|
93 | WindowRef window;
|
---|
94 | WindowRef nativeWindow; /**< for render_to_app_window */
|
---|
95 | WindowRef appWindow;
|
---|
96 | EventHandlerUPP event_handler;
|
---|
97 | GLint bufferName;
|
---|
98 | AGLContext dummyContext;
|
---|
99 | RgnHandle hVisibleRegion;
|
---|
100 | /* unsigned long context_ptr; */
|
---|
101 | # else
|
---|
102 | NativeViewRef window;
|
---|
103 | NativeViewRef nativeWindow; /**< for render_to_app_window */
|
---|
104 | NativeGLCtxRef *currentCtx;
|
---|
105 | # endif
|
---|
106 | #elif defined(GLX)
|
---|
107 | Window window;
|
---|
108 | Window nativeWindow; /**< for render_to_app_window */
|
---|
109 | Window appWindow; /**< Same as nativeWindow but for garbage collections purposes */
|
---|
110 | #endif
|
---|
111 | int nvSwapGroup;
|
---|
112 |
|
---|
113 | #ifdef USE_OSMESA
|
---|
114 | GLubyte *buffer; /**< for rendering to off screen buffer. */
|
---|
115 | int in_buffer_width;
|
---|
116 | int in_buffer_height;
|
---|
117 | #endif
|
---|
118 |
|
---|
119 | } WindowInfo;
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Context Info
|
---|
123 | */
|
---|
124 | typedef struct _ContextInfo {
|
---|
125 | int id; /**< integer context ID */
|
---|
126 | VisualInfo *visual;
|
---|
127 | GLboolean everCurrent;
|
---|
128 | GLboolean haveWindowPosARB;
|
---|
129 | WindowInfo *currentWindow;
|
---|
130 | #if defined(WINDOWS)
|
---|
131 | HGLRC hRC;
|
---|
132 | #elif defined(DARWIN)
|
---|
133 | # ifndef VBOX_WITH_COCOA_QT
|
---|
134 | AGLContext context;
|
---|
135 | # else
|
---|
136 | NativeGLCtxRef context;
|
---|
137 | # endif
|
---|
138 | #elif defined(GLX)
|
---|
139 | GLXContext context;
|
---|
140 | #endif
|
---|
141 | struct _ContextInfo *shared;
|
---|
142 | char *extensionString;
|
---|
143 | } ContextInfo;
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Barrier info
|
---|
147 | */
|
---|
148 | typedef struct {
|
---|
149 | CRbarrier barrier;
|
---|
150 | GLuint count;
|
---|
151 | } Barrier;
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Renderspu state info
|
---|
155 | */
|
---|
156 | typedef struct {
|
---|
157 | SPUDispatchTable self;
|
---|
158 | int id;
|
---|
159 |
|
---|
160 | unsigned int window_id;
|
---|
161 | unsigned int context_id;
|
---|
162 |
|
---|
163 | /** config options */
|
---|
164 | /*@{*/
|
---|
165 | char *window_title;
|
---|
166 | int defaultX, defaultY;
|
---|
167 | unsigned int defaultWidth, defaultHeight;
|
---|
168 | int default_visual;
|
---|
169 | int use_L2;
|
---|
170 | int fullscreen, ontop;
|
---|
171 | char display_string[100];
|
---|
172 | #if defined(GLX)
|
---|
173 | int try_direct;
|
---|
174 | int force_direct;
|
---|
175 | int sync;
|
---|
176 | #endif
|
---|
177 | int render_to_app_window;
|
---|
178 | int render_to_crut_window;
|
---|
179 | int crut_drawable;
|
---|
180 | int resizable;
|
---|
181 | int use_lut8, lut8[3][256];
|
---|
182 | int borderless;
|
---|
183 | int nvSwapGroup;
|
---|
184 | int ignore_papi;
|
---|
185 | int ignore_window_moves;
|
---|
186 | int pbufferWidth, pbufferHeight;
|
---|
187 | int use_glxchoosevisual;
|
---|
188 | int draw_bbox;
|
---|
189 | /*@}*/
|
---|
190 |
|
---|
191 | CRServer *server;
|
---|
192 | int gather_port;
|
---|
193 | int gather_userbuf_size;
|
---|
194 | CRConnection **gather_conns;
|
---|
195 |
|
---|
196 | GLint drawCursor;
|
---|
197 | GLint cursorX, cursorY;
|
---|
198 |
|
---|
199 | int numVisuals;
|
---|
200 | VisualInfo visuals[MAX_VISUALS];
|
---|
201 |
|
---|
202 | CRHashTable *windowTable;
|
---|
203 | CRHashTable *contextTable;
|
---|
204 |
|
---|
205 | #ifndef CHROMIUM_THREADSAFE
|
---|
206 | ContextInfo *currentContext;
|
---|
207 | #endif
|
---|
208 |
|
---|
209 | crOpenGLInterface ws; /**< Window System interface */
|
---|
210 |
|
---|
211 | CRHashTable *barrierHash;
|
---|
212 |
|
---|
213 | int is_swap_master, num_swap_clients;
|
---|
214 | int swap_mtu;
|
---|
215 | char *swap_master_url;
|
---|
216 | CRConnection **swap_conns;
|
---|
217 |
|
---|
218 | #ifdef USE_OSMESA
|
---|
219 | /** Off screen rendering hooks. */
|
---|
220 | int use_osmesa;
|
---|
221 |
|
---|
222 | OSMesaContext (*OSMesaCreateContext)( GLenum format, OSMesaContext sharelist );
|
---|
223 | GLboolean (* OSMesaMakeCurrent)( OSMesaContext ctx,
|
---|
224 | GLubyte *buffer,
|
---|
225 | GLenum type,
|
---|
226 | GLsizei width,
|
---|
227 | GLsizei height );
|
---|
228 | void (*OSMesaDestroyContext)( OSMesaContext ctx );
|
---|
229 | #endif
|
---|
230 |
|
---|
231 | #ifdef RT_OS_WINDOWS
|
---|
232 | DWORD dwWinThreadId;
|
---|
233 | HANDLE hWinThreadReadyEvent;
|
---|
234 | #endif
|
---|
235 |
|
---|
236 | #ifdef RT_OS_DARWIN
|
---|
237 | # ifndef VBOX_WITH_COCOA_QT
|
---|
238 | RgnHandle hRootVisibleRegion;
|
---|
239 | RTSEMFASTMUTEX syncMutex;
|
---|
240 | EventHandlerUPP hParentEventHandler;
|
---|
241 | WindowGroupRef pParentGroup;
|
---|
242 | WindowGroupRef pMasterGroup;
|
---|
243 | GLint currentBufferName;
|
---|
244 | uint64_t uiDockUpdateTS;
|
---|
245 | bool fInit;
|
---|
246 | # endif
|
---|
247 | #endif /* RT_OS_DARWIN */
|
---|
248 | } RenderSPU;
|
---|
249 |
|
---|
250 | #ifdef RT_OS_WINDOWS
|
---|
251 |
|
---|
252 | /* Asks window thread to create new window.
|
---|
253 | msg.lParam - holds pointer to CREATESTRUCT structure
|
---|
254 | note that lpCreateParams is used to specify address to store handle of created window
|
---|
255 | msg.wParam - unused, should be NULL
|
---|
256 | */
|
---|
257 | #define WM_VBOX_RENDERSPU_CREATE_WINDOW (WM_APP+1)
|
---|
258 |
|
---|
259 | typedef struct _VBOX_RENDERSPU_DESTROY_WINDOW {
|
---|
260 | HWND hWnd; /* handle to window to destroy */
|
---|
261 | } VBOX_RENDERSPU_DESTROY_WINDOW;
|
---|
262 |
|
---|
263 | /* Asks window thread to destroy previously created window.
|
---|
264 | msg.lParam - holds pointer to RENDERSPU_VBOX_WINDOW_DESTROY structure
|
---|
265 | msg.wParam - unused, should be NULL
|
---|
266 | */
|
---|
267 | #define WM_VBOX_RENDERSPU_DESTROY_WINDOW (WM_APP+2)
|
---|
268 |
|
---|
269 | #endif
|
---|
270 |
|
---|
271 | extern RenderSPU render_spu;
|
---|
272 |
|
---|
273 | /* @todo remove this hack */
|
---|
274 | extern uint64_t render_spu_parent_window_id;
|
---|
275 |
|
---|
276 | #ifdef CHROMIUM_THREADSAFE
|
---|
277 | extern CRtsd _RenderTSD;
|
---|
278 | #define GET_CONTEXT(T) ContextInfo *T = (ContextInfo *) crGetTSD(&_RenderTSD)
|
---|
279 | #else
|
---|
280 | #define GET_CONTEXT(T) ContextInfo *T = render_spu.currentContext
|
---|
281 | #endif
|
---|
282 |
|
---|
283 | extern void renderspuSetVBoxConfiguration( RenderSPU *spu );
|
---|
284 | extern void renderspuMakeVisString( GLbitfield visAttribs, char *s );
|
---|
285 | extern VisualInfo *renderspuFindVisual(const char *displayName, GLbitfield visAttribs );
|
---|
286 | extern GLboolean renderspu_SystemInitVisual( VisualInfo *visual );
|
---|
287 | extern GLboolean renderspu_SystemCreateContext( VisualInfo *visual, ContextInfo *context, ContextInfo *sharedContext );
|
---|
288 | extern void renderspu_SystemDestroyContext( ContextInfo *context );
|
---|
289 | extern GLboolean renderspu_SystemCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window );
|
---|
290 | extern GLboolean renderspu_SystemVBoxCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window );
|
---|
291 | extern void renderspu_SystemDestroyWindow( WindowInfo *window );
|
---|
292 | extern void renderspu_SystemWindowSize( WindowInfo *window, GLint w, GLint h );
|
---|
293 | extern void renderspu_SystemGetWindowGeometry( WindowInfo *window, GLint *x, GLint *y, GLint *w, GLint *h );
|
---|
294 | extern void renderspu_SystemGetMaxWindowSize( WindowInfo *window, GLint *w, GLint *h );
|
---|
295 | extern void renderspu_SystemWindowPosition( WindowInfo *window, GLint x, GLint y );
|
---|
296 | extern void renderspu_SystemWindowVisibleRegion(WindowInfo *window, GLint cRects, GLint* pRects);
|
---|
297 | extern void renderspu_SystemWindowApplyVisibleRegion(WindowInfo *window);
|
---|
298 | #ifdef RT_OS_DARWIN
|
---|
299 | extern void renderspu_SystemSetRootVisibleRegion(GLint cRects, GLint *pRects);
|
---|
300 | # ifdef VBOX_WITH_COCOA_QT
|
---|
301 | extern void renderspu_SystemFlush();
|
---|
302 | extern void renderspu_SystemFinish();
|
---|
303 | extern void renderspu_SystemBindFramebufferEXT(GLenum target, GLuint framebuffer);
|
---|
304 | # endif
|
---|
305 | #endif
|
---|
306 | extern void renderspu_SystemShowWindow( WindowInfo *window, GLboolean showIt );
|
---|
307 | extern void renderspu_SystemMakeCurrent( WindowInfo *window, GLint windowInfor, ContextInfo *context );
|
---|
308 | extern void renderspu_SystemSwapBuffers( WindowInfo *window, GLint flags );
|
---|
309 | extern void renderspu_GCWindow(void);
|
---|
310 | extern int renderspuCreateFunctions( SPUNamedFunctionTable table[] );
|
---|
311 |
|
---|
312 | extern GLint RENDER_APIENTRY renderspuWindowCreate( const char *dpyName, GLint visBits );
|
---|
313 | extern GLint RENDER_APIENTRY renderspuCreateContext( const char *dpyname, GLint visBits, GLint shareCtx );
|
---|
314 | extern void RENDER_APIENTRY renderspuMakeCurrent(GLint crWindow, GLint nativeWindow, GLint ctx);
|
---|
315 | extern void RENDER_APIENTRY renderspuSwapBuffers( GLint window, GLint flags );
|
---|
316 |
|
---|
317 | #if defined(WINDOWS) || defined(GLX)
|
---|
318 | extern void renderspu_SystemReparentWindow(WindowInfo *window);
|
---|
319 | #endif
|
---|
320 |
|
---|
321 | #ifdef __cplusplus
|
---|
322 | extern "C" {
|
---|
323 | #endif
|
---|
324 | DECLEXPORT(void) renderspuSetWindowId(uint64_t winId);
|
---|
325 | DECLEXPORT(void) renderspuSetRootVisibleRegion(GLint cRects, GLint *pRects);
|
---|
326 | DECLEXPORT(void) renderspuReparentWindow(GLint window);
|
---|
327 | #ifdef __cplusplus
|
---|
328 | }
|
---|
329 | #endif
|
---|
330 |
|
---|
331 | #endif /* CR_RENDERSPU_H */
|
---|