VirtualBox

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

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

crOpenGL: 1. osx: do everything we can do in the main thread 2. bugfixes

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