VirtualBox

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

Last change on this file since 76771 was 70851, checked in by vboxsync, 7 years ago

HostServices/SharedOpenGL: turn CR_RENDER_FORCE_PRESENT_MAIN_THREAD conditional compilation into a runtime check based on an env variable, for both glx (where it defaults to 1) and wgl (where it defaults to 0).

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