VirtualBox

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

Last change on this file since 51423 was 51349, checked in by vboxsync, 11 years ago

crOpenGL: saved state fixes, misc fixes

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

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