VirtualBox

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

Last change on this file since 78408 was 78408, checked in by vboxsync, 6 years ago

Additions,GuestHost/OpenGL,HostServices/SharedOpenGL: Get rid of the individual SPU shared libraries and merge them into the VBoxSharedCrOpenGL shared libraries on the host and VBoxOGL{,-x86} shared libraries for the guest additions, bugref:9435

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 14.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 <iprt/win/windows.h>
13#define RENDER_APIENTRY __stdcall
14#define snprintf _snprintf
15#elif defined(DARWIN)
16# include "renderspu_cocoa_helper.h"
17#define RENDER_APIENTRY
18#else
19#include <GL/glx.h>
20#define RENDER_APIENTRY
21#endif
22#include "cr_threads.h"
23#include "cr_spu.h"
24#include "cr_hash.h"
25#include "cr_server.h"
26#include "cr_blitter.h"
27#include "cr_compositor.h"
28
29#include <iprt/cdefs.h>
30#include <iprt/critsect.h>
31#if defined(GLX) /* @todo: unify windows and glx thread creation code */
32#include <iprt/thread.h>
33#include <iprt/semaphore.h>
34
35/* special window id used for representing the command window CRWindowInfo */
36#define CR_RENDER_WINCMD_ID (INT32_MAX-2)
37AssertCompile(CR_RENDER_WINCMD_ID != CR_RENDER_DEFAULT_WINDOW_ID);
38/* CRHashTable is using unsigned long keys, we use it to trore X Window -> CRWindowInfo association */
39AssertCompile(sizeof (Window) == sizeof (unsigned long));
40#endif
41
42
43#define MAX_VISUALS 32
44
45/**
46 * Visual info
47 */
48typedef struct {
49 GLbitfield visAttribs;
50 const char *displayName;
51#if defined(WINDOWS)
52// HDC device_context;
53#elif defined(DARWIN)
54#elif defined(GLX)
55 Display *dpy;
56 XVisualInfo *visual;
57#ifdef GLX_VERSION_1_3
58 GLXFBConfig fbconfig;
59#endif /* GLX_VERSION_1_3 */
60#endif
61} VisualInfo;
62
63/**
64 * Window info
65 */
66typedef struct WindowInfo {
67 int x, y;
68// int width, height;
69// int id; /**< integer window ID */
70 CR_BLITTER_WINDOW BltInfo;
71
72 VisualInfo *visual;
73
74 volatile uint32_t cRefs;
75
76 GLboolean mapPending;
77 GLboolean visible;
78 GLboolean everCurrent; /**< has this window ever been bound? */
79 char *title;
80
81 const VBOXVR_SCR_COMPOSITOR *pCompositor;
82 /* the composotor lock is used to synchronize the current compositor access,
83 * i.e. the compositor can be accessed by a gui refraw thread,
84 * while chromium thread might try to set a new compositor
85 * note that the compositor internally has its own lock to be used for accessing its data
86 * see CrVrScrCompositorLock/Unlock; renderspu and crserverlib would use it for compositor data access */
87 RTCRITSECT CompositorLock;
88 PCR_BLITTER pBlitter;
89#if defined(WINDOWS)
90 HDC nativeWindow; /**< for render_to_app_window */
91 HWND hWnd;
92 HDC device_context;
93 HDC redraw_device_context;
94 HRGN hRgn;
95#elif defined(DARWIN)
96 NativeNSViewRef window;
97 NativeNSViewRef nativeWindow; /**< for render_to_app_window */
98 NativeNSOpenGLContextRef *currentCtx;
99#elif defined(GLX)
100 Window window;
101 Window nativeWindow; /**< for render_to_app_window */
102 Window appWindow; /**< Same as nativeWindow but for garbage collections purposes */
103#endif
104 int nvSwapGroup;
105
106} WindowInfo;
107
108/**
109 * Context Info
110 */
111typedef struct _ContextInfo {
112// int id; /**< integer context ID */
113 CR_BLITTER_CONTEXT BltInfo;
114 VisualInfo *visual;
115 GLboolean everCurrent;
116 GLboolean haveWindowPosARB;
117 WindowInfo *currentWindow;
118#if defined(WINDOWS)
119 HGLRC hRC;
120#elif defined(DARWIN)
121 NativeNSOpenGLContextRef context;
122#elif defined(GLX)
123 GLXContext context;
124#endif
125 struct _ContextInfo *shared;
126 char *extensionString;
127 volatile uint32_t cRefs;
128} ContextInfo;
129
130/**
131 * Barrier info
132 */
133typedef struct {
134 CRbarrier barrier;
135 GLuint count;
136} Barrier;
137
138#ifdef GLX
139typedef enum
140{
141 CR_RENDER_WINCMD_TYPE_UNDEFINED = 0,
142 /* create the window (not used for now) */
143 CR_RENDER_WINCMD_TYPE_WIN_CREATE,
144 /* destroy the window (not used for now) */
145 CR_RENDER_WINCMD_TYPE_WIN_DESTROY,
146 /* notify the WinCmd thread about window creation */
147 CR_RENDER_WINCMD_TYPE_WIN_ON_CREATE,
148 /* notify the WinCmd thread about window destroy */
149 CR_RENDER_WINCMD_TYPE_WIN_ON_DESTROY,
150 /* nop used to synchronize with the WinCmd thread */
151 CR_RENDER_WINCMD_TYPE_NOP,
152 /* exit Win Cmd thread */
153 CR_RENDER_WINCMD_TYPE_EXIT,
154} CR_RENDER_WINCMD_TYPE;
155
156typedef struct CR_RENDER_WINCMD
157{
158 /* command type */
159 CR_RENDER_WINCMD_TYPE enmCmd;
160 /* command result */
161 int rc;
162 /* valid for WIN_CREATE & WIN_DESTROY only */
163 WindowInfo *pWindow;
164} CR_RENDER_WINCMD, *PCR_RENDER_WINCMD;
165#endif
166
167#ifdef RT_OS_DARWIN
168typedef void (*PFNDELETE_OBJECT)(GLhandleARB obj);
169typedef void (*PFNGET_ATTACHED_OBJECTS)( GLhandleARB containerObj, GLsizei maxCount, GLsizei * count, GLhandleARB * obj );
170typedef GLhandleARB (*PFNGET_HANDLE)(GLenum pname);
171typedef void (*PFNGET_INFO_LOG)( GLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * infoLog );
172typedef void (*PFNGET_OBJECT_PARAMETERFV)( GLhandleARB obj, GLenum pname, GLfloat * params );
173typedef void (*PFNGET_OBJECT_PARAMETERIV)( GLhandleARB obj, GLenum pname, GLint * params );
174#endif
175
176typedef DECLCALLBACKPTR(void, PFNVCRSERVER_CLIENT_CALLOUT_CB)(void *pvCb);
177typedef DECLCALLBACKPTR(void, PFNVCRSERVER_CLIENT_CALLOUT)(PFNVCRSERVER_CLIENT_CALLOUT_CB pfnCb, void*pvCb);
178
179
180/**
181 * Renderspu state info
182 */
183typedef struct {
184 SPUDispatchTable self;
185 int id;
186
187 /** config options */
188 /*@{*/
189 char *window_title;
190 int defaultX, defaultY;
191 unsigned int defaultWidth, defaultHeight;
192 int default_visual;
193 int use_L2;
194 int fullscreen, ontop;
195 char display_string[100];
196#if defined(GLX)
197 int try_direct;
198 int force_direct;
199 int sync;
200#endif
201 int force_present_main_thread;
202 int render_to_app_window;
203 int render_to_crut_window;
204 int crut_drawable;
205 int resizable;
206 int use_lut8, lut8[3][256];
207 int borderless;
208 int nvSwapGroup;
209 int ignore_papi;
210 int ignore_window_moves;
211 int pbufferWidth, pbufferHeight;
212 int use_glxchoosevisual;
213 int draw_bbox;
214 /*@}*/
215
216 CRServer *server;
217 int gather_port;
218 int gather_userbuf_size;
219 CRConnection **gather_conns;
220
221 GLint drawCursor;
222 GLint cursorX, cursorY;
223
224 int numVisuals;
225 VisualInfo visuals[MAX_VISUALS];
226
227 CRHashTable *windowTable;
228 CRHashTable *contextTable;
229
230 CRHashTable *dummyWindowTable;
231
232 ContextInfo *defaultSharedContext;
233
234 crOpenGLInterface ws; /**< Window System interface */
235
236 CRHashTable *barrierHash;
237
238 int num_swap_clients;
239 CRConnection **swap_conns;
240
241 SPUDispatchTable blitterDispatch;
242 CRHashTable *blitterTable;
243
244 PFNVCRSERVER_CLIENT_CALLOUT pfnClientCallout;
245
246#if defined(GLX)
247 RTTHREAD hWinCmdThread;
248 VisualInfo WinCmdVisual;
249 WindowInfo WinCmdWindow;
250 RTSEMEVENT hWinCmdCompleteEvent;
251 /* display connection used to send data to the WinCmd thread */
252 Display *pCommunicationDisplay;
253 Atom WinCmdAtom;
254 /* X Window -> CRWindowInfo table */
255 CRHashTable *pWinToInfoTable;
256#endif
257
258#ifdef RT_OS_WINDOWS
259 DWORD dwWinThreadId;
260 HANDLE hWinThreadReadyEvent;
261#endif
262
263#ifdef RT_OS_DARWIN
264 PFNDELETE_OBJECT pfnDeleteObject;
265 PFNGET_ATTACHED_OBJECTS pfnGetAttachedObjects;
266 PFNGET_HANDLE pfnGetHandle;
267 PFNGET_INFO_LOG pfnGetInfoLog;
268 PFNGET_OBJECT_PARAMETERFV pfnGetObjectParameterfv;
269 PFNGET_OBJECT_PARAMETERIV pfnGetObjectParameteriv;
270
271 CR_GLSL_CACHE GlobalShaders;
272#endif /* RT_OS_DARWIN */
273 /* If TRUE, render should tell window server to prevent artificial content
274 * up-scaling when displayed on HiDPI monitor. */
275 bool fUnscaledHiDPI;
276} RenderSPU;
277
278#ifdef RT_OS_WINDOWS
279
280/* Asks window thread to create new window.
281 msg.lParam - holds pointer to CREATESTRUCT structure
282 note that lpCreateParams is used to specify address to store handle of created window
283 msg.wParam - unused, should be NULL
284*/
285#define WM_VBOX_RENDERSPU_CREATE_WINDOW (WM_APP+1)
286
287typedef struct _VBOX_RENDERSPU_DESTROY_WINDOW {
288 HWND hWnd; /* handle to window to destroy */
289} VBOX_RENDERSPU_DESTROY_WINDOW;
290
291/* Asks window thread to destroy previously created window.
292 msg.lParam - holds pointer to RENDERSPU_VBOX_WINDOW_DESTROY structure
293 msg.wParam - unused, should be NULL
294*/
295#define WM_VBOX_RENDERSPU_DESTROY_WINDOW (WM_APP+2)
296
297#endif
298
299extern RenderSPU render_spu;
300
301/* @todo remove this hack */
302extern uint64_t render_spu_parent_window_id;
303
304extern CRtsd _RenderTSD;
305#define GET_CONTEXT_VAL() ((ContextInfo *) crGetTSD(&_RenderTSD))
306#define SET_CONTEXT_VAL(_v) do { \
307 crSetTSD(&_RenderTSD, (_v)); \
308 } while (0)
309
310#define GET_CONTEXT(T) ContextInfo *T = GET_CONTEXT_VAL()
311
312
313extern void renderspuSetDefaultSharedContext(ContextInfo *pCtx);
314extern void renderspuSetVBoxConfiguration( RenderSPU *spu );
315extern void renderspuMakeVisString( GLbitfield visAttribs, char *s );
316extern VisualInfo *renderspuFindVisual(const char *displayName, GLbitfield visAttribs );
317extern GLboolean renderspu_SystemInitVisual( VisualInfo *visual );
318extern GLboolean renderspu_SystemCreateContext( VisualInfo *visual, ContextInfo *context, ContextInfo *sharedContext );
319extern void renderspu_SystemDestroyContext( ContextInfo *context );
320extern GLboolean renderspu_SystemCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window );
321extern GLboolean renderspu_SystemVBoxCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window );
322extern void renderspu_SystemDestroyWindow( WindowInfo *window );
323extern void renderspu_SystemWindowSize( WindowInfo *window, GLint w, GLint h );
324extern void renderspu_SystemGetWindowGeometry( WindowInfo *window, GLint *x, GLint *y, GLint *w, GLint *h );
325extern void renderspu_SystemGetMaxWindowSize( WindowInfo *window, GLint *w, GLint *h );
326extern void renderspu_SystemWindowPosition( WindowInfo *window, GLint x, GLint y );
327extern void renderspu_SystemWindowVisibleRegion(WindowInfo *window, GLint cRects, const GLint* pRects);
328extern GLboolean renderspu_SystemWindowNeedEmptyPresent(WindowInfo *window);
329extern int renderspu_SystemInit(void);
330extern int renderspu_SystemTerm(void);
331extern void renderspu_SystemDefaultSharedContextChanged(ContextInfo *fromContext, ContextInfo *toContext);
332extern void renderspu_SystemShowWindow( WindowInfo *window, GLboolean showIt );
333extern void renderspu_SystemMakeCurrent( WindowInfo *window, GLint windowInfor, ContextInfo *context );
334extern void renderspu_SystemSwapBuffers( WindowInfo *window, GLint flags );
335extern void renderspu_SystemReparentWindow(WindowInfo *window);
336extern void renderspu_SystemVBoxPresentComposition( WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry );
337uint32_t renderspu_SystemPostprocessFunctions(SPUNamedFunctionTable *aFunctions, uint32_t cFunctions, uint32_t cTable);
338extern void renderspu_GCWindow(void);
339extern int renderspuCreateFunctions( SPUNamedFunctionTable table[] );
340extern GLboolean renderspuVBoxCompositorSet( WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR * pCompositor);
341extern void renderspuVBoxCompositorClearAll(void);
342extern int renderspuVBoxCompositorLock(WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR **ppCompositor);
343extern int renderspuVBoxCompositorUnlock(WindowInfo *window);
344extern const struct VBOXVR_SCR_COMPOSITOR * renderspuVBoxCompositorAcquire( WindowInfo *window);
345extern int renderspuVBoxCompositorTryAcquire(WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR **ppCompositor);
346extern void renderspuVBoxCompositorRelease( WindowInfo *window);
347extern void renderspuVBoxPresentCompositionGeneric( WindowInfo *window, const struct VBOXVR_SCR_COMPOSITOR * pCompositor,
348 const struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry, int32_t i32MakeCurrentUserData,
349 bool fRedraw);
350extern PCR_BLITTER renderspuVBoxPresentBlitterGet( WindowInfo *window );
351void renderspuVBoxPresentBlitterCleanup( WindowInfo *window );
352extern int renderspuVBoxPresentBlitterEnter( PCR_BLITTER pBlitter, int32_t i32MakeCurrentUserData );
353extern PCR_BLITTER renderspuVBoxPresentBlitterGetAndEnter( WindowInfo *window, int32_t i32MakeCurrentUserData, bool fRedraw );
354extern PCR_BLITTER renderspuVBoxPresentBlitterEnsureCreated( WindowInfo *window, int32_t i32MakeCurrentUserData );
355WindowInfo* renderspuWinCreate(GLint visBits, GLint id);
356void renderspuWinTermOnShutdown(WindowInfo *window);
357void renderspuWinTerm( WindowInfo *window );
358void renderspuWinCleanup(WindowInfo *window);
359void renderspuWinDestroy(WindowInfo *window);
360GLboolean renderspuWinInitWithVisual( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id );
361GLboolean renderspuWinInit(WindowInfo *pWindow, const char *dpyName, GLint visBits, GLint id);
362
363DECLINLINE(void) renderspuWinRetain(WindowInfo *window)
364{
365 ASMAtomicIncU32(&window->cRefs);
366}
367
368DECLINLINE(bool) renderspuWinIsTermed(WindowInfo *window)
369{
370 return window->BltInfo.Base.id < 0;
371}
372
373DECLINLINE(void) renderspuWinRelease(WindowInfo *window)
374{
375 uint32_t cRefs = ASMAtomicDecU32(&window->cRefs);
376 if (!cRefs)
377 {
378 renderspuWinDestroy(window);
379 }
380}
381
382extern WindowInfo* renderspuGetDummyWindow(GLint visBits);
383extern void renderspuPerformMakeCurrent(WindowInfo *window, GLint nativeWindow, ContextInfo *context);
384extern GLboolean renderspuInitVisual(VisualInfo *pVisInfo, const char *displayName, GLbitfield visAttribs);
385extern void renderspuVBoxCompositorBlit ( const struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter);
386extern void renderspuVBoxCompositorBlitStretched ( const struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter, GLfloat scaleX, GLfloat scaleY);
387extern GLint renderspuCreateContextEx(const char *dpyName, GLint visBits, GLint id, GLint shareCtx);
388extern GLint renderspuWindowCreateEx( const char *dpyName, GLint visBits, GLint id );
389
390extern GLint RENDER_APIENTRY renderspuWindowCreate( const char *dpyName, GLint visBits );
391void RENDER_APIENTRY renderspuWindowDestroy( GLint win );
392extern GLint RENDER_APIENTRY renderspuCreateContext( const char *dpyname, GLint visBits, GLint shareCtx );
393extern void RENDER_APIENTRY renderspuMakeCurrent(GLint crWindow, GLint nativeWindow, GLint ctx);
394extern void RENDER_APIENTRY renderspuSwapBuffers( GLint window, GLint flags );
395
396extern uint32_t renderspuContextMarkDeletedAndRelease( ContextInfo *context );
397
398int renderspuDefaultCtxInit(void);
399void renderspuCleanupBase(bool fDeleteTables);
400
401ContextInfo * renderspuDefaultSharedContextAcquire(void);
402void renderspuDefaultSharedContextRelease(ContextInfo * pCtx);
403uint32_t renderspuContextRelease(ContextInfo *context);
404uint32_t renderspuContextRetain(ContextInfo *context);
405
406bool renderspuCalloutAvailable(void);
407bool renderspuCalloutClient(PFNVCRSERVER_CLIENT_CALLOUT_CB pfnCb, void *pvCb);
408
409
410#ifdef __cplusplus
411extern "C" {
412#endif
413DECLHIDDEN(void) renderspuSetWindowId(uint64_t winId);
414DECLEXPORT(void) renderspuReparentWindow(GLint window);
415DECLEXPORT(void) renderspuSetUnscaledHiDPI(bool fEnable);
416#ifdef __cplusplus
417}
418#endif
419
420#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