VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_misc.c@ 33223

Last change on this file since 33223 was 33093, checked in by vboxsync, 14 years ago

crOpenGL/wddm: huge aero speedup with GL_EXT_framebuffer_blit, working but more cases to check/fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 17.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_dispatch.h"
8#include "server.h"
9#include "cr_error.h"
10#include "cr_mem.h"
11#include "cr_string.h"
12#include "cr_pixeldata.h"
13
14void SERVER_DISPATCH_APIENTRY crServerDispatchSelectBuffer( GLsizei size, GLuint *buffer )
15{
16 (void) size;
17 (void) buffer;
18 crError( "Unsupported network glSelectBuffer call." );
19}
20
21void SERVER_DISPATCH_APIENTRY crServerDispatchGetChromiumParametervCR(GLenum target, GLuint index, GLenum type, GLsizei count, GLvoid *values)
22{
23 GLubyte local_storage[4096];
24 GLint bytes = 0;
25
26 switch (type) {
27 case GL_BYTE:
28 case GL_UNSIGNED_BYTE:
29 bytes = count * sizeof(GLbyte);
30 break;
31 case GL_SHORT:
32 case GL_UNSIGNED_SHORT:
33 bytes = count * sizeof(GLshort);
34 break;
35 case GL_INT:
36 case GL_UNSIGNED_INT:
37 bytes = count * sizeof(GLint);
38 break;
39 case GL_FLOAT:
40 bytes = count * sizeof(GLfloat);
41 break;
42 case GL_DOUBLE:
43 bytes = count * sizeof(GLdouble);
44 break;
45 default:
46 crError("Bad type in crServerDispatchGetChromiumParametervCR");
47 }
48
49 CRASSERT(bytes >= 0);
50 CRASSERT(bytes < 4096);
51
52 cr_server.head_spu->dispatch_table.GetChromiumParametervCR( target, index, type, count, local_storage );
53
54 crServerReturnValue( local_storage, bytes );
55}
56
57void SERVER_DISPATCH_APIENTRY crServerDispatchChromiumParametervCR(GLenum target, GLenum type, GLsizei count, const GLvoid *values)
58{
59 CRMuralInfo *mural = cr_server.curClient->currentMural;
60 static int gather_connect_count = 0;
61
62 switch (target) {
63 case GL_SET_MAX_VIEWPORT_CR:
64 {
65 GLint *maxDims = (GLint *)values;
66 cr_server.limits.maxViewportDims[0] = maxDims[0];
67 cr_server.limits.maxViewportDims[1] = maxDims[1];
68 }
69 break;
70
71 case GL_TILE_INFO_CR:
72 /* message from tilesort SPU to set new tile bounds */
73 {
74 GLint numTiles, muralWidth, muralHeight, server, tiles;
75 GLint *tileBounds;
76 CRASSERT(count >= 4);
77 CRASSERT((count - 4) % 4 == 0); /* must be multiple of four */
78 CRASSERT(type == GL_INT);
79 numTiles = (count - 4) / 4;
80 tileBounds = (GLint *) values;
81 server = tileBounds[0];
82 muralWidth = tileBounds[1];
83 muralHeight = tileBounds[2];
84 tiles = tileBounds[3];
85 CRASSERT(tiles == numTiles);
86 tileBounds += 4; /* skip over header values */
87 /*crServerNewMuralTiling(mural, muralWidth, muralHeight, numTiles, tileBounds);
88 mural->viewportValidated = GL_FALSE;*/
89 }
90 break;
91
92 case GL_GATHER_DRAWPIXELS_CR:
93 if (cr_server.only_swap_once && cr_server.curClient != cr_server.clients[0])
94 break;
95 cr_server.head_spu->dispatch_table.ChromiumParametervCR( target, type, count, values );
96 break;
97
98 case GL_GATHER_CONNECT_CR:
99 /*
100 * We want the last connect to go through,
101 * otherwise we might deadlock in CheckWindowSize()
102 * in the readback spu
103 */
104 gather_connect_count++;
105 if (cr_server.only_swap_once && (gather_connect_count != cr_server.numClients))
106 {
107 break;
108 }
109 cr_server.head_spu->dispatch_table.ChromiumParametervCR( target, type, count, values );
110 gather_connect_count = 0;
111 break;
112
113 case GL_SERVER_VIEW_MATRIX_CR:
114 /* Set this server's view matrix which will get premultiplied onto the
115 * modelview matrix. For non-planar tilesort and stereo.
116 */
117 CRASSERT(count == 18);
118 CRASSERT(type == GL_FLOAT);
119 /* values[0] is the server index. Ignored here but used in tilesort SPU */
120 /* values[1] is the left/right eye index (0 or 1) */
121 {
122 const GLfloat *v = (const GLfloat *) values;
123 const int eye = v[1] == 0.0 ? 0 : 1;
124 crMatrixInitFromFloats(&cr_server.viewMatrix[eye], v + 2);
125
126 crDebug("Got GL_SERVER_VIEW_MATRIX_CR:\n"
127 " %f %f %f %f\n"
128 " %f %f %f %f\n"
129 " %f %f %f %f\n"
130 " %f %f %f %f",
131 cr_server.viewMatrix[eye].m00,
132 cr_server.viewMatrix[eye].m10,
133 cr_server.viewMatrix[eye].m20,
134 cr_server.viewMatrix[eye].m30,
135 cr_server.viewMatrix[eye].m01,
136 cr_server.viewMatrix[eye].m11,
137 cr_server.viewMatrix[eye].m21,
138 cr_server.viewMatrix[eye].m31,
139 cr_server.viewMatrix[eye].m02,
140 cr_server.viewMatrix[eye].m12,
141 cr_server.viewMatrix[eye].m22,
142 cr_server.viewMatrix[eye].m32,
143 cr_server.viewMatrix[eye].m03,
144 cr_server.viewMatrix[eye].m13,
145 cr_server.viewMatrix[eye].m23,
146 cr_server.viewMatrix[eye].m33);
147 }
148 cr_server.viewOverride = GL_TRUE;
149 break;
150
151 case GL_SERVER_PROJECTION_MATRIX_CR:
152 /* Set this server's projection matrix which will get replace the user's
153 * projection matrix. For non-planar tilesort and stereo.
154 */
155 CRASSERT(count == 18);
156 CRASSERT(type == GL_FLOAT);
157 /* values[0] is the server index. Ignored here but used in tilesort SPU */
158 /* values[1] is the left/right eye index (0 or 1) */
159 {
160 const GLfloat *v = (const GLfloat *) values;
161 const int eye = v[1] == 0.0 ? 0 : 1;
162 crMatrixInitFromFloats(&cr_server.projectionMatrix[eye], v + 2);
163
164 crDebug("Got GL_SERVER_PROJECTION_MATRIX_CR:\n"
165 " %f %f %f %f\n"
166 " %f %f %f %f\n"
167 " %f %f %f %f\n"
168 " %f %f %f %f",
169 cr_server.projectionMatrix[eye].m00,
170 cr_server.projectionMatrix[eye].m10,
171 cr_server.projectionMatrix[eye].m20,
172 cr_server.projectionMatrix[eye].m30,
173 cr_server.projectionMatrix[eye].m01,
174 cr_server.projectionMatrix[eye].m11,
175 cr_server.projectionMatrix[eye].m21,
176 cr_server.projectionMatrix[eye].m31,
177 cr_server.projectionMatrix[eye].m02,
178 cr_server.projectionMatrix[eye].m12,
179 cr_server.projectionMatrix[eye].m22,
180 cr_server.projectionMatrix[eye].m32,
181 cr_server.projectionMatrix[eye].m03,
182 cr_server.projectionMatrix[eye].m13,
183 cr_server.projectionMatrix[eye].m23,
184 cr_server.projectionMatrix[eye].m33);
185
186 if (cr_server.projectionMatrix[eye].m33 == 0.0f) {
187 float x = cr_server.projectionMatrix[eye].m00;
188 float y = cr_server.projectionMatrix[eye].m11;
189 float a = cr_server.projectionMatrix[eye].m20;
190 float b = cr_server.projectionMatrix[eye].m21;
191 float c = cr_server.projectionMatrix[eye].m22;
192 float d = cr_server.projectionMatrix[eye].m32;
193 float znear = -d / (1.0f - c);
194 float zfar = (c - 1.0f) * znear / (c + 1.0f);
195 float left = znear * (a - 1.0f) / x;
196 float right = 2.0f * znear / x + left;
197 float bottom = znear * (b - 1.0f) / y;
198 float top = 2.0f * znear / y + bottom;
199 crDebug("Frustum: left, right, bottom, top, near, far: %f, %f, %f, %f, %f, %f", left, right, bottom, top, znear, zfar);
200 }
201 else {
202 /* Todo: Add debug output for orthographic projection*/
203 }
204
205 }
206 cr_server.projectionOverride = GL_TRUE;
207 break;
208
209 default:
210 /* Pass the parameter info to the head SPU */
211 cr_server.head_spu->dispatch_table.ChromiumParametervCR( target, type, count, values );
212 break;
213 }
214}
215
216
217void SERVER_DISPATCH_APIENTRY crServerDispatchChromiumParameteriCR(GLenum target, GLint value)
218{
219 switch (target) {
220 case GL_SHARE_CONTEXT_RESOURCES_CR:
221 crStateShareContext(value);
222 break;
223 case GL_SHARED_DISPLAY_LISTS_CR:
224 cr_server.sharedDisplayLists = value;
225 break;
226 case GL_SHARED_TEXTURE_OBJECTS_CR:
227 cr_server.sharedTextureObjects = value;
228 break;
229 case GL_SHARED_PROGRAMS_CR:
230 cr_server.sharedPrograms = value;
231 break;
232 case GL_SERVER_CURRENT_EYE_CR:
233 cr_server.currentEye = value ? 1 : 0;
234 break;
235 default:
236 /* Pass the parameter info to the head SPU */
237 cr_server.head_spu->dispatch_table.ChromiumParameteriCR( target, value );
238 }
239}
240
241
242void SERVER_DISPATCH_APIENTRY crServerDispatchChromiumParameterfCR(GLenum target, GLfloat value)
243{
244 switch (target) {
245 case GL_SHARED_DISPLAY_LISTS_CR:
246 cr_server.sharedDisplayLists = (int) value;
247 break;
248 case GL_SHARED_TEXTURE_OBJECTS_CR:
249 cr_server.sharedTextureObjects = (int) value;
250 break;
251 case GL_SHARED_PROGRAMS_CR:
252 cr_server.sharedPrograms = (int) value;
253 break;
254 default:
255 /* Pass the parameter info to the head SPU */
256 cr_server.head_spu->dispatch_table.ChromiumParameterfCR( target, value );
257 }
258}
259
260void crServerCreateInfoDeleteCB(void *data)
261{
262 CRCreateInfo_t *pCreateInfo = (CRCreateInfo_t *) data;
263 if (pCreateInfo->pszDpyName)
264 crFree(pCreateInfo->pszDpyName);
265}
266
267GLint crServerGenerateID(GLint *pCounter)
268{
269 return (*pCounter)++;
270}
271
272void SERVER_DISPATCH_APIENTRY
273crServerDispatchCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
274{
275 /*@todo pbo/fbo disabled for now as it's slower, check on other gpus*/
276 static int siHavePBO = 0;
277 static int siHaveFBO = 0;
278
279 if ((target!=GL_TEXTURE_2D) || (height>=0))
280 {
281 cr_server.head_spu->dispatch_table.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
282 }
283 else /* negative height, means we have to Yinvert the source pixels while copying */
284 {
285 SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
286
287 if (siHavePBO<0)
288 {
289 const char *ext = (const char*)gl->GetString(GL_EXTENSIONS);
290 siHavePBO = crStrstr(ext, "GL_ARB_pixel_buffer_object") ? 1:0;
291 }
292
293 if (siHaveFBO<0)
294 {
295 const char *ext = (const char*)gl->GetString(GL_EXTENSIONS);
296 siHaveFBO = crStrstr(ext, "GL_EXT_framebuffer_object") ? 1:0;
297 }
298
299 if (siHavePBO==0 && siHaveFBO==0)
300 {
301#if 1
302 GLint dRow, sRow;
303 for (dRow=yoffset, sRow=y-height-1; dRow<yoffset-height; dRow++, sRow--)
304 {
305 gl->CopyTexSubImage2D(target, level, xoffset, dRow, x, sRow, width, 1);
306 }
307#else
308 {
309 GLint w, h, i;
310 char *img1, *img2, *sPtr, *dPtr;
311 CRContext *ctx = crStateGetCurrent();
312
313 w = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->level[0][level].width;
314 h = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->level[0][level].height;
315
316 img1 = crAlloc(4*w*h);
317 img2 = crAlloc(4*width*(-height));
318 CRASSERT(img1 && img2);
319
320 gl->CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, -height);
321 gl->GetTexImage(target, level, GL_RGBA, GL_UNSIGNED_BYTE, img1);
322
323 sPtr=img1+4*xoffset+4*w*yoffset;
324 dPtr=img2+4*width*(-height-1);
325
326 for (i=0; i<-height; ++i)
327 {
328 crMemcpy(dPtr, sPtr, 4*width);
329 sPtr += 4*w;
330 dPtr -= 4*width;
331 }
332
333 gl->TexSubImage2D(target, level, xoffset, yoffset, width, -height, GL_RGBA, GL_UNSIGNED_BYTE, img2);
334
335 crFree(img1);
336 crFree(img2);
337 }
338#endif
339 }
340 else if (siHaveFBO==1) /*@todo more states to set and restore here*/
341 {
342 GLuint tID, fboID;
343 GLenum status;
344 CRContext *ctx = crStateGetCurrent();
345
346 gl->GenTextures(1, &tID);
347 gl->BindTexture(target, tID);
348 gl->CopyTexImage2D(target, level, GL_RGBA, x, y, width, -height, 0);
349 gl->GenFramebuffersEXT(1, &fboID);
350 gl->BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID);
351 gl->FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, target,
352 ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->hwid, level);
353 status = gl->CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
354 if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
355 {
356 crWarning("Framebuffer status 0x%x", status);
357 }
358
359 gl->Enable(target);
360 gl->PushAttrib(GL_VIEWPORT_BIT);
361 gl->Viewport(xoffset, yoffset, width, -height);
362 gl->MatrixMode(GL_PROJECTION);
363 gl->PushMatrix();
364 gl->LoadIdentity();
365 gl->MatrixMode(GL_MODELVIEW);
366 gl->PushMatrix();
367 gl->LoadIdentity();
368
369 gl->Disable(GL_DEPTH_TEST);
370 gl->Disable(GL_CULL_FACE);
371 gl->Disable(GL_STENCIL_TEST);
372 gl->Disable(GL_SCISSOR_TEST);
373
374 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
375 gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
376 gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
377 gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
378 gl->TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
379
380 gl->Begin(GL_QUADS);
381 gl->TexCoord2f(0.0f, 1.0f);
382 gl->Vertex2f(-1.0, -1.0);
383
384 gl->TexCoord2f(0.0f, 0.0f);
385 gl->Vertex2f(-1.0f, 1.0f);
386
387 gl->TexCoord2f(1.0f, 0.0f);
388 gl->Vertex2f(1.0f, 1.0f);
389
390 gl->TexCoord2f(1.0f, 1.0f);
391 gl->Vertex2f(1.0f, -1.0f);
392 gl->End();
393
394 gl->PopMatrix();
395 gl->MatrixMode(GL_PROJECTION);
396 gl->PopMatrix();
397 gl->PopAttrib();
398
399 gl->FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, target, 0, level);
400 gl->BindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->framebufferobject.drawFB ? ctx->framebufferobject.drawFB->hwid:0);
401 gl->BindTexture(target, ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->hwid);
402 gl->DeleteFramebuffersEXT(1, &fboID);
403 gl->DeleteTextures(1, &tID);
404
405#if 0
406 {
407 GLint dRow, sRow, w, h;
408 void *img1, *img2;
409
410 w = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->level[0][level].width;
411 h = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->level[0][level].height;
412
413 img1 = crAlloc(4*w*h);
414 img2 = crAlloc(4*w*h);
415 CRASSERT(img1 && img2);
416
417 gl->GetTexImage(target, level, GL_BGRA, GL_UNSIGNED_BYTE, img1);
418
419
420 for (dRow=yoffset, sRow=y-height-1; dRow<yoffset-height; dRow++, sRow--)
421 {
422 gl->CopyTexSubImage2D(target, level, xoffset, dRow, x, sRow, width, 1);
423 }
424
425 gl->GetTexImage(target, level, GL_BGRA, GL_UNSIGNED_BYTE, img2);
426
427 if (crMemcmp(img1, img2, 4*w*h))
428 {
429 crDebug("MISMATCH! (%x, %i, ->%i,%i <-%i, %i [%ix%i])", target, level, xoffset, yoffset, x, y, width, height);
430 crDumpTGA(w, h, img1);
431 crDumpTGA(w, h, img2);
432 DebugBreak();
433 }
434 crFree(img1);
435 crFree(img2);
436 }
437#endif
438 }
439 else
440 {
441 GLuint pboId, dRow, sRow;
442 CRContext *ctx = crStateGetCurrent();
443
444 gl->GenBuffersARB(1, &pboId);
445 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboId);
446 gl->BufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, -width*height*4, 0, GL_STATIC_COPY_ARB);
447
448#if 1
449 gl->ReadPixels(x, y, width, -height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
450 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid);
451
452 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboId);
453 for (dRow=yoffset, sRow=-height-1; dRow<yoffset-height; dRow++, sRow--)
454 {
455 gl->TexSubImage2D(target, level, xoffset, dRow, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)((uintptr_t)sRow*width*4));
456 }
457#else /*few times slower again*/
458 for (dRow=0, sRow=y-height-1; dRow<-height; dRow++, sRow--)
459 {
460 gl->ReadPixels(x, sRow, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)((uintptr_t)dRow*width*4));
461 }
462 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid);
463
464 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboId);
465 gl->TexSubImage2D(target, level, xoffset, yoffset, width, -height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
466#endif
467
468 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, ctx->bufferobject.unpackBuffer->hwid);
469 gl->DeleteBuffersARB(1, &pboId);
470 }
471 }
472}
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