VirtualBox

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

Last change on this file since 51589 was 51442, checked in by vboxsync, 11 years ago

crOpenGL: fix flickering on osx

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.5 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 GLboolean mapPending;
101 GLboolean visible;
102 GLboolean everCurrent; /**< has this window ever been bound? */
103 char *title;
104
105 const VBOXVR_SCR_COMPOSITOR *pCompositor;
106 /* the composotor lock is used to synchronize the current compositor access,
107 * i.e. the compositor can be accessed by a gui refraw thread,
108 * while chromium thread might try to set a new compositor
109 * note that the compositor internally has its own lock to be used for accessing its data
110 * see CrVrScrCompositorLock/Unlock; renderspu and crserverlib would use it for compositor data access */
111 RTCRITSECT CompositorLock;
112 PCR_BLITTER pBlitter;
113#if defined(WINDOWS)
114 HDC nativeWindow; /**< for render_to_app_window */
115 HWND hWnd;
116 HDC device_context;
117 HDC redraw_device_context;
118 HRGN hRgn;
119#elif defined(DARWIN)
120# ifndef VBOX_WITH_COCOA_QT
121 WindowRef window;
122 WindowRef nativeWindow; /**< for render_to_app_window */
123 WindowRef appWindow;
124 EventHandlerUPP event_handler;
125 GLint bufferName;
126 AGLContext dummyContext;
127 RgnHandle hVisibleRegion;
128 /* unsigned long context_ptr; */
129# else
130 NativeNSViewRef window;
131 NativeNSViewRef nativeWindow; /**< for render_to_app_window */
132 NativeNSOpenGLContextRef *currentCtx;
133# endif
134#elif defined(GLX)
135 Window window;
136 Window nativeWindow; /**< for render_to_app_window */
137 Window appWindow; /**< Same as nativeWindow but for garbage collections purposes */
138#endif
139 int nvSwapGroup;
140
141#ifdef USE_OSMESA
142 GLubyte *buffer; /**< for rendering to off screen buffer. */
143 int in_buffer_width;
144 int in_buffer_height;
145#endif
146
147} WindowInfo;
148
149/**
150 * Context Info
151 */
152typedef struct _ContextInfo {
153// int id; /**< integer context ID */
154 CR_BLITTER_CONTEXT BltInfo;
155 VisualInfo *visual;
156 GLboolean everCurrent;
157 GLboolean haveWindowPosARB;
158 WindowInfo *currentWindow;
159#if defined(WINDOWS)
160 HGLRC hRC;
161#elif defined(DARWIN)
162# ifndef VBOX_WITH_COCOA_QT
163 AGLContext context;
164# else
165 NativeNSOpenGLContextRef context;
166# endif
167#elif defined(GLX)
168 GLXContext context;
169#endif
170 struct _ContextInfo *shared;
171 char *extensionString;
172 volatile uint32_t cRefs;
173} ContextInfo;
174
175/**
176 * Barrier info
177 */
178typedef struct {
179 CRbarrier barrier;
180 GLuint count;
181} Barrier;
182
183#ifdef GLX
184typedef enum
185{
186 CR_RENDER_WINCMD_TYPE_UNDEFINED = 0,
187 /* create the window (not used for now) */
188 CR_RENDER_WINCMD_TYPE_WIN_CREATE,
189 /* destroy the window (not used for now) */
190 CR_RENDER_WINCMD_TYPE_WIN_DESTROY,
191 /* notify the WinCmd thread about window creation */
192 CR_RENDER_WINCMD_TYPE_WIN_ON_CREATE,
193 /* notify the WinCmd thread about window destroy */
194 CR_RENDER_WINCMD_TYPE_WIN_ON_DESTROY,
195 /* nop used to synchronize with the WinCmd thread */
196 CR_RENDER_WINCMD_TYPE_NOP,
197 /* exit Win Cmd thread */
198 CR_RENDER_WINCMD_TYPE_EXIT,
199} CR_RENDER_WINCMD_TYPE;
200
201typedef struct CR_RENDER_WINCMD
202{
203 /* command type */
204 CR_RENDER_WINCMD_TYPE enmCmd;
205 /* command result */
206 int rc;
207 /* valid for WIN_CREATE & WIN_DESTROY only */
208 WindowInfo *pWindow;
209} CR_RENDER_WINCMD, *PCR_RENDER_WINCMD;
210#endif
211
212#ifdef RT_OS_DARWIN
213typedef void (*PFNDELETE_OBJECT)(GLhandleARB obj);
214typedef void (*PFNGET_ATTACHED_OBJECTS)( GLhandleARB containerObj, GLsizei maxCount, GLsizei * count, GLhandleARB * obj );
215typedef GLhandleARB (*PFNGET_HANDLE)(GLenum pname);
216typedef void (*PFNGET_INFO_LOG)( GLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * infoLog );
217typedef void (*PFNGET_OBJECT_PARAMETERFV)( GLhandleARB obj, GLenum pname, GLfloat * params );
218typedef void (*PFNGET_OBJECT_PARAMETERIV)( GLhandleARB obj, GLenum pname, GLint * params );
219#endif
220
221/**
222 * Renderspu state info
223 */
224typedef struct {
225 SPUDispatchTable self;
226 int id;
227
228 /** config options */
229 /*@{*/
230 char *window_title;
231 int defaultX, defaultY;
232 unsigned int defaultWidth, defaultHeight;
233 int default_visual;
234 int use_L2;
235 int fullscreen, ontop;
236 char display_string[100];
237#if defined(GLX)
238 int try_direct;
239 int force_direct;
240 int sync;
241#endif
242 int render_to_app_window;
243 int render_to_crut_window;
244 int crut_drawable;
245 int resizable;
246 int use_lut8, lut8[3][256];
247 int borderless;
248 int nvSwapGroup;
249 int ignore_papi;
250 int ignore_window_moves;
251 int pbufferWidth, pbufferHeight;
252 int use_glxchoosevisual;
253 int draw_bbox;
254 /*@}*/
255
256 CRServer *server;
257 int gather_port;
258 int gather_userbuf_size;
259 CRConnection **gather_conns;
260
261 GLint drawCursor;
262 GLint cursorX, cursorY;
263
264 int numVisuals;
265 VisualInfo visuals[MAX_VISUALS];
266
267 CRHashTable *windowTable;
268 CRHashTable *contextTable;
269
270 CRHashTable *dummyWindowTable;
271
272 ContextInfo *defaultSharedContext;
273
274#ifndef CHROMIUM_THREADSAFE
275 ContextInfo *currentContext;
276#endif
277
278 crOpenGLInterface ws; /**< Window System interface */
279
280 CRHashTable *barrierHash;
281
282 int is_swap_master, num_swap_clients;
283 int swap_mtu;
284 char *swap_master_url;
285 CRConnection **swap_conns;
286
287 SPUDispatchTable blitterDispatch;
288 CRHashTable *blitterTable;
289
290#ifdef USE_OSMESA
291 /** Off screen rendering hooks. */
292 int use_osmesa;
293
294 OSMesaContext (*OSMesaCreateContext)( GLenum format, OSMesaContext sharelist );
295 GLboolean (* OSMesaMakeCurrent)( OSMesaContext ctx,
296 GLubyte *buffer,
297 GLenum type,
298 GLsizei width,
299 GLsizei height );
300 void (*OSMesaDestroyContext)( OSMesaContext ctx );
301#endif
302
303#if defined(GLX)
304 RTTHREAD hWinCmdThread;
305 VisualInfo WinCmdVisual;
306 WindowInfo WinCmdWindow;
307 RTSEMEVENT hWinCmdCompleteEvent;
308 /* display connection used to send data to the WinCmd thread */
309 Display *pCommunicationDisplay;
310 Atom WinCmdAtom;
311 /* X Window -> CRWindowInfo table */
312 CRHashTable *pWinToInfoTable;
313#endif
314
315#ifdef RT_OS_WINDOWS
316 DWORD dwWinThreadId;
317 HANDLE hWinThreadReadyEvent;
318#endif
319
320#ifdef RT_OS_DARWIN
321# ifdef VBOX_WITH_COCOA_QT
322 PFNDELETE_OBJECT pfnDeleteObject;
323 PFNGET_ATTACHED_OBJECTS pfnGetAttachedObjects;
324 PFNGET_HANDLE pfnGetHandle;
325 PFNGET_INFO_LOG pfnGetInfoLog;
326 PFNGET_OBJECT_PARAMETERFV pfnGetObjectParameterfv;
327 PFNGET_OBJECT_PARAMETERIV pfnGetObjectParameteriv;
328
329 CR_GLSL_CACHE GlobalShaders;
330# else
331 RgnHandle hRootVisibleRegion;
332 RTSEMFASTMUTEX syncMutex;
333 EventHandlerUPP hParentEventHandler;
334 WindowGroupRef pParentGroup;
335 WindowGroupRef pMasterGroup;
336 GLint currentBufferName;
337 uint64_t uiDockUpdateTS;
338 bool fInit;
339# endif
340#endif /* RT_OS_DARWIN */
341} RenderSPU;
342
343#ifdef RT_OS_WINDOWS
344
345/* Asks window thread to create new window.
346 msg.lParam - holds pointer to CREATESTRUCT structure
347 note that lpCreateParams is used to specify address to store handle of created window
348 msg.wParam - unused, should be NULL
349*/
350#define WM_VBOX_RENDERSPU_CREATE_WINDOW (WM_APP+1)
351
352typedef struct _VBOX_RENDERSPU_DESTROY_WINDOW {
353 HWND hWnd; /* handle to window to destroy */
354} VBOX_RENDERSPU_DESTROY_WINDOW;
355
356/* Asks window thread to destroy previously created window.
357 msg.lParam - holds pointer to RENDERSPU_VBOX_WINDOW_DESTROY structure
358 msg.wParam - unused, should be NULL
359*/
360#define WM_VBOX_RENDERSPU_DESTROY_WINDOW (WM_APP+2)
361
362#endif
363
364extern RenderSPU render_spu;
365
366/* @todo remove this hack */
367extern uint64_t render_spu_parent_window_id;
368
369#ifdef CHROMIUM_THREADSAFE
370extern CRtsd _RenderTSD;
371#define GET_CONTEXT_VAL() ((ContextInfo *) crGetTSD(&_RenderTSD))
372#define SET_CONTEXT_VAL(_v) do { \
373 crSetTSD(&_RenderTSD, (_v)); \
374 } while (0)
375#else
376#define GET_CONTEXT_VAL() (render_spu.currentContext)
377#define SET_CONTEXT_VAL(_v) do { \
378 render_spu.currentContext = (_v); \
379 } while (0)
380
381#endif
382
383#define GET_CONTEXT(T) ContextInfo *T = GET_CONTEXT_VAL()
384
385
386extern void renderspuSetDefaultSharedContext(ContextInfo *pCtx);
387extern void renderspuSetVBoxConfiguration( RenderSPU *spu );
388extern void renderspuMakeVisString( GLbitfield visAttribs, char *s );
389extern VisualInfo *renderspuFindVisual(const char *displayName, GLbitfield visAttribs );
390extern GLboolean renderspu_SystemInitVisual( VisualInfo *visual );
391extern GLboolean renderspu_SystemCreateContext( VisualInfo *visual, ContextInfo *context, ContextInfo *sharedContext );
392extern void renderspu_SystemDestroyContext( ContextInfo *context );
393extern GLboolean renderspu_SystemCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window );
394extern GLboolean renderspu_SystemVBoxCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window );
395extern void renderspu_SystemDestroyWindow( WindowInfo *window );
396extern void renderspu_SystemWindowSize( WindowInfo *window, GLint w, GLint h );
397extern void renderspu_SystemGetWindowGeometry( WindowInfo *window, GLint *x, GLint *y, GLint *w, GLint *h );
398extern void renderspu_SystemGetMaxWindowSize( WindowInfo *window, GLint *w, GLint *h );
399extern void renderspu_SystemWindowPosition( WindowInfo *window, GLint x, GLint y );
400extern void renderspu_SystemWindowVisibleRegion(WindowInfo *window, GLint cRects, const GLint* pRects);
401extern GLboolean renderspu_SystemWindowNeedEmptyPresent(WindowInfo *window);
402extern int renderspu_SystemInit();
403extern int renderspu_SystemTerm();
404extern void renderspu_SystemDefaultSharedContextChanged(ContextInfo *fromContext, ContextInfo *toContext);
405extern void renderspu_SystemShowWindow( WindowInfo *window, GLboolean showIt );
406extern void renderspu_SystemMakeCurrent( WindowInfo *window, GLint windowInfor, ContextInfo *context );
407extern void renderspu_SystemSwapBuffers( WindowInfo *window, GLint flags );
408extern void renderspu_SystemReparentWindow(WindowInfo *window);
409extern void renderspu_SystemVBoxPresentComposition( WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry );
410uint32_t renderspu_SystemPostprocessFunctions(SPUNamedFunctionTable *aFunctions, uint32_t cFunctions, uint32_t cTable);
411extern void renderspu_GCWindow(void);
412extern int renderspuCreateFunctions( SPUNamedFunctionTable table[] );
413extern GLboolean renderspuVBoxCompositorSet( WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR * pCompositor);
414extern void renderspuVBoxCompositorClearAll();
415extern int renderspuVBoxCompositorLock(WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR **ppCompositor);
416extern int renderspuVBoxCompositorUnlock(WindowInfo *window);
417extern const struct VBOXVR_SCR_COMPOSITOR * renderspuVBoxCompositorAcquire( WindowInfo *window);
418extern int renderspuVBoxCompositorTryAcquire(WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR **ppCompositor);
419extern void renderspuVBoxCompositorRelease( WindowInfo *window);
420extern void renderspuVBoxPresentCompositionGeneric( WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR * pCompositor,
421 const struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry, int32_t i32MakeCurrentUserData,
422 bool fRedraw);
423extern PCR_BLITTER renderspuVBoxPresentBlitterGet( WindowInfo *window );
424void renderspuVBoxPresentBlitterCleanup( WindowInfo *window );
425extern int renderspuVBoxPresentBlitterEnter( PCR_BLITTER pBlitter, int32_t i32MakeCurrentUserData );
426extern PCR_BLITTER renderspuVBoxPresentBlitterGetAndEnter( WindowInfo *window, int32_t i32MakeCurrentUserData, bool fRedraw );
427extern PCR_BLITTER renderspuVBoxPresentBlitterEnsureCreated( WindowInfo *window, int32_t i32MakeCurrentUserData );
428void renderspuWindowTermBase( WindowInfo *window );
429extern void renderspuWindowTerm( WindowInfo *window );
430extern WindowInfo* renderspuGetDummyWindow(GLint visBits);
431extern void renderspuPerformMakeCurrent(WindowInfo *window, GLint nativeWindow, ContextInfo *context);
432extern GLboolean renderspuWindowInit(WindowInfo *pWindow, const char *dpyName, GLint visBits, GLint id);
433extern GLboolean renderspuWindowInitWithVisual( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id );
434extern GLboolean renderspuInitVisual(VisualInfo *pVisInfo, const char *displayName, GLbitfield visAttribs);
435extern void renderspuVBoxCompositorBlit ( const struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter);
436extern void renderspuVBoxCompositorBlitStretched ( const struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter, GLfloat scaleX, GLfloat scaleY);
437extern GLint renderspuCreateContextEx(const char *dpyName, GLint visBits, GLint id, GLint shareCtx);
438extern GLint renderspuWindowCreateEx( const char *dpyName, GLint visBits, GLint id );
439
440extern GLint RENDER_APIENTRY renderspuWindowCreate( const char *dpyName, GLint visBits );
441void RENDER_APIENTRY renderspuWindowDestroy( GLint win );
442extern GLint RENDER_APIENTRY renderspuCreateContext( const char *dpyname, GLint visBits, GLint shareCtx );
443extern void RENDER_APIENTRY renderspuMakeCurrent(GLint crWindow, GLint nativeWindow, GLint ctx);
444extern void RENDER_APIENTRY renderspuSwapBuffers( GLint window, GLint flags );
445
446extern uint32_t renderspuContextMarkDeletedAndRelease( ContextInfo *context );
447
448int renderspuDefaultCtxInit();
449void renderspuCleanupBase(bool fDeleteTables);
450
451ContextInfo * renderspuDefaultSharedContextAcquire();
452void renderspuDefaultSharedContextRelease(ContextInfo * pCtx);
453uint32_t renderspuContextRelease(ContextInfo *context);
454uint32_t renderspuContextRetain(ContextInfo *context);
455
456#ifdef __cplusplus
457extern "C" {
458#endif
459DECLEXPORT(void) renderspuSetWindowId(uint64_t winId);
460DECLEXPORT(void) renderspuReparentWindow(GLint window);
461#ifdef __cplusplus
462}
463#endif
464
465#endif /* CR_RENDERSPU_H */
Note: See TracBrowser for help on using the repository browser.

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