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