VirtualBox

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

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

crOpenGL: add visible region support for host offscreen rendering

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.9 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->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
119void SERVER_DISPATCH_APIENTRY
120crServerDispatchWindowDestroy( GLint window )
121{
122 CRMuralInfo *mural;
123 int pos;
124
125 mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
126 if (!mural) {
127 crWarning("CRServer: invalid window %d passed to WindowDestroy()", window);
128 return;
129 }
130
131 crDebug("CRServer: Destroying window %d (spu window %d)", window, mural->spuWindow);
132 cr_server.head_spu->dispatch_table.WindowDestroy( mural->spuWindow );
133
134 if (cr_server.curClient)
135 {
136 if (cr_server.curClient->currentMural == mural)
137 {
138 cr_server.curClient->currentMural = NULL;
139 cr_server.curClient->currentWindow = -1;
140 }
141
142 for (pos = 0; pos < CR_MAX_WINDOWS; ++pos)
143 if (cr_server.curClient->windowList[pos] == window)
144 {
145 cr_server.curClient->windowList[pos] = 0;
146 break;
147 }
148
149 /*Same as with contexts, some apps destroy it not in a thread where it was created*/
150 if (CR_MAX_WINDOWS==pos)
151 {
152 int32_t client;
153
154 for (client=0; client<cr_server.numClients; ++client)
155 {
156 if (cr_server.clients[client]==cr_server.curClient)
157 continue;
158
159 for (pos = 0; pos < CR_MAX_WINDOWS; ++pos)
160 if (cr_server.clients[client]->windowList[pos] == window)
161 {
162 cr_server.clients[client]->windowList[pos] = 0;
163 break;
164 }
165
166 if (pos<CR_MAX_WINDOWS)
167 {
168 if (cr_server.clients[client]->currentMural == mural)
169 {
170 cr_server.clients[client]->currentMural = NULL;
171 cr_server.clients[client]->currentWindow = -1;
172 }
173 break;
174 }
175 }
176 }
177
178 CRASSERT(pos<CR_MAX_WINDOWS);
179 }
180
181 if (cr_server.currentWindow == window)
182 {
183 cr_server.currentWindow = -1;
184 }
185
186 crHashtableDelete(cr_server.pWindowCreateInfoTable, window, crServerCreateInfoDeleteCB);
187
188 if (mural->pVisibleRects)
189 {
190 crFree(mural->pVisibleRects);
191 }
192 crHashtableDelete(cr_server.muralTable, window, crFree);
193}
194
195void SERVER_DISPATCH_APIENTRY
196crServerDispatchWindowSize( GLint window, GLint width, GLint height )
197{
198 CRMuralInfo *mural;
199
200 /* crDebug("CRServer: Window %d size %d x %d", window, width, height);*/
201 mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
202 if (!mural) {
203#if EXTRA_WARN
204 crWarning("CRServer: invalid window %d passed to WindowSize()", window);
205#endif
206 return;
207 }
208 mural->width = width;
209 mural->height = height;
210
211 crServerCheckMuralGeometry(mural);
212
213 if (!mural->bUseFBO)
214 {
215 cr_server.head_spu->dispatch_table.WindowSize(mural->spuWindow, width, height);
216 }
217}
218
219
220void SERVER_DISPATCH_APIENTRY
221crServerDispatchWindowPosition( GLint window, GLint x, GLint y )
222{
223 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
224 /* crDebug("CRServer: Window %d pos %d, %d", window, x, y);*/
225 if (!mural) {
226#if EXTRA_WARN
227 crWarning("CRServer: invalid window %d passed to WindowPosition()", window);
228#endif
229 return;
230 }
231 mural->gX = x;
232 mural->gY = y;
233
234 crServerCheckMuralGeometry(mural);
235}
236
237void SERVER_DISPATCH_APIENTRY
238crServerDispatchWindowVisibleRegion( GLint window, GLint cRects, GLint *pRects )
239{
240 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
241 if (!mural) {
242#if EXTRA_WARN
243 crWarning("CRServer: invalid window %d passed to WindowVisibleRegion()", window);
244#endif
245 return;
246 }
247
248 if (mural->pVisibleRects)
249 {
250 crFree(mural->pVisibleRects);
251 mural->pVisibleRects = NULL;
252 }
253
254 mural->cVisibleRects = cRects;
255 if (cRects)
256 {
257 mural->pVisibleRects = (GLint*) crAlloc(4*sizeof(GLint)*cRects);
258 if (!mural->pVisibleRects)
259 {
260 crError("Out of memory in crServerDispatchWindowVisibleRegion");
261 }
262 crMemcpy(mural->pVisibleRects, pRects, 4*sizeof(GLint)*cRects);
263 }
264
265 cr_server.head_spu->dispatch_table.WindowVisibleRegion(mural->spuWindow, cRects, pRects);
266}
267
268
269
270void SERVER_DISPATCH_APIENTRY
271crServerDispatchWindowShow( GLint window, GLint state )
272{
273 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
274 if (!mural) {
275#if EXTRA_WARN
276 crWarning("CRServer: invalid window %d passed to WindowShow()", window);
277#endif
278 return;
279 }
280
281 if (!mural->bUseFBO)
282 {
283 cr_server.head_spu->dispatch_table.WindowShow(mural->spuWindow, state);
284 }
285
286 mural->bVisible = state;
287}
288
289
290GLint
291crServerSPUWindowID(GLint serverWindow)
292{
293 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, serverWindow);
294 if (!mural) {
295#if EXTRA_WARN
296 crWarning("CRServer: invalid window %d passed to crServerSPUWindowID()",
297 serverWindow);
298#endif
299 return -1;
300 }
301 return mural->spuWindow;
302}
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