VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server.h@ 46165

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

crOpenGL->Fe/Qt notification mechanism

  • 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_SERVER_H
8#define CR_SERVER_H
9
10#include "cr_protocol.h"
11#include "cr_glstate.h"
12#include "spu_dispatch_table.h"
13
14#include "state/cr_currentpointers.h"
15
16#include "cr_server.h"
17
18#ifdef VBOX_WITH_CRHGSMI
19# include <VBox/VBoxVideo.h>
20
21#include <iprt/cdefs.h>
22
23RT_C_DECLS_BEGIN
24
25extern uint8_t* g_pvVRamBase;
26extern uint32_t g_cbVRam;
27extern HCRHGSMICMDCOMPLETION g_hCrHgsmiCompletion;
28extern PFNCRHGSMICMDCOMPLETION g_pfnCrHgsmiCompletion;
29
30#define VBOXCRHGSMI_PTR(_off, _t) ((_t*)(g_pvVRamBase + (_off)))
31#define VBOXCRHGSMI_PTR_SAFE(_off, _cb, _t) ((_t*)crServerCrHgsmiPtrGet(_off, _cb))
32
33DECLINLINE(void*) crServerCrHgsmiPtrGet(VBOXVIDEOOFFSET offBuffer, uint32_t cbBuffer)
34{
35 return ((offBuffer) + (cbBuffer) <= g_cbVRam ? VBOXCRHGSMI_PTR(offBuffer, void) : NULL);
36}
37
38DECLINLINE(void) crServerCrHgsmiCmdComplete(struct VBOXVDMACMD_CHROMIUM_CMD *pCmd, int cmdProcessingRc)
39{
40 g_pfnCrHgsmiCompletion(g_hCrHgsmiCompletion, pCmd, cmdProcessingRc);
41}
42
43#define VBOXCRHGSMI_CMD_COMPLETE(_pData, _rc) do { \
44 CRVBOXHGSMI_CMDDATA_ASSERT_ISSET(_pData); \
45 CRVBOXHGSMI_CMDDATA_RC(_pData, _rc); \
46 crServerCrHgsmiCmdComplete((_pData)->pCmd, VINF_SUCCESS); \
47 } while (0)
48
49#define VBOXCRHGSMI_CMD_CHECK_COMPLETE(_pData, _rc) do { \
50 if (CRVBOXHGSMI_CMDDATA_IS_SET(_pData)) { \
51 VBOXCRHGSMI_CMD_COMPLETE(_pData, _rc); \
52 } \
53 } while (0)
54
55#endif
56
57/*
58 * This is the base number for window and context IDs
59 */
60#define MAGIC_OFFSET 5000
61
62extern CRServer cr_server;
63
64/* Semaphore wait queue node */
65typedef struct _wqnode {
66 RunQueue *q;
67 struct _wqnode *next;
68} wqnode;
69
70typedef struct {
71 GLuint count;
72 GLuint num_waiting;
73 RunQueue **waiting;
74} CRServerBarrier;
75
76typedef struct {
77 GLuint count;
78 wqnode *waiting, *tail;
79} CRServerSemaphore;
80
81typedef struct {
82 GLuint id;
83 GLint projParamStart;
84 GLfloat projMat[16]; /* projection matrix, accumulated via calls to */
85 /* glProgramLocalParameterARB, glProgramParameterNV */
86} CRServerProgram;
87
88void crServerSetVBoxConfiguration();
89void crServerSetVBoxConfigurationHGCM();
90void crServerInitDispatch(void);
91void crServerReturnValue( const void *payload, unsigned int payload_len );
92void crServerWriteback(void);
93int crServerRecv( CRConnection *conn, CRMessage *msg, unsigned int len );
94void crServerSerializeRemoteStreams(void);
95void crServerAddToRunQueue( CRClient *client );
96void crServerDeleteClient( CRClient *client );
97
98
99void crServerApplyBaseProjection( const CRmatrix *baseProj );
100void crServerApplyViewMatrix( const CRmatrix *view );
101void crServerSetOutputBounds( const CRMuralInfo *mural, int extNum );
102void crServerComputeViewportBounds( const CRViewportState *v, CRMuralInfo *mural );
103
104GLboolean crServerInitializeBucketing(CRMuralInfo *mural);
105
106void crComputeOverlapGeom(double *quads, int nquad, CRPoly ***res);
107void crComputeKnockoutGeom(double *quads, int nquad, int my_quad_idx, CRPoly **res);
108
109int crServerGetCurrentEye(void);
110
111GLboolean crServerClientInBeginEnd(const CRClient *client);
112
113GLint crServerDispatchCreateContextEx(const char *dpyName, GLint visualBits, GLint shareCtx, GLint preloadCtxID, int32_t internalID);
114GLint crServerDispatchWindowCreateEx(const char *dpyName, GLint visBits, GLint preloadWinID);
115GLint crServerMuralInit(CRMuralInfo *mural, const char *dpyName, GLint visBits, GLint preloadWinID);
116void crServerMuralTerm(CRMuralInfo *mural);
117void crServerMuralSize(CRMuralInfo *mural, GLint width, GLint height);
118int crServerMuralSynchRootVr(CRMuralInfo *mural, uint32_t *pcRects, const RTRECT **ppRects);
119
120GLint crServerGenerateID(GLint *pCounter);
121
122GLint crServerSPUWindowID(GLint serverWindow);
123
124GLuint crServerTranslateProgramID(GLuint id);
125
126CRMuralInfo * crServerGetDummyMural(GLint visualBits);
127
128void crServerSetupOutputRedirect(CRMuralInfo *mural);
129void crServerCheckMuralGeometry(CRMuralInfo *mural);
130GLboolean crServerSupportRedirMuralFBO(void);
131
132void crVBoxServerNotifyEvent(int32_t idScreen);
133
134#define CR_SERVER_REDIR_F_NONE 0x00
135/* the data should be displayed on host (unset when is on or when CR_SERVER_REDIR_F_FBO_RAM_VMFB is set) */
136#define CR_SERVER_REDIR_F_DISPLAY 0x01
137/* guest window data get redirected to FBO on host */
138#define CR_SERVER_REDIR_F_FBO 0x02
139/* used with CR_SERVER_REDIR_F_FBO only
140 * indicates that FBO data should be copied to RAM for further processing */
141#define CR_SERVER_REDIR_F_FBO_RAM 0x04
142/* used with CR_SERVER_REDIR_F_FBO_RAM only
143 * indicates that FBO data should be passed to VRDP backend */
144#define CR_SERVER_REDIR_F_FBO_RAM_VRDP 0x08
145/* used with CR_SERVER_REDIR_F_FBO_RAM only
146 * indicates that FBO data should be passed to VM Framebuffer */
147#define CR_SERVER_REDIR_F_FBO_RAM_VMFB 0x10
148/* used with CR_SERVER_REDIR_F_FBO_RAM only
149 * makes the RPW (Read Pixels Worker) mechanism to be used for GPU memory aquisition */
150#define CR_SERVER_REDIR_F_FBO_RPW 0x20
151
152
153#define CR_SERVER_REDIR_F_ALL 0x3f
154
155#define CR_SERVER_REDIR_FGROUP_REQUIRE_FBO (CR_SERVER_REDIR_F_ALL & ~CR_SERVER_REDIR_F_DISPLAY)
156#define CR_SERVER_REDIR_FGROUP_REQUIRE_FBO_RAM (CR_SERVER_REDIR_F_FBO_RAM_VRDP | CR_SERVER_REDIR_F_FBO_RAM_VMFB | CR_SERVER_REDIR_F_FBO_RPW)
157
158DECLINLINE(GLuint) crServerRedirModeAdjust(GLuint value)
159{
160 /* sanitize values */
161 value &= CR_SERVER_REDIR_F_ALL;
162
163 if (value & CR_SERVER_REDIR_FGROUP_REQUIRE_FBO)
164 value |= CR_SERVER_REDIR_F_FBO;
165 if (value & CR_SERVER_REDIR_FGROUP_REQUIRE_FBO_RAM)
166 value |= CR_SERVER_REDIR_F_FBO_RAM;
167
168 return value;
169}
170
171int32_t crServerSetOffscreenRenderingMode(GLuint value);
172void crServerRedirMuralFBO(CRMuralInfo *mural, GLuint redir);
173void crServerDeleteMuralFBO(CRMuralInfo *mural);
174void crServerPresentFBO(CRMuralInfo *mural);
175GLboolean crServerIsRedirectedToFBO();
176GLuint crServerMuralFBOIdxFromBufferName(CRMuralInfo *mural, GLenum buffer);
177void crServerMuralFBOSwapBuffers(CRMuralInfo *mural);
178
179void crServerVBoxCompositionDisableEnter(CRMuralInfo *mural);
180void crServerVBoxCompositionDisableLeave(CRMuralInfo *mural, GLboolean fForcePresentOnEnabled);
181void crServerVBoxCompositionPresent(CRMuralInfo *mural);
182DECLINLINE(GLboolean) crServerVBoxCompositionPresentNeeded(CRMuralInfo *mural)
183{
184 return mural->bVisible
185 && mural->width
186 && mural->height
187 && !mural->fRootVrOn ? CrVrScrCompositorEntryIsInList(&mural->CEntry) : CrVrScrCompositorEntryIsInList(&mural->RootVrCEntry);
188}
189
190#define CR_SERVER_FBO_BB_IDX(_mural) ((_mural)->iBbBuffer)
191#define CR_SERVER_FBO_FB_IDX(_mural) (((_mural)->iBbBuffer + 1) % ((_mural)->cBuffers))
192
193int32_t crVBoxServerInternalClientRead(CRClient *pClient, uint8_t *pBuffer, uint32_t *pcbBuffer);
194
195PCR_DISPLAY crServerDisplayGetInitialized(uint32_t idScreen);
196
197void crServerPerformMakeCurrent( CRMuralInfo *mural, CRContextInfo *ctxInfo );
198
199PCR_BLITTER crServerVBoxBlitterGet();
200
201DECLINLINE(void) crServerVBoxBlitterWinInit(CR_BLITTER_WINDOW *win, CRMuralInfo *mural)
202{
203 win->Base.id = mural->spuWindow;
204 win->Base.visualBits = mural->CreateInfo.visualBits;
205 win->width = mural->width;
206 win->height = mural->height;
207}
208
209DECLINLINE(void) crServerVBoxBlitterCtxInit(CR_BLITTER_CONTEXT *ctx, CRContextInfo *ctxInfo)
210{
211 ctx->Base.id = ctxInfo->SpuContext;
212 if (ctx->Base.id < 0)
213 ctx->Base.id = cr_server.MainContextInfo.SpuContext;
214 ctx->Base.visualBits = cr_server.curClient->currentCtxInfo->CreateInfo.visualBits;
215}
216
217/* display worker thread.
218 * see comments for CR_SERVER_RPW struct definition in cr_server.h */
219DECLINLINE(void) crServerXchgI8(int8_t *pu8Val1, int8_t *pu8Val2)
220{
221 int8_t tmp;
222 tmp = *pu8Val1;
223 *pu8Val1 = *pu8Val2;
224 *pu8Val2 = tmp;
225}
226
227#ifdef DEBUG_misha
228# define CR_SERVER_RPW_DEBUG
229#endif
230/* *
231 * _name : Draw, Submitted, Worker, Gpu
232 */
233
234#ifdef CR_SERVER_RPW_DEBUG
235# define crServerRpwEntryDbgVerify(_pE) crServerRpwEntryDbgDoVerify(_pE)
236#else
237# define crServerRpwEntryDbgVerify(_pE) do {} while (0)
238#endif
239
240
241#define CR_SERVER_RPW_ENTRY_TEX_IS_VALID(_pEntry, _name) ((_pEntry)->iTex##_name > 0)
242
243#define CR_SERVER_RPW_ENTRY_TEX_INVALIDATE(_pEntry, _name) do { \
244 crServerRpwEntryDbgVerify(_pEntry); \
245 Assert(CR_SERVER_RPW_ENTRY_TEX_IS_VALID(_pEntry, _name)); \
246 (_pEntry)->iTex##_name = -(_pEntry)->iTex##_name; \
247 crServerRpwEntryDbgVerify(_pEntry); \
248 } while (0)
249
250#define CR_SERVER_RPW_ENTRY_TEX_PROMOTE(_pEntry, _fromName, _toName) do { \
251 crServerRpwEntryDbgVerify(_pEntry); \
252 Assert(CR_SERVER_RPW_ENTRY_TEX_IS_VALID(_pEntry, _fromName)); \
253 Assert(!CR_SERVER_RPW_ENTRY_TEX_IS_VALID(_pEntry, _toName)); \
254 crServerXchgI8(&(_pEntry)->iTex##_fromName, &(_pEntry)->iTex##_toName); \
255 crServerRpwEntryDbgVerify(_pEntry); \
256 } while (0)
257
258#define CR_SERVER_RPW_ENTRY_TEX_XCHG_VALID(_pEntry, _fromName, _toName) do { \
259 crServerRpwEntryDbgVerify(_pEntry); \
260 Assert(CR_SERVER_RPW_ENTRY_TEX_IS_VALID(_pEntry, _fromName)); \
261 Assert(CR_SERVER_RPW_ENTRY_TEX_IS_VALID(_pEntry, _toName)); \
262 crServerXchgI8(&(_pEntry)->iTex##_fromName, &(_pEntry)->iTex##_toName); \
263 Assert(CR_SERVER_RPW_ENTRY_TEX_IS_VALID(_pEntry, _fromName)); \
264 Assert(CR_SERVER_RPW_ENTRY_TEX_IS_VALID(_pEntry, _toName)); \
265 crServerRpwEntryDbgVerify(_pEntry); \
266 } while (0)
267
268
269#define CR_SERVER_RPW_ENTRY_TEX_PROMOTE_KEEPVALID(_pEntry, _fromName, _toName) do { \
270 crServerRpwEntryDbgVerify(_pEntry); \
271 Assert(CR_SERVER_RPW_ENTRY_TEX_IS_VALID(_pEntry, _fromName)); \
272 Assert(!CR_SERVER_RPW_ENTRY_TEX_IS_VALID(_pEntry, _toName)); \
273 crServerXchgI8(&(_pEntry)->iTex##_fromName, &(_pEntry)->iTex##_toName); \
274 (_pEntry)->iTex##_fromName = -(_pEntry)->iTex##_fromName; \
275 Assert(CR_SERVER_RPW_ENTRY_TEX_IS_VALID(_pEntry, _fromName)); \
276 Assert(CR_SERVER_RPW_ENTRY_TEX_IS_VALID(_pEntry, _toName)); \
277 crServerRpwEntryDbgVerify(_pEntry); \
278 } while (0)
279
280#define CR_SERVER_RPW_ENTRY_TEX(_pEntry, _name) ((_pEntry)->aidWorkerTexs[(_pEntry)->iTex##_name - 1])
281
282#define CR_SERVER_RPW_ENTRY_PBO_NEXT_ID(_i) (((_i) + 1) % 2)
283#define CR_SERVER_RPW_ENTRY_PBO_IS_ACTIVE(_pEntry) ((_pEntry)->iCurPBO >= 0)
284#define CR_SERVER_RPW_ENTRY_PBO_CUR(_pEntry) ((_pEntry)->aidPBOs[(_pEntry)->iCurPBO])
285#define CR_SERVER_RPW_ENTRY_PBO_COMPLETED(_pEntry) ((_pEntry)->aidPBOs[CR_SERVER_RPW_ENTRY_PBO_NEXT_ID((_pEntry)->iCurPBO)])
286#define CR_SERVER_RPW_ENTRY_PBO_FLIP(_pEntry) do { \
287 (_pEntry)->iCurPBO = CR_SERVER_RPW_ENTRY_PBO_NEXT_ID((_pEntry)->iCurPBO); \
288 } while (0)
289
290#ifdef CR_SERVER_RPW_DEBUG
291DECLINLINE(void) crServerRpwEntryDbgDoVerify(CR_SERVER_RPW_ENTRY *pEntry)
292{
293 int tstMask = 0;
294 int8_t iVal;
295 Assert(CR_SERVER_RPW_ENTRY_TEX_IS_VALID(pEntry, Draw));
296
297#define CR_VERVER_RPW_ENTRY_DBG_CHECKVAL(_v) do { \
298 iVal = RT_ABS(_v); \
299 Assert(iVal > 0); \
300 Assert(iVal < 5); \
301 Assert(!(tstMask & (1 << iVal))); \
302 tstMask |= (1 << iVal); \
303 } while (0)
304
305 CR_VERVER_RPW_ENTRY_DBG_CHECKVAL(pEntry->iTexDraw);
306 CR_VERVER_RPW_ENTRY_DBG_CHECKVAL(pEntry->iTexSubmitted);
307 CR_VERVER_RPW_ENTRY_DBG_CHECKVAL(pEntry->iTexWorker);
308 CR_VERVER_RPW_ENTRY_DBG_CHECKVAL(pEntry->iTexGpu);
309 Assert(tstMask == 0x1E);
310}
311#endif
312
313DECLINLINE(bool) crServerRpwIsInitialized(const CR_SERVER_RPW *pWorker)
314{
315 return !!pWorker->ctxId;
316}
317int crServerRpwInit(CR_SERVER_RPW *pWorker);
318int crServerRpwTerm(CR_SERVER_RPW *pWorker);
319DECLINLINE(bool) crServerRpwEntryIsInitialized(const CR_SERVER_RPW_ENTRY *pEntry)
320{
321 return !!pEntry->pfnData;
322}
323int crServerRpwEntryInit(CR_SERVER_RPW *pWorker, CR_SERVER_RPW_ENTRY *pEntry, uint32_t width, uint32_t height, PFNCR_SERVER_RPW_DATA pfnData);
324int crServerRpwEntryCleanup(CR_SERVER_RPW *pWorker, CR_SERVER_RPW_ENTRY *pEntry);
325int crServerRpwEntryResize(CR_SERVER_RPW *pWorker, CR_SERVER_RPW_ENTRY *pEntry, uint32_t width, uint32_t height);
326int crServerRpwEntrySubmit(CR_SERVER_RPW *pWorker, CR_SERVER_RPW_ENTRY *pEntry);
327int crServerRpwEntryWaitComplete(CR_SERVER_RPW *pWorker, CR_SERVER_RPW_ENTRY *pEntry);
328int crServerRpwEntryCancel(CR_SERVER_RPW *pWorker, CR_SERVER_RPW_ENTRY *pEntry);
329DECLINLINE(void) crServerRpwEntryDrawSettingsToTex(const CR_SERVER_RPW_ENTRY *pEntry, VBOXVR_TEXTURE *pTex)
330{
331 pTex->width = pEntry->Size.cx;
332 pTex->height = pEntry->Size.cy;
333 pTex->target = GL_TEXTURE_2D;
334 Assert(CR_SERVER_RPW_ENTRY_TEX_IS_VALID(pEntry, Draw));
335 pTex->hwid = CR_SERVER_RPW_ENTRY_TEX(pEntry, Draw);
336}
337/**/
338
339typedef struct CR_SERVER_CTX_SWITCH
340{
341 GLuint idDrawFBO, idReadFBO;
342 CRContext *pNewCtx;
343 CRContext *pOldCtx;
344} CR_SERVER_CTX_SWITCH;
345
346DECLINLINE(void) cr_serverCtxSwitchPrepare(CR_SERVER_CTX_SWITCH *pData, CRContext *pNewCtx)
347{
348 CRMuralInfo *pCurrentMural = cr_server.currentMural;
349 CRContextInfo *pCurCtxInfo = cr_server.currentCtxInfo;
350 GLuint idDrawFBO, idReadFBO;
351 CRContext *pCurCtx = pCurCtxInfo ? pCurCtxInfo->pContext : NULL;
352
353 CRASSERT(pCurCtx == crStateGetCurrent());
354
355 if (pCurrentMural)
356 {
357 idDrawFBO = pCurrentMural->aidFBOs[pCurrentMural->iCurDrawBuffer];
358 idReadFBO = pCurrentMural->aidFBOs[pCurrentMural->iCurReadBuffer];
359 }
360 else
361 {
362 idDrawFBO = 0;
363 idReadFBO = 0;
364 }
365
366 crStateSwitchPrepare(pNewCtx, pCurCtx, idDrawFBO, idReadFBO);
367
368 pData->idDrawFBO = idDrawFBO;
369 pData->idReadFBO = idReadFBO;
370 pData->pNewCtx = pNewCtx;
371 pData->pOldCtx = pCurCtx;
372}
373
374DECLINLINE(void) cr_serverCtxSwitchPostprocess(CR_SERVER_CTX_SWITCH *pData)
375{
376 crStateSwitchPostprocess(pData->pOldCtx, pData->pNewCtx, pData->idDrawFBO, pData->idReadFBO);
377}
378RT_C_DECLS_END
379
380#endif /* CR_SERVER_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