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 | GLint SERVER_DISPATCH_APIENTRY
|
---|
14 | crServerDispatchWindowCreate(const char *dpyName, GLint visBits)
|
---|
15 | {
|
---|
16 | return crServerDispatchWindowCreateEx(dpyName, visBits, -1);
|
---|
17 | }
|
---|
18 |
|
---|
19 |
|
---|
20 | GLint
|
---|
21 | crServerDispatchWindowCreateEx(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 | /* generate ID for this new window/mural (special-case for file conns) */
|
---|
87 | if (cr_server.curClient && cr_server.curClient->conn->type == CR_FILE)
|
---|
88 | windowID = spuWindow;
|
---|
89 | else
|
---|
90 | windowID = preloadWinID<0 ? crServerGenerateID(&cr_server.idsPool.freeWindowID) : preloadWinID;
|
---|
91 | crHashtableAdd(cr_server.muralTable, windowID, mural);
|
---|
92 |
|
---|
93 | pCreateInfo = (CRCreateInfo_t *) crAlloc(sizeof(CRCreateInfo_t));
|
---|
94 | pCreateInfo->pszDpyName = dpyName ? crStrdup(dpyName) : NULL;
|
---|
95 | pCreateInfo->visualBits = visBits;
|
---|
96 | crHashtableAdd(cr_server.pWindowCreateInfoTable, windowID, pCreateInfo);
|
---|
97 | }
|
---|
98 |
|
---|
99 | crDebug("CRServer: client %p created new window %d (SPU window %d)",
|
---|
100 | cr_server.curClient, windowID, spuWindow);
|
---|
101 |
|
---|
102 | if (windowID != -1 && !cr_server.bIsInLoadingState) {
|
---|
103 | int pos;
|
---|
104 | for (pos = 0; pos < CR_MAX_WINDOWS; pos++) {
|
---|
105 | if (cr_server.curClient->windowList[pos] == 0) {
|
---|
106 | cr_server.curClient->windowList[pos] = windowID;
|
---|
107 | break;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | crServerReturnValue( &windowID, sizeof(windowID) );
|
---|
113 | return windowID;
|
---|
114 | }
|
---|
115 |
|
---|
116 | void SERVER_DISPATCH_APIENTRY
|
---|
117 | crServerDispatchWindowDestroy( GLint window )
|
---|
118 | {
|
---|
119 | CRMuralInfo *mural;
|
---|
120 | int pos;
|
---|
121 |
|
---|
122 | mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
|
---|
123 | if (!mural) {
|
---|
124 | crWarning("CRServer: invalid window %d passed to WindowDestroy()", window);
|
---|
125 | return;
|
---|
126 | }
|
---|
127 |
|
---|
128 | crDebug("CRServer: Destroying window %d (spu window %d)", window, mural->spuWindow);
|
---|
129 | cr_server.head_spu->dispatch_table.WindowDestroy( mural->spuWindow );
|
---|
130 |
|
---|
131 | if (cr_server.curClient)
|
---|
132 | {
|
---|
133 | if (cr_server.curClient->currentMural == mural)
|
---|
134 | {
|
---|
135 | cr_server.curClient->currentMural = NULL;
|
---|
136 | cr_server.curClient->currentWindow = -1;
|
---|
137 | }
|
---|
138 |
|
---|
139 | for (pos = 0; pos < CR_MAX_WINDOWS; ++pos)
|
---|
140 | if (cr_server.curClient->windowList[pos] == window)
|
---|
141 | {
|
---|
142 | cr_server.curClient->windowList[pos] = 0;
|
---|
143 | break;
|
---|
144 | }
|
---|
145 |
|
---|
146 | /*Same as with contexts, some apps destroy it not in a thread where it was created*/
|
---|
147 | if (CR_MAX_WINDOWS==pos)
|
---|
148 | {
|
---|
149 | int32_t client;
|
---|
150 |
|
---|
151 | for (client=0; client<cr_server.numClients; ++client)
|
---|
152 | {
|
---|
153 | if (cr_server.clients[client]==cr_server.curClient)
|
---|
154 | continue;
|
---|
155 |
|
---|
156 | for (pos = 0; pos < CR_MAX_WINDOWS; ++pos)
|
---|
157 | if (cr_server.clients[client]->windowList[pos] == window)
|
---|
158 | {
|
---|
159 | cr_server.clients[client]->windowList[pos] = 0;
|
---|
160 | break;
|
---|
161 | }
|
---|
162 |
|
---|
163 | if (pos<CR_MAX_WINDOWS)
|
---|
164 | {
|
---|
165 | if (cr_server.clients[client]->currentMural == mural)
|
---|
166 | {
|
---|
167 | cr_server.clients[client]->currentMural = NULL;
|
---|
168 | cr_server.clients[client]->currentWindow = -1;
|
---|
169 | }
|
---|
170 | break;
|
---|
171 | }
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 | CRASSERT(pos<CR_MAX_WINDOWS);
|
---|
176 | }
|
---|
177 |
|
---|
178 | if (cr_server.currentWindow == window)
|
---|
179 | {
|
---|
180 | cr_server.currentWindow = -1;
|
---|
181 | }
|
---|
182 |
|
---|
183 | crHashtableDelete(cr_server.pWindowCreateInfoTable, window, crServerCreateInfoDeleteCB);
|
---|
184 | crHashtableDelete(cr_server.muralTable, window, crFree);
|
---|
185 | }
|
---|
186 |
|
---|
187 | void SERVER_DISPATCH_APIENTRY
|
---|
188 | crServerDispatchWindowSize( GLint window, GLint width, GLint height )
|
---|
189 | {
|
---|
190 | CRMuralInfo *mural;
|
---|
191 |
|
---|
192 | /* crDebug("CRServer: Window %d size %d x %d", window, width, height);*/
|
---|
193 | mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
|
---|
194 | if (!mural) {
|
---|
195 | #if EXTRA_WARN
|
---|
196 | crWarning("CRServer: invalid window %d passed to WindowSize()", window);
|
---|
197 | #endif
|
---|
198 | return;
|
---|
199 | }
|
---|
200 | mural->width = width;
|
---|
201 | mural->height = height;
|
---|
202 |
|
---|
203 | crServerCheckMuralGeometry(mural);
|
---|
204 |
|
---|
205 | if (!mural->bUseFBO)
|
---|
206 | {
|
---|
207 | cr_server.head_spu->dispatch_table.WindowSize(mural->spuWindow, width, height);
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 |
|
---|
212 | void SERVER_DISPATCH_APIENTRY
|
---|
213 | crServerDispatchWindowPosition( GLint window, GLint x, GLint y )
|
---|
214 | {
|
---|
215 | CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
|
---|
216 | /* crDebug("CRServer: Window %d pos %d, %d", window, x, y);*/
|
---|
217 | if (!mural) {
|
---|
218 | #if EXTRA_WARN
|
---|
219 | crWarning("CRServer: invalid window %d passed to WindowPosition()", window);
|
---|
220 | #endif
|
---|
221 | return;
|
---|
222 | }
|
---|
223 | mural->gX = x;
|
---|
224 | mural->gY = y;
|
---|
225 |
|
---|
226 | crServerCheckMuralGeometry(mural);
|
---|
227 | }
|
---|
228 |
|
---|
229 | void SERVER_DISPATCH_APIENTRY
|
---|
230 | crServerDispatchWindowVisibleRegion( GLint window, GLint cRects, GLint *pRects )
|
---|
231 | {
|
---|
232 | CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
|
---|
233 | if (!mural) {
|
---|
234 | #if EXTRA_WARN
|
---|
235 | crWarning("CRServer: invalid window %d passed to WindowVisibleRegion()", window);
|
---|
236 | #endif
|
---|
237 | return;
|
---|
238 | }
|
---|
239 | cr_server.head_spu->dispatch_table.WindowVisibleRegion(mural->spuWindow, cRects, pRects);
|
---|
240 | }
|
---|
241 |
|
---|
242 |
|
---|
243 |
|
---|
244 | void SERVER_DISPATCH_APIENTRY
|
---|
245 | crServerDispatchWindowShow( GLint window, GLint state )
|
---|
246 | {
|
---|
247 | CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
|
---|
248 | if (!mural) {
|
---|
249 | #if EXTRA_WARN
|
---|
250 | crWarning("CRServer: invalid window %d passed to WindowShow()", window);
|
---|
251 | #endif
|
---|
252 | return;
|
---|
253 | }
|
---|
254 |
|
---|
255 | if (!mural->bUseFBO)
|
---|
256 | {
|
---|
257 | cr_server.head_spu->dispatch_table.WindowShow(mural->spuWindow, state);
|
---|
258 | }
|
---|
259 |
|
---|
260 | mural->bVisible = state;
|
---|
261 | }
|
---|
262 |
|
---|
263 |
|
---|
264 | GLint
|
---|
265 | crServerSPUWindowID(GLint serverWindow)
|
---|
266 | {
|
---|
267 | CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, serverWindow);
|
---|
268 | if (!mural) {
|
---|
269 | #if EXTRA_WARN
|
---|
270 | crWarning("CRServer: invalid window %d passed to crServerSPUWindowID()",
|
---|
271 | serverWindow);
|
---|
272 | #endif
|
---|
273 | return -1;
|
---|
274 | }
|
---|
275 | return mural->spuWindow;
|
---|
276 | }
|
---|