VirtualBox

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

Last change on this file since 44908 was 44908, checked in by vboxsync, 12 years ago

crOpenGL: work around context destruction ogl driver bug

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