VirtualBox

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

最後變更 在這個檔案從34382是 33988,由 vboxsync 提交於 14 年 前

crOpenGL/wddm: more multithreading fixes, vista expirience index works now

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 9.4 KB
 
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->gX = 0;
77 mural->gY = 0;
78 mural->width = dims[0];
79 mural->height = dims[1];
80
81 mural->spuWindow = spuWindow;
82 mural->screenId = 0;
83 mural->bVisible = GL_FALSE;
84 mural->bUseFBO = GL_FALSE;
85
86 mural->cVisibleRects = 0;
87 mural->pVisibleRects = NULL;
88
89 /* generate ID for this new window/mural (special-case for file conns) */
90 if (cr_server.curClient && cr_server.curClient->conn->type == CR_FILE)
91 windowID = spuWindow;
92 else
93 windowID = preloadWinID<0 ? crServerGenerateID(&cr_server.idsPool.freeWindowID) : preloadWinID;
94 crHashtableAdd(cr_server.muralTable, windowID, mural);
95
96 pCreateInfo = (CRCreateInfo_t *) crAlloc(sizeof(CRCreateInfo_t));
97 pCreateInfo->pszDpyName = dpyName ? crStrdup(dpyName) : NULL;
98 pCreateInfo->visualBits = visBits;
99 crHashtableAdd(cr_server.pWindowCreateInfoTable, windowID, pCreateInfo);
100 }
101
102 crDebug("CRServer: client %p created new window %d (SPU window %d)",
103 cr_server.curClient, windowID, spuWindow);
104
105 if (windowID != -1 && !cr_server.bIsInLoadingState) {
106 int pos;
107 for (pos = 0; pos < CR_MAX_WINDOWS; pos++) {
108 if (cr_server.curClient->windowList[pos] == 0) {
109 cr_server.curClient->windowList[pos] = windowID;
110 break;
111 }
112 }
113 }
114
115 crServerReturnValue( &windowID, sizeof(windowID) );
116 return windowID;
117}
118
119static int crServerRemoveClientWindow(CRClient *pClient, GLint window)
120{
121 int pos;
122
123 for (pos = 0; pos < CR_MAX_WINDOWS; ++pos)
124 {
125 if (pClient->windowList[pos] == window)
126 {
127 pClient->windowList[pos] = 0;
128 return true;
129 }
130 }
131
132 return false;
133}
134
135void SERVER_DISPATCH_APIENTRY
136crServerDispatchWindowDestroy( GLint window )
137{
138 CRMuralInfo *mural;
139 int32_t client;
140 CRClientNode *pNode;
141 int found=false;
142
143 mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
144 if (!mural) {
145 crWarning("CRServer: invalid window %d passed to WindowDestroy()", window);
146 return;
147 }
148
149 if (cr_server.currentWindow == window)
150 {
151 cr_server.currentWindow = -1;
152 crServerRedirMuralFBO(mural, GL_FALSE);
153 crServerDeleteMuralFBO(mural);
154 }
155
156 crDebug("CRServer: Destroying window %d (spu window %d)", window, mural->spuWindow);
157 cr_server.head_spu->dispatch_table.WindowDestroy( mural->spuWindow );
158
159 if (cr_server.curClient)
160 {
161 if (cr_server.curClient->currentMural == mural)
162 {
163 cr_server.curClient->currentMural = NULL;
164 cr_server.curClient->currentWindow = -1;
165 }
166
167 found = crServerRemoveClientWindow(cr_server.curClient, window);
168
169 /*Same as with contexts, some apps destroy it not in a thread where it was created*/
170 if (!found)
171 {
172 for (client=0; client<cr_server.numClients; ++client)
173 {
174 if (cr_server.clients[client]==cr_server.curClient)
175 continue;
176
177 found = crServerRemoveClientWindow(cr_server.clients[client], window);
178
179 if (found) break;
180 }
181 }
182
183 if (!found)
184 {
185 pNode=cr_server.pCleanupClient;
186
187 while (pNode && !found)
188 {
189 found = crServerRemoveClientWindow(pNode->pClient, window);
190 pNode = pNode->next;
191 }
192 }
193
194 CRASSERT(found);
195 }
196
197 /*Make sure this window isn't active in other clients*/
198 for (client=0; client<cr_server.numClients; ++client)
199 {
200 if (cr_server.clients[client]->currentMural == mural)
201 {
202 cr_server.clients[client]->currentMural = NULL;
203 cr_server.clients[client]->currentWindow = -1;
204 }
205 }
206
207 pNode=cr_server.pCleanupClient;
208 while (pNode)
209 {
210 if (pNode->pClient->currentMural == mural)
211 {
212 pNode->pClient->currentMural = NULL;
213 pNode->pClient->currentWindow = -1;
214 }
215 pNode = pNode->next;
216 }
217
218 crHashtableDelete(cr_server.pWindowCreateInfoTable, window, crServerCreateInfoDeleteCB);
219
220 if (mural->pVisibleRects)
221 {
222 crFree(mural->pVisibleRects);
223 }
224 crHashtableDelete(cr_server.muralTable, window, crFree);
225}
226
227void SERVER_DISPATCH_APIENTRY
228crServerDispatchWindowSize( GLint window, GLint width, GLint height )
229{
230 CRMuralInfo *mural;
231
232 /* crDebug("CRServer: Window %d size %d x %d", window, width, height);*/
233 mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
234 if (!mural) {
235#if EXTRA_WARN
236 crWarning("CRServer: invalid window %d passed to WindowSize()", window);
237#endif
238 return;
239 }
240 mural->width = width;
241 mural->height = height;
242
243 crServerCheckMuralGeometry(mural);
244
245 cr_server.head_spu->dispatch_table.WindowSize(mural->spuWindow, width, height);
246}
247
248
249void SERVER_DISPATCH_APIENTRY
250crServerDispatchWindowPosition( GLint window, GLint x, GLint y )
251{
252 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
253 /* crDebug("CRServer: Window %d pos %d, %d", window, x, y);*/
254 if (!mural) {
255#if EXTRA_WARN
256 crWarning("CRServer: invalid window %d passed to WindowPosition()", window);
257#endif
258 return;
259 }
260 mural->gX = x;
261 mural->gY = y;
262
263 crServerCheckMuralGeometry(mural);
264}
265
266void SERVER_DISPATCH_APIENTRY
267crServerDispatchWindowVisibleRegion( GLint window, GLint cRects, GLint *pRects )
268{
269 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
270 if (!mural) {
271#if EXTRA_WARN
272 crWarning("CRServer: invalid window %d passed to WindowVisibleRegion()", window);
273#endif
274 return;
275 }
276
277 if (mural->pVisibleRects)
278 {
279 crFree(mural->pVisibleRects);
280 mural->pVisibleRects = NULL;
281 }
282
283 mural->cVisibleRects = cRects;
284 if (cRects)
285 {
286 mural->pVisibleRects = (GLint*) crAlloc(4*sizeof(GLint)*cRects);
287 if (!mural->pVisibleRects)
288 {
289 crError("Out of memory in crServerDispatchWindowVisibleRegion");
290 }
291 crMemcpy(mural->pVisibleRects, pRects, 4*sizeof(GLint)*cRects);
292 }
293
294 cr_server.head_spu->dispatch_table.WindowVisibleRegion(mural->spuWindow, cRects, pRects);
295}
296
297
298
299void SERVER_DISPATCH_APIENTRY
300crServerDispatchWindowShow( GLint window, GLint state )
301{
302 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
303 if (!mural) {
304#if EXTRA_WARN
305 crWarning("CRServer: invalid window %d passed to WindowShow()", window);
306#endif
307 return;
308 }
309
310 if (!mural->bUseFBO)
311 {
312 cr_server.head_spu->dispatch_table.WindowShow(mural->spuWindow, state);
313 }
314
315 mural->bVisible = state;
316}
317
318
319GLint
320crServerSPUWindowID(GLint serverWindow)
321{
322 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, serverWindow);
323 if (!mural) {
324#if EXTRA_WARN
325 crWarning("CRServer: invalid window %d passed to crServerSPUWindowID()",
326 serverWindow);
327#endif
328 return -1;
329 }
330 return mural->spuWindow;
331}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette