VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/include/cr_server.h@ 45201

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

crOpenGL: basics for BlitFramebuffer driver bugs work around

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.8 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 INCLUDE_CR_SERVER_H
8#define INCLUDE_CR_SERVER_H
9
10#include "cr_spu.h"
11#include "cr_net.h"
12#include "cr_hash.h"
13#include "cr_protocol.h"
14#include "cr_glstate.h"
15#include "cr_vreg.h"
16#include "cr_blitter.h"
17#include "spu_dispatch_table.h"
18
19#include "state/cr_currentpointers.h"
20
21#include <iprt/types.h>
22#include <iprt/err.h>
23#include <iprt/string.h>
24
25#include <VBox/vmm/ssm.h>
26
27#ifdef VBOX_WITH_CRHGSMI
28# include <VBox/VBoxVideo.h>
29#endif
30#include <VBox/Hardware/VBoxVideoVBE.h>
31
32#include "cr_vreg.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#define CR_MAX_WINDOWS 100
39#define CR_MAX_CLIENTS 64
40
41/*@todo must match MaxGuestMonitors from SchemaDefs.h*/
42#define CR_MAX_GUEST_MONITORS VBOX_VIDEO_MAX_SCREENS
43
44typedef DECLCALLBACKPTR(void, PFNCRSERVERPRESENTFBO) (void *data, int32_t screenId, int32_t x, int32_t y, uint32_t w, uint32_t h);
45
46/* Callbacks for output of the rendered frames.
47 *
48 * This allows to pass rendered frames to an external component rather than draw them on screen.
49 *
50 * An external component registers the redirection callbacks using crVBoxServerOutputRedirectSet.
51 *
52 * The list of formats supported by the caller is obtained using CRORContextProperty.
53 * The actual format choosed by the service is passed as a CRORBegin parameter.
54 */
55typedef struct {
56 const void *pvContext; /* Supplied by crVBoxServerOutputRedirectSet. */
57 DECLR3CALLBACKMEMBER(void, CRORBegin, (const void *pvContext, void **ppvInstance,
58 const char *pszFormat));
59 DECLR3CALLBACKMEMBER(void, CRORGeometry, (void *pvInstance,
60 int32_t x, int32_t y, uint32_t w, uint32_t h));
61 DECLR3CALLBACKMEMBER(void, CRORVisibleRegion, (void *pvInstance,
62 uint32_t cRects, const RTRECT *paRects));
63 DECLR3CALLBACKMEMBER(void, CRORFrame, (void *pvInstance,
64 void *pvData, uint32_t cbData));
65 DECLR3CALLBACKMEMBER(void, CROREnd, (void *pvInstance));
66 DECLR3CALLBACKMEMBER(int, CRORContextProperty, (const void *pvContext, uint32_t index,
67 void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut));
68} CROutputRedirect;
69
70typedef struct {
71 CRrecti imagewindow; /**< coordinates in mural space */
72 CRrectf bounds; /**< normalized coordinates in [-1,-1] x [1,1] */
73 CRrecti outputwindow; /**< coordinates in server's rendering window */
74 CRrecti clippedImagewindow; /**< imagewindow clipped to current viewport */
75 CRmatrix baseProjection; /**< pre-multiplied onto projection matrix */
76 CRrecti scissorBox; /**< passed to back-end OpenGL */
77 CRrecti viewport; /**< passed to back-end OpenGL */
78 GLuint serialNo; /**< an optimization */
79} CRExtent;
80
81struct BucketingInfo;
82
83typedef struct {
84 char *pszDpyName;
85 GLint visualBits;
86 int32_t externalID;
87} CRCreateInfo_t;
88
89/**
90 * Mural info
91 */
92typedef struct {
93 GLuint width, height;
94 GLint gX, gY; /*guest coordinates*/
95 GLint hX, hY; /*host coordinates, screenID related*/
96
97 int spuWindow; /*the SPU's corresponding window ID */
98
99 int screenId;
100
101 GLboolean bVisible; /*guest window is visible*/
102 GLubyte fUseFBO; /*redirect to FBO instead of real host window*/
103 GLboolean bFbDraw; /*GL_FRONT buffer is drawn to directly*/
104 GLboolean fDataPresented;
105
106 GLint cVisibleRects; /*count of visible rects*/
107 GLint *pVisibleRects; /*visible rects left, top, right, bottom*/
108 GLboolean bReceivedRects; /*indicates if guest did any updates for visible regions*/
109
110 GLuint cBuffers;
111 GLuint iBbBuffer;
112 GLuint aidFBOs[2];
113 GLuint aidColorTexs[2];
114
115 void *pvOutputRedirectInstance;
116
117 CRCreateInfo_t CreateInfo;
118
119 /* to avoid saved state breakage we need to keep RT_OFFSETOF(CRMuralInfo, CreateInfo) intact
120 * this is why we place some FBO stuff to the tail
121 * @todo: once we need to increment a saved state version, we could refactor this structure */
122 GLuint iCurDrawBuffer;
123 GLuint iCurReadBuffer;
124
125 GLuint idDepthStencilRB;
126 GLuint fboWidth, fboHeight;
127 GLuint idPBO;
128
129 GLuint cDisabled;
130
131 GLboolean fRootVrOn;
132 GLboolean fForcePresentState;
133
134 VBOXVR_SCR_COMPOSITOR_ENTRY CEntry;
135 VBOXVR_SCR_COMPOSITOR Compositor;
136
137 /* if root Visible regions are set, these two contain actual regions being passed to render spu */
138 VBOXVR_SCR_COMPOSITOR_ENTRY RootVrCEntry;
139 VBOXVR_SCR_COMPOSITOR RootVrCompositor;
140
141 /* bitfield representing contexts the mural has been ever current with
142 * we just reuse CR_STATE_SHAREDOBJ_USAGE_XXX API here for simplicity */
143 CRbitvalue ctxUsage[CR_MAX_BITARRAY];
144} CRMuralInfo;
145
146typedef struct {
147 CRContext *pContext;
148 int SpuContext;
149 CRCreateInfo_t CreateInfo;
150 CRMuralInfo * currentMural;
151} CRContextInfo;
152
153/**
154 * A client is basically an upstream Cr Node (connected via mothership)
155 */
156typedef struct _crclient {
157 int spu_id; /**< id of the last SPU in the client's SPU chain */
158 CRConnection *conn; /**< network connection from the client */
159 int number; /**< a unique number for each client */
160 uint64_t pid; /*guest pid*/
161 GLint currentContextNumber;
162 CRContextInfo *currentCtxInfo;
163 GLint currentWindow;
164 CRMuralInfo *currentMural;
165 GLint windowList[CR_MAX_WINDOWS];
166 GLint contextList[CR_MAX_CONTEXTS];
167#ifdef VBOXCR_LOGFPS
168 uint64_t timeUsed;
169#endif
170} CRClient;
171
172typedef struct _crclientnode {
173 CRClient *pClient;
174 struct _crclientnode *prev, *next;
175} CRClientNode;
176
177typedef struct CRPoly_t {
178 int npoints;
179 double *points;
180 struct CRPoly_t *next;
181} CRPoly;
182
183/**
184 * There's one of these run queue entries per client
185 * The run queue is a circular, doubly-linked list of these objects.
186 */
187typedef struct RunQueue_t {
188 CRClient *client;
189 int blocked;
190 struct RunQueue_t *next;
191 struct RunQueue_t *prev;
192} RunQueue;
193
194typedef struct {
195 GLint freeWindowID;
196 GLint freeContextID;
197 GLint freeClientID;
198} CRServerFreeIDsPool_t;
199
200typedef struct {
201 int32_t x, y;
202 uint32_t w, h;
203 uint64_t winID;
204} CRScreenInfo;
205
206typedef struct {
207 int32_t x, y;
208 uint32_t w, h;
209} CRScreenViewportInfo;
210
211
212/* DISPLAY */
213
214typedef struct CR_DISPLAY_ENTRY
215{
216 VBOXVR_SCR_COMPOSITOR_ENTRY CEntry;
217} CR_DISPLAY_ENTRY, *PCR_DISPLAY_ENTRY;
218
219/* @todo:
220 * 1. use compositor stored inside mural to use current MuralFBO and window-related API
221 * 2. CR_SERVER_REDIR_NONE and CR_SERVER_REDIR_FBO_BLT should be trated identically for presented window
222 * since we just need to blit the given textures to it if we are NOT in CR_SERVER_REDIR_FBO_RAM mode */
223typedef struct CR_DISPLAY
224{
225 VBOXVR_SCR_COMPOSITOR Compositor;
226 CRMuralInfo Mural;
227} CR_DISPLAY, *PCR_DISPLAY;
228
229int CrDpInit(PCR_DISPLAY pDisplay);
230void CrDpTerm(PCR_DISPLAY pDisplay);
231void CrDpResize(PCR_DISPLAY pDisplay, uint32_t width, uint32_t height,
232 uint32_t stretchedWidth, uint32_t stretchedHeight);
233void CrDpEntryInit(PCR_DISPLAY_ENTRY pEntry, const VBOXVR_TEXTURE *pTextureData);
234void CrDpEntryCleanup(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry);
235int CrDpEntryRegionsSet(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions);
236int CrDpEntryRegionsAdd(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions);
237int CrDpPresentEntry(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry);
238DECLINLINE(bool) CrDpEntryIsUsed(PCR_DISPLAY_ENTRY pEntry)
239{
240 return CrVrScrCompositorEntryIsInList(&pEntry->CEntry);
241}
242
243DECLINLINE(CRMuralInfo*) CrDpGetMural(PCR_DISPLAY pDisplay)
244{
245 return &pDisplay->Mural;
246}
247
248typedef struct CR_DISPLAY_ENTRY_MAP
249{
250 CRHashTable * pTextureMap;
251} CR_DISPLAY_ENTRY_MAP, *PCR_DISPLAY_ENTRY_MAP;
252
253int CrDemInit(PCR_DISPLAY_ENTRY_MAP pMap);
254void CrDemTerm(PCR_DISPLAY_ENTRY_MAP pMap);
255PCR_DISPLAY_ENTRY CrDemEntryGetCreate(PCR_DISPLAY_ENTRY_MAP pMap, GLuint idTexture, CRContextInfo *pCtxInfo);
256void CrDemEntryDestroy(PCR_DISPLAY_ENTRY_MAP pMap, GLuint idTexture);
257
258/* */
259
260/* helpers */
261
262void CrHlpFreeTexImage(CRContext *pCurCtx, GLuint idPBO, void *pvData);
263void* CrHlpGetTexImage(CRContext *pCurCtx, PVBOXVR_TEXTURE pTexture, GLuint idPBO, GLenum enmFormat);
264void CrHlpPutTexImage(CRContext *pCurCtx, PVBOXVR_TEXTURE pTexture, GLenum enmFormat, void *pvData);
265
266/* */
267
268typedef struct {
269 unsigned short tcpip_port;
270
271 CRScreenInfo screen[CR_MAX_GUEST_MONITORS];
272 CRScreenViewportInfo screenVieport[CR_MAX_GUEST_MONITORS];
273 int screenCount;
274
275 int numClients;
276 CRClient *clients[CR_MAX_CLIENTS]; /**< array [numClients] */
277 CRClient *curClient;
278 CRClientNode *pCleanupClient; /*list of clients with pending clean up*/
279 CRCurrentStatePointers current;
280
281 GLboolean firstCallCreateContext;
282 GLboolean firstCallMakeCurrent;
283 GLboolean bIsInLoadingState; /* Indicates if we're in process of loading VM snapshot */
284 GLboolean bIsInSavingState; /* Indicates if we're in process of saving VM snapshot */
285 GLboolean bForceMakeCurrentOnClientSwitch;
286 CRContextInfo *currentCtxInfo;
287 GLint currentWindow;
288 GLint currentNativeWindow;
289 CRMuralInfo *currentMural;
290
291 CRHashTable *muralTable; /**< hash table where all murals are stored */
292
293 int client_spu_id;
294
295 int mtu;
296 int buffer_size;
297 char protocol[1024];
298
299 SPU *head_spu;
300 SPUDispatchTable dispatch;
301
302 CRNetworkPointer return_ptr;
303 CRNetworkPointer writeback_ptr;
304
305 CRLimitsState limits; /**< GL limits for any contexts we create */
306
307 CRContextInfo MainContextInfo;
308
309 CRHashTable *contextTable; /**< hash table for rendering contexts */
310
311 CRHashTable *programTable; /**< for vertex programs */
312 GLuint currentProgram;
313
314 /* visBits -> dummy mural association */
315 CRHashTable *dummyMuralTable;
316
317 GLboolean fRootVrOn;
318 VBOXVR_LIST RootVr;
319 /* we need to translate Root Vr to each window coords, this one cpecifies the current translation point
320 * note that since window attributes modifications is performed in HGCM thread only and thus is serialized,
321 * we deal with the global RootVr data directly */
322 RTPOINT RootVrCurPoint;
323
324 CR_BLITTER Blitter;
325
326 /** configuration options */
327 /*@{*/
328 int useL2;
329 int ignore_papi;
330 unsigned int maxBarrierCount;
331 unsigned int clearCount;
332 int optimizeBucket;
333 int only_swap_once;
334 int debug_barriers;
335 int sharedDisplayLists;
336 int sharedTextureObjects;
337 int sharedPrograms;
338 int sharedWindows;
339 int uniqueWindows;
340 int localTileSpec;
341 int useDMX;
342 int overlapBlending;
343 int vpProjectionMatrixParameter;
344 const char *vpProjectionMatrixVariable;
345 int stereoView;
346 int vncMode; /* cmd line option */
347 /*@}*/
348 /** view_matrix config */
349 /*@{*/
350 GLboolean viewOverride;
351 CRmatrix viewMatrix[2]; /**< left and right eye */
352 /*@}*/
353 /** projection_matrix config */
354 /*@{*/
355 GLboolean projectionOverride;
356 CRmatrix projectionMatrix[2]; /**< left and right eye */
357 int currentEye;
358 /*@}*/
359
360 /** for warped tiles */
361 /*@{*/
362 GLfloat alignment_matrix[16], unnormalized_alignment_matrix[16];
363 /*@}*/
364
365 /** tile overlap/blending info - this should probably be per-mural */
366 /*@{*/
367 CRPoly **overlap_geom;
368 CRPoly *overlap_knockout;
369 float *overlap_intens;
370 int num_overlap_intens;
371 int num_overlap_levels;
372 /*@}*/
373
374 CRHashTable *barriers, *semaphores;
375
376 RunQueue *run_queue;
377
378 GLuint currentSerialNo;
379
380 PFNCRSERVERPRESENTFBO pfnPresentFBO;
381 GLubyte bForceOffscreenRendering; /*Force server to render 3d data offscreen
382 *using callback above to update vbox framebuffers*/
383 GLubyte bOffscreenRenderingDefault; /*can be set with CR_SERVER_DEFAULT_RENDER_TYPE*/
384 GLboolean bUsePBOForReadback; /*Use PBO's for data readback*/
385
386 GLboolean bUseOutputRedirect; /* Whether the output redirect was set. */
387 CROutputRedirect outputRedirect;
388
389 GLboolean bUseMultipleContexts;
390
391 /* @todo: should we use just one blitter?
392 * we use two currently because the drawable attribs can differ*/
393 CR_DISPLAY_ENTRY_MAP PresentTexturepMap;
394 uint32_t DisplaysInitMap[(CR_MAX_GUEST_MONITORS + 31)/32];
395 CR_DISPLAY aDispplays[CR_MAX_GUEST_MONITORS];
396} CRServer;
397
398
399extern DECLEXPORT(void) crServerInit( int argc, char *argv[] );
400extern DECLEXPORT(int) CRServerMain( int argc, char *argv[] );
401extern DECLEXPORT(void) crServerServiceClients(void);
402extern DECLEXPORT(void) crServerAddNewClient(void);
403extern DECLEXPORT(SPU*) crServerHeadSPU(void);
404extern DECLEXPORT(void) crServerSetPort(int port);
405
406extern DECLEXPORT(GLboolean) crVBoxServerInit(void);
407extern DECLEXPORT(void) crVBoxServerTearDown(void);
408extern DECLEXPORT(int32_t) crVBoxServerAddClient(uint32_t u32ClientID);
409extern DECLEXPORT(void) crVBoxServerRemoveClient(uint32_t u32ClientID);
410extern DECLEXPORT(int32_t) crVBoxServerClientWrite(uint32_t u32ClientID, uint8_t *pBuffer, uint32_t cbBuffer);
411extern DECLEXPORT(int32_t) crVBoxServerClientRead(uint32_t u32ClientID, uint8_t *pBuffer, uint32_t *pcbBuffer);
412extern DECLEXPORT(int32_t) crVBoxServerClientSetVersion(uint32_t u32ClientID, uint32_t vMajor, uint32_t vMinor);
413extern DECLEXPORT(int32_t) crVBoxServerClientSetPID(uint32_t u32ClientID, uint64_t pid);
414
415extern DECLEXPORT(int32_t) crVBoxServerSaveState(PSSMHANDLE pSSM);
416extern DECLEXPORT(int32_t) crVBoxServerLoadState(PSSMHANDLE pSSM, uint32_t version);
417
418extern DECLEXPORT(int32_t) crVBoxServerSetScreenCount(int sCount);
419extern DECLEXPORT(int32_t) crVBoxServerUnmapScreen(int sIndex);
420extern DECLEXPORT(int32_t) crVBoxServerMapScreen(int sIndex, int32_t x, int32_t y, uint32_t w, uint32_t h, uint64_t winID);
421extern DECLEXPORT(void) crServerVBoxCompositionSetEnableStateGlobal(GLboolean fEnable);
422extern DECLEXPORT(int32_t) crVBoxServerSetRootVisibleRegion(GLint cRects, const RTRECT *pRects);
423
424extern DECLEXPORT(void) crVBoxServerSetPresentFBOCB(PFNCRSERVERPRESENTFBO pfnPresentFBO);
425
426extern DECLEXPORT(int32_t) crVBoxServerSetOffscreenRendering(GLboolean value);
427
428extern DECLEXPORT(int32_t) crVBoxServerOutputRedirectSet(const CROutputRedirect *pCallbacks);
429
430extern DECLEXPORT(int32_t) crVBoxServerSetScreenViewport(int sIndex, int32_t x, int32_t y, uint32_t w, uint32_t h);
431
432#ifdef VBOX_WITH_CRHGSMI
433/* We moved all CrHgsmi command processing to crserverlib to keep the logic of dealing with CrHgsmi commands in one place.
434 *
435 * For now we need the notion of CrHgdmi commands in the crserver_lib to be able to complete it asynchronously once it is really processed.
436 * This help avoiding the "blocked-client" issues. The client is blocked if another client is doing begin-end stuff.
437 * For now we eliminated polling that could occur on block, which caused a higher-priority thread (in guest) polling for the blocked command complition
438 * to block the lower-priority thread trying to complete the blocking command.
439 * And removed extra memcpy done on blocked command arrival.
440 *
441 * In the future we will extend CrHgsmi functionality to maintain texture data directly in CrHgsmi allocation to avoid extra memcpy-ing with PBO,
442 * implement command completion and stuff necessary for GPU scheduling to work properly for WDDM Windows guests, etc.
443 *
444 * NOTE: it is ALWAYS responsibility of the crVBoxServerCrHgsmiCmd to complete the command!
445 * */
446extern DECLEXPORT(int32_t) crVBoxServerCrHgsmiCmd(struct VBOXVDMACMD_CHROMIUM_CMD *pCmd, uint32_t cbCmd);
447extern DECLEXPORT(int32_t) crVBoxServerCrHgsmiCtl(struct VBOXVDMACMD_CHROMIUM_CTL *pCtl, uint32_t cbCtl);
448#endif
449
450#ifdef __cplusplus
451}
452#endif
453
454#endif
455
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