VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_window.c@ 58231

Last change on this file since 58231 was 57543, checked in by vboxsync, 9 years ago

warning

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