VirtualBox

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

Last change on this file since 55840 was 54582, checked in by vboxsync, 10 years ago

Host 3D unscaled HiDPI output: privide notifyHiDPIOutputPolicyChange() IDisplay interface to GUI in ouder to notify 3D about corresponding user option value change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
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 <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 render_to_app_window;
250 int render_to_crut_window;
251 int crut_drawable;
252 int resizable;
253 int use_lut8, lut8[3][256];
254 int borderless;
255 int nvSwapGroup;
256 int ignore_papi;
257 int ignore_window_moves;
258 int pbufferWidth, pbufferHeight;
259 int use_glxchoosevisual;
260 int draw_bbox;
261 /*@}*/
262
263 CRServer *server;
264 int gather_port;
265 int gather_userbuf_size;
266 CRConnection **gather_conns;
267
268 GLint drawCursor;
269 GLint cursorX, cursorY;
270
271 int numVisuals;
272 VisualInfo visuals[MAX_VISUALS];
273
274 CRHashTable *windowTable;
275 CRHashTable *contextTable;
276
277 CRHashTable *dummyWindowTable;
278
279 ContextInfo *defaultSharedContext;
280
281#ifndef CHROMIUM_THREADSAFE
282 ContextInfo *currentContext;
283#endif
284
285 crOpenGLInterface ws; /**< Window System interface */
286
287 CRHashTable *barrierHash;
288
289 int is_swap_master, num_swap_clients;
290 int swap_mtu;
291 char *swap_master_url;
292 CRConnection **swap_conns;
293
294 SPUDispatchTable blitterDispatch;
295 CRHashTable *blitterTable;
296
297 PFNVCRSERVER_CLIENT_CALLOUT pfnClientCallout;
298
299#ifdef USE_OSMESA
300 /** Off screen rendering hooks. */
301 int use_osmesa;
302
303 OSMesaContext (*OSMesaCreateContext)( GLenum format, OSMesaContext sharelist );
304 GLboolean (* OSMesaMakeCurrent)( OSMesaContext ctx,
305 GLubyte *buffer,
306 GLenum type,
307 GLsizei width,
308 GLsizei height );
309 void (*OSMesaDestroyContext)( OSMesaContext ctx );
310#endif
311
312#if defined(GLX)
313 RTTHREAD hWinCmdThread;
314 VisualInfo WinCmdVisual;
315 WindowInfo WinCmdWindow;
316 RTSEMEVENT hWinCmdCompleteEvent;
317 /* display connection used to send data to the WinCmd thread */
318 Display *pCommunicationDisplay;
319 Atom WinCmdAtom;
320 /* X Window -> CRWindowInfo table */
321 CRHashTable *pWinToInfoTable;
322#endif
323
324#ifdef RT_OS_WINDOWS
325 DWORD dwWinThreadId;
326 HANDLE hWinThreadReadyEvent;
327#endif
328
329#ifdef RT_OS_DARWIN
330# ifdef VBOX_WITH_COCOA_QT
331 PFNDELETE_OBJECT pfnDeleteObject;
332 PFNGET_ATTACHED_OBJECTS pfnGetAttachedObjects;
333 PFNGET_HANDLE pfnGetHandle;
334 PFNGET_INFO_LOG pfnGetInfoLog;
335 PFNGET_OBJECT_PARAMETERFV pfnGetObjectParameterfv;
336 PFNGET_OBJECT_PARAMETERIV pfnGetObjectParameteriv;
337
338 CR_GLSL_CACHE GlobalShaders;
339# else
340 RgnHandle hRootVisibleRegion;
341 RTSEMFASTMUTEX syncMutex;
342 EventHandlerUPP hParentEventHandler;
343 WindowGroupRef pParentGroup;
344 WindowGroupRef pMasterGroup;
345 GLint currentBufferName;
346 uint64_t uiDockUpdateTS;
347 bool fInit;
348# endif
349#endif /* RT_OS_DARWIN */
350 /* If TRUE, render should tell window server to prevent artificial content
351 * up-scaling when displayed on HiDPI monitor. */
352 bool fUnscaledHiDPI;
353} RenderSPU;
354
355#ifdef RT_OS_WINDOWS
356
357/* Asks window thread to create new window.
358 msg.lParam - holds pointer to CREATESTRUCT structure
359 note that lpCreateParams is used to specify address to store handle of created window
360 msg.wParam - unused, should be NULL
361*/
362#define WM_VBOX_RENDERSPU_CREATE_WINDOW (WM_APP+1)
363
364typedef struct _VBOX_RENDERSPU_DESTROY_WINDOW {
365 HWND hWnd; /* handle to window to destroy */
366} VBOX_RENDERSPU_DESTROY_WINDOW;
367
368/* Asks window thread to destroy previously created window.
369 msg.lParam - holds pointer to RENDERSPU_VBOX_WINDOW_DESTROY structure
370 msg.wParam - unused, should be NULL
371*/
372#define WM_VBOX_RENDERSPU_DESTROY_WINDOW (WM_APP+2)
373
374#endif
375
376extern RenderSPU render_spu;
377
378/* @todo remove this hack */
379extern uint64_t render_spu_parent_window_id;
380
381#ifdef CHROMIUM_THREADSAFE
382extern CRtsd _RenderTSD;
383#define GET_CONTEXT_VAL() ((ContextInfo *) crGetTSD(&_RenderTSD))
384#define SET_CONTEXT_VAL(_v) do { \
385 crSetTSD(&_RenderTSD, (_v)); \
386 } while (0)
387#else
388#define GET_CONTEXT_VAL() (render_spu.currentContext)
389#define SET_CONTEXT_VAL(_v) do { \
390 render_spu.currentContext = (_v); \
391 } while (0)
392
393#endif
394
395#define GET_CONTEXT(T) ContextInfo *T = GET_CONTEXT_VAL()
396
397
398extern void renderspuSetDefaultSharedContext(ContextInfo *pCtx);
399extern void renderspuSetVBoxConfiguration( RenderSPU *spu );
400extern void renderspuMakeVisString( GLbitfield visAttribs, char *s );
401extern VisualInfo *renderspuFindVisual(const char *displayName, GLbitfield visAttribs );
402extern GLboolean renderspu_SystemInitVisual( VisualInfo *visual );
403extern GLboolean renderspu_SystemCreateContext( VisualInfo *visual, ContextInfo *context, ContextInfo *sharedContext );
404extern void renderspu_SystemDestroyContext( ContextInfo *context );
405extern GLboolean renderspu_SystemCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window );
406extern GLboolean renderspu_SystemVBoxCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window );
407extern void renderspu_SystemDestroyWindow( WindowInfo *window );
408extern void renderspu_SystemWindowSize( WindowInfo *window, GLint w, GLint h );
409extern void renderspu_SystemGetWindowGeometry( WindowInfo *window, GLint *x, GLint *y, GLint *w, GLint *h );
410extern void renderspu_SystemGetMaxWindowSize( WindowInfo *window, GLint *w, GLint *h );
411extern void renderspu_SystemWindowPosition( WindowInfo *window, GLint x, GLint y );
412extern void renderspu_SystemWindowVisibleRegion(WindowInfo *window, GLint cRects, const GLint* pRects);
413extern GLboolean renderspu_SystemWindowNeedEmptyPresent(WindowInfo *window);
414extern int renderspu_SystemInit();
415extern int renderspu_SystemTerm();
416extern void renderspu_SystemDefaultSharedContextChanged(ContextInfo *fromContext, ContextInfo *toContext);
417extern void renderspu_SystemShowWindow( WindowInfo *window, GLboolean showIt );
418extern void renderspu_SystemMakeCurrent( WindowInfo *window, GLint windowInfor, ContextInfo *context );
419extern void renderspu_SystemSwapBuffers( WindowInfo *window, GLint flags );
420extern void renderspu_SystemReparentWindow(WindowInfo *window);
421extern void renderspu_SystemVBoxPresentComposition( WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry );
422uint32_t renderspu_SystemPostprocessFunctions(SPUNamedFunctionTable *aFunctions, uint32_t cFunctions, uint32_t cTable);
423extern void renderspu_GCWindow(void);
424extern int renderspuCreateFunctions( SPUNamedFunctionTable table[] );
425extern GLboolean renderspuVBoxCompositorSet( WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR * pCompositor);
426extern void renderspuVBoxCompositorClearAll();
427extern int renderspuVBoxCompositorLock(WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR **ppCompositor);
428extern int renderspuVBoxCompositorUnlock(WindowInfo *window);
429extern const struct VBOXVR_SCR_COMPOSITOR * renderspuVBoxCompositorAcquire( WindowInfo *window);
430extern int renderspuVBoxCompositorTryAcquire(WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR **ppCompositor);
431extern void renderspuVBoxCompositorRelease( WindowInfo *window);
432extern void renderspuVBoxPresentCompositionGeneric( WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR * pCompositor,
433 const struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry, int32_t i32MakeCurrentUserData,
434 bool fRedraw);
435extern PCR_BLITTER renderspuVBoxPresentBlitterGet( WindowInfo *window );
436void renderspuVBoxPresentBlitterCleanup( WindowInfo *window );
437extern int renderspuVBoxPresentBlitterEnter( PCR_BLITTER pBlitter, int32_t i32MakeCurrentUserData );
438extern PCR_BLITTER renderspuVBoxPresentBlitterGetAndEnter( WindowInfo *window, int32_t i32MakeCurrentUserData, bool fRedraw );
439extern PCR_BLITTER renderspuVBoxPresentBlitterEnsureCreated( WindowInfo *window, int32_t i32MakeCurrentUserData );
440WindowInfo* renderspuWinCreate(GLint visBits, GLint id);
441void renderspuWinTermOnShutdown(WindowInfo *window);
442void renderspuWinTerm( WindowInfo *window );
443void renderspuWinCleanup(WindowInfo *window);
444void renderspuWinDestroy(WindowInfo *window);
445GLboolean renderspuWinInitWithVisual( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id );
446GLboolean renderspuWinInit(WindowInfo *pWindow, const char *dpyName, GLint visBits, GLint id);
447
448DECLINLINE(void) renderspuWinRetain(WindowInfo *window)
449{
450 ASMAtomicIncU32(&window->cRefs);
451}
452
453DECLINLINE(bool) renderspuWinIsTermed(WindowInfo *window)
454{
455 return window->BltInfo.Base.id < 0;
456}
457
458DECLINLINE(void) renderspuWinRelease(WindowInfo *window)
459{
460 uint32_t cRefs = ASMAtomicDecU32(&window->cRefs);
461 if (!cRefs)
462 {
463 renderspuWinDestroy(window);
464 }
465}
466
467extern WindowInfo* renderspuGetDummyWindow(GLint visBits);
468extern void renderspuPerformMakeCurrent(WindowInfo *window, GLint nativeWindow, ContextInfo *context);
469extern GLboolean renderspuInitVisual(VisualInfo *pVisInfo, const char *displayName, GLbitfield visAttribs);
470extern void renderspuVBoxCompositorBlit ( const struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter);
471extern void renderspuVBoxCompositorBlitStretched ( const struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter, GLfloat scaleX, GLfloat scaleY);
472extern GLint renderspuCreateContextEx(const char *dpyName, GLint visBits, GLint id, GLint shareCtx);
473extern GLint renderspuWindowCreateEx( const char *dpyName, GLint visBits, GLint id );
474
475extern GLint RENDER_APIENTRY renderspuWindowCreate( const char *dpyName, GLint visBits );
476void RENDER_APIENTRY renderspuWindowDestroy( GLint win );
477extern GLint RENDER_APIENTRY renderspuCreateContext( const char *dpyname, GLint visBits, GLint shareCtx );
478extern void RENDER_APIENTRY renderspuMakeCurrent(GLint crWindow, GLint nativeWindow, GLint ctx);
479extern void RENDER_APIENTRY renderspuSwapBuffers( GLint window, GLint flags );
480
481extern uint32_t renderspuContextMarkDeletedAndRelease( ContextInfo *context );
482
483int renderspuDefaultCtxInit();
484void renderspuCleanupBase(bool fDeleteTables);
485
486ContextInfo * renderspuDefaultSharedContextAcquire();
487void renderspuDefaultSharedContextRelease(ContextInfo * pCtx);
488uint32_t renderspuContextRelease(ContextInfo *context);
489uint32_t renderspuContextRetain(ContextInfo *context);
490
491bool renderspuCalloutAvailable();
492bool renderspuCalloutClient(PFNVCRSERVER_CLIENT_CALLOUT_CB pfnCb, void *pvCb);
493
494
495#ifdef __cplusplus
496extern "C" {
497#endif
498DECLEXPORT(void) renderspuSetWindowId(uint64_t winId);
499DECLEXPORT(void) renderspuReparentWindow(GLint window);
500DECLEXPORT(void) renderspuSetUnscaledHiDPI(bool fEnable);
501#ifdef __cplusplus
502}
503#endif
504
505#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