VirtualBox

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

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

crOpenGL: fix window mgmt

  • 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 GLboolean fCompositorPresentEmpty;
103 char *title;
104
105 PVBOXVR_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/**
213 * Renderspu state info
214 */
215typedef struct {
216 SPUDispatchTable self;
217 int id;
218
219 /** config options */
220 /*@{*/
221 char *window_title;
222 int defaultX, defaultY;
223 unsigned int defaultWidth, defaultHeight;
224 int default_visual;
225 int use_L2;
226 int fullscreen, ontop;
227 char display_string[100];
228#if defined(GLX)
229 int try_direct;
230 int force_direct;
231 int sync;
232#endif
233 int render_to_app_window;
234 int render_to_crut_window;
235 int crut_drawable;
236 int resizable;
237 int use_lut8, lut8[3][256];
238 int borderless;
239 int nvSwapGroup;
240 int ignore_papi;
241 int ignore_window_moves;
242 int pbufferWidth, pbufferHeight;
243 int use_glxchoosevisual;
244 int draw_bbox;
245 /*@}*/
246
247 CRServer *server;
248 int gather_port;
249 int gather_userbuf_size;
250 CRConnection **gather_conns;
251
252 GLint drawCursor;
253 GLint cursorX, cursorY;
254
255 int numVisuals;
256 VisualInfo visuals[MAX_VISUALS];
257
258 CRHashTable *windowTable;
259 CRHashTable *contextTable;
260
261#ifndef CHROMIUM_THREADSAFE
262 ContextInfo *currentContext;
263#endif
264
265 crOpenGLInterface ws; /**< Window System interface */
266
267 CRHashTable *barrierHash;
268
269 int is_swap_master, num_swap_clients;
270 int swap_mtu;
271 char *swap_master_url;
272 CRConnection **swap_conns;
273
274 SPUDispatchTable *blitterDispatch;
275 CRHashTable *blitterTable;
276
277#ifdef USE_OSMESA
278 /** Off screen rendering hooks. */
279 int use_osmesa;
280
281 OSMesaContext (*OSMesaCreateContext)( GLenum format, OSMesaContext sharelist );
282 GLboolean (* OSMesaMakeCurrent)( OSMesaContext ctx,
283 GLubyte *buffer,
284 GLenum type,
285 GLsizei width,
286 GLsizei height );
287 void (*OSMesaDestroyContext)( OSMesaContext ctx );
288#endif
289
290#if defined(GLX)
291 RTTHREAD hWinCmdThread;
292 VisualInfo WinCmdVisual;
293 WindowInfo WinCmdWindow;
294 RTSEMEVENT hWinCmdCompleteEvent;
295 /* display connection used to send data to the WinCmd thread */
296 Display *pCommunicationDisplay;
297 Atom WinCmdAtom;
298 /* X Window -> CRWindowInfo table */
299 CRHashTable *pWinToInfoTable;
300#endif
301
302#ifdef RT_OS_WINDOWS
303 DWORD dwWinThreadId;
304 HANDLE hWinThreadReadyEvent;
305#endif
306
307#ifdef RT_OS_DARWIN
308# ifndef VBOX_WITH_COCOA_QT
309 RgnHandle hRootVisibleRegion;
310 RTSEMFASTMUTEX syncMutex;
311 EventHandlerUPP hParentEventHandler;
312 WindowGroupRef pParentGroup;
313 WindowGroupRef pMasterGroup;
314 GLint currentBufferName;
315 uint64_t uiDockUpdateTS;
316 bool fInit;
317# endif
318#endif /* RT_OS_DARWIN */
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, const GLint* pRects);
379
380#ifdef GLX
381extern int renderspu_SystemInit();
382extern int renderspu_SystemTerm();
383#endif
384extern void renderspu_SystemShowWindow( WindowInfo *window, GLboolean showIt );
385extern void renderspu_SystemMakeCurrent( WindowInfo *window, GLint windowInfor, ContextInfo *context );
386extern void renderspu_SystemSwapBuffers( WindowInfo *window, GLint flags );
387extern void renderspu_SystemReparentWindow(WindowInfo *window);
388extern void renderspu_SystemVBoxPresentComposition( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry );
389extern void renderspu_GCWindow(void);
390extern int renderspuCreateFunctions( SPUNamedFunctionTable table[] );
391extern void renderspuVBoxCompositorSet( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor);
392extern void renderspuVBoxCompositorClearAll();
393extern int renderspuVBoxCompositorLock(WindowInfo *window);
394extern int renderspuVBoxCompositorUnlock(WindowInfo *window);
395extern struct VBOXVR_SCR_COMPOSITOR * renderspuVBoxCompositorAcquire( WindowInfo *window);
396extern int renderspuVBoxCompositorTryAcquire(WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR **ppCompositor);
397extern void renderspuVBoxCompositorRelease( WindowInfo *window);
398extern void renderspuVBoxPresentCompositionGeneric( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry, int32_t i32MakeCurrentUserData );
399extern PCR_BLITTER renderspuVBoxPresentBlitterGet( WindowInfo *window );
400void renderspuVBoxPresentBlitterCleanup( WindowInfo *window );
401extern int renderspuVBoxPresentBlitterEnter( PCR_BLITTER pBlitter, int32_t i32MakeCurrentUserData );
402extern PCR_BLITTER renderspuVBoxPresentBlitterGetAndEnter( WindowInfo *window, int32_t i32MakeCurrentUserData );
403extern PCR_BLITTER renderspuVBoxPresentBlitterEnsureCreated( WindowInfo *window, int32_t i32MakeCurrentUserData );
404extern void renderspuWindowTerm( WindowInfo *window );
405extern GLboolean renderspuWindowInit( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id );
406extern GLboolean renderspuInitVisual(VisualInfo *pVisInfo, const char *displayName, GLbitfield visAttribs);
407extern void renderspuVBoxCompositorBlit ( struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter);
408extern void renderspuVBoxCompositorBlitStretched ( struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter, GLfloat scaleX, GLfloat scaleY);
409extern GLint renderspuCreateContextEx(const char *dpyName, GLint visBits, GLint id, GLint shareCtx);
410extern GLint renderspuWindowCreateEx( const char *dpyName, GLint visBits, GLint id );
411
412extern GLint RENDER_APIENTRY renderspuWindowCreate( const char *dpyName, GLint visBits );
413void RENDER_APIENTRY renderspuWindowDestroy( GLint win );
414extern GLint RENDER_APIENTRY renderspuCreateContext( const char *dpyname, GLint visBits, GLint shareCtx );
415extern void RENDER_APIENTRY renderspuMakeCurrent(GLint crWindow, GLint nativeWindow, GLint ctx);
416extern void RENDER_APIENTRY renderspuSwapBuffers( GLint window, GLint flags );
417
418extern uint32_t renderspuContextMarkDeletedAndRelease( ContextInfo *context );
419
420#ifdef __cplusplus
421extern "C" {
422#endif
423DECLEXPORT(void) renderspuSetWindowId(uint64_t winId);
424DECLEXPORT(void) renderspuReparentWindow(GLint window);
425#ifdef __cplusplus
426}
427#endif
428
429#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