VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.h@ 45053

Last change on this file since 45053 was 44997, checked in by vboxsync, 12 years ago

crOpenGL/win: fix redraw concurrency

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.8 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#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#include <iprt/critsect.h>
34#if defined(GLX) /* @todo: unify windows and glx thread creation code */
35#include <iprt/thread.h>
36#include <iprt/semaphore.h>
37
38/* special window id used for representing the command window CRWindowInfo */
39#define CR_RENDER_WINCMD_ID (INT32_MAX-2)
40AssertCompile(CR_RENDER_WINCMD_ID != CR_RENDER_DEFAULT_WINDOW_ID);
41/* CRHashTable is using unsigned long keys, we use it to trore X Window -> CRWindowInfo association */
42AssertCompile(sizeof (Window) == sizeof (unsigned long));
43#endif
44
45
46#define MAX_VISUALS 32
47
48#ifdef RT_OS_DARWIN
49# ifndef VBOX_WITH_COCOA_QT
50enum
51{
52 /* Event classes */
53 kEventClassVBox = 'vbox',
54 /* Event kinds */
55 kEventVBoxShowWindow = 'swin',
56 kEventVBoxHideWindow = 'hwin',
57 kEventVBoxMoveWindow = 'mwin',
58 kEventVBoxResizeWindow = 'rwin',
59 kEventVBoxDisposeWindow = 'dwin',
60 kEventVBoxUpdateDock = 'udck',
61 kEventVBoxUpdateContext = 'uctx',
62 kEventVBoxBoundsChanged = 'bchg'
63};
64pascal OSStatus windowEvtHndlr(EventHandlerCallRef myHandler, EventRef event, void* userData);
65# endif
66#endif /* RT_OS_DARWIN */
67
68/**
69 * Visual info
70 */
71typedef struct {
72 GLbitfield visAttribs;
73 const char *displayName;
74#if defined(WINDOWS)
75// HDC device_context;
76#elif defined(DARWIN)
77# ifndef VBOX_WITH_COCOA_QT
78 WindowRef window;
79# endif
80#elif defined(GLX)
81 Display *dpy;
82 XVisualInfo *visual;
83#ifdef GLX_VERSION_1_3
84 GLXFBConfig fbconfig;
85#endif /* GLX_VERSION_1_3 */
86#endif
87} VisualInfo;
88
89/**
90 * Window info
91 */
92typedef struct WindowInfo {
93 int x, y;
94// int width, height;
95// int id; /**< integer window ID */
96 CR_BLITTER_WINDOW BltInfo;
97
98 VisualInfo *visual;
99 GLboolean mapPending;
100 GLboolean visible;
101 GLboolean everCurrent; /**< has this window ever been bound? */
102 char *title;
103
104 PVBOXVR_SCR_COMPOSITOR pCompositor;
105 /* the composotor lock is used to synchronize the current compositor access,
106 * i.e. the compositor can be accessed by a gui refraw thread,
107 * while chromium thread might try to set a new compositor
108 * note that the compositor internally has its own lock to be used for accessing its data
109 * see CrVrScrCompositorLock/Unlock; renderspu and crserverlib would use it for compositor data access */
110 RTCRITSECT CompositorLock;
111 PCR_BLITTER pBlitter;
112#if defined(WINDOWS)
113 HDC nativeWindow; /**< for render_to_app_window */
114 HWND hWnd;
115 HDC device_context;
116 HDC redraw_device_context;
117 HRGN hRgn;
118#elif defined(DARWIN)
119# ifndef VBOX_WITH_COCOA_QT
120 WindowRef window;
121 WindowRef nativeWindow; /**< for render_to_app_window */
122 WindowRef appWindow;
123 EventHandlerUPP event_handler;
124 GLint bufferName;
125 AGLContext dummyContext;
126 RgnHandle hVisibleRegion;
127 /* unsigned long context_ptr; */
128# else
129 NativeNSViewRef window;
130 NativeNSViewRef nativeWindow; /**< for render_to_app_window */
131 NativeNSOpenGLContextRef *currentCtx;
132# endif
133#elif defined(GLX)
134 Window window;
135 Window nativeWindow; /**< for render_to_app_window */
136 Window appWindow; /**< Same as nativeWindow but for garbage collections purposes */
137#endif
138 int nvSwapGroup;
139
140#ifdef USE_OSMESA
141 GLubyte *buffer; /**< for rendering to off screen buffer. */
142 int in_buffer_width;
143 int in_buffer_height;
144#endif
145
146} WindowInfo;
147
148/**
149 * Context Info
150 */
151typedef struct _ContextInfo {
152// int id; /**< integer context ID */
153 CR_BLITTER_CONTEXT BltInfo;
154 VisualInfo *visual;
155 GLboolean everCurrent;
156 GLboolean haveWindowPosARB;
157 WindowInfo *currentWindow;
158#if defined(WINDOWS)
159 HGLRC hRC;
160#elif defined(DARWIN)
161# ifndef VBOX_WITH_COCOA_QT
162 AGLContext context;
163# else
164 NativeNSOpenGLContextRef context;
165# endif
166#elif defined(GLX)
167 GLXContext context;
168#endif
169 struct _ContextInfo *shared;
170 char *extensionString;
171 volatile uint32_t cRefs;
172} ContextInfo;
173
174/**
175 * Barrier info
176 */
177typedef struct {
178 CRbarrier barrier;
179 GLuint count;
180} Barrier;
181
182#ifdef GLX
183typedef enum
184{
185 CR_RENDER_WINCMD_TYPE_UNDEFINED = 0,
186 /* create the window (not used for now) */
187 CR_RENDER_WINCMD_TYPE_WIN_CREATE,
188 /* destroy the window (not used for now) */
189 CR_RENDER_WINCMD_TYPE_WIN_DESTROY,
190 /* notify the WinCmd thread about window creation */
191 CR_RENDER_WINCMD_TYPE_WIN_ON_CREATE,
192 /* notify the WinCmd thread about window destroy */
193 CR_RENDER_WINCMD_TYPE_WIN_ON_DESTROY,
194 /* nop used to synchronize with the WinCmd thread */
195 CR_RENDER_WINCMD_TYPE_NOP,
196 /* exit Win Cmd thread */
197 CR_RENDER_WINCMD_TYPE_EXIT,
198} CR_RENDER_WINCMD_TYPE;
199
200typedef struct CR_RENDER_WINCMD
201{
202 /* command type */
203 CR_RENDER_WINCMD_TYPE enmCmd;
204 /* command result */
205 int rc;
206 /* valid for WIN_CREATE & WIN_DESTROY only */
207 WindowInfo *pWindow;
208} CR_RENDER_WINCMD, *PCR_RENDER_WINCMD;
209#endif
210
211/**
212 * Renderspu state info
213 */
214typedef struct {
215 SPUDispatchTable self;
216 int id;
217
218 /** config options */
219 /*@{*/
220 char *window_title;
221 int defaultX, defaultY;
222 unsigned int defaultWidth, defaultHeight;
223 int default_visual;
224 int use_L2;
225 int fullscreen, ontop;
226 char display_string[100];
227#if defined(GLX)
228 int try_direct;
229 int force_direct;
230 int sync;
231#endif
232 int render_to_app_window;
233 int render_to_crut_window;
234 int crut_drawable;
235 int resizable;
236 int use_lut8, lut8[3][256];
237 int borderless;
238 int nvSwapGroup;
239 int ignore_papi;
240 int ignore_window_moves;
241 int pbufferWidth, pbufferHeight;
242 int use_glxchoosevisual;
243 int draw_bbox;
244 /*@}*/
245
246 CRServer *server;
247 int gather_port;
248 int gather_userbuf_size;
249 CRConnection **gather_conns;
250
251 GLint drawCursor;
252 GLint cursorX, cursorY;
253
254 int numVisuals;
255 VisualInfo visuals[MAX_VISUALS];
256
257 CRHashTable *windowTable;
258 CRHashTable *contextTable;
259
260#ifndef CHROMIUM_THREADSAFE
261 ContextInfo *currentContext;
262#endif
263
264 crOpenGLInterface ws; /**< Window System interface */
265
266 CRHashTable *barrierHash;
267
268 int is_swap_master, num_swap_clients;
269 int swap_mtu;
270 char *swap_master_url;
271 CRConnection **swap_conns;
272
273 SPUDispatchTable *blitterDispatch;
274 CRHashTable *blitterTable;
275
276#ifdef USE_OSMESA
277 /** Off screen rendering hooks. */
278 int use_osmesa;
279
280 OSMesaContext (*OSMesaCreateContext)( GLenum format, OSMesaContext sharelist );
281 GLboolean (* OSMesaMakeCurrent)( OSMesaContext ctx,
282 GLubyte *buffer,
283 GLenum type,
284 GLsizei width,
285 GLsizei height );
286 void (*OSMesaDestroyContext)( OSMesaContext ctx );
287#endif
288
289#if defined(GLX)
290 RTTHREAD hWinCmdThread;
291 VisualInfo WinCmdVisual;
292 WindowInfo WinCmdWindow;
293 RTSEMEVENT hWinCmdCompleteEvent;
294 /* display connection used to send data to the WinCmd thread */
295 Display *pCommunicationDisplay;
296 Atom WinCmdAtom;
297 /* X Window -> CRWindowInfo table */
298 CRHashTable *pWinToInfoTable;
299#endif
300
301#ifdef RT_OS_WINDOWS
302 DWORD dwWinThreadId;
303 HANDLE hWinThreadReadyEvent;
304#endif
305
306#ifdef RT_OS_DARWIN
307# ifndef VBOX_WITH_COCOA_QT
308 RgnHandle hRootVisibleRegion;
309 RTSEMFASTMUTEX syncMutex;
310 EventHandlerUPP hParentEventHandler;
311 WindowGroupRef pParentGroup;
312 WindowGroupRef pMasterGroup;
313 GLint currentBufferName;
314 uint64_t uiDockUpdateTS;
315 bool fInit;
316# endif
317#endif /* RT_OS_DARWIN */
318
319 int force_hidden_wdn_create;
320} RenderSPU;
321
322#ifdef RT_OS_WINDOWS
323
324/* Asks window thread to create new window.
325 msg.lParam - holds pointer to CREATESTRUCT structure
326 note that lpCreateParams is used to specify address to store handle of created window
327 msg.wParam - unused, should be NULL
328*/
329#define WM_VBOX_RENDERSPU_CREATE_WINDOW (WM_APP+1)
330
331typedef struct _VBOX_RENDERSPU_DESTROY_WINDOW {
332 HWND hWnd; /* handle to window to destroy */
333} VBOX_RENDERSPU_DESTROY_WINDOW;
334
335/* Asks window thread to destroy previously created window.
336 msg.lParam - holds pointer to RENDERSPU_VBOX_WINDOW_DESTROY structure
337 msg.wParam - unused, should be NULL
338*/
339#define WM_VBOX_RENDERSPU_DESTROY_WINDOW (WM_APP+2)
340
341#endif
342
343extern RenderSPU render_spu;
344
345/* @todo remove this hack */
346extern uint64_t render_spu_parent_window_id;
347
348#ifdef CHROMIUM_THREADSAFE
349extern CRtsd _RenderTSD;
350#define GET_CONTEXT_VAL() ((ContextInfo *) crGetTSD(&_RenderTSD))
351#define SET_CONTEXT_VAL(_v) do { \
352 crSetTSD(&_RenderTSD, (_v)); \
353 } while (0)
354#else
355#define GET_CONTEXT_VAL() (render_spu.currentContext)
356#define SET_CONTEXT_VAL(_v) do { \
357 render_spu.currentContext = (_v); \
358 } while (0)
359
360#endif
361
362#define GET_CONTEXT(T) ContextInfo *T = GET_CONTEXT_VAL()
363
364
365
366extern void renderspuSetVBoxConfiguration( RenderSPU *spu );
367extern void renderspuMakeVisString( GLbitfield visAttribs, char *s );
368extern VisualInfo *renderspuFindVisual(const char *displayName, GLbitfield visAttribs );
369extern GLboolean renderspu_SystemInitVisual( VisualInfo *visual );
370extern GLboolean renderspu_SystemCreateContext( VisualInfo *visual, ContextInfo *context, ContextInfo *sharedContext );
371extern void renderspu_SystemDestroyContext( ContextInfo *context );
372extern GLboolean renderspu_SystemCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window );
373extern GLboolean renderspu_SystemVBoxCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window );
374extern void renderspu_SystemDestroyWindow( WindowInfo *window );
375extern void renderspu_SystemWindowSize( WindowInfo *window, GLint w, GLint h );
376extern void renderspu_SystemGetWindowGeometry( WindowInfo *window, GLint *x, GLint *y, GLint *w, GLint *h );
377extern void renderspu_SystemGetMaxWindowSize( WindowInfo *window, GLint *w, GLint *h );
378extern void renderspu_SystemWindowPosition( WindowInfo *window, GLint x, GLint y );
379extern void renderspu_SystemWindowVisibleRegion(WindowInfo *window, GLint cRects, GLint* pRects);
380extern void renderspu_SystemWindowApplyVisibleRegion(WindowInfo *window);
381#ifdef RT_OS_DARWIN
382extern void renderspu_SystemSetRootVisibleRegion(GLint cRects, GLint *pRects);
383#endif
384
385#ifdef GLX
386extern int renderspu_SystemInit();
387extern int renderspu_SystemTerm();
388#endif
389extern void renderspu_SystemShowWindow( WindowInfo *window, GLboolean showIt );
390extern void renderspu_SystemMakeCurrent( WindowInfo *window, GLint windowInfor, ContextInfo *context );
391extern void renderspu_SystemSwapBuffers( WindowInfo *window, GLint flags );
392extern void renderspu_SystemReparentWindow(WindowInfo *window);
393extern void renderspu_SystemVBoxPresentComposition( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry );
394extern void renderspu_GCWindow(void);
395extern int renderspuCreateFunctions( SPUNamedFunctionTable table[] );
396extern void renderspuVBoxCompositorSet( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor);
397extern void renderspuVBoxCompositorClearAll();
398extern int renderspuVBoxCompositorLock(WindowInfo *window);
399extern int renderspuVBoxCompositorUnlock(WindowInfo *window);
400extern struct VBOXVR_SCR_COMPOSITOR * renderspuVBoxCompositorAcquire( WindowInfo *window);
401extern int renderspuVBoxCompositorTryAcquire(WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR **ppCompositor);
402extern void renderspuVBoxCompositorRelease( WindowInfo *window);
403extern void renderspuVBoxPresentCompositionGeneric( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry, int32_t i32MakeCurrentUserData );
404extern PCR_BLITTER renderspuVBoxPresentBlitterGet( WindowInfo *window );
405void renderspuVBoxPresentBlitterCleanup( WindowInfo *window );
406extern int renderspuVBoxPresentBlitterEnter( PCR_BLITTER pBlitter, int32_t i32MakeCurrentUserData );
407extern PCR_BLITTER renderspuVBoxPresentBlitterGetAndEnter( WindowInfo *window, int32_t i32MakeCurrentUserData );
408extern PCR_BLITTER renderspuVBoxPresentBlitterEnsureCreated( WindowInfo *window, int32_t i32MakeCurrentUserData );
409extern void renderspuWindowTerm( WindowInfo *window );
410extern GLboolean renderspuWindowInit( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id );
411extern GLboolean renderspuInitVisual(VisualInfo *pVisInfo, const char *displayName, GLbitfield visAttribs);
412extern void renderspuVBoxCompositorBlit ( struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter);
413extern void renderspuVBoxCompositorBlitStretched ( struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter, GLfloat scaleX, GLfloat scaleY);
414extern GLint renderspuCreateContextEx(const char *dpyName, GLint visBits, GLint id, GLint shareCtx);
415extern GLint renderspuWindowCreateEx( const char *dpyName, GLint visBits, GLint id );
416
417extern GLint RENDER_APIENTRY renderspuWindowCreate( const char *dpyName, GLint visBits );
418void RENDER_APIENTRY renderspuWindowDestroy( GLint win );
419extern GLint RENDER_APIENTRY renderspuCreateContext( const char *dpyname, GLint visBits, GLint shareCtx );
420extern void RENDER_APIENTRY renderspuMakeCurrent(GLint crWindow, GLint nativeWindow, GLint ctx);
421extern void RENDER_APIENTRY renderspuSwapBuffers( GLint window, GLint flags );
422
423extern uint32_t renderspuContextMarkDeletedAndRelease( ContextInfo *context );
424
425#ifdef __cplusplus
426extern "C" {
427#endif
428DECLEXPORT(void) renderspuSetWindowId(uint64_t winId);
429DECLEXPORT(void) renderspuSetRootVisibleRegion(GLint cRects, GLint *pRects);
430DECLEXPORT(void) renderspuReparentWindow(GLint window);
431#ifdef __cplusplus
432}
433#endif
434
435#endif /* CR_RENDERSPU_H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette