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