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 | #include "server.h"
|
---|
8 | #include "server_dispatch.h"
|
---|
9 | #include "cr_mem.h"
|
---|
10 | #include "cr_string.h"
|
---|
11 |
|
---|
12 | #include "render/renderspu.h"
|
---|
13 |
|
---|
14 | GLint SERVER_DISPATCH_APIENTRY
|
---|
15 | crServerDispatchWindowCreate(const char *dpyName, GLint visBits)
|
---|
16 | {
|
---|
17 | return crServerDispatchWindowCreateEx(dpyName, visBits, -1);
|
---|
18 | }
|
---|
19 |
|
---|
20 | GLint crServerMuralInit(CRMuralInfo *mural, GLboolean fGuestWindow, GLint visBits, GLint preloadWinID)
|
---|
21 | {
|
---|
22 | CRMuralInfo *defaultMural;
|
---|
23 | GLint dims[2];
|
---|
24 | GLint windowID = -1;
|
---|
25 | GLint spuWindow = 0;
|
---|
26 | GLint realVisBits = visBits;
|
---|
27 | const char *dpyName = "";
|
---|
28 |
|
---|
29 | crMemset(mural, 0, sizeof (*mural));
|
---|
30 |
|
---|
31 | if (cr_server.fVisualBitsDefault)
|
---|
32 | realVisBits = cr_server.fVisualBitsDefault;
|
---|
33 |
|
---|
34 | #ifdef RT_OS_DARWIN
|
---|
35 | if (fGuestWindow)
|
---|
36 | {
|
---|
37 | CRMuralInfo *dummy = crServerGetDummyMural(realVisBits);
|
---|
38 | if (!dummy)
|
---|
39 | {
|
---|
40 | WARN(("crServerGetDummyMural failed"));
|
---|
41 | return -1;
|
---|
42 | }
|
---|
43 | spuWindow = dummy->spuWindow;
|
---|
44 | mural->fIsDummyRefference = GL_TRUE;
|
---|
45 |
|
---|
46 | dims[0] = dummy->width;
|
---|
47 | dims[1] = dummy->height;
|
---|
48 | }
|
---|
49 | else
|
---|
50 | #endif
|
---|
51 | {
|
---|
52 | /*
|
---|
53 | * Have first SPU make a new window.
|
---|
54 | */
|
---|
55 | spuWindow = cr_server.head_spu->dispatch_table.WindowCreate( dpyName, realVisBits );
|
---|
56 | if (spuWindow < 0) {
|
---|
57 | return spuWindow;
|
---|
58 | }
|
---|
59 | mural->fIsDummyRefference = GL_FALSE;
|
---|
60 |
|
---|
61 | /* get initial window size */
|
---|
62 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, spuWindow, GL_INT, 2, dims);
|
---|
63 | }
|
---|
64 |
|
---|
65 | defaultMural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, 0);
|
---|
66 | CRASSERT(defaultMural);
|
---|
67 | mural->gX = 0;
|
---|
68 | mural->gY = 0;
|
---|
69 | mural->width = dims[0];
|
---|
70 | mural->height = dims[1];
|
---|
71 |
|
---|
72 | mural->spuWindow = spuWindow;
|
---|
73 | mural->screenId = 0;
|
---|
74 | mural->fHasParentWindow = !!cr_server.screen[0].winID;
|
---|
75 | mural->bVisible = !cr_server.bWindowsInitiallyHidden;
|
---|
76 |
|
---|
77 | mural->cVisibleRects = 0;
|
---|
78 | mural->pVisibleRects = NULL;
|
---|
79 | mural->bReceivedRects = GL_FALSE;
|
---|
80 |
|
---|
81 | /* generate ID for this new window/mural. */
|
---|
82 | windowID = preloadWinID<0 ? (GLint)crHashtableAllocKeys( cr_server.muralTable, 1 ) : preloadWinID;
|
---|
83 |
|
---|
84 | mural->CreateInfo.realVisualBits = realVisBits;
|
---|
85 | mural->CreateInfo.requestedVisualBits = visBits;
|
---|
86 | mural->CreateInfo.externalID = windowID;
|
---|
87 | mural->CreateInfo.pszDpyName = dpyName ? crStrdup(dpyName) : NULL;
|
---|
88 |
|
---|
89 | CR_STATE_SHAREDOBJ_USAGE_INIT(mural);
|
---|
90 |
|
---|
91 | return windowID;
|
---|
92 | }
|
---|
93 |
|
---|
94 | GLint crServerDispatchWindowCreateEx(const char *dpyName, GLint visBits, GLint preloadWinID)
|
---|
95 | {
|
---|
96 | CRMuralInfo *mural;
|
---|
97 | GLint windowID = -1;
|
---|
98 |
|
---|
99 | NOREF(dpyName);
|
---|
100 |
|
---|
101 | if (cr_server.sharedWindows) {
|
---|
102 | int pos, j;
|
---|
103 |
|
---|
104 | /* find empty position in my (curclient) windowList */
|
---|
105 | for (pos = 0; pos < CR_MAX_WINDOWS; pos++) {
|
---|
106 | if (cr_server.curClient->windowList[pos] == 0) {
|
---|
107 | break;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | if (pos == CR_MAX_WINDOWS) {
|
---|
111 | crWarning("Too many windows in crserver!");
|
---|
112 | return -1;
|
---|
113 | }
|
---|
114 |
|
---|
115 | /* Look if any other client has a window for this slot */
|
---|
116 | for (j = 0; j < cr_server.numClients; j++) {
|
---|
117 | if (cr_server.clients[j]->windowList[pos] != 0) {
|
---|
118 | /* use that client's window */
|
---|
119 | windowID = cr_server.clients[j]->windowList[pos];
|
---|
120 | cr_server.curClient->windowList[pos] = windowID;
|
---|
121 | crServerReturnValue( &windowID, sizeof(windowID) ); /* real return value */
|
---|
122 | crDebug("CRServer: client %p sharing window %d",
|
---|
123 | cr_server.curClient, windowID);
|
---|
124 | return windowID;
|
---|
125 | }
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | /*
|
---|
131 | * Create a new mural for the new window.
|
---|
132 | */
|
---|
133 | mural = (CRMuralInfo *) crCalloc(sizeof(CRMuralInfo));
|
---|
134 | if (!mural)
|
---|
135 | {
|
---|
136 | crWarning("crCalloc failed!");
|
---|
137 | return -1;
|
---|
138 | }
|
---|
139 |
|
---|
140 | windowID = crServerMuralInit(mural, GL_TRUE, visBits, preloadWinID);
|
---|
141 | if (windowID < 0)
|
---|
142 | {
|
---|
143 | crWarning("crServerMuralInit failed!");
|
---|
144 | crServerReturnValue( &windowID, sizeof(windowID) );
|
---|
145 | crFree(mural);
|
---|
146 | return windowID;
|
---|
147 | }
|
---|
148 |
|
---|
149 | crHashtableAdd(cr_server.muralTable, windowID, mural);
|
---|
150 |
|
---|
151 | crDebug("CRServer: client %p created new window %d (SPU window %d)",
|
---|
152 | cr_server.curClient, windowID, mural->spuWindow);
|
---|
153 |
|
---|
154 | if (windowID != -1 && !cr_server.bIsInLoadingState) {
|
---|
155 | int pos;
|
---|
156 | for (pos = 0; pos < CR_MAX_WINDOWS; pos++) {
|
---|
157 | if (cr_server.curClient->windowList[pos] == 0) {
|
---|
158 | cr_server.curClient->windowList[pos] = windowID;
|
---|
159 | break;
|
---|
160 | }
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | /* ensure we have a dummy mural created right away to avoid potential deadlocks on VM shutdown */
|
---|
165 | crServerGetDummyMural(mural->CreateInfo.realVisualBits);
|
---|
166 |
|
---|
167 | crServerReturnValue( &windowID, sizeof(windowID) );
|
---|
168 | return windowID;
|
---|
169 | }
|
---|
170 |
|
---|
171 | static int crServerRemoveClientWindow(CRClient *pClient, GLint window)
|
---|
172 | {
|
---|
173 | int pos;
|
---|
174 |
|
---|
175 | for (pos = 0; pos < CR_MAX_WINDOWS; ++pos)
|
---|
176 | {
|
---|
177 | if (pClient->windowList[pos] == window)
|
---|
178 | {
|
---|
179 | pClient->windowList[pos] = 0;
|
---|
180 | return true;
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | return false;
|
---|
185 | }
|
---|
186 |
|
---|
187 | void crServerMuralTerm(CRMuralInfo *mural)
|
---|
188 | {
|
---|
189 | PCR_BLITTER pBlitter;
|
---|
190 | crServerRedirMuralFBO(mural, false);
|
---|
191 | crServerDeleteMuralFBO(mural);
|
---|
192 |
|
---|
193 | if (cr_server.currentMural == mural)
|
---|
194 | {
|
---|
195 | CRMuralInfo *dummyMural = crServerGetDummyMural(cr_server.MainContextInfo.CreateInfo.realVisualBits);
|
---|
196 | /* reset the current context to some dummy values to ensure render spu does not switch to a default "0" context,
|
---|
197 | * which might lead to muralFBO (offscreen rendering) gl entities being created in a scope of that context */
|
---|
198 | cr_server.head_spu->dispatch_table.MakeCurrent(dummyMural->spuWindow, 0, cr_server.MainContextInfo.SpuContext);
|
---|
199 | cr_server.currentWindow = -1;
|
---|
200 | cr_server.currentMural = dummyMural;
|
---|
201 | }
|
---|
202 | else
|
---|
203 | {
|
---|
204 | CRASSERT(cr_server.currentMural != mural);
|
---|
205 | }
|
---|
206 |
|
---|
207 | pBlitter = crServerVBoxBlitterGetInitialized();
|
---|
208 | if (pBlitter)
|
---|
209 | {
|
---|
210 | const CR_BLITTER_WINDOW * pWindow = CrBltMuralGetCurrentInfo(pBlitter);
|
---|
211 | if (pWindow && pWindow->Base.id == mural->spuWindow)
|
---|
212 | {
|
---|
213 | CRMuralInfo *dummy = crServerGetDummyMural(mural->CreateInfo.realVisualBits);
|
---|
214 | CR_BLITTER_WINDOW DummyInfo;
|
---|
215 | CRASSERT(dummy);
|
---|
216 | crServerVBoxBlitterWinInit(&DummyInfo, dummy);
|
---|
217 | CrBltMuralSetCurrentInfo(pBlitter, &DummyInfo);
|
---|
218 | }
|
---|
219 | }
|
---|
220 |
|
---|
221 | if (!mural->fIsDummyRefference)
|
---|
222 | cr_server.head_spu->dispatch_table.WindowDestroy( mural->spuWindow );
|
---|
223 |
|
---|
224 | mural->spuWindow = 0;
|
---|
225 |
|
---|
226 | if (mural->pVisibleRects)
|
---|
227 | {
|
---|
228 | crFree(mural->pVisibleRects);
|
---|
229 | }
|
---|
230 |
|
---|
231 | if (mural->CreateInfo.pszDpyName)
|
---|
232 | crFree(mural->CreateInfo.pszDpyName);
|
---|
233 |
|
---|
234 | crServerRedirMuralFbClear(mural);
|
---|
235 | }
|
---|
236 |
|
---|
237 | static void crServerCleanupCtxMuralRefsCB(unsigned long key, void *data1, void *data2)
|
---|
238 | {
|
---|
239 | CRContextInfo *ctxInfo = (CRContextInfo *) data1;
|
---|
240 | CRMuralInfo *mural = (CRMuralInfo *) data2;
|
---|
241 |
|
---|
242 | if (ctxInfo->currentMural == mural)
|
---|
243 | ctxInfo->currentMural = NULL;
|
---|
244 | }
|
---|
245 |
|
---|
246 | void SERVER_DISPATCH_APIENTRY
|
---|
247 | crServerDispatchWindowDestroy( GLint window )
|
---|
248 | {
|
---|
249 | CRMuralInfo *mural;
|
---|
250 | int32_t client;
|
---|
251 | CRClientNode *pNode;
|
---|
252 | int found=false;
|
---|
253 |
|
---|
254 | if (!window)
|
---|
255 | {
|
---|
256 | crWarning("Unexpected attempt to delete default mural, ignored!");
|
---|
257 | return;
|
---|
258 | }
|
---|
259 |
|
---|
260 | mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
|
---|
261 | if (!mural) {
|
---|
262 | crWarning("CRServer: invalid window %d passed to WindowDestroy()", window);
|
---|
263 | return;
|
---|
264 | }
|
---|
265 |
|
---|
266 | crDebug("CRServer: Destroying window %d (spu window %d)", window, mural->spuWindow);
|
---|
267 |
|
---|
268 | crHashtableWalk(cr_server.contextTable, crServerCleanupCtxMuralRefsCB, mural);
|
---|
269 |
|
---|
270 | crServerMuralTerm(mural);
|
---|
271 |
|
---|
272 | CRASSERT(cr_server.currentWindow != window);
|
---|
273 |
|
---|
274 | if (cr_server.curClient)
|
---|
275 | {
|
---|
276 | if (cr_server.curClient->currentMural == mural)
|
---|
277 | {
|
---|
278 | cr_server.curClient->currentMural = NULL;
|
---|
279 | cr_server.curClient->currentWindow = -1;
|
---|
280 | }
|
---|
281 |
|
---|
282 | found = crServerRemoveClientWindow(cr_server.curClient, window);
|
---|
283 |
|
---|
284 | /*Same as with contexts, some apps destroy it not in a thread where it was created*/
|
---|
285 | if (!found)
|
---|
286 | {
|
---|
287 | for (client=0; client<cr_server.numClients; ++client)
|
---|
288 | {
|
---|
289 | if (cr_server.clients[client]==cr_server.curClient)
|
---|
290 | continue;
|
---|
291 |
|
---|
292 | found = crServerRemoveClientWindow(cr_server.clients[client], window);
|
---|
293 |
|
---|
294 | if (found) break;
|
---|
295 | }
|
---|
296 | }
|
---|
297 |
|
---|
298 | if (!found)
|
---|
299 | {
|
---|
300 | pNode=cr_server.pCleanupClient;
|
---|
301 |
|
---|
302 | while (pNode && !found)
|
---|
303 | {
|
---|
304 | found = crServerRemoveClientWindow(pNode->pClient, window);
|
---|
305 | pNode = pNode->next;
|
---|
306 | }
|
---|
307 | }
|
---|
308 |
|
---|
309 | CRASSERT(found);
|
---|
310 | }
|
---|
311 |
|
---|
312 | /*Make sure this window isn't active in other clients*/
|
---|
313 | for (client=0; client<cr_server.numClients; ++client)
|
---|
314 | {
|
---|
315 | if (cr_server.clients[client]->currentMural == mural)
|
---|
316 | {
|
---|
317 | cr_server.clients[client]->currentMural = NULL;
|
---|
318 | cr_server.clients[client]->currentWindow = -1;
|
---|
319 | }
|
---|
320 | }
|
---|
321 |
|
---|
322 | pNode=cr_server.pCleanupClient;
|
---|
323 | while (pNode)
|
---|
324 | {
|
---|
325 | if (pNode->pClient->currentMural == mural)
|
---|
326 | {
|
---|
327 | pNode->pClient->currentMural = NULL;
|
---|
328 | pNode->pClient->currentWindow = -1;
|
---|
329 | }
|
---|
330 | pNode = pNode->next;
|
---|
331 | }
|
---|
332 |
|
---|
333 | crHashtableDelete(cr_server.muralTable, window, crFree);
|
---|
334 |
|
---|
335 | crServerCheckAllMuralGeometry(NULL);
|
---|
336 | }
|
---|
337 |
|
---|
338 | GLboolean crServerMuralSize(CRMuralInfo *mural, GLint width, GLint height)
|
---|
339 | {
|
---|
340 | if (mural->width == width && mural->height == height)
|
---|
341 | return GL_FALSE;
|
---|
342 |
|
---|
343 | mural->width = width;
|
---|
344 | mural->height = height;
|
---|
345 |
|
---|
346 | if (cr_server.curClient && cr_server.curClient->currentMural == mural
|
---|
347 | && !mural->fRedirected)
|
---|
348 | {
|
---|
349 | crStateGetCurrent()->buffer.width = mural->width;
|
---|
350 | crStateGetCurrent()->buffer.height = mural->height;
|
---|
351 | }
|
---|
352 |
|
---|
353 | crServerCheckAllMuralGeometry(mural);
|
---|
354 |
|
---|
355 | return GL_TRUE;
|
---|
356 | }
|
---|
357 |
|
---|
358 | void SERVER_DISPATCH_APIENTRY
|
---|
359 | crServerDispatchWindowSize( GLint window, GLint width, GLint height )
|
---|
360 | {
|
---|
361 | CRMuralInfo *mural;
|
---|
362 |
|
---|
363 | /* crDebug("CRServer: Window %d size %d x %d", window, width, height);*/
|
---|
364 | mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
|
---|
365 | if (!mural) {
|
---|
366 | #ifdef EXTRA_WARN
|
---|
367 | crWarning("CRServer: invalid window %d passed to WindowSize()", window);
|
---|
368 | #endif
|
---|
369 | return;
|
---|
370 | }
|
---|
371 |
|
---|
372 | crServerMuralSize(mural, width, height);
|
---|
373 |
|
---|
374 | if (cr_server.currentMural == mural)
|
---|
375 | {
|
---|
376 | crServerPerformMakeCurrent( mural, cr_server.currentCtxInfo );
|
---|
377 | }
|
---|
378 | }
|
---|
379 |
|
---|
380 | void crServerMuralPosition(CRMuralInfo *mural, GLint x, GLint y)
|
---|
381 | {
|
---|
382 | if (mural->gX == x && mural->gY == y)
|
---|
383 | return;
|
---|
384 |
|
---|
385 | mural->gX = x;
|
---|
386 | mural->gY = y;
|
---|
387 |
|
---|
388 | crServerCheckAllMuralGeometry(mural);
|
---|
389 | }
|
---|
390 |
|
---|
391 | void SERVER_DISPATCH_APIENTRY
|
---|
392 | crServerDispatchWindowPosition( GLint window, GLint x, GLint y )
|
---|
393 | {
|
---|
394 | CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
|
---|
395 | if (!mural) {
|
---|
396 | #ifdef EXTRA_WARN
|
---|
397 | crWarning("CRServer: invalid window %d passed to WindowPosition()", window);
|
---|
398 | #endif
|
---|
399 | return;
|
---|
400 | }
|
---|
401 | crServerMuralPosition(mural, x, y);
|
---|
402 | }
|
---|
403 |
|
---|
404 | void crServerMuralVisibleRegion( CRMuralInfo *mural, GLint cRects, const GLint *pRects )
|
---|
405 | {
|
---|
406 | if (mural->pVisibleRects)
|
---|
407 | {
|
---|
408 | crFree(mural->pVisibleRects);
|
---|
409 | mural->pVisibleRects = NULL;
|
---|
410 | }
|
---|
411 |
|
---|
412 | mural->cVisibleRects = cRects;
|
---|
413 | mural->bReceivedRects = GL_TRUE;
|
---|
414 | if (cRects)
|
---|
415 | {
|
---|
416 | mural->pVisibleRects = (GLint*) crAlloc(4*sizeof(GLint)*cRects);
|
---|
417 | if (!mural->pVisibleRects)
|
---|
418 | {
|
---|
419 | crError("Out of memory in crServerDispatchWindowVisibleRegion");
|
---|
420 | }
|
---|
421 | crMemcpy(mural->pVisibleRects, pRects, 4*sizeof(GLint)*cRects);
|
---|
422 | }
|
---|
423 |
|
---|
424 | crServerCheckAllMuralGeometry(mural);
|
---|
425 | }
|
---|
426 |
|
---|
427 | void SERVER_DISPATCH_APIENTRY
|
---|
428 | crServerDispatchWindowVisibleRegion( GLint window, GLint cRects, const GLint *pRects )
|
---|
429 | {
|
---|
430 | CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
|
---|
431 | if (!mural) {
|
---|
432 | #ifdef EXTRA_WARN
|
---|
433 | crWarning("CRServer: invalid window %d passed to WindowVisibleRegion()", window);
|
---|
434 | #endif
|
---|
435 | return;
|
---|
436 | }
|
---|
437 |
|
---|
438 | crServerMuralVisibleRegion( mural, cRects, pRects );
|
---|
439 | }
|
---|
440 |
|
---|
441 | void crServerMuralShow( CRMuralInfo *mural, GLint state )
|
---|
442 | {
|
---|
443 | if (!mural->bVisible == !state)
|
---|
444 | return;
|
---|
445 |
|
---|
446 | mural->bVisible = !!state;
|
---|
447 |
|
---|
448 | if (mural->bVisible)
|
---|
449 | crServerCheckMuralGeometry(mural);
|
---|
450 | else
|
---|
451 | crServerCheckAllMuralGeometry(mural);
|
---|
452 | }
|
---|
453 |
|
---|
454 | void SERVER_DISPATCH_APIENTRY
|
---|
455 | crServerDispatchWindowShow( GLint window, GLint state )
|
---|
456 | {
|
---|
457 | CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
|
---|
458 | if (!mural) {
|
---|
459 | #ifdef EXTRA_WARN
|
---|
460 | crWarning("CRServer: invalid window %d passed to WindowShow()", window);
|
---|
461 | #endif
|
---|
462 | return;
|
---|
463 | }
|
---|
464 |
|
---|
465 | crServerMuralShow( mural, state );
|
---|
466 | }
|
---|
467 |
|
---|
468 | GLint
|
---|
469 | crServerSPUWindowID(GLint serverWindow)
|
---|
470 | {
|
---|
471 | CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, serverWindow);
|
---|
472 | if (!mural) {
|
---|
473 | #ifdef EXTRA_WARN
|
---|
474 | crWarning("CRServer: invalid window %d passed to crServerSPUWindowID()",
|
---|
475 | serverWindow);
|
---|
476 | #endif
|
---|
477 | return -1;
|
---|
478 | }
|
---|
479 | return mural->spuWindow;
|
---|
480 | }
|
---|