VirtualBox

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

Last change on this file since 21380 was 21380, checked in by vboxsync, 16 years ago

crOpenGL: fix check typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.1 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 crServerCheckCurrentCtxWindowCB(unsigned long key, void *data1, void *data2)
122{
123 CRContext *crCtx = (CRContext *) data1;
124 GLint window = *(GLint*)data2;
125
126 (void) key;
127}
128
129void SERVER_DISPATCH_APIENTRY
130crServerDispatchWindowDestroy( GLint window )
131{
132 CRMuralInfo *mural;
133 int pos;
134
135 mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
136 if (!mural) {
137 crWarning("CRServer: invalid window %d passed to WindowDestroy()", window);
138 return;
139 }
140
141 crDebug("CRServer: Destroying window %d (spu window %d)", window, mural->spuWindow);
142 cr_server.head_spu->dispatch_table.WindowDestroy( mural->spuWindow );
143
144 if (cr_server.curClient)
145 {
146 for (pos = 0; pos < CR_MAX_WINDOWS; ++pos)
147 if (cr_server.curClient->windowList[pos] == window)
148 {
149 cr_server.curClient->windowList[pos] = 0;
150 break;
151 }
152 CRASSERT(pos<CR_MAX_WINDOWS);
153
154 if (cr_server.curClient->currentMural == mural)
155 {
156 cr_server.curClient->currentMural = NULL;
157 cr_server.curClient->currentWindow = -1;
158 }
159 }
160
161 if (cr_server.currentWindow == window)
162 {
163 cr_server.currentWindow = -1;
164 }
165
166 crHashtableWalk(cr_server.contextTable, crServerCheckCurrentCtxWindowCB, &window);
167 crHashtableDelete(cr_server.pWindowCreateInfoTable, window, crServerCreateInfoDeleteCB);
168 crHashtableDelete(cr_server.muralTable, window, crFree);
169}
170
171
172void SERVER_DISPATCH_APIENTRY
173crServerDispatchWindowSize( GLint window, GLint width, GLint height )
174{
175 CRMuralInfo *mural;
176
177 /* crDebug("CRServer: Window %d size %d x %d", window, width, height);*/
178 mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
179 if (!mural) {
180#if EXTRA_WARN
181 crWarning("CRServer: invalid window %d passed to WindowSize()", window);
182#endif
183 return;
184 }
185 mural->underlyingDisplay[2] = width;
186 mural->underlyingDisplay[3] = height;
187 crServerInitializeTiling(mural);
188
189 cr_server.head_spu->dispatch_table.WindowSize(mural->spuWindow, width, height);
190}
191
192
193void SERVER_DISPATCH_APIENTRY
194crServerDispatchWindowPosition( GLint window, GLint x, GLint y )
195{
196 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
197 /* crDebug("CRServer: Window %d pos %d, %d", window, x, y);*/
198 if (!mural) {
199#if EXTRA_WARN
200 crWarning("CRServer: invalid window %d passed to WindowPosition()", window);
201#endif
202 return;
203 }
204 mural->underlyingDisplay[0] = x;
205 mural->underlyingDisplay[1] = y;
206
207#if EXTRA_WARN /* don't believe this is needed */
208 crServerInitializeTiling(mural);
209#endif
210 cr_server.head_spu->dispatch_table.WindowPosition(mural->spuWindow, x, y);
211}
212
213void SERVER_DISPATCH_APIENTRY
214crServerDispatchWindowVisibleRegion( GLint window, GLint cRects, GLint *pRects )
215{
216 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
217 if (!mural) {
218#if EXTRA_WARN
219 crWarning("CRServer: invalid window %d passed to WindowVisibleRegion()", window);
220#endif
221 return;
222 }
223#if EXTRA_WARN /* don't believe this is needed */
224 crServerInitializeTiling(mural);
225#endif
226 cr_server.head_spu->dispatch_table.WindowVisibleRegion(mural->spuWindow, cRects, pRects);
227}
228
229
230
231void SERVER_DISPATCH_APIENTRY
232crServerDispatchWindowShow( GLint window, GLint state )
233{
234 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
235 if (!mural) {
236#if EXTRA_WARN
237 crWarning("CRServer: invalid window %d passed to WindowShow()", window);
238#endif
239 return;
240 }
241 cr_server.head_spu->dispatch_table.WindowShow(mural->spuWindow, state);
242}
243
244
245GLint
246crServerSPUWindowID(GLint serverWindow)
247{
248 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, serverWindow);
249 if (!mural) {
250#if EXTRA_WARN
251 crWarning("CRServer: invalid window %d passed to crServerSPUWindowID()",
252 serverWindow);
253#endif
254 return -1;
255 }
256 return mural->spuWindow;
257}
Note: See TracBrowser for help on using the repository browser.

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