VirtualBox

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

Last change on this file since 27116 was 23840, checked in by vboxsync, 15 years ago

crOpenGL: make sure window being destroyed isn't bound to opengl contexts

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.8 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
13GLint SERVER_DISPATCH_APIENTRY
14crServerDispatchWindowCreate(const char *dpyName, GLint visBits)
15{
16 return crServerDispatchWindowCreateEx(dpyName, visBits, -1);
17}
18
19
20GLint
21crServerDispatchWindowCreateEx(const char *dpyName, GLint visBits, GLint preloadWinID)
22{
23 CRMuralInfo *mural;
24 GLint windowID = -1;
25 GLint spuWindow;
26 GLint dims[2];
27 CRCreateInfo_t *pCreateInfo;
28
29 if (cr_server.sharedWindows) {
30 int pos, j;
31
32 /* find empty position in my (curclient) windowList */
33 for (pos = 0; pos < CR_MAX_WINDOWS; pos++) {
34 if (cr_server.curClient->windowList[pos] == 0) {
35 break;
36 }
37 }
38 if (pos == CR_MAX_WINDOWS) {
39 crWarning("Too many windows in crserver!");
40 return -1;
41 }
42
43 /* Look if any other client has a window for this slot */
44 for (j = 0; j < cr_server.numClients; j++) {
45 if (cr_server.clients[j]->windowList[pos] != 0) {
46 /* use that client's window */
47 windowID = cr_server.clients[j]->windowList[pos];
48 cr_server.curClient->windowList[pos] = windowID;
49 crServerReturnValue( &windowID, sizeof(windowID) ); /* real return value */
50 crDebug("CRServer: client %p sharing window %d",
51 cr_server.curClient, windowID);
52 return windowID;
53 }
54 }
55 }
56
57 /*
58 * Have first SPU make a new window.
59 */
60 spuWindow = cr_server.head_spu->dispatch_table.WindowCreate( dpyName, visBits );
61 if (spuWindow < 0) {
62 crServerReturnValue( &spuWindow, sizeof(spuWindow) );
63 return spuWindow;
64 }
65
66 /* get initial window size */
67 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, spuWindow, GL_INT, 2, dims);
68
69 /*
70 * Create a new mural for the new window.
71 */
72 mural = (CRMuralInfo *) crCalloc(sizeof(CRMuralInfo));
73 if (mural) {
74 CRMuralInfo *defaultMural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, 0);
75 CRASSERT(defaultMural);
76 mural->width = defaultMural->width;
77 mural->height = defaultMural->height;
78 mural->optimizeBucket = 0; /* might get enabled later */
79 mural->numExtents = defaultMural->numExtents;
80 mural->curExtent = 0;
81 crMemcpy(mural->extents, defaultMural->extents,
82 defaultMural->numExtents * sizeof(CRExtent));
83 mural->underlyingDisplay[0] = 0;
84 mural->underlyingDisplay[1] = 0;
85 mural->underlyingDisplay[2] = dims[0];
86 mural->underlyingDisplay[3] = dims[1];
87
88 mural->spuWindow = spuWindow;
89 crServerInitializeTiling(mural);
90
91 /* generate ID for this new window/mural (special-case for file conns) */
92 if (cr_server.curClient && cr_server.curClient->conn->type == CR_FILE)
93 windowID = spuWindow;
94 else
95 windowID = preloadWinID<0 ? crServerGenerateID(&cr_server.idsPool.freeWindowID) : preloadWinID;
96 crHashtableAdd(cr_server.muralTable, windowID, mural);
97
98 pCreateInfo = (CRCreateInfo_t *) crAlloc(sizeof(CRCreateInfo_t));
99 pCreateInfo->pszDpyName = dpyName ? crStrdup(dpyName) : NULL;
100 pCreateInfo->visualBits = visBits;
101 crHashtableAdd(cr_server.pWindowCreateInfoTable, windowID, pCreateInfo);
102 }
103
104 crDebug("CRServer: client %p created new window %d (SPU window %d)",
105 cr_server.curClient, windowID, spuWindow);
106
107 if (windowID != -1 && !cr_server.bIsInLoadingState) {
108 int pos;
109 for (pos = 0; pos < CR_MAX_WINDOWS; pos++) {
110 if (cr_server.curClient->windowList[pos] == 0) {
111 cr_server.curClient->windowList[pos] = windowID;
112 break;
113 }
114 }
115 }
116
117 crServerReturnValue( &windowID, sizeof(windowID) );
118 return windowID;
119}
120
121void SERVER_DISPATCH_APIENTRY
122crServerDispatchWindowDestroy( GLint window )
123{
124 CRMuralInfo *mural;
125 int pos;
126
127 mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
128 if (!mural) {
129 crWarning("CRServer: invalid window %d passed to WindowDestroy()", window);
130 return;
131 }
132
133 crDebug("CRServer: Destroying window %d (spu window %d)", window, mural->spuWindow);
134 cr_server.head_spu->dispatch_table.WindowDestroy( mural->spuWindow );
135
136 if (cr_server.curClient)
137 {
138 if (cr_server.curClient->currentMural == mural)
139 {
140 cr_server.curClient->currentMural = NULL;
141 cr_server.curClient->currentWindow = -1;
142 }
143
144 for (pos = 0; pos < CR_MAX_WINDOWS; ++pos)
145 if (cr_server.curClient->windowList[pos] == window)
146 {
147 cr_server.curClient->windowList[pos] = 0;
148 break;
149 }
150
151 /*Same as with contexts, some apps destroy it not in a thread where it was created*/
152 if (CR_MAX_WINDOWS==pos)
153 {
154 int32_t client;
155
156 for (client=0; client<cr_server.numClients; ++client)
157 {
158 if (cr_server.clients[client]==cr_server.curClient)
159 continue;
160
161 for (pos = 0; pos < CR_MAX_WINDOWS; ++pos)
162 if (cr_server.clients[client]->windowList[pos] == window)
163 {
164 cr_server.clients[client]->windowList[pos] = 0;
165 break;
166 }
167
168 if (pos<CR_MAX_WINDOWS)
169 {
170 if (cr_server.clients[client]->currentMural == mural)
171 {
172 cr_server.clients[client]->currentMural = NULL;
173 cr_server.clients[client]->currentWindow = -1;
174 }
175 break;
176 }
177 }
178 }
179
180 CRASSERT(pos<CR_MAX_WINDOWS);
181 }
182
183 if (cr_server.currentWindow == window)
184 {
185 cr_server.currentWindow = -1;
186 }
187
188 crHashtableDelete(cr_server.pWindowCreateInfoTable, window, crServerCreateInfoDeleteCB);
189 crHashtableDelete(cr_server.muralTable, window, crFree);
190}
191
192void SERVER_DISPATCH_APIENTRY
193crServerDispatchWindowSize( GLint window, GLint width, GLint height )
194{
195 CRMuralInfo *mural;
196
197 /* crDebug("CRServer: Window %d size %d x %d", window, width, height);*/
198 mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
199 if (!mural) {
200#if EXTRA_WARN
201 crWarning("CRServer: invalid window %d passed to WindowSize()", window);
202#endif
203 return;
204 }
205 mural->underlyingDisplay[2] = width;
206 mural->underlyingDisplay[3] = height;
207 crServerInitializeTiling(mural);
208
209 cr_server.head_spu->dispatch_table.WindowSize(mural->spuWindow, width, height);
210}
211
212
213void SERVER_DISPATCH_APIENTRY
214crServerDispatchWindowPosition( GLint window, GLint x, GLint y )
215{
216 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
217 /* crDebug("CRServer: Window %d pos %d, %d", window, x, y);*/
218 if (!mural) {
219#if EXTRA_WARN
220 crWarning("CRServer: invalid window %d passed to WindowPosition()", window);
221#endif
222 return;
223 }
224 mural->underlyingDisplay[0] = x;
225 mural->underlyingDisplay[1] = y;
226
227#if EXTRA_WARN /* don't believe this is needed */
228 crServerInitializeTiling(mural);
229#endif
230 cr_server.head_spu->dispatch_table.WindowPosition(mural->spuWindow, x, y);
231}
232
233void SERVER_DISPATCH_APIENTRY
234crServerDispatchWindowVisibleRegion( GLint window, GLint cRects, GLint *pRects )
235{
236 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
237 if (!mural) {
238#if EXTRA_WARN
239 crWarning("CRServer: invalid window %d passed to WindowVisibleRegion()", window);
240#endif
241 return;
242 }
243#if EXTRA_WARN /* don't believe this is needed */
244 crServerInitializeTiling(mural);
245#endif
246 cr_server.head_spu->dispatch_table.WindowVisibleRegion(mural->spuWindow, cRects, pRects);
247}
248
249
250
251void SERVER_DISPATCH_APIENTRY
252crServerDispatchWindowShow( GLint window, GLint state )
253{
254 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
255 if (!mural) {
256#if EXTRA_WARN
257 crWarning("CRServer: invalid window %d passed to WindowShow()", window);
258#endif
259 return;
260 }
261 cr_server.head_spu->dispatch_table.WindowShow(mural->spuWindow, state);
262}
263
264
265GLint
266crServerSPUWindowID(GLint serverWindow)
267{
268 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, serverWindow);
269 if (!mural) {
270#if EXTRA_WARN
271 crWarning("CRServer: invalid window %d passed to crServerSPUWindowID()",
272 serverWindow);
273#endif
274 return -1;
275 }
276 return mural->spuWindow;
277}
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