VirtualBox

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

Last change on this file since 50098 was 50095, checked in by vboxsync, 11 years ago

crOpenGL: presentation infrastructure rework (still work in progress)

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