VirtualBox

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

最後變更 在這個檔案從45376是 45132,由 vboxsync 提交於 12 年 前

crOpenGL: seamles mode support impl; bugfizes & cleanup

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 13.5 KB
 
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
320 int force_hidden_wdn_create;
321} RenderSPU;
322
323#ifdef RT_OS_WINDOWS
324
325/* Asks window thread to create new window.
326 msg.lParam - holds pointer to CREATESTRUCT structure
327 note that lpCreateParams is used to specify address to store handle of created window
328 msg.wParam - unused, should be NULL
329*/
330#define WM_VBOX_RENDERSPU_CREATE_WINDOW (WM_APP+1)
331
332typedef struct _VBOX_RENDERSPU_DESTROY_WINDOW {
333 HWND hWnd; /* handle to window to destroy */
334} VBOX_RENDERSPU_DESTROY_WINDOW;
335
336/* Asks window thread to destroy previously created window.
337 msg.lParam - holds pointer to RENDERSPU_VBOX_WINDOW_DESTROY structure
338 msg.wParam - unused, should be NULL
339*/
340#define WM_VBOX_RENDERSPU_DESTROY_WINDOW (WM_APP+2)
341
342#endif
343
344extern RenderSPU render_spu;
345
346/* @todo remove this hack */
347extern uint64_t render_spu_parent_window_id;
348
349#ifdef CHROMIUM_THREADSAFE
350extern CRtsd _RenderTSD;
351#define GET_CONTEXT_VAL() ((ContextInfo *) crGetTSD(&_RenderTSD))
352#define SET_CONTEXT_VAL(_v) do { \
353 crSetTSD(&_RenderTSD, (_v)); \
354 } while (0)
355#else
356#define GET_CONTEXT_VAL() (render_spu.currentContext)
357#define SET_CONTEXT_VAL(_v) do { \
358 render_spu.currentContext = (_v); \
359 } while (0)
360
361#endif
362
363#define GET_CONTEXT(T) ContextInfo *T = GET_CONTEXT_VAL()
364
365
366
367extern void renderspuSetVBoxConfiguration( RenderSPU *spu );
368extern void renderspuMakeVisString( GLbitfield visAttribs, char *s );
369extern VisualInfo *renderspuFindVisual(const char *displayName, GLbitfield visAttribs );
370extern GLboolean renderspu_SystemInitVisual( VisualInfo *visual );
371extern GLboolean renderspu_SystemCreateContext( VisualInfo *visual, ContextInfo *context, ContextInfo *sharedContext );
372extern void renderspu_SystemDestroyContext( ContextInfo *context );
373extern GLboolean renderspu_SystemCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window );
374extern GLboolean renderspu_SystemVBoxCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window );
375extern void renderspu_SystemDestroyWindow( WindowInfo *window );
376extern void renderspu_SystemWindowSize( WindowInfo *window, GLint w, GLint h );
377extern void renderspu_SystemGetWindowGeometry( WindowInfo *window, GLint *x, GLint *y, GLint *w, GLint *h );
378extern void renderspu_SystemGetMaxWindowSize( WindowInfo *window, GLint *w, GLint *h );
379extern void renderspu_SystemWindowPosition( WindowInfo *window, GLint x, GLint y );
380extern void renderspu_SystemWindowVisibleRegion(WindowInfo *window, GLint cRects, const GLint* pRects);
381
382#ifdef GLX
383extern int renderspu_SystemInit();
384extern int renderspu_SystemTerm();
385#endif
386extern void renderspu_SystemShowWindow( WindowInfo *window, GLboolean showIt );
387extern void renderspu_SystemMakeCurrent( WindowInfo *window, GLint windowInfor, ContextInfo *context );
388extern void renderspu_SystemSwapBuffers( WindowInfo *window, GLint flags );
389extern void renderspu_SystemReparentWindow(WindowInfo *window);
390extern void renderspu_SystemVBoxPresentComposition( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry );
391extern void renderspu_GCWindow(void);
392extern int renderspuCreateFunctions( SPUNamedFunctionTable table[] );
393extern void renderspuVBoxCompositorSet( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor);
394extern void renderspuVBoxCompositorClearAll();
395extern int renderspuVBoxCompositorLock(WindowInfo *window);
396extern int renderspuVBoxCompositorUnlock(WindowInfo *window);
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, int32_t i32MakeCurrentUserData );
401extern PCR_BLITTER renderspuVBoxPresentBlitterGet( WindowInfo *window );
402void renderspuVBoxPresentBlitterCleanup( WindowInfo *window );
403extern int renderspuVBoxPresentBlitterEnter( PCR_BLITTER pBlitter, int32_t i32MakeCurrentUserData );
404extern PCR_BLITTER renderspuVBoxPresentBlitterGetAndEnter( WindowInfo *window, int32_t i32MakeCurrentUserData );
405extern PCR_BLITTER renderspuVBoxPresentBlitterEnsureCreated( WindowInfo *window, int32_t i32MakeCurrentUserData );
406extern void renderspuWindowTerm( WindowInfo *window );
407extern GLboolean renderspuWindowInit( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id );
408extern GLboolean renderspuInitVisual(VisualInfo *pVisInfo, const char *displayName, GLbitfield visAttribs);
409extern void renderspuVBoxCompositorBlit ( struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter);
410extern void renderspuVBoxCompositorBlitStretched ( struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter, GLfloat scaleX, GLfloat scaleY);
411extern GLint renderspuCreateContextEx(const char *dpyName, GLint visBits, GLint id, GLint shareCtx);
412extern GLint renderspuWindowCreateEx( const char *dpyName, GLint visBits, GLint id );
413
414extern GLint RENDER_APIENTRY renderspuWindowCreate( const char *dpyName, GLint visBits );
415void RENDER_APIENTRY renderspuWindowDestroy( GLint win );
416extern GLint RENDER_APIENTRY renderspuCreateContext( const char *dpyname, GLint visBits, GLint shareCtx );
417extern void RENDER_APIENTRY renderspuMakeCurrent(GLint crWindow, GLint nativeWindow, GLint ctx);
418extern void RENDER_APIENTRY renderspuSwapBuffers( GLint window, GLint flags );
419
420extern uint32_t renderspuContextMarkDeletedAndRelease( ContextInfo *context );
421
422#ifdef __cplusplus
423extern "C" {
424#endif
425DECLEXPORT(void) renderspuSetWindowId(uint64_t winId);
426DECLEXPORT(void) renderspuReparentWindow(GLint window);
427#ifdef __cplusplus
428}
429#endif
430
431#endif /* CR_RENDERSPU_H */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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