VirtualBox

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

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

crOpenGL: export to OSE

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