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