VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_lists.c@ 48275

Last change on this file since 48275 was 45910, checked in by vboxsync, 12 years ago

crOpenGL: display lists hw sync fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.8 KB
Line 
1/* Copyright (c) 2001-2003, Stanford University
2 All rights reserved.
3
4 See the file LICENSE.txt for information on redistributing this software. */
5
6#include "server_dispatch.h"
7#include "server.h"
8#include "cr_mem.h"
9
10
11/*
12 * Notes on ID translation:
13 *
14 * If a server has multiple clients (in the case of parallel applications)
15 * and N of the clients all create a display list with ID K, does K name
16 * one display list or N different display lists?
17 *
18 * By default, there is one display list named K. If the clients put
19 * identical commands into list K, then this is fine. But if the clients
20 * each put something different into list K when they created it, then this
21 * is a serious problem.
22 *
23 * By zeroing the 'shared_display_lists' configuration option, we can tell
24 * the server to make list K be unique for all N clients. We do this by
25 * translating K into a new, unique ID dependent on which client we're
26 * talking to (curClient->number).
27 *
28 * Same story for texture objects, vertex programs, etc.
29 *
30 * The application can also dynamically switch between shared and private
31 * display lists with:
32 * glChromiumParameteri(GL_SHARED_DISPLAY_LISTS_CR, GL_TRUE)
33 * and
34 * glChromiumParameteri(GL_SHARED_DISPLAY_LISTS_CR, GL_FALSE)
35 *
36 */
37
38
39
40static GLuint TranslateListID( GLuint id )
41{
42 if (!cr_server.sharedDisplayLists) {
43 int client = cr_server.curClient->number;
44 return id + client * 100000;
45 }
46 return id;
47}
48
49/* XXXX Note: shared/separate Program ID numbers aren't totally implemented! */
50GLuint crServerTranslateProgramID( GLuint id )
51{
52 if (!cr_server.sharedPrograms && id) {
53 int client = cr_server.curClient->number;
54 return id + client * 100000;
55 }
56 return id;
57}
58
59
60void SERVER_DISPATCH_APIENTRY
61crServerDispatchNewList( GLuint list, GLenum mode )
62{
63 if (mode == GL_COMPILE_AND_EXECUTE)
64 crWarning("using glNewList(GL_COMPILE_AND_EXECUTE) can confuse the crserver");
65
66 list = TranslateListID( list );
67 crStateNewList( list, mode );
68 cr_server.head_spu->dispatch_table.NewList( list, mode );
69}
70
71static void crServerQueryHWState()
72{
73 GLuint fbFbo, bbFbo;
74 CRClient *client = cr_server.curClient;
75 CRMuralInfo *mural = client ? client->currentMural : NULL;
76 if (mural && mural->fPresentMode & CR_SERVER_REDIR_F_FBO)
77 {
78 fbFbo = mural->aidFBOs[CR_SERVER_FBO_FB_IDX(mural)];
79 bbFbo = mural->aidFBOs[CR_SERVER_FBO_BB_IDX(mural)];
80 }
81 else
82 {
83 fbFbo = bbFbo = 0;
84 }
85 crStateQueryHWState(fbFbo, bbFbo);
86}
87
88void SERVER_DISPATCH_APIENTRY crServerDispatchEndList(void)
89{
90 CRContext *g = crStateGetCurrent();
91 CRListsState *l = &(g->lists);
92
93 cr_server.head_spu->dispatch_table.EndList();
94 crStateEndList();
95
96#ifndef IN_GUEST
97 if (l->mode==GL_COMPILE)
98 {
99 crServerQueryHWState();
100 }
101#endif
102}
103
104void SERVER_DISPATCH_APIENTRY
105crServerDispatchCallList( GLuint list )
106{
107 list = TranslateListID( list );
108
109 if (cr_server.curClient->currentCtxInfo->pContext->lists.mode == 0) {
110 /* we're not compiling, so execute the list now */
111 /* Issue the list as-is */
112 cr_server.head_spu->dispatch_table.CallList( list );
113 crServerQueryHWState();
114 }
115 else {
116 /* we're compiling glCallList into another list - just pass it through */
117 cr_server.head_spu->dispatch_table.CallList( list );
118 }
119}
120
121
122/**
123 * Translate an array of display list IDs from various datatypes to GLuint
124 * IDs while adding the per-client offset.
125 */
126static void
127TranslateListIDs(GLsizei n, GLenum type, const GLvoid *lists, GLuint *newLists)
128{
129 int offset = cr_server.curClient->number * 100000;
130 GLsizei i;
131 switch (type) {
132 case GL_UNSIGNED_BYTE:
133 {
134 const GLubyte *src = (const GLubyte *) lists;
135 for (i = 0; i < n; i++) {
136 newLists[i] = src[i] + offset;
137 }
138 }
139 break;
140 case GL_BYTE:
141 {
142 const GLbyte *src = (const GLbyte *) lists;
143 for (i = 0; i < n; i++) {
144 newLists[i] = src[i] + offset;
145 }
146 }
147 break;
148 case GL_UNSIGNED_SHORT:
149 {
150 const GLushort *src = (const GLushort *) lists;
151 for (i = 0; i < n; i++) {
152 newLists[i] = src[i] + offset;
153 }
154 }
155 break;
156 case GL_SHORT:
157 {
158 const GLshort *src = (const GLshort *) lists;
159 for (i = 0; i < n; i++) {
160 newLists[i] = src[i] + offset;
161 }
162 }
163 break;
164 case GL_UNSIGNED_INT:
165 {
166 const GLuint *src = (const GLuint *) lists;
167 for (i = 0; i < n; i++) {
168 newLists[i] = src[i] + offset;
169 }
170 }
171 break;
172 case GL_INT:
173 {
174 const GLint *src = (const GLint *) lists;
175 for (i = 0; i < n; i++) {
176 newLists[i] = src[i] + offset;
177 }
178 }
179 break;
180 case GL_FLOAT:
181 {
182 const GLfloat *src = (const GLfloat *) lists;
183 for (i = 0; i < n; i++) {
184 newLists[i] = (GLuint) src[i] + offset;
185 }
186 }
187 break;
188 case GL_2_BYTES:
189 {
190 const GLubyte *src = (const GLubyte *) lists;
191 for (i = 0; i < n; i++) {
192 newLists[i] = (src[i*2+0] * 256 +
193 src[i*2+1]) + offset;
194 }
195 }
196 break;
197 case GL_3_BYTES:
198 {
199 const GLubyte *src = (const GLubyte *) lists;
200 for (i = 0; i < n; i++) {
201 newLists[i] = (src[i*3+0] * 256 * 256 +
202 src[i*3+1] * 256 +
203 src[i*3+2]) + offset;
204 }
205 }
206 break;
207 case GL_4_BYTES:
208 {
209 const GLubyte *src = (const GLubyte *) lists;
210 for (i = 0; i < n; i++) {
211 newLists[i] = (src[i*4+0] * 256 * 256 * 256 +
212 src[i*4+1] * 256 * 256 +
213 src[i*4+2] * 256 +
214 src[i*4+3]) + offset;
215 }
216 }
217 break;
218 default:
219 crWarning("CRServer: invalid display list datatype 0x%x", type);
220 }
221}
222
223
224void SERVER_DISPATCH_APIENTRY
225crServerDispatchCallLists( GLsizei n, GLenum type, const GLvoid *lists )
226{
227 if (!cr_server.sharedDisplayLists) {
228 /* need to translate IDs */
229 GLuint *newLists = (GLuint *) crAlloc(n * sizeof(GLuint));
230 if (newLists) {
231 TranslateListIDs(n, type, lists, newLists);
232 }
233 lists = newLists;
234 type = GL_UNSIGNED_INT;
235 }
236
237 if (cr_server.curClient->currentCtxInfo->pContext->lists.mode == 0) {
238 /* we're not compiling, so execute the list now */
239 /* Issue the list as-is */
240 cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
241 crServerQueryHWState();
242 }
243 else {
244 /* we're compiling glCallList into another list - just pass it through */
245 cr_server.head_spu->dispatch_table.CallLists( n, type, lists );
246 }
247
248 if (!cr_server.sharedDisplayLists) {
249 crFree((void *) lists); /* malloc'd above */
250 }
251}
252
253
254GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsList( GLuint list )
255{
256 GLboolean retval;
257 list = TranslateListID( list );
258 retval = cr_server.head_spu->dispatch_table.IsList( list );
259 crServerReturnValue( &retval, sizeof(retval) );
260 return retval;
261}
262
263
264void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteLists( GLuint list, GLsizei range )
265{
266 list = TranslateListID( list );
267 crStateDeleteLists( list, range );
268 cr_server.head_spu->dispatch_table.DeleteLists( list, range );
269}
270
271
272void SERVER_DISPATCH_APIENTRY crServerDispatchBindTexture( GLenum target, GLuint texture )
273{
274 crStateBindTexture( target, texture );
275 cr_server.head_spu->dispatch_table.BindTexture(target, crStateGetTextureHWID(texture));
276}
277
278void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteTextures( GLsizei n, const GLuint *textures)
279{
280 GLuint *newTextures = (GLuint *) crAlloc(n * sizeof(GLuint));
281 GLint i;
282
283 if (!newTextures)
284 {
285 crError("crServerDispatchDeleteTextures: out of memory");
286 return;
287 }
288
289 for (i = 0; i < n; i++)
290 {
291 newTextures[i] = crStateGetTextureHWID(textures[i]);
292 }
293
294 crStateDeleteTextures(n, textures);
295 cr_server.head_spu->dispatch_table.DeleteTextures(n, newTextures);
296 crFree(newTextures);
297}
298
299void SERVER_DISPATCH_APIENTRY crServerDispatchPrioritizeTextures( GLsizei n, const GLuint * textures, const GLclampf * priorities )
300{
301 GLuint *newTextures = (GLuint *) crAlloc(n * sizeof(GLuint));
302 GLint i;
303
304 if (!newTextures)
305 {
306 crError("crServerDispatchDeleteTextures: out of memory");
307 return;
308 }
309
310 for (i = 0; i < n; i++)
311 {
312 newTextures[i] = crStateGetTextureHWID(textures[i]);
313 }
314
315 crStatePrioritizeTextures(n, textures, priorities);
316 cr_server.head_spu->dispatch_table.PrioritizeTextures(n, newTextures, priorities);
317 crFree(newTextures);
318}
319
320void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteProgramsARB(GLsizei n, const GLuint * programs)
321{
322 GLuint *pLocalProgs = (GLuint *) crAlloc(n * sizeof(GLuint));
323 GLint i;
324 if (!pLocalProgs) {
325 crError("crServerDispatchDeleteProgramsARB: out of memory");
326 return;
327 }
328 for (i = 0; i < n; i++) {
329 pLocalProgs[i] = crServerTranslateProgramID(programs[i]);
330 }
331 crStateDeleteProgramsARB(n, pLocalProgs);
332 cr_server.head_spu->dispatch_table.DeleteProgramsARB(n, pLocalProgs);
333 crFree(pLocalProgs);
334}
335
336/*@todo will fail for textures loaded from snapshot */
337GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsTexture( GLuint texture )
338{
339 GLboolean retval;
340 retval = cr_server.head_spu->dispatch_table.IsTexture(crStateGetTextureHWID(texture));
341 crServerReturnValue( &retval, sizeof(retval) );
342 return retval; /* WILL PROBABLY BE IGNORED */
343}
344
345/*@todo will fail for progs loaded from snapshot */
346GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsProgramARB( GLuint program )
347{
348 GLboolean retval;
349 program = crServerTranslateProgramID(program);
350 retval = cr_server.head_spu->dispatch_table.IsProgramARB( program );
351 crServerReturnValue( &retval, sizeof(retval) );
352 return retval; /* WILL PROBABLY BE IGNORED */
353}
354
355GLboolean SERVER_DISPATCH_APIENTRY
356crServerDispatchAreTexturesResident(GLsizei n, const GLuint *textures,
357 GLboolean *residences)
358{
359 GLboolean retval;
360 GLsizei i;
361 GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
362 GLuint *textures2 = (GLuint *) crAlloc(n * sizeof(GLuint));
363
364 (void) residences;
365
366 for (i = 0; i < n; i++)
367 {
368 textures2[i] = crStateGetTextureHWID(textures[i]);
369 }
370 retval = cr_server.head_spu->dispatch_table.AreTexturesResident(n, textures2, res);
371
372 crFree(textures2);
373
374 crServerReturnValue(res, n * sizeof(GLboolean));
375
376 crFree(res);
377
378 return retval; /* WILL PROBABLY BE IGNORED */
379}
380
381
382GLboolean SERVER_DISPATCH_APIENTRY
383crServerDispatchAreProgramsResidentNV(GLsizei n, const GLuint *programs,
384 GLboolean *residences)
385{
386 GLboolean retval;
387 GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
388 GLsizei i;
389
390 (void) residences;
391
392 if (!cr_server.sharedTextureObjects) {
393 GLuint *programs2 = (GLuint *) crAlloc(n * sizeof(GLuint));
394 for (i = 0; i < n; i++)
395 programs2[i] = crServerTranslateProgramID(programs[i]);
396 retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs2, res);
397 crFree(programs2);
398 }
399 else {
400 retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs, res);
401 }
402
403 crServerReturnValue(res, n * sizeof(GLboolean));
404 crFree(res);
405
406 return retval; /* WILL PROBABLY BE IGNORED */
407}
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