VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.c@ 23750

最後變更 在這個檔案從23750是 22509,由 vboxsync 提交於 16 年 前

crOpenGL-OSX: Initial version for the Cocoa port.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 31.8 KB
 
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 "cr_environment.h"
8#include "cr_string.h"
9#include "cr_error.h"
10#include "cr_mem.h"
11#include "cr_spu.h"
12#include "renderspu.h"
13#include "cr_extstring.h"
14
15
16static void
17DoSync(void)
18{
19 CRMessage *in, out;
20
21 out.header.type = CR_MESSAGE_OOB;
22
23 if (render_spu.is_swap_master)
24 {
25 int a;
26
27 for (a = 0; a < render_spu.num_swap_clients; a++)
28 {
29 crNetGetMessage( render_spu.swap_conns[a], &in );
30 crNetFree( render_spu.swap_conns[a], in);
31 }
32
33 for (a = 0; a < render_spu.num_swap_clients; a++)
34 crNetSend( render_spu.swap_conns[a], NULL, &out, sizeof(CRMessage));
35 }
36 else
37 {
38 crNetSend( render_spu.swap_conns[0], NULL, &out, sizeof(CRMessage));
39
40 crNetGetMessage( render_spu.swap_conns[0], &in );
41 crNetFree( render_spu.swap_conns[0], in);
42 }
43}
44
45
46
47/*
48 * Visual functions
49 */
50
51/**
52 * used for debugging and giving info to the user.
53 */
54void
55renderspuMakeVisString( GLbitfield visAttribs, char *s )
56{
57 s[0] = 0;
58
59 if (visAttribs & CR_RGB_BIT)
60 crStrcat(s, "RGB");
61 if (visAttribs & CR_ALPHA_BIT)
62 crStrcat(s, "A");
63 if (visAttribs & CR_DOUBLE_BIT)
64 crStrcat(s, ", Doublebuffer");
65 if (visAttribs & CR_STEREO_BIT)
66 crStrcat(s, ", Stereo");
67 if (visAttribs & CR_DEPTH_BIT)
68 crStrcat(s, ", Z");
69 if (visAttribs & CR_STENCIL_BIT)
70 crStrcat(s, ", Stencil");
71 if (visAttribs & CR_ACCUM_BIT)
72 crStrcat(s, ", Accum");
73 if (visAttribs & CR_MULTISAMPLE_BIT)
74 crStrcat(s, ", Multisample");
75 if (visAttribs & CR_OVERLAY_BIT)
76 crStrcat(s, ", Overlay");
77 if (visAttribs & CR_PBUFFER_BIT)
78 crStrcat(s, ", PBuffer");
79}
80
81
82/*
83 * Find a VisualInfo which matches the given display name and attribute
84 * bitmask, or return a pointer to a new visual.
85 */
86VisualInfo *
87renderspuFindVisual(const char *displayName, GLbitfield visAttribs)
88{
89 int i;
90
91 if (!displayName)
92 displayName = "";
93
94 /* first, try to find a match */
95#if defined(WINDOWS) || defined(DARWIN)
96 for (i = 0; i < render_spu.numVisuals; i++) {
97 if (visAttribs == render_spu.visuals[i].visAttribs) {
98 return &(render_spu.visuals[i]);
99 }
100 }
101#elif defined(GLX)
102 for (i = 0; i < render_spu.numVisuals; i++) {
103 if (crStrcmp(displayName, render_spu.visuals[i].displayName) == 0
104 && visAttribs == render_spu.visuals[i].visAttribs) {
105 return &(render_spu.visuals[i]);
106 }
107 }
108#endif
109
110 if (render_spu.numVisuals >= MAX_VISUALS)
111 {
112 crWarning("Render SPU: Couldn't create a visual, too many visuals already");
113 return NULL;
114 }
115
116 /* create a new visual */
117 i = render_spu.numVisuals;
118 render_spu.visuals[i].displayName = crStrdup(displayName);
119 render_spu.visuals[i].visAttribs = visAttribs;
120 if (renderspu_SystemInitVisual(&(render_spu.visuals[i]))) {
121 render_spu.numVisuals++;
122 return &(render_spu.visuals[i]);
123 }
124 else {
125 crWarning("Render SPU: Couldn't get a visual, renderspu_SystemInitVisual failed");
126 return NULL;
127 }
128}
129
130/*
131 * Context functions
132 */
133
134GLint RENDER_APIENTRY
135renderspuCreateContext(const char *dpyName, GLint visBits, GLint shareCtx)
136{
137 ContextInfo *context, *sharedContext = NULL;
138 VisualInfo *visual;
139
140 if (shareCtx > 0) {
141 sharedContext
142 = (ContextInfo *) crHashtableSearch(render_spu.contextTable, shareCtx);
143 }
144
145 if (!dpyName || crStrlen(render_spu.display_string)>0)
146 dpyName = render_spu.display_string;
147
148 visual = renderspuFindVisual(dpyName, visBits);
149 if (!visual)
150 return -1;
151
152 context = (ContextInfo *) crCalloc(sizeof(ContextInfo));
153 if (!context)
154 return -1;
155 context->id = render_spu.context_id;
156 context->shared = sharedContext;
157 if (!renderspu_SystemCreateContext(visual, context, sharedContext))
158 return -1;
159
160 crHashtableAdd(render_spu.contextTable, render_spu.context_id, context);
161 render_spu.context_id++;
162
163 /*
164 crDebug("Render SPU: CreateContext(%s, 0x%x) returning %d",
165 dpyName, visBits, context->id);
166 */
167
168 return context->id;
169}
170
171
172static void RENDER_APIENTRY
173renderspuDestroyContext( GLint ctx )
174{
175 ContextInfo *context;
176
177 CRASSERT(ctx);
178
179 context = (ContextInfo *) crHashtableSearch(render_spu.contextTable, ctx);
180 CRASSERT(context);
181 renderspu_SystemDestroyContext( context );
182 if (context->extensionString) {
183 crFree(context->extensionString);
184 context->extensionString = NULL;
185 }
186 crHashtableDelete(render_spu.contextTable, ctx, crFree);
187}
188
189
190void RENDER_APIENTRY
191renderspuMakeCurrent(GLint crWindow, GLint nativeWindow, GLint ctx)
192{
193 WindowInfo *window;
194 ContextInfo *context;
195
196 /*
197 crDebug("%s win=%d native=0x%x ctx=%d", __FUNCTION__, crWindow, (int) nativeWindow, ctx);
198 */
199
200 window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, crWindow);
201 context = (ContextInfo *) crHashtableSearch(render_spu.contextTable, ctx);
202
203 if (window && context)
204 {
205#ifdef CHROMIUM_THREADSAFE
206 crSetTSD(&_RenderTSD, context);
207#else
208 render_spu.currentContext = context;
209#endif
210 context->currentWindow = window;
211 if (!window)
212 {
213 crDebug("Render SPU: MakeCurrent invalid window id: %d", crWindow);
214 return;
215 }
216 if (!context)
217 {
218 crDebug("Render SPU: MakeCurrent invalid context id: %d", ctx);
219 return;
220 }
221
222 renderspu_SystemMakeCurrent( window, nativeWindow, context );
223 if (!context->everCurrent) {
224 /* print OpenGL info */
225 const char *extString = (const char *) render_spu.ws.glGetString( GL_EXTENSIONS );
226 /*
227 crDebug( "Render SPU: GL_EXTENSIONS: %s", render_spu.ws.glGetString( GL_EXTENSIONS ) );
228 */
229 crInfo( "Render SPU: GL_VENDOR: %s", render_spu.ws.glGetString( GL_VENDOR ) );
230 crInfo( "Render SPU: GL_RENDERER: %s", render_spu.ws.glGetString( GL_RENDERER ) );
231 crInfo( "Render SPU: GL_VERSION: %s", render_spu.ws.glGetString( GL_VERSION ) );
232 crInfo( "Render SPU: GL_EXTENSIONS: %s", render_spu.ws.glGetString( GL_EXTENSIONS ) );
233 if (crStrstr(extString, "GL_ARB_window_pos"))
234 context->haveWindowPosARB = GL_TRUE;
235 else
236 context->haveWindowPosARB = GL_FALSE;
237 context->everCurrent = GL_TRUE;
238 }
239 if (crWindow == 0 && window->mapPending &&
240 !render_spu.render_to_app_window && !render_spu.render_to_crut_window) {
241 /* Window[0] is special, it's the default window and normally hidden.
242 * If the mapPending flag is set, then we should now make the window
243 * visible.
244 */
245 renderspu_SystemShowWindow( window, GL_TRUE );
246 window->mapPending = GL_FALSE;
247 }
248 window->everCurrent = GL_TRUE;
249 }
250 else
251 {
252#ifdef CHROMIUM_THREADSAFE
253 crSetTSD(&_RenderTSD, NULL);
254#else
255 render_spu.currentContext = NULL;
256#endif
257 }
258}
259
260
261/*
262 * Window functions
263 */
264
265GLint RENDER_APIENTRY
266renderspuWindowCreate( const char *dpyName, GLint visBits )
267{
268 WindowInfo *window;
269 VisualInfo *visual;
270 GLboolean showIt;
271
272 if (!dpyName || crStrlen(render_spu.display_string) > 0)
273 dpyName = render_spu.display_string;
274
275 visual = renderspuFindVisual( dpyName, visBits );
276 if (!visual)
277 {
278 crWarning( "Render SPU: Couldn't create a window, renderspuFindVisual returned NULL" );
279 return -1;
280 }
281
282 /* Allocate WindowInfo */
283 window = (WindowInfo *) crCalloc(sizeof(WindowInfo));
284 if (!window)
285 {
286 crWarning( "Render SPU: Couldn't create a window" );
287 return -1;
288 }
289
290 crHashtableAdd(render_spu.windowTable, render_spu.window_id, window);
291 window->id = render_spu.window_id;
292 render_spu.window_id++;
293
294 window->x = render_spu.defaultX;
295 window->y = render_spu.defaultY;
296 window->width = render_spu.defaultWidth;
297 window->height = render_spu.defaultHeight;
298
299 if ((render_spu.render_to_app_window || render_spu.render_to_crut_window) && !crGetenv("CRNEWSERVER"))
300 showIt = 0;
301 else
302 showIt = window->id > 0;
303
304 /* Set window->title, replacing %i with the window ID number */
305 {
306 const char *s = crStrstr(render_spu.window_title, "%i");
307 if (s) {
308 int i, j, k;
309 window->title = crAlloc(crStrlen(render_spu.window_title) + 10);
310 for (i = 0; render_spu.window_title[i] != '%'; i++)
311 window->title[i] = render_spu.window_title[i];
312 k = sprintf(window->title + i, "%d", window->id);
313 CRASSERT(k < 10);
314 i++; /* skip the 'i' after the '%' */
315 j = i + k;
316 for (; (window->title[j] = s[i]) != 0; i++, j++)
317 ;
318 }
319 else {
320 window->title = crStrdup(render_spu.window_title);
321 }
322 }
323
324 /*
325 crDebug("Render SPU: Creating window (visBits=0x%x, id=%d)", visBits, window->id);
326 */
327 /* Have GLX/WGL/AGL create the window */
328 if (!renderspu_SystemVBoxCreateWindow( visual, showIt, window ))
329 {
330 crFree(window);
331 crWarning( "Render SPU: Couldn't create a window, renderspu_SystemCreateWindow failed" );
332 return -1;
333 }
334
335 CRASSERT(window->visual == visual);
336
337 return window->id;
338}
339
340
341static void
342RENDER_APIENTRY renderspuWindowDestroy( GLint win )
343{
344 WindowInfo *window;
345 CRASSERT(win >= 0);
346 window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, win);
347 if (window) {
348 crDebug("Render SPU: Destroy window (%d)", win);
349 renderspu_SystemDestroyWindow( window );
350 /* remove window info from hash table, and free it */
351 crHashtableDelete(render_spu.windowTable, win, crFree);
352 }
353 else {
354 crDebug("Render SPU: Attempt to destroy invalid window (%d)", win);
355 }
356}
357
358
359static void RENDER_APIENTRY
360renderspuWindowSize( GLint win, GLint w, GLint h )
361{
362 WindowInfo *window;
363 CRASSERT(win >= 0);
364 window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, win);
365 if (window) {
366 renderspu_SystemWindowSize( window, w, h );
367 }
368 else {
369 crDebug("Render SPU: Attempt to resize invalid window (%d)", win);
370 }
371}
372
373
374static void RENDER_APIENTRY
375renderspuWindowPosition( GLint win, GLint x, GLint y )
376{
377 if (!render_spu.ignore_window_moves) {
378 WindowInfo *window;
379 CRASSERT(win >= 0);
380 window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, win);
381 if (window) {
382 renderspu_SystemWindowPosition( window, x, y );
383 window->x = x;
384 window->y = y;
385 }
386 else {
387 crDebug("Render SPU: Attempt to move invalid window (%d)", win);
388 }
389 }
390}
391
392static void RENDER_APIENTRY
393renderspuWindowVisibleRegion(GLint win, GLint cRects, GLint *pRects)
394{
395 WindowInfo *window;
396 CRASSERT(win >= 0);
397 window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, win);
398 if (window) {
399 renderspu_SystemWindowVisibleRegion( window, cRects, pRects );
400 }
401 else {
402 crDebug("Render SPU: Attempt to set VisibleRegion for invalid window (%d)", win);
403 }
404}
405
406static void RENDER_APIENTRY
407renderspuWindowShow( GLint win, GLint flag )
408{
409 WindowInfo *window;
410 CRASSERT(win >= 0);
411 window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, win);
412 if (window) {
413 if (window->nativeWindow) {
414 /* We're rendering back to the native app window instead of the
415 * new window which we (the Render SPU) created earlier.
416 * So, we never want to show the Render SPU's window.
417 */
418 flag = 0;
419 }
420 renderspu_SystemShowWindow( window, (GLboolean) flag );
421 }
422 else {
423 crDebug("Render SPU: Attempt to hide/show invalid window (%d)", win);
424 }
425}
426
427
428/*
429 * Set the current raster position to the given window coordinate.
430 */
431static void
432SetRasterPos( GLint winX, GLint winY )
433{
434 GLfloat fx, fy;
435
436 /* Push current matrix mode and viewport attributes */
437 render_spu.self.PushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
438
439 /* Setup projection parameters */
440 render_spu.self.MatrixMode( GL_PROJECTION );
441 render_spu.self.PushMatrix();
442 render_spu.self.LoadIdentity();
443 render_spu.self.MatrixMode( GL_MODELVIEW );
444 render_spu.self.PushMatrix();
445 render_spu.self.LoadIdentity();
446
447 render_spu.self.Viewport( winX - 1, winY - 1, 2, 2 );
448
449 /* set the raster (window) position */
450 /* huh ? */
451 fx = (GLfloat) (winX - (int) winX);
452 fy = (GLfloat) (winY - (int) winY);
453 render_spu.self.RasterPos4f( fx, fy, 0.0, 1.0 );
454
455 /* restore matrices, viewport and matrix mode */
456 render_spu.self.PopMatrix();
457 render_spu.self.MatrixMode( GL_PROJECTION );
458 render_spu.self.PopMatrix();
459
460 render_spu.self.PopAttrib();
461}
462
463
464/*
465 * Draw the mouse pointer bitmap at (x,y) in window coords.
466 */
467static void DrawCursor( GLint x, GLint y )
468{
469#define POINTER_WIDTH 32
470#define POINTER_HEIGHT 32
471 /* Somebody artistic could probably do better here */
472 static const char *pointerImage[POINTER_HEIGHT] =
473 {
474 "XX..............................",
475 "XXXX............................",
476 ".XXXXX..........................",
477 ".XXXXXXX........................",
478 "..XXXXXXXX......................",
479 "..XXXXXXXXXX....................",
480 "...XXXXXXXXXXX..................",
481 "...XXXXXXXXXXXXX................",
482 "....XXXXXXXXXXXXXX..............",
483 "....XXXXXXXXXXXXXXXX............",
484 ".....XXXXXXXXXXXXXXXXX..........",
485 ".....XXXXXXXXXXXXXXXXXXX........",
486 "......XXXXXXXXXXXXXXXXXXXX......",
487 "......XXXXXXXXXXXXXXXXXXXXXX....",
488 ".......XXXXXXXXXXXXXXXXXXXXXXX..",
489 ".......XXXXXXXXXXXXXXXXXXXXXXXX.",
490 "........XXXXXXXXXXXXX...........",
491 "........XXXXXXXX.XXXXX..........",
492 ".........XXXXXX...XXXXX.........",
493 ".........XXXXX.....XXXXX........",
494 "..........XXX.......XXXXX.......",
495 "..........XX.........XXXXX......",
496 "......................XXXXX.....",
497 ".......................XXXXX....",
498 "........................XXX.....",
499 ".........................X......",
500 "................................",
501 "................................",
502 "................................",
503 "................................",
504 "................................",
505 "................................"
506
507 };
508 static GLubyte pointerBitmap[POINTER_HEIGHT][POINTER_WIDTH / 8];
509 static GLboolean firstCall = GL_TRUE;
510 GLboolean lighting, depthTest, scissorTest;
511
512 if (firstCall) {
513 /* Convert pointerImage into pointerBitmap */
514 GLint i, j;
515 for (i = 0; i < POINTER_HEIGHT; i++) {
516 for (j = 0; j < POINTER_WIDTH; j++) {
517 if (pointerImage[POINTER_HEIGHT - i - 1][j] == 'X') {
518 GLubyte bit = 128 >> (j & 0x7);
519 pointerBitmap[i][j / 8] |= bit;
520 }
521 }
522 }
523 firstCall = GL_FALSE;
524 }
525
526 render_spu.self.GetBooleanv(GL_LIGHTING, &lighting);
527 render_spu.self.GetBooleanv(GL_DEPTH_TEST, &depthTest);
528 render_spu.self.GetBooleanv(GL_SCISSOR_TEST, &scissorTest);
529 render_spu.self.Disable(GL_LIGHTING);
530 render_spu.self.Disable(GL_DEPTH_TEST);
531 render_spu.self.Disable(GL_SCISSOR_TEST);
532 render_spu.self.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
533
534 render_spu.self.Color3f(1, 1, 1);
535
536 /* save current raster pos */
537 render_spu.self.PushAttrib(GL_CURRENT_BIT);
538 SetRasterPos(x, y);
539 render_spu.self.Bitmap(POINTER_WIDTH, POINTER_HEIGHT, 1.0, 31.0, 0, 0,
540 (const GLubyte *) pointerBitmap);
541 /* restore current raster pos */
542 render_spu.self.PopAttrib();
543
544 if (lighting)
545 render_spu.self.Enable(GL_LIGHTING);
546 if (depthTest)
547 render_spu.self.Enable(GL_DEPTH_TEST);
548 if (scissorTest)
549 render_spu.self.Enable(GL_SCISSOR_TEST);
550}
551
552void RENDER_APIENTRY renderspuSwapBuffers( GLint window, GLint flags )
553{
554 WindowInfo *w = (WindowInfo *) crHashtableSearch(render_spu.windowTable, window);
555
556 if (!w)
557 {
558 crDebug("Render SPU: SwapBuffers invalid window id: %d", window);
559 return;
560 }
561
562 if (flags & CR_SUPPRESS_SWAP_BIT)
563 {
564 render_spu.self.Finish();
565 return;
566 }
567
568 if (render_spu.drawCursor)
569 DrawCursor( render_spu.cursorX, render_spu.cursorY );
570
571 if (render_spu.swap_master_url)
572 DoSync();
573
574 renderspu_SystemSwapBuffers( w, flags );
575}
576
577
578/*
579 * Barrier functions
580 * Normally, we'll have a crserver somewhere that handles the barrier calls.
581 * However, if we're running the render SPU on the client node, then we
582 * should handle barriers here. The threadtest demo illustrates this.
583 * If we have N threads calling using this SPU we need these barrier
584 * functions to synchronize them.
585 */
586
587static void RENDER_APIENTRY renderspuBarrierCreateCR( GLuint name, GLuint count )
588{
589 Barrier *b;
590
591 if (render_spu.ignore_papi)
592 return;
593
594 b = (Barrier *) crHashtableSearch( render_spu.barrierHash, name );
595 if (b) {
596 /* HACK -- this allows everybody to create a barrier, and all
597 but the first creation are ignored, assuming the count
598 match. */
599 if ( b->count != count ) {
600 crError( "Render SPU: Barrier name=%u created with count=%u, but already "
601 "exists with count=%u", name, count, b->count );
602 }
603 }
604 else {
605 b = (Barrier *) crAlloc( sizeof(Barrier) );
606 b->count = count;
607 crInitBarrier( &b->barrier, count );
608 crHashtableAdd( render_spu.barrierHash, name, b );
609 }
610}
611
612static void RENDER_APIENTRY renderspuBarrierDestroyCR( GLuint name )
613{
614 if (render_spu.ignore_papi)
615 return;
616 crHashtableDelete( render_spu.barrierHash, name, crFree );
617}
618
619static void RENDER_APIENTRY renderspuBarrierExecCR( GLuint name )
620{
621 Barrier *b;
622
623 if (render_spu.ignore_papi)
624 return;
625
626 b = (Barrier *) crHashtableSearch( render_spu.barrierHash, name );
627 if (b) {
628 crWaitBarrier( &(b->barrier) );
629 }
630 else {
631 crWarning("Render SPU: Bad barrier name %d in BarrierExec()", name);
632 }
633}
634
635
636/*
637 * Semaphore functions
638 * XXX we should probably implement these too, for the same reason as
639 * barriers (see above).
640 */
641
642static void RENDER_APIENTRY renderspuSemaphoreCreateCR( GLuint name, GLuint count )
643{
644 (void) name;
645 (void) count;
646}
647
648static void RENDER_APIENTRY renderspuSemaphoreDestroyCR( GLuint name )
649{
650 (void) name;
651}
652
653static void RENDER_APIENTRY renderspuSemaphorePCR( GLuint name )
654{
655 (void) name;
656}
657
658static void RENDER_APIENTRY renderspuSemaphoreVCR( GLuint name )
659{
660 (void) name;
661}
662
663
664/*
665 * Misc functions
666 */
667
668
669
670static void RENDER_APIENTRY renderspuChromiumParameteriCR(GLenum target, GLint value)
671{
672 (void) target;
673 (void) value;
674
675
676#if 0
677 switch (target)
678 {
679 default:
680 crWarning("Unhandled target in renderspuChromiumParameteriCR()");
681 break;
682 }
683#endif
684}
685
686static void RENDER_APIENTRY
687renderspuChromiumParameterfCR(GLenum target, GLfloat value)
688{
689 (void) target;
690 (void) value;
691
692#if 0
693 switch (target) {
694 default:
695 crWarning("Unhandled target in renderspuChromiumParameterfCR()");
696 break;
697 }
698#endif
699}
700
701
702static void RENDER_APIENTRY
703renderspuChromiumParametervCR(GLenum target, GLenum type, GLsizei count,
704 const GLvoid *values)
705{
706 int client_num;
707 unsigned short port;
708 CRMessage *msg, pingback;
709 unsigned char *privbuf = NULL;
710
711 switch (target) {
712
713 case GL_GATHER_CONNECT_CR:
714 if (render_spu.gather_userbuf_size)
715 privbuf = (unsigned char *)crAlloc(1024*768*4);
716
717 port = ((GLint *) values)[0];
718
719 if (render_spu.gather_conns == NULL)
720 render_spu.gather_conns = crAlloc(render_spu.server->numClients*sizeof(CRConnection *));
721 else
722 {
723 crError("Oh bother! duplicate GL_GATHER_CONNECT_CR getting through");
724 }
725
726 for (client_num=0; client_num< render_spu.server->numClients; client_num++)
727 {
728 switch (render_spu.server->clients[client_num]->conn->type)
729 {
730 case CR_TCPIP:
731 crDebug("Render SPU: AcceptClient from %s on %d",
732 render_spu.server->clients[client_num]->conn->hostname, render_spu.gather_port);
733 render_spu.gather_conns[client_num] =
734 crNetAcceptClient("tcpip", NULL, port, 1024*1024, 1);
735 break;
736
737 case CR_GM:
738 render_spu.gather_conns[client_num] =
739 crNetAcceptClient("gm", NULL, port, 1024*1024, 1);
740 break;
741
742 default:
743 crError("Render SPU: Unknown Network Type to Open Gather Connection");
744 }
745
746
747 if (render_spu.gather_userbuf_size)
748 {
749 render_spu.gather_conns[client_num]->userbuf = privbuf;
750 render_spu.gather_conns[client_num]->userbuf_len = render_spu.gather_userbuf_size;
751 }
752 else
753 {
754 render_spu.gather_conns[client_num]->userbuf = NULL;
755 render_spu.gather_conns[client_num]->userbuf_len = 0;
756 }
757
758 if (render_spu.gather_conns[client_num])
759 {
760 crDebug("Render SPU: success! from %s", render_spu.gather_conns[client_num]->hostname);
761 }
762 }
763
764 break;
765
766 case GL_GATHER_DRAWPIXELS_CR:
767 pingback.header.type = CR_MESSAGE_OOB;
768
769 for (client_num=0; client_num< render_spu.server->numClients; client_num++)
770 {
771 crNetGetMessage(render_spu.gather_conns[client_num], &msg);
772 if (msg->header.type == CR_MESSAGE_GATHER)
773 {
774 crNetFree(render_spu.gather_conns[client_num], msg);
775 }
776 else
777 {
778 crError("Render SPU: expecting MESSAGE_GATHER. got crap! (%d of %d)",
779 client_num, render_spu.server->numClients-1);
780 }
781 }
782
783 /*
784 * We're only hitting the case if we're not actually calling
785 * child.SwapBuffers from readback, so a switch about which
786 * call to DoSync() we really want [this one, or the one
787 * in SwapBuffers above] is not necessary -- karl
788 */
789
790 if (render_spu.swap_master_url)
791 DoSync();
792
793 for (client_num=0; client_num< render_spu.server->numClients; client_num++)
794 crNetSend(render_spu.gather_conns[client_num], NULL, &pingback,
795 sizeof(CRMessageHeader));
796
797 render_spu.self.RasterPos2i(((GLint *)values)[0], ((GLint *)values)[1]);
798 render_spu.self.DrawPixels( ((GLint *)values)[2], ((GLint *)values)[3],
799 ((GLint *)values)[4], ((GLint *)values)[5],
800 render_spu.gather_conns[0]->userbuf);
801
802
803 render_spu.self.SwapBuffers(((GLint *)values)[6], 0);
804 break;
805
806 case GL_CURSOR_POSITION_CR:
807 if (type == GL_INT && count == 2) {
808 render_spu.cursorX = ((GLint *) values)[0];
809 render_spu.cursorY = ((GLint *) values)[1];
810 crDebug("Render SPU: GL_CURSOR_POSITION_CR (%d, %d)", render_spu.cursorX, render_spu.cursorY);
811 }
812 else {
813 crWarning("Render SPU: Bad type or count for ChromiumParametervCR(GL_CURSOR_POSITION_CR)");
814 }
815 break;
816
817 case GL_WINDOW_SIZE_CR:
818 /* XXX this is old code that should be removed.
819 * NOTE: we can only resize the default (id=0) window!!!
820 */
821 {
822 GLint w, h;
823 WindowInfo *window;
824 CRASSERT(type == GL_INT);
825 CRASSERT(count == 2);
826 CRASSERT(values);
827 w = ((GLint*)values)[0];
828 h = ((GLint*)values)[1];
829 window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, 0);
830 if (window)
831 {
832 renderspu_SystemWindowSize(window, w, h);
833 }
834 }
835 break;
836
837 default:
838#if 0
839 crWarning("Unhandled target in renderspuChromiumParametervCR(0x%x)", (int) target);
840#endif
841 break;
842 }
843}
844
845
846static void RENDER_APIENTRY
847renderspuGetChromiumParametervCR(GLenum target, GLuint index, GLenum type,
848 GLsizei count, GLvoid *values)
849{
850 switch (target) {
851 case GL_WINDOW_SIZE_CR:
852 {
853 GLint x, y, w, h, *size = (GLint *) values;
854 WindowInfo *window;
855 CRASSERT(type == GL_INT);
856 CRASSERT(count == 2);
857 CRASSERT(values);
858 size[0] = size[1] = 0; /* default */
859 window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, index);
860 if (window)
861 {
862 renderspu_SystemGetWindowGeometry(window, &x, &y, &w, &h);
863 size[0] = w;
864 size[1] = h;
865 }
866 }
867 break;
868 case GL_WINDOW_POSITION_CR:
869 /* return window position, as a screen coordinate */
870 {
871 GLint *pos = (GLint *) values;
872 GLint x, y, w, h;
873 WindowInfo *window;
874 CRASSERT(type == GL_INT);
875 CRASSERT(count == 2);
876 CRASSERT(values);
877 pos[0] = pos[1] = 0; /* default */
878 window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, index);
879 if (window)
880 {
881 renderspu_SystemGetWindowGeometry(window, &x, &y, &w, &h);
882 pos[0] = x;/*window->x;*/
883 pos[1] = y;/*window->y;*/
884 }
885 }
886 break;
887 case GL_MAX_WINDOW_SIZE_CR:
888 {
889 GLint *maxSize = (GLint *) values;
890 WindowInfo *window;
891 CRASSERT(type == GL_INT);
892 CRASSERT(count == 2);
893 CRASSERT(values);
894 window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, index);
895 if (window)
896 {
897 renderspu_SystemGetMaxWindowSize(window, maxSize + 0, maxSize + 1);
898 }
899 }
900 break;
901 default:
902 ; /* nothing - silence compiler */
903 }
904}
905
906
907static void RENDER_APIENTRY
908renderspuBoundsInfoCR( CRrecti *bounds, GLbyte *payload, GLint len,
909 GLint num_opcodes )
910{
911 (void) bounds;
912 (void) payload;
913 (void) len;
914 (void) num_opcodes;
915 /* draw the bounding box */
916 if (render_spu.draw_bbox) {
917 GET_CONTEXT(context);
918 WindowInfo *window = context->currentWindow;
919 GLint x, y, w, h;
920
921 renderspu_SystemGetWindowGeometry(window, &x, &y, &w, &h);
922
923 render_spu.self.PushMatrix();
924 render_spu.self.LoadIdentity();
925 render_spu.self.MatrixMode(GL_PROJECTION);
926 render_spu.self.PushMatrix();
927 render_spu.self.LoadIdentity();
928 render_spu.self.Ortho(0, w, 0, h, -1, 1);
929 render_spu.self.Color3f(1, 1, 1);
930 render_spu.self.Begin(GL_LINE_LOOP);
931 render_spu.self.Vertex2i(bounds->x1, bounds->y1);
932 render_spu.self.Vertex2i(bounds->x2, bounds->y1);
933 render_spu.self.Vertex2i(bounds->x2, bounds->y2);
934 render_spu.self.Vertex2i(bounds->x1, bounds->y2);
935 render_spu.self.End();
936 render_spu.self.PopMatrix();
937 render_spu.self.MatrixMode(GL_MODELVIEW);
938 render_spu.self.PopMatrix();
939 }
940}
941
942
943static void RENDER_APIENTRY
944renderspuWriteback( GLint *writeback )
945{
946 (void) writeback;
947}
948
949
950static void
951remove_trailing_space(char *s)
952{
953 int k = crStrlen(s);
954 while (k > 0 && s[k-1] == ' ')
955 k--;
956 s[k] = 0;
957}
958
959static const GLubyte * RENDER_APIENTRY
960renderspuGetString(GLenum pname)
961{
962 static char tempStr[1000];
963 GET_CONTEXT(context);
964
965 if (pname == GL_EXTENSIONS)
966 {
967 const char *nativeExt;
968 char *crExt, *s1, *s2;
969
970 if (!render_spu.ws.glGetString)
971 return NULL;
972
973 nativeExt = (const char *) render_spu.ws.glGetString(GL_EXTENSIONS);
974 if (!nativeExt) {
975 /* maybe called w/out current context. */
976 return NULL;
977 }
978
979 crExt = crStrjoin3(crExtensions, " ", crAppOnlyExtensions);
980 s1 = crStrIntersect(nativeExt, crExt);
981 remove_trailing_space(s1);
982 s2 = crStrjoin3(s1, " ", crChromiumExtensions);
983 remove_trailing_space(s2);
984 crFree(crExt);
985 crFree(s1);
986 if (context->extensionString)
987 crFree(context->extensionString);
988 context->extensionString = s2;
989 return (const GLubyte *) s2;
990 }
991 else if (pname == GL_VENDOR)
992 return (const GLubyte *) CR_VENDOR;
993 else if (pname == GL_VERSION)
994 return render_spu.ws.glGetString(GL_VERSION);
995 else if (pname == GL_RENDERER) {
996 sprintf(tempStr, "Chromium (%s)", (char *) render_spu.ws.glGetString(GL_RENDERER));
997 return (const GLubyte *) tempStr;
998 }
999#ifdef CR_OPENGL_VERSION_2_0
1000 else if (pname == GL_SHADING_LANGUAGE_VERSION)
1001 return render_spu.ws.glGetString(GL_SHADING_LANGUAGE_VERSION);
1002#endif
1003#ifdef GL_CR_real_vendor_strings
1004 else if (pname == GL_REAL_VENDOR)
1005 return render_spu.ws.glGetString(GL_VENDOR);
1006 else if (pname == GL_REAL_VERSION)
1007 return render_spu.ws.glGetString(GL_VERSION);
1008 else if (pname == GL_REAL_RENDERER)
1009 return render_spu.ws.glGetString(GL_RENDERER);
1010#endif
1011 else
1012 return NULL;
1013}
1014
1015
1016#if defined(DARWIN)
1017# ifdef VBOX_WITH_COCOA_QT
1018void renderspuFlush()
1019{
1020 renderspu_SystemFlush();
1021}
1022
1023void renderspuFinish()
1024{
1025 renderspu_SystemFinish();
1026}
1027
1028void renderspuBindFramebufferEXT(GLenum target, GLuint framebuffer)
1029{
1030 renderspu_SystemBindFramebufferEXT(target, framebuffer);
1031}
1032# endif
1033#endif
1034
1035#define FILLIN( NAME, FUNC ) \
1036 table[i].name = crStrdup(NAME); \
1037 table[i].fn = (SPUGenericFunction) FUNC; \
1038 i++;
1039
1040
1041/* These are the functions which the render SPU implements, not OpenGL.
1042 */
1043int
1044renderspuCreateFunctions(SPUNamedFunctionTable table[])
1045{
1046 int i = 0;
1047 FILLIN( "SwapBuffers", renderspuSwapBuffers );
1048 FILLIN( "CreateContext", renderspuCreateContext );
1049 FILLIN( "DestroyContext", renderspuDestroyContext );
1050 FILLIN( "MakeCurrent", renderspuMakeCurrent );
1051 FILLIN( "WindowCreate", renderspuWindowCreate );
1052 FILLIN( "WindowDestroy", renderspuWindowDestroy );
1053 FILLIN( "WindowSize", renderspuWindowSize );
1054 FILLIN( "WindowPosition", renderspuWindowPosition );
1055 FILLIN( "WindowVisibleRegion", renderspuWindowVisibleRegion );
1056 FILLIN( "WindowShow", renderspuWindowShow );
1057 FILLIN( "BarrierCreateCR", renderspuBarrierCreateCR );
1058 FILLIN( "BarrierDestroyCR", renderspuBarrierDestroyCR );
1059 FILLIN( "BarrierExecCR", renderspuBarrierExecCR );
1060 FILLIN( "BoundsInfoCR", renderspuBoundsInfoCR );
1061 FILLIN( "SemaphoreCreateCR", renderspuSemaphoreCreateCR );
1062 FILLIN( "SemaphoreDestroyCR", renderspuSemaphoreDestroyCR );
1063 FILLIN( "SemaphorePCR", renderspuSemaphorePCR );
1064 FILLIN( "SemaphoreVCR", renderspuSemaphoreVCR );
1065 FILLIN( "Writeback", renderspuWriteback );
1066 FILLIN( "ChromiumParameteriCR", renderspuChromiumParameteriCR );
1067 FILLIN( "ChromiumParameterfCR", renderspuChromiumParameterfCR );
1068 FILLIN( "ChromiumParametervCR", renderspuChromiumParametervCR );
1069 FILLIN( "GetChromiumParametervCR", renderspuGetChromiumParametervCR );
1070 FILLIN( "GetString", renderspuGetString );
1071#if defined(DARWIN)
1072# ifdef VBOX_WITH_COCOA_QT
1073 FILLIN( "Flush", renderspuFlush );
1074 FILLIN( "Finish", renderspuFinish );
1075 FILLIN( "BindFramebufferEXT", renderspuBindFramebufferEXT );
1076# endif
1077#endif
1078 return i;
1079}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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