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 "spu_dispatch_table.h"
|
---|
16 |
|
---|
17 | #include "state/cr_currentpointers.h"
|
---|
18 |
|
---|
19 | #include <iprt/types.h>
|
---|
20 | #include <iprt/err.h>
|
---|
21 | #include <iprt/string.h>
|
---|
22 |
|
---|
23 | #include <VBox/vmm/ssm.h>
|
---|
24 |
|
---|
25 | #ifdef VBOX_WITH_CRHGSMI
|
---|
26 | # include <VBox/VBoxVideo.h>
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | #ifdef __cplusplus
|
---|
30 | extern "C" {
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #define CR_MAX_WINDOWS 100
|
---|
34 | #define CR_MAX_CLIENTS 64
|
---|
35 |
|
---|
36 | /*@todo must match MaxGuestMonitors from SchemaDefs.h*/
|
---|
37 | #define CR_MAX_GUEST_MONITORS 8
|
---|
38 |
|
---|
39 | typedef DECLCALLBACKPTR(void, PFNCRSERVERPRESENTFBO) (void *data, int32_t screenId, int32_t x, int32_t y, uint32_t w, uint32_t h);
|
---|
40 |
|
---|
41 | /* Callbacks for output of the rendered frames.
|
---|
42 | *
|
---|
43 | * This allows to pass rendered frames to an external component rather than draw them on screen.
|
---|
44 | *
|
---|
45 | * An external component registers the redirection callbacks using crVBoxServerOutputRedirectSet.
|
---|
46 | *
|
---|
47 | * The list of formats supported by the caller is obtained using CRORContextProperty.
|
---|
48 | * The actual format choosed by the service is passed as a CRORBegin parameter.
|
---|
49 | */
|
---|
50 | typedef struct {
|
---|
51 | const void *pvContext; /* Supplied by crVBoxServerOutputRedirectSet. */
|
---|
52 | DECLR3CALLBACKMEMBER(void, CRORBegin, (const void *pvContext, void **ppvInstance,
|
---|
53 | const char *pszFormat));
|
---|
54 | DECLR3CALLBACKMEMBER(void, CRORGeometry, (void *pvInstance,
|
---|
55 | int32_t x, int32_t y, uint32_t w, uint32_t h));
|
---|
56 | DECLR3CALLBACKMEMBER(void, CRORVisibleRegion, (void *pvInstance,
|
---|
57 | uint32_t cRects, RTRECT *paRects));
|
---|
58 | DECLR3CALLBACKMEMBER(void, CRORFrame, (void *pvInstance,
|
---|
59 | void *pvData, uint32_t cbData));
|
---|
60 | DECLR3CALLBACKMEMBER(void, CROREnd, (void *pvInstance));
|
---|
61 | DECLR3CALLBACKMEMBER(int, CRORContextProperty, (const void *pvContext, uint32_t index,
|
---|
62 | void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut));
|
---|
63 | } CROutputRedirect;
|
---|
64 |
|
---|
65 | typedef struct {
|
---|
66 | CRrecti imagewindow; /**< coordinates in mural space */
|
---|
67 | CRrectf bounds; /**< normalized coordinates in [-1,-1] x [1,1] */
|
---|
68 | CRrecti outputwindow; /**< coordinates in server's rendering window */
|
---|
69 | CRrecti clippedImagewindow; /**< imagewindow clipped to current viewport */
|
---|
70 | CRmatrix baseProjection; /**< pre-multiplied onto projection matrix */
|
---|
71 | CRrecti scissorBox; /**< passed to back-end OpenGL */
|
---|
72 | CRrecti viewport; /**< passed to back-end OpenGL */
|
---|
73 | GLuint serialNo; /**< an optimization */
|
---|
74 | } CRExtent;
|
---|
75 |
|
---|
76 | struct BucketingInfo;
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Mural info
|
---|
80 | */
|
---|
81 | typedef struct {
|
---|
82 | GLuint width, height;
|
---|
83 | GLint gX, gY; /*guest coordinates*/
|
---|
84 | GLint hX, hY; /*host coordinates, screenID related*/
|
---|
85 |
|
---|
86 | int spuWindow; /*the SPU's corresponding window ID */
|
---|
87 |
|
---|
88 | int screenId;
|
---|
89 |
|
---|
90 | GLboolean bVisible; /*guest window is visible*/
|
---|
91 | GLboolean bUseFBO; /*redirect to FBO instead of real host window*/
|
---|
92 | GLboolean bFbDraw; /*GL_FRONT buffer is drawn to directly*/
|
---|
93 |
|
---|
94 | GLint cVisibleRects; /*count of visible rects*/
|
---|
95 | GLint *pVisibleRects; /*visible rects left, top, right, bottom*/
|
---|
96 | GLboolean bReceivedRects; /*indicates if guest did any updates for visible regions*/
|
---|
97 |
|
---|
98 | GLuint idFBO, idColorTex, idDepthStencilRB;
|
---|
99 | GLuint fboWidth, fboHeight;
|
---|
100 | GLuint idPBO;
|
---|
101 |
|
---|
102 | void *pvOutputRedirectInstance;
|
---|
103 | } CRMuralInfo;
|
---|
104 |
|
---|
105 | typedef struct {
|
---|
106 | char *pszDpyName;
|
---|
107 | GLint visualBits;
|
---|
108 | int32_t externalID;
|
---|
109 | } CRCreateInfo_t;
|
---|
110 |
|
---|
111 | typedef struct {
|
---|
112 | CRContext *pContext;
|
---|
113 | int SpuContext;
|
---|
114 | CRCreateInfo_t CreateInfo;
|
---|
115 | } CRContextInfo;
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * A client is basically an upstream Cr Node (connected via mothership)
|
---|
119 | */
|
---|
120 | typedef struct _crclient {
|
---|
121 | int spu_id; /**< id of the last SPU in the client's SPU chain */
|
---|
122 | CRConnection *conn; /**< network connection from the client */
|
---|
123 | int number; /**< a unique number for each client */
|
---|
124 | uint64_t pid; /*guest pid*/
|
---|
125 | GLint currentContextNumber;
|
---|
126 | CRContextInfo *currentCtxInfo;
|
---|
127 | GLint currentWindow;
|
---|
128 | CRMuralInfo *currentMural;
|
---|
129 | GLint windowList[CR_MAX_WINDOWS];
|
---|
130 | GLint contextList[CR_MAX_CONTEXTS];
|
---|
131 | #ifdef VBOXCR_LOGFPS
|
---|
132 | uint64_t timeUsed;
|
---|
133 | #endif
|
---|
134 | } CRClient;
|
---|
135 |
|
---|
136 | typedef struct _crclientnode {
|
---|
137 | CRClient *pClient;
|
---|
138 | struct _crclientnode *prev, *next;
|
---|
139 | } CRClientNode;
|
---|
140 |
|
---|
141 | typedef struct CRPoly_t {
|
---|
142 | int npoints;
|
---|
143 | double *points;
|
---|
144 | struct CRPoly_t *next;
|
---|
145 | } CRPoly;
|
---|
146 |
|
---|
147 | /**
|
---|
148 | * There's one of these run queue entries per client
|
---|
149 | * The run queue is a circular, doubly-linked list of these objects.
|
---|
150 | */
|
---|
151 | typedef struct RunQueue_t {
|
---|
152 | CRClient *client;
|
---|
153 | int blocked;
|
---|
154 | struct RunQueue_t *next;
|
---|
155 | struct RunQueue_t *prev;
|
---|
156 | } RunQueue;
|
---|
157 |
|
---|
158 | typedef struct {
|
---|
159 | GLint freeWindowID;
|
---|
160 | GLint freeContextID;
|
---|
161 | GLint freeClientID;
|
---|
162 | } CRServerFreeIDsPool_t;
|
---|
163 |
|
---|
164 | typedef struct {
|
---|
165 | int32_t x, y;
|
---|
166 | uint32_t w, h;
|
---|
167 | uint64_t winID;
|
---|
168 | } CRScreenInfo;
|
---|
169 |
|
---|
170 | typedef struct {
|
---|
171 | int32_t x, y;
|
---|
172 | uint32_t w, h;
|
---|
173 | } CRScreenViewportInfo;
|
---|
174 |
|
---|
175 |
|
---|
176 | typedef struct {
|
---|
177 | unsigned short tcpip_port;
|
---|
178 |
|
---|
179 | CRScreenInfo screen[CR_MAX_GUEST_MONITORS];
|
---|
180 | CRScreenViewportInfo screenVieport[CR_MAX_GUEST_MONITORS];
|
---|
181 | int screenCount;
|
---|
182 |
|
---|
183 | int numClients;
|
---|
184 | CRClient *clients[CR_MAX_CLIENTS]; /**< array [numClients] */
|
---|
185 | CRClient *curClient;
|
---|
186 | CRClientNode *pCleanupClient; /*list of clients with pending clean up*/
|
---|
187 | CRCurrentStatePointers current;
|
---|
188 |
|
---|
189 | GLboolean firstCallCreateContext;
|
---|
190 | GLboolean firstCallMakeCurrent;
|
---|
191 | GLboolean bIsInLoadingState; /* Indicates if we're in process of loading VM snapshot */
|
---|
192 | GLboolean bIsInSavingState; /* Indicates if we're in process of saving VM snapshot */
|
---|
193 | GLboolean bForceMakeCurrentOnClientSwitch;
|
---|
194 | CRContextInfo *currentCtxInfo;
|
---|
195 | GLint currentWindow;
|
---|
196 | GLint currentNativeWindow;
|
---|
197 |
|
---|
198 | CRHashTable *muralTable; /**< hash table where all murals are stored */
|
---|
199 | CRHashTable *pWindowCreateInfoTable; /**< hash table with windows creation info */
|
---|
200 |
|
---|
201 | int client_spu_id;
|
---|
202 |
|
---|
203 | CRServerFreeIDsPool_t idsPool;
|
---|
204 |
|
---|
205 | int mtu;
|
---|
206 | int buffer_size;
|
---|
207 | char protocol[1024];
|
---|
208 |
|
---|
209 | SPU *head_spu;
|
---|
210 | SPUDispatchTable dispatch;
|
---|
211 |
|
---|
212 | CRNetworkPointer return_ptr;
|
---|
213 | CRNetworkPointer writeback_ptr;
|
---|
214 |
|
---|
215 | CRLimitsState limits; /**< GL limits for any contexts we create */
|
---|
216 |
|
---|
217 | CRContextInfo MainContextInfo;
|
---|
218 |
|
---|
219 | CRHashTable *contextTable; /**< hash table for rendering contexts */
|
---|
220 |
|
---|
221 | CRHashTable *programTable; /**< for vertex programs */
|
---|
222 | GLuint currentProgram;
|
---|
223 |
|
---|
224 | /** configuration options */
|
---|
225 | /*@{*/
|
---|
226 | int useL2;
|
---|
227 | int ignore_papi;
|
---|
228 | unsigned int maxBarrierCount;
|
---|
229 | unsigned int clearCount;
|
---|
230 | int optimizeBucket;
|
---|
231 | int only_swap_once;
|
---|
232 | int debug_barriers;
|
---|
233 | int sharedDisplayLists;
|
---|
234 | int sharedTextureObjects;
|
---|
235 | int sharedPrograms;
|
---|
236 | int sharedWindows;
|
---|
237 | int uniqueWindows;
|
---|
238 | int localTileSpec;
|
---|
239 | int useDMX;
|
---|
240 | int overlapBlending;
|
---|
241 | int vpProjectionMatrixParameter;
|
---|
242 | const char *vpProjectionMatrixVariable;
|
---|
243 | int stereoView;
|
---|
244 | int vncMode; /* cmd line option */
|
---|
245 | /*@}*/
|
---|
246 | /** view_matrix config */
|
---|
247 | /*@{*/
|
---|
248 | GLboolean viewOverride;
|
---|
249 | CRmatrix viewMatrix[2]; /**< left and right eye */
|
---|
250 | /*@}*/
|
---|
251 | /** projection_matrix config */
|
---|
252 | /*@{*/
|
---|
253 | GLboolean projectionOverride;
|
---|
254 | CRmatrix projectionMatrix[2]; /**< left and right eye */
|
---|
255 | int currentEye;
|
---|
256 | /*@}*/
|
---|
257 |
|
---|
258 | /** for warped tiles */
|
---|
259 | /*@{*/
|
---|
260 | GLfloat alignment_matrix[16], unnormalized_alignment_matrix[16];
|
---|
261 | /*@}*/
|
---|
262 |
|
---|
263 | /** tile overlap/blending info - this should probably be per-mural */
|
---|
264 | /*@{*/
|
---|
265 | CRPoly **overlap_geom;
|
---|
266 | CRPoly *overlap_knockout;
|
---|
267 | float *overlap_intens;
|
---|
268 | int num_overlap_intens;
|
---|
269 | int num_overlap_levels;
|
---|
270 | /*@}*/
|
---|
271 |
|
---|
272 | CRHashTable *barriers, *semaphores;
|
---|
273 |
|
---|
274 | RunQueue *run_queue;
|
---|
275 |
|
---|
276 | GLuint currentSerialNo;
|
---|
277 |
|
---|
278 | PFNCRSERVERPRESENTFBO pfnPresentFBO;
|
---|
279 | GLboolean bForceOffscreenRendering; /*Force server to render 3d data offscreen
|
---|
280 | *using callback above to update vbox framebuffers*/
|
---|
281 | GLboolean bUsePBOForReadback; /*Use PBO's for data readback*/
|
---|
282 |
|
---|
283 | GLboolean bUseOutputRedirect; /* Whether the output redirect was set. */
|
---|
284 | CROutputRedirect outputRedirect;
|
---|
285 |
|
---|
286 | GLboolean bUseMultipleContexts;
|
---|
287 | } CRServer;
|
---|
288 |
|
---|
289 |
|
---|
290 | extern DECLEXPORT(void) crServerInit( int argc, char *argv[] );
|
---|
291 | extern DECLEXPORT(int) CRServerMain( int argc, char *argv[] );
|
---|
292 | extern DECLEXPORT(void) crServerServiceClients(void);
|
---|
293 | extern DECLEXPORT(void) crServerAddNewClient(void);
|
---|
294 | extern DECLEXPORT(SPU*) crServerHeadSPU(void);
|
---|
295 | extern DECLEXPORT(void) crServerSetPort(int port);
|
---|
296 |
|
---|
297 | extern DECLEXPORT(GLboolean) crVBoxServerInit(void);
|
---|
298 | extern DECLEXPORT(void) crVBoxServerTearDown(void);
|
---|
299 | extern DECLEXPORT(int32_t) crVBoxServerAddClient(uint32_t u32ClientID);
|
---|
300 | extern DECLEXPORT(void) crVBoxServerRemoveClient(uint32_t u32ClientID);
|
---|
301 | extern DECLEXPORT(int32_t) crVBoxServerClientWrite(uint32_t u32ClientID, uint8_t *pBuffer, uint32_t cbBuffer);
|
---|
302 | extern DECLEXPORT(int32_t) crVBoxServerClientRead(uint32_t u32ClientID, uint8_t *pBuffer, uint32_t *pcbBuffer);
|
---|
303 | extern DECLEXPORT(int32_t) crVBoxServerClientSetVersion(uint32_t u32ClientID, uint32_t vMajor, uint32_t vMinor);
|
---|
304 | extern DECLEXPORT(int32_t) crVBoxServerClientSetPID(uint32_t u32ClientID, uint64_t pid);
|
---|
305 |
|
---|
306 | extern DECLEXPORT(int32_t) crVBoxServerSaveState(PSSMHANDLE pSSM);
|
---|
307 | extern DECLEXPORT(int32_t) crVBoxServerLoadState(PSSMHANDLE pSSM, uint32_t version);
|
---|
308 |
|
---|
309 | extern DECLEXPORT(int32_t) crVBoxServerSetScreenCount(int sCount);
|
---|
310 | extern DECLEXPORT(int32_t) crVBoxServerUnmapScreen(int sIndex);
|
---|
311 | extern DECLEXPORT(int32_t) crVBoxServerMapScreen(int sIndex, int32_t x, int32_t y, uint32_t w, uint32_t h, uint64_t winID);
|
---|
312 |
|
---|
313 | extern DECLEXPORT(int32_t) crVBoxServerSetRootVisibleRegion(GLint cRects, GLint *pRects);
|
---|
314 |
|
---|
315 | extern DECLEXPORT(void) crVBoxServerSetPresentFBOCB(PFNCRSERVERPRESENTFBO pfnPresentFBO);
|
---|
316 |
|
---|
317 | extern DECLEXPORT(int32_t) crVBoxServerSetOffscreenRendering(GLboolean value);
|
---|
318 |
|
---|
319 | extern DECLEXPORT(int32_t) crVBoxServerOutputRedirectSet(const CROutputRedirect *pCallbacks);
|
---|
320 |
|
---|
321 | extern DECLEXPORT(int32_t) crVBoxServerSetScreenViewport(int sIndex, int32_t x, int32_t y, uint32_t w, uint32_t h);
|
---|
322 |
|
---|
323 | #ifdef VBOX_WITH_CRHGSMI
|
---|
324 | /* We moved all CrHgsmi command processing to crserverlib to keep the logic of dealing with CrHgsmi commands in one place.
|
---|
325 | *
|
---|
326 | * 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.
|
---|
327 | * This help avoiding the "blocked-client" issues. The client is blocked if another client is doing begin-end stuff.
|
---|
328 | * For now we eliminated polling that could occur on block, which caused a higher-priority thread (in guest) polling for the blocked command complition
|
---|
329 | * to block the lower-priority thread trying to complete the blocking command.
|
---|
330 | * And removed extra memcpy done on blocked command arrival.
|
---|
331 | *
|
---|
332 | * In the future we will extend CrHgsmi functionality to maintain texture data directly in CrHgsmi allocation to avoid extra memcpy-ing with PBO,
|
---|
333 | * implement command completion and stuff necessary for GPU scheduling to work properly for WDDM Windows guests, etc.
|
---|
334 | *
|
---|
335 | * NOTE: it is ALWAYS responsibility of the crVBoxServerCrHgsmiCmd to complete the command!
|
---|
336 | * */
|
---|
337 | extern DECLEXPORT(int32_t) crVBoxServerCrHgsmiCmd(struct VBOXVDMACMD_CHROMIUM_CMD *pCmd, uint32_t cbCmd);
|
---|
338 | extern DECLEXPORT(int32_t) crVBoxServerCrHgsmiCtl(struct VBOXVDMACMD_CHROMIUM_CTL *pCtl, uint32_t cbCtl);
|
---|
339 | #endif
|
---|
340 |
|
---|
341 | #ifdef __cplusplus
|
---|
342 | }
|
---|
343 | #endif
|
---|
344 |
|
---|
345 | #endif
|
---|
346 |
|
---|