VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/context.c@ 65902

最後變更 在這個檔案從65902是 65787,由 vboxsync 提交於 8 年 前

bugref:8748: Additions/Graphics/Wayland: investigate EGLStreams support feasibility:

Removed more dependencies on native X11 visuals in the GLX code, with a view to stop using a visual ID as an fbconfig ID next. I tested the Mesa GLX demos before and after, and those which worked before to some extent still worked after, namely: glxcontexts, glxdemo, glxgears, glxgears_fbconfig, glxheads (one head of course), glxinfo, glxswapcontrol, manywin (with assertion), multictx, offset, pbinfo, shape, sharedtex (without the texture), texture_from_pixmap (without any animation), wincopy (without the copy), xfont and xrotfontdemo.

I did not test FBCONFIG_SGIX, as nothing I have available will use it if OpenGL 1.3 or later is available. I suspect that the code is broken from looking at it - the Mesa code it is presumably based on should work, but the Chromium code has diverged since then in ways which look incorrect.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 41.3 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/**
8 * \mainpage OpenGL_stub
9 *
10 * \section OpenGL_stubIntroduction Introduction
11 *
12 * Chromium consists of all the top-level files in the cr
13 * directory. The OpenGL_stub module basically takes care of API dispatch,
14 * and OpenGL state management.
15 *
16 */
17
18/**
19 * This file manages OpenGL rendering contexts in the faker library.
20 * The big issue is switching between Chromium and native GL context
21 * management. This is where we support multiple client OpenGL
22 * windows. Typically, one window is handled by Chromium while any
23 * other windows are handled by the native OpenGL library.
24 */
25
26#include "chromium.h"
27#include "cr_error.h"
28#include "cr_spu.h"
29#include "cr_mem.h"
30#include "cr_string.h"
31#include "cr_environment.h"
32#include "stub.h"
33
34/**
35 * This function should be called from MakeCurrent(). It'll detect if
36 * we're in a multi-thread situation, and do the right thing for dispatch.
37 */
38#ifdef CHROMIUM_THREADSAFE
39 static void
40stubCheckMultithread( void )
41{
42 static unsigned long knownID;
43 static GLboolean firstCall = GL_TRUE;
44
45 if (stub.threadSafe)
46 return; /* nothing new, nothing to do */
47
48 if (firstCall) {
49 knownID = crThreadID();
50 firstCall = GL_FALSE;
51 }
52 else if (knownID != crThreadID()) {
53 /* going thread-safe now! */
54 stub.threadSafe = GL_TRUE;
55 crSPUCopyDispatchTable(&glim, &stubThreadsafeDispatch);
56 }
57}
58#endif
59
60
61/**
62 * Install the given dispatch table as the table used for all gl* calls.
63 */
64 static void
65stubSetDispatch( SPUDispatchTable *table )
66{
67 CRASSERT(table);
68
69#ifdef CHROMIUM_THREADSAFE
70 /* always set the per-thread dispatch pointer */
71 crSetTSD(&stub.dispatchTSD, (void *) table);
72 if (stub.threadSafe) {
73 /* Do nothing - the thread-safe dispatch functions will call GetTSD()
74 * to get a pointer to the dispatch table, and jump through it.
75 */
76 }
77 else
78#endif
79 {
80 /* Single thread mode - just install the caller's dispatch table */
81 /* This conditional is an optimization to try to avoid unnecessary
82 * copying. It seems to work with atlantis, multiwin, etc. but
83 * _could_ be a problem. (Brian)
84 */
85 if (glim.copy_of != table->copy_of)
86 crSPUCopyDispatchTable(&glim, table);
87 }
88}
89
90void stubForcedFlush(GLint con)
91{
92#if 0
93 GLint buffer;
94 stub.spu->dispatch_table.GetIntegerv(GL_DRAW_BUFFER, &buffer);
95 stub.spu->dispatch_table.DrawBuffer(GL_FRONT);
96 stub.spu->dispatch_table.Flush();
97 stub.spu->dispatch_table.DrawBuffer(buffer);
98#else
99 if (con)
100 {
101 stub.spu->dispatch_table.VBoxConFlush(con);
102 }
103 else
104 {
105 stub.spu->dispatch_table.Flush();
106 }
107#endif
108}
109
110void stubConChromiumParameteriCR(GLint con, GLenum param, GLint value)
111{
112// if (con)
113 stub.spu->dispatch_table.VBoxConChromiumParameteriCR(con, param, value);
114// else
115// crError("VBoxConChromiumParameteriCR called with null connection");
116}
117
118void stubConChromiumParametervCR(GLint con, GLenum target, GLenum type, GLsizei count, const GLvoid *values)
119{
120// if (con)
121 stub.spu->dispatch_table.VBoxConChromiumParametervCR(con, target, type, count, values);
122// else
123// crError("VBoxConChromiumParameteriCR called with null connection");
124}
125
126void stubConFlush(GLint con)
127{
128 if (con)
129 stub.spu->dispatch_table.VBoxConFlush(con);
130 else
131 crError("stubConFlush called with null connection");
132}
133
134static void stubWindowCleanupForContextsCB(unsigned long key, void *data1, void *data2)
135{
136 ContextInfo *context = (ContextInfo *) data1;
137 RT_NOREF(key);
138
139 CRASSERT(context);
140
141 if (context->currentDrawable == data2)
142 context->currentDrawable = NULL;
143}
144
145void stubDestroyWindow( GLint con, GLint window )
146{
147 WindowInfo *winInfo = (WindowInfo *)
148 crHashtableSearch(stub.windowTable, (unsigned int) window);
149 if (winInfo && winInfo->type == CHROMIUM && stub.spu)
150 {
151 crHashtableLock(stub.windowTable);
152
153 stub.spu->dispatch_table.VBoxWindowDestroy(con, winInfo->spuWindow );
154
155#ifdef WINDOWS
156 if (winInfo->hVisibleRegion != INVALID_HANDLE_VALUE)
157 {
158 DeleteObject(winInfo->hVisibleRegion);
159 }
160#elif defined(GLX)
161 if (winInfo->pVisibleRegions)
162 {
163 XFree(winInfo->pVisibleRegions);
164 }
165# ifdef CR_NEWWINTRACK
166 if (winInfo->syncDpy)
167 {
168 XCloseDisplay(winInfo->syncDpy);
169 }
170# endif
171#endif
172
173 stubForcedFlush(con);
174
175 crHashtableWalk(stub.contextTable, stubWindowCleanupForContextsCB, winInfo);
176
177 crHashtableDelete(stub.windowTable, window, crFree);
178
179 crHashtableUnlock(stub.windowTable);
180 }
181}
182
183/**
184 * Create a new _Chromium_ window, not GLX, WGL or CGL.
185 * Called by crWindowCreate() only.
186 */
187 GLint
188stubNewWindow( const char *dpyName, GLint visBits )
189{
190 WindowInfo *winInfo;
191 GLint spuWin, size[2];
192
193 spuWin = stub.spu->dispatch_table.WindowCreate( dpyName, visBits );
194 if (spuWin < 0) {
195 return -1;
196 }
197
198 winInfo = (WindowInfo *) crCalloc(sizeof(WindowInfo));
199 if (!winInfo) {
200 stub.spu->dispatch_table.WindowDestroy(spuWin);
201 return -1;
202 }
203
204 winInfo->type = CHROMIUM;
205
206 /* Ask the head SPU for the initial window size */
207 size[0] = size[1] = 0;
208 stub.spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, size);
209 if (size[0] == 0 && size[1] == 0) {
210 /* use some reasonable defaults */
211 size[0] = size[1] = 512;
212 }
213 winInfo->width = size[0];
214 winInfo->height = size[1];
215#ifdef VBOX_WITH_WDDM
216 if (stub.bRunningUnderWDDM)
217 {
218 crError("Should not be here: WindowCreate/Destroy & VBoxPackGetInjectID require connection id!");
219 winInfo->mapped = 0;
220 }
221 else
222#endif
223 {
224 winInfo->mapped = 1;
225 }
226
227 if (!dpyName)
228 dpyName = "";
229
230 crStrncpy(winInfo->dpyName, dpyName, MAX_DPY_NAME);
231 winInfo->dpyName[MAX_DPY_NAME-1] = 0;
232
233 /* Use spuWin as the hash table index and GLX/WGL handle */
234#ifdef WINDOWS
235 winInfo->drawable = (HDC) spuWin;
236 winInfo->hVisibleRegion = INVALID_HANDLE_VALUE;
237#elif defined(Darwin)
238 winInfo->drawable = (CGSWindowID) spuWin;
239#elif defined(GLX)
240 winInfo->drawable = (GLXDrawable) spuWin;
241 winInfo->pVisibleRegions = NULL;
242 winInfo->cVisibleRegions = 0;
243#endif
244#ifdef CR_NEWWINTRACK
245 winInfo->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID(0);
246#endif
247 winInfo->spuWindow = spuWin;
248
249 crHashtableAdd(stub.windowTable, (unsigned int) spuWin, winInfo);
250
251 return spuWin;
252}
253
254#ifdef GLX
255# if 0 /* unused */
256static XErrorHandler oldErrorHandler;
257static unsigned char lastXError = Success;
258
259static int
260errorHandler (Display *dpy, XErrorEvent *e)
261{
262 RT_NOREF(dpy);
263
264 lastXError = e->error_code;
265 return 0;
266}
267# endif /* unused */
268#endif
269
270GLboolean
271stubIsWindowVisible(WindowInfo *win)
272{
273#if defined(WINDOWS)
274# ifdef VBOX_WITH_WDDM
275 if (stub.bRunningUnderWDDM)
276 return win->mapped;
277# endif
278 return GL_TRUE;
279#elif defined(Darwin)
280 return GL_TRUE;
281#elif defined(GLX)
282 Display *dpy = stubGetWindowDisplay(win);
283 if (dpy)
284 {
285 XWindowAttributes attr;
286 XLOCK(dpy);
287 XGetWindowAttributes(dpy, win->drawable, &attr);
288 XUNLOCK(dpy);
289
290 if (attr.map_state == IsUnmapped)
291 {
292 return GL_FALSE;
293 }
294# if 1
295 return GL_TRUE;
296# else
297 if (attr.override_redirect)
298 {
299 return GL_TRUE;
300 }
301
302 if (!stub.bXExtensionsChecked)
303 {
304 stubCheckXExtensions(win);
305 }
306
307 if (!stub.bHaveXComposite)
308 {
309 return GL_TRUE;
310 }
311 else
312 {
313 Pixmap p;
314
315 crLockMutex(&stub.mutex);
316
317 XLOCK(dpy);
318 XSync(dpy, false);
319 oldErrorHandler = XSetErrorHandler(errorHandler);
320 /*@todo this will create new pixmap for window every call*/
321 p = XCompositeNameWindowPixmap(dpy, win->drawable);
322 XSync(dpy, false);
323 XSetErrorHandler(oldErrorHandler);
324 XUNLOCK(dpy);
325
326 switch (lastXError)
327 {
328 case Success:
329 XFreePixmap(dpy, p);
330 crUnlockMutex(&stub.mutex);
331 return GL_FALSE;
332 break;
333 case BadMatch:
334 /*Window isn't redirected*/
335 lastXError = Success;
336 break;
337 default:
338 crWarning("Unexpected XError %i", (int)lastXError);
339 lastXError = Success;
340 }
341
342 crUnlockMutex(&stub.mutex);
343
344 return GL_TRUE;
345 }
346# endif
347 }
348 else {
349 /* probably created by crWindowCreate() */
350 return win->mapped;
351 }
352#endif
353}
354
355
356/**
357 * Given a Windows HDC or GLX Drawable, return the corresponding
358 * WindowInfo structure. Create a new one if needed.
359 */
360WindowInfo *
361#ifdef WINDOWS
362 stubGetWindowInfo( HDC drawable )
363#elif defined(Darwin)
364 stubGetWindowInfo( CGSWindowID drawable )
365#elif defined(GLX)
366stubGetWindowInfo( Display *dpy, GLXDrawable drawable )
367#endif
368{
369#ifndef WINDOWS
370 WindowInfo *winInfo = (WindowInfo *) crHashtableSearch(stub.windowTable, (unsigned int) drawable);
371#else
372 WindowInfo *winInfo;
373 HWND hwnd;
374 hwnd = WindowFromDC(drawable);
375
376 if (!hwnd)
377 {
378 return NULL;
379 }
380
381 winInfo = (WindowInfo *) crHashtableSearch(stub.windowTable, (unsigned int) hwnd);
382#endif
383 if (!winInfo) {
384 winInfo = (WindowInfo *) crCalloc(sizeof(WindowInfo));
385 if (!winInfo)
386 return NULL;
387#ifdef GLX
388 crStrncpy(winInfo->dpyName, DisplayString(dpy), MAX_DPY_NAME);
389 winInfo->dpyName[MAX_DPY_NAME-1] = 0;
390 winInfo->dpy = dpy;
391 winInfo->pVisibleRegions = NULL;
392#elif defined(Darwin)
393 winInfo->connection = _CGSDefaultConnection(); // store our connection as default
394#elif defined(WINDOWS)
395 winInfo->hVisibleRegion = INVALID_HANDLE_VALUE;
396 winInfo->hWnd = hwnd;
397#endif
398 winInfo->drawable = drawable;
399 winInfo->type = UNDECIDED;
400 winInfo->spuWindow = -1;
401#ifdef VBOX_WITH_WDDM
402 if (stub.bRunningUnderWDDM)
403 winInfo->mapped = 0;
404 else
405#endif
406 {
407 winInfo->mapped = -1; /* don't know */
408 }
409 winInfo->pOwner = NULL;
410#ifdef CR_NEWWINTRACK
411 winInfo->u32ClientID = -1;
412#endif
413#ifndef WINDOWS
414 crHashtableAdd(stub.windowTable, (unsigned int) drawable, winInfo);
415#else
416 crHashtableAdd(stub.windowTable, (unsigned int) hwnd, winInfo);
417#endif
418 }
419#ifdef WINDOWS
420 else
421 {
422 winInfo->drawable = drawable;
423 }
424#endif
425 return winInfo;
426}
427
428static void stubWindowCheckOwnerCB(unsigned long key, void *data1, void *data2);
429
430static void
431stubContextFree( ContextInfo *context )
432{
433 crMemZero(context, sizeof(ContextInfo)); /* just to be safe */
434 crFree(context);
435}
436
437static void
438stubDestroyContextLocked( ContextInfo *context )
439{
440 unsigned long contextId = context->id;
441 if (context->type == NATIVE) {
442#ifdef WINDOWS
443 stub.wsInterface.wglDeleteContext( context->hglrc );
444#elif defined(Darwin)
445 stub.wsInterface.CGLDestroyContext( context->cglc );
446#elif defined(GLX)
447 stub.wsInterface.glXDestroyContext( context->dpy, context->glxContext );
448#endif
449 }
450 else if (context->type == CHROMIUM) {
451 /* Have pack SPU or tilesort SPU, etc. destroy the context */
452 CRASSERT(context->spuContext >= 0);
453 stub.spu->dispatch_table.DestroyContext( context->spuContext );
454 crHashtableWalk(stub.windowTable, stubWindowCheckOwnerCB, context);
455#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
456 if (context->spuConnection)
457 {
458 stub.spu->dispatch_table.VBoxConDestroy(context->spuConnection);
459 context->spuConnection = 0;
460 }
461#endif
462 }
463
464#ifdef GLX
465 crFreeHashtable(context->pGLXPixmapsHash, crFree);
466#endif
467
468 crHashtableDelete(stub.contextTable, contextId, NULL);
469}
470
471#ifdef CHROMIUM_THREADSAFE
472static DECLCALLBACK(void) stubContextDtor(void*pvContext)
473{
474 stubContextFree((ContextInfo*)pvContext);
475}
476#endif
477
478/**
479 * Allocate a new ContextInfo object, initialize it, put it into the
480 * context hash table. If type==CHROMIUM, call the head SPU's
481 * CreateContext() function too.
482 */
483 ContextInfo *
484stubNewContext(char *dpyName, GLint visBits, ContextType type, unsigned long shareCtx
485#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
486 , struct VBOXUHGSMI *pHgsmi
487#endif
488 )
489{
490 GLint spuContext = -1, spuShareCtx = 0, spuConnection = 0;
491 ContextInfo *context;
492
493 if (shareCtx > 0) {
494 /* translate shareCtx to a SPU context ID */
495 context = (ContextInfo *)
496 crHashtableSearch(stub.contextTable, shareCtx);
497 if (context)
498 spuShareCtx = context->spuContext;
499 }
500
501 if (type == CHROMIUM) {
502#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
503 if (pHgsmi)
504 {
505 spuConnection = stub.spu->dispatch_table.VBoxConCreate(pHgsmi);
506 if (!spuConnection)
507 {
508 crWarning("VBoxConCreate failed");
509 return NULL;
510 }
511 }
512#endif
513 spuContext
514 = stub.spu->dispatch_table.VBoxCreateContext(spuConnection, dpyName, visBits, spuShareCtx);
515 if (spuContext < 0)
516 {
517 crWarning("VBoxCreateContext failed");
518#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
519 if (spuConnection)
520 stub.spu->dispatch_table.VBoxConDestroy(spuConnection);
521#endif
522 return NULL;
523 }
524 }
525
526 context = crCalloc(sizeof(ContextInfo));
527 if (!context) {
528 stub.spu->dispatch_table.DestroyContext(spuContext);
529#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
530 if (spuConnection)
531 stub.spu->dispatch_table.VBoxConDestroy(spuConnection);
532#endif
533 return NULL;
534 }
535
536 if (!dpyName)
537 dpyName = "";
538
539 context->id = stub.freeContextNumber++;
540 context->type = type;
541 context->spuContext = spuContext;
542 context->visBits = visBits;
543 context->currentDrawable = NULL;
544 crStrncpy(context->dpyName, dpyName, MAX_DPY_NAME);
545 context->dpyName[MAX_DPY_NAME-1] = 0;
546
547#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
548 context->spuConnection = spuConnection;
549 context->pHgsmi = pHgsmi;
550#endif
551
552#ifdef CHROMIUM_THREADSAFE
553 VBoxTlsRefInit(context, stubContextDtor);
554#endif
555
556#if defined(GLX) || defined(DARWIN)
557 context->share = (ContextInfo *)
558 crHashtableSearch(stub.contextTable, (unsigned long) shareCtx);
559#endif
560
561#ifdef GLX
562 context->pGLXPixmapsHash = crAllocHashtable();
563 context->damageQueryFailed = GL_FALSE;
564 context->damageEventsBase = 0;
565#endif
566
567 crHashtableAdd(stub.contextTable, context->id, (void *) context);
568
569 return context;
570}
571
572
573#ifdef Darwin
574
575#define SET_ATTR(l,i,a) ( (l)[(i)++] = (a) )
576#define SET_ATTR_V(l,i,a,v) ( SET_ATTR(l,i,a), SET_ATTR(l,i,v) )
577
578void stubSetPFA( ContextInfo *ctx, CGLPixelFormatAttribute *attribs, int size, GLint *num ) {
579 GLuint visual = ctx->visBits;
580 int i = 0;
581
582 CRASSERT(visual & CR_RGB_BIT);
583
584 SET_ATTR_V(attribs, i, kCGLPFAColorSize, 8);
585
586 if( visual & CR_DEPTH_BIT )
587 SET_ATTR_V(attribs, i, kCGLPFADepthSize, 16);
588
589 if( visual & CR_ACCUM_BIT )
590 SET_ATTR_V(attribs, i, kCGLPFAAccumSize, 1);
591
592 if( visual & CR_STENCIL_BIT )
593 SET_ATTR_V(attribs, i, kCGLPFAStencilSize, 1);
594
595 if( visual & CR_ALPHA_BIT )
596 SET_ATTR_V(attribs, i, kCGLPFAAlphaSize, 1);
597
598 if( visual & CR_DOUBLE_BIT )
599 SET_ATTR(attribs, i, kCGLPFADoubleBuffer);
600
601 if( visual & CR_STEREO_BIT )
602 SET_ATTR(attribs, i, kCGLPFAStereo);
603
604/* SET_ATTR_V(attribs, i, kCGLPFASampleBuffers, 1);
605 SET_ATTR_V(attribs, i, kCGLPFASamples, 0);
606 SET_ATTR_V(attribs, i, kCGLPFADisplayMask, 0); */
607 SET_ATTR(attribs, i, kCGLPFABackingStore);
608 //SET_ATTR(attribs, i, kCGLPFAWindow); // kCGLPFAWindow deprecated starting from OSX 10.7
609 SET_ATTR_V(attribs, i, kCGLPFADisplayMask, ctx->disp_mask);
610
611 SET_ATTR(attribs, i, 0);
612
613 *num = i;
614}
615
616#endif
617
618#ifndef GLX
619/**
620 * This creates a native GLX/WGL context.
621 */
622static GLboolean
623InstantiateNativeContext( WindowInfo *window, ContextInfo *context )
624{
625#ifdef WINDOWS
626 context->hglrc = stub.wsInterface.wglCreateContext( window->drawable );
627 return context->hglrc ? GL_TRUE : GL_FALSE;
628#elif defined(Darwin)
629 CGLContextObj shareCtx = NULL;
630 CGLPixelFormatObj pix;
631 long npix;
632
633 CGLPixelFormatAttribute attribs[16];
634 GLint ind = 0;
635
636 if( context->share ) {
637 if( context->cglc != context->share->cglc ) {
638 crWarning("CGLCreateContext() is trying to share a non-existant "
639 "CGL context. Setting share context to zero.");
640 shareCtx = 0;
641 }
642 else
643 shareCtx = context->cglc;
644 }
645
646 stubSetPFA( context, attribs, 16, &ind );
647
648 stub.wsInterface.CGLChoosePixelFormat( attribs, &pix, &npix );
649 stub.wsInterface.CGLCreateContext( pix, shareCtx, &context->cglc );
650 if( !context->cglc )
651 crError("InstantiateNativeContext: Couldn't Create the context!");
652
653 stub.wsInterface.CGLDestroyPixelFormat( pix );
654
655 if( context->parambits ) {
656 /* Set the delayed parameters */
657 if( context->parambits & VISBIT_SWAP_RECT )
658 stub.wsInterface.CGLSetParameter( context->cglc, kCGLCPSwapRectangle, context->swap_rect );
659
660 if( context->parambits & VISBIT_SWAP_INTERVAL )
661 stub.wsInterface.CGLSetParameter( context->cglc, kCGLCPSwapInterval, &(context->swap_interval) );
662
663 if( context->parambits & VISBIT_CLIENT_STORAGE )
664 stub.wsInterface.CGLSetParameter( context->cglc, kCGLCPClientStorage, (long*)&(context->client_storage) );
665
666 context->parambits = 0;
667 }
668
669 return context->cglc ? GL_TRUE : GL_FALSE;
670#elif defined(GLX)
671 GLXContext shareCtx = 0;
672
673 /* sort out context sharing here */
674 if (context->share) {
675 if (context->glxContext != context->share->glxContext) {
676 crWarning("glXCreateContext() is trying to share a non-existant "
677 "GLX context. Setting share context to zero.");
678 shareCtx = 0;
679 }
680 else {
681 shareCtx = context->glxContext;
682 }
683 }
684
685 context->glxContext = stub.wsInterface.glXCreateContext( window->dpy,
686 context->visual, shareCtx, context->direct );
687
688 return context->glxContext ? GL_TRUE : GL_FALSE;
689#endif
690}
691#endif /* !GLX */
692
693
694/**
695 * Utility functions to get window size and titlebar text.
696 */
697#ifdef WINDOWS
698
699void
700stubGetWindowGeometry(WindowInfo *window, int *x, int *y,
701 unsigned int *w, unsigned int *h )
702{
703 RECT rect;
704
705 if (!window->drawable || !window->hWnd) {
706 *w = *h = 0;
707 return;
708 }
709
710 if (window->hWnd!=WindowFromDC(window->drawable))
711 {
712 crWarning("Window(%i) DC is no longer valid", window->spuWindow);
713 return;
714 }
715
716 if (!GetClientRect(window->hWnd, &rect))
717 {
718 crWarning("GetClientRect failed for %p", window->hWnd);
719 *w = *h = 0;
720 return;
721 }
722 *w = rect.right - rect.left;
723 *h = rect.bottom - rect.top;
724
725 if (!ClientToScreen( window->hWnd, (LPPOINT) &rect ))
726 {
727 crWarning("ClientToScreen failed for %p", window->hWnd);
728 *w = *h = 0;
729 return;
730 }
731 *x = rect.left;
732 *y = rect.top;
733}
734
735static void
736GetWindowTitle( const WindowInfo *window, char *title )
737{
738 /* XXX - we don't handle recurseUp */
739 if (window->hWnd)
740 GetWindowText(window->hWnd, title, 100);
741 else
742 title[0] = 0;
743}
744
745static void
746GetCursorPosition(WindowInfo *window, int pos[2])
747{
748 RECT rect;
749 POINT point;
750 GLint size[2], x, y;
751 unsigned int NativeHeight, NativeWidth, ChromiumHeight, ChromiumWidth;
752 float WidthRatio, HeightRatio;
753 static int DebugFlag = 0;
754
755 // apparently the "window" parameter passed to this
756 // function contains the native window information
757 HWND NATIVEhwnd = window->hWnd;
758
759 if (NATIVEhwnd!=WindowFromDC(window->drawable))
760 {
761 crWarning("Window(%i) DC is no longer valid", window->spuWindow);
762 return;
763 }
764
765 // get the native window's height and width
766 stubGetWindowGeometry(window, &x, &y, &NativeWidth, &NativeHeight);
767
768 // get the spu window's height and width
769 stub.spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, window->spuWindow, GL_INT, 2, size);
770 ChromiumWidth = size[0];
771 ChromiumHeight = size[1];
772
773 // get the ratio of the size of the native window to the cr window
774 WidthRatio = (float)ChromiumWidth / (float)NativeWidth;
775 HeightRatio = (float)ChromiumHeight / (float)NativeHeight;
776
777 // output some debug information at the beginning
778 if(DebugFlag)
779 {
780 DebugFlag = 0;
781 crDebug("Native Window Handle = %d", NATIVEhwnd);
782 crDebug("Native Width = %i", NativeWidth);
783 crDebug("Native Height = %i", NativeHeight);
784 crDebug("Chromium Width = %i", ChromiumWidth);
785 crDebug("Chromium Height = %i", ChromiumHeight);
786 }
787
788 if (NATIVEhwnd)
789 {
790 GetClientRect( NATIVEhwnd, &rect );
791 GetCursorPos (&point);
792
793 // make sure these coordinates are relative to the native window,
794 // not the whole desktop
795 ScreenToClient(NATIVEhwnd, &point);
796
797 // calculate the new position of the virtual cursor
798 pos[0] = (int)(point.x * WidthRatio);
799 pos[1] = (int)((NativeHeight - point.y) * HeightRatio);
800 }
801 else
802 {
803 pos[0] = 0;
804 pos[1] = 0;
805 }
806}
807
808#elif defined(Darwin)
809
810extern OSStatus CGSGetScreenRectForWindow( CGSConnectionID cid, CGSWindowID wid, float *outRect );
811extern OSStatus CGSGetWindowBounds( CGSConnectionID cid, CGSWindowID wid, float *bounds );
812
813void
814stubGetWindowGeometry( const WindowInfo *window, int *x, int *y, unsigned int *w, unsigned int *h )
815{
816 float rect[4];
817
818 if( !window ||
819 !window->connection ||
820 !window->drawable ||
821 CGSGetWindowBounds( window->connection, window->drawable, rect ) != noErr )
822 {
823 *x = *y = 0;
824 *w = *h = 0;
825 } else {
826 *x = (int) rect[0];
827 *y = (int) rect[1];
828 *w = (int) rect[2];
829 *h = (int) rect[3];
830 }
831}
832
833
834static void
835GetWindowTitle( const WindowInfo *window, char *title )
836{
837 /* XXX \todo Darwin window Title */
838 title[0] = '\0';
839}
840
841
842static void
843GetCursorPosition( const WindowInfo *window, int pos[2] )
844{
845 Point mouse_pos;
846 float window_rect[4];
847
848 GetMouse( &mouse_pos );
849 CGSGetScreenRectForWindow( window->connection, window->drawable, window_rect );
850
851 pos[0] = mouse_pos.h - (int) window_rect[0];
852 pos[1] = (int) window_rect[3] - (mouse_pos.v - (int) window_rect[1]);
853
854 /*crDebug( "%i %i", pos[0], pos[1] );*/
855}
856
857#elif defined(GLX)
858
859void
860stubGetWindowGeometry(WindowInfo *window, int *x, int *y, unsigned int *w, unsigned int *h)
861{
862 Window root, child;
863 unsigned int border, depth;
864 Display *dpy;
865
866 dpy = stubGetWindowDisplay(window);
867
868 //@todo: Performing those checks is expensive operation, especially for simple apps with high FPS.
869 // Disabling those triples glxgears fps, thus using xevents instead of per frame polling is much more preferred.
870 //@todo: Check similar on windows guests, though doubtful as there're no XSync like calls on windows.
871 if (window && dpy)
872 {
873 XLOCK(dpy);
874 }
875
876 if (!window
877 || !dpy
878 || !window->drawable
879 || !XGetGeometry(dpy, window->drawable, &root, x, y, w, h, &border, &depth)
880 || !XTranslateCoordinates(dpy, window->drawable, root, 0, 0, x, y, &child))
881 {
882 crWarning("Failed to get windows geometry for %p, try xwininfo", window);
883 *x = *y = 0;
884 *w = *h = 0;
885 }
886
887 if (window && dpy)
888 {
889 XUNLOCK(dpy);
890 }
891}
892
893static char *
894GetWindowTitleHelper( Display *dpy, Window window, GLboolean recurseUp )
895{
896 while (1) {
897 char *name;
898 if (!XFetchName(dpy, window, &name))
899 return NULL;
900 if (name[0]) {
901 return name;
902 }
903 else if (recurseUp) {
904 /* This window has no name, try the parent */
905 Status stat;
906 Window root, parent, *children;
907 unsigned int numChildren;
908 stat = XQueryTree( dpy, window, &root, &parent,
909 &children, &numChildren );
910 if (!stat || window == root)
911 return NULL;
912 if (children)
913 XFree(children);
914 window = parent;
915 }
916 else {
917 XFree(name);
918 return NULL;
919 }
920 }
921}
922
923static void
924GetWindowTitle( const WindowInfo *window, char *title )
925{
926 char *t = GetWindowTitleHelper(window->dpy, window->drawable, GL_TRUE);
927 if (t) {
928 crStrcpy(title, t);
929 XFree(t);
930 }
931 else {
932 title[0] = 0;
933 }
934}
935
936
937/**
938 *Return current cursor position in local window coords.
939 */
940static void
941GetCursorPosition(WindowInfo *window, int pos[2] )
942{
943 int rootX, rootY;
944 Window root, child;
945 unsigned int mask;
946 int x, y;
947
948 XLOCK(window->dpy);
949
950 Bool q = XQueryPointer(window->dpy, window->drawable, &root, &child,
951 &rootX, &rootY, &pos[0], &pos[1], &mask);
952 if (q) {
953 unsigned int w, h;
954 stubGetWindowGeometry( window, &x, &y, &w, &h );
955 /* invert Y */
956 pos[1] = (int) h - pos[1] - 1;
957 }
958 else {
959 pos[0] = pos[1] = 0;
960 }
961
962 XUNLOCK(window->dpy);
963}
964
965#endif
966
967
968/**
969 * This function is called by MakeCurrent() and determines whether or
970 * not a new rendering context should be bound to Chromium or the native
971 * OpenGL.
972 * \return GL_FALSE if native OpenGL should be used, or GL_TRUE if Chromium
973 * should be used.
974 */
975static GLboolean
976stubCheckUseChromium( WindowInfo *window )
977{
978 int x, y;
979 unsigned int w, h;
980
981 /* If the provided window is CHROMIUM, we're clearly intended
982 * to create a CHROMIUM context.
983 */
984 if (window->type == CHROMIUM)
985 return GL_TRUE;
986
987 if (stub.ignoreFreeglutMenus) {
988 const char *glutMenuTitle = "freeglut menu";
989 char title[1000];
990 GetWindowTitle(window, title);
991 if (crStrcmp(title, glutMenuTitle) == 0) {
992 crDebug("GL faker: Ignoring freeglut menu window");
993 return GL_FALSE;
994 }
995 }
996
997 /* If the user's specified a window count for Chromium, see if
998 * this window satisfies that criterium.
999 */
1000 stub.matchChromiumWindowCounter++;
1001 if (stub.matchChromiumWindowCount > 0) {
1002 if (stub.matchChromiumWindowCounter != stub.matchChromiumWindowCount) {
1003 crDebug("Using native GL, app window doesn't meet match_window_count");
1004 return GL_FALSE;
1005 }
1006 }
1007
1008 /* If the user's specified a window list to ignore, see if this
1009 * window satisfies that criterium.
1010 */
1011 if (stub.matchChromiumWindowID) {
1012 GLuint i;
1013
1014 for (i = 0; i <= stub.numIgnoreWindowID; i++) {
1015 if (stub.matchChromiumWindowID[i] == stub.matchChromiumWindowCounter) {
1016 crDebug("Ignore window ID %d, using native GL", stub.matchChromiumWindowID[i]);
1017 return GL_FALSE;
1018 }
1019 }
1020 }
1021
1022 /* If the user's specified a minimum window size for Chromium, see if
1023 * this window satisfies that criterium.
1024 */
1025 if (stub.minChromiumWindowWidth > 0 &&
1026 stub.minChromiumWindowHeight > 0) {
1027 stubGetWindowGeometry( window, &x, &y, &w, &h );
1028 if (w >= stub.minChromiumWindowWidth &&
1029 h >= stub.minChromiumWindowHeight) {
1030
1031 /* Check for maximum sized window now too */
1032 if (stub.maxChromiumWindowWidth &&
1033 stub.maxChromiumWindowHeight) {
1034 if (w < stub.maxChromiumWindowWidth &&
1035 h < stub.maxChromiumWindowHeight)
1036 return GL_TRUE;
1037 else
1038 return GL_FALSE;
1039 }
1040
1041 return GL_TRUE;
1042 }
1043 crDebug("Using native GL, app window doesn't meet minimum_window_size");
1044 return GL_FALSE;
1045 }
1046 else if (stub.matchWindowTitle) {
1047 /* If the user's specified a window title for Chromium, see if this
1048 * window satisfies that criterium.
1049 */
1050 GLboolean wildcard = GL_FALSE;
1051 char title[1000];
1052 char *titlePattern;
1053 int len;
1054 /* check for leading '*' wildcard */
1055 if (stub.matchWindowTitle[0] == '*') {
1056 titlePattern = crStrdup( stub.matchWindowTitle + 1 );
1057 wildcard = GL_TRUE;
1058 }
1059 else {
1060 titlePattern = crStrdup( stub.matchWindowTitle );
1061 }
1062 /* check for trailing '*' wildcard */
1063 len = crStrlen(titlePattern);
1064 if (len > 0 && titlePattern[len - 1] == '*') {
1065 titlePattern[len - 1] = '\0'; /* terminate here */
1066 wildcard = GL_TRUE;
1067 }
1068
1069 GetWindowTitle( window, title );
1070 if (title[0]) {
1071 if (wildcard) {
1072 if (crStrstr(title, titlePattern)) {
1073 crFree(titlePattern);
1074 return GL_TRUE;
1075 }
1076 }
1077 else if (crStrcmp(title, titlePattern) == 0) {
1078 crFree(titlePattern);
1079 return GL_TRUE;
1080 }
1081 }
1082 crFree(titlePattern);
1083 crDebug("Using native GL, app window title doesn't match match_window_title string (\"%s\" != \"%s\")", title, stub.matchWindowTitle);
1084 return GL_FALSE;
1085 }
1086
1087 /* Window title and size don't matter */
1088 CRASSERT(stub.minChromiumWindowWidth == 0);
1089 CRASSERT(stub.minChromiumWindowHeight == 0);
1090 CRASSERT(stub.matchWindowTitle == NULL);
1091
1092 /* User hasn't specified a width/height or window title.
1093 * We'll use chromium for this window (and context) if no other is.
1094 */
1095
1096 return GL_TRUE; /* use Chromium! */
1097}
1098
1099static void stubWindowCheckOwnerCB(unsigned long key, void *data1, void *data2)
1100{
1101 WindowInfo *pWindow = (WindowInfo *) data1;
1102 ContextInfo *pCtx = (ContextInfo *) data2;
1103
1104 RT_NOREF(key);
1105
1106
1107 if (pWindow->pOwner == pCtx)
1108 {
1109#ifdef WINDOWS
1110 /* Note: can't use WindowFromDC(context->pOwnWindow->drawable) here
1111 because GL context is already released from DC and actual guest window
1112 could be destroyed.
1113 */
1114 stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->hWnd);
1115#else
1116 stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->drawable);
1117#endif
1118 }
1119}
1120
1121GLboolean stubCtxCreate(ContextInfo *context)
1122{
1123 /*
1124 * Create a Chromium context.
1125 */
1126#if defined(GLX) || defined(DARWIN)
1127 GLint spuShareCtx = context->share ? context->share->spuContext : 0;
1128#else
1129 GLint spuShareCtx = 0;
1130#endif
1131 GLint spuConnection = 0;
1132 CRASSERT(stub.spu);
1133 CRASSERT(stub.spu->dispatch_table.CreateContext);
1134 context->type = CHROMIUM;
1135
1136#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
1137 if (context->pHgsmi)
1138 {
1139 spuConnection = stub.spu->dispatch_table.VBoxConCreate(context->pHgsmi);
1140 if (!spuConnection)
1141 {
1142 crError("VBoxConCreate failed");
1143 return GL_FALSE;
1144 }
1145 context->spuConnection = spuConnection;
1146 }
1147#endif
1148
1149 context->spuContext
1150 = stub.spu->dispatch_table.VBoxCreateContext(spuConnection, context->dpyName,
1151 context->visBits,
1152 spuShareCtx);
1153
1154 return GL_TRUE;
1155}
1156
1157GLboolean stubCtxCheckCreate(ContextInfo *context)
1158{
1159 if (context->type == UNDECIDED)
1160 return stubCtxCreate(context);
1161 return CHROMIUM == context->type;
1162}
1163
1164
1165GLboolean
1166stubMakeCurrent( WindowInfo *window, ContextInfo *context )
1167{
1168 GLboolean retVal = GL_FALSE;
1169
1170 /*
1171 * Get WindowInfo and ContextInfo pointers.
1172 */
1173
1174 if (!context || !window) {
1175 ContextInfo * currentContext = stubGetCurrentContext();
1176 if (currentContext)
1177 currentContext->currentDrawable = NULL;
1178 if (context)
1179 context->currentDrawable = NULL;
1180 stubSetCurrentContext(NULL);
1181 return GL_TRUE; /* OK */
1182 }
1183
1184#ifdef CHROMIUM_THREADSAFE
1185 stubCheckMultithread();
1186#endif
1187
1188 if (context->type == UNDECIDED) {
1189 /* Here's where we really create contexts */
1190#ifdef CHROMIUM_THREADSAFE
1191 crLockMutex(&stub.mutex);
1192#endif
1193
1194 if (stubCheckUseChromium(window)) {
1195 GLint spuConnection = 0;
1196
1197 if (!stubCtxCreate(context))
1198 {
1199 crWarning("stubCtxCreate failed");
1200 return GL_FALSE;
1201 }
1202
1203#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
1204 spuConnection = context->spuConnection;
1205#endif
1206
1207 if (window->spuWindow == -1)
1208 {
1209 /*crDebug("(1)stubMakeCurrent ctx=%p(%i) window=%p(%i)", context, context->spuContext, window, window->spuWindow);*/
1210 window->spuWindow = stub.spu->dispatch_table.VBoxWindowCreate(spuConnection, window->dpyName, context->visBits );
1211#ifdef CR_NEWWINTRACK
1212 window->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID(spuConnection);
1213#endif
1214 }
1215 }
1216#ifndef GLX
1217 else {
1218 /*
1219 * Create a native OpenGL context.
1220 */
1221 if (!InstantiateNativeContext(window, context))
1222 {
1223# ifdef CHROMIUM_THREADSAFE
1224 crUnlockMutex(&stub.mutex);
1225# endif
1226 return 0; /* false */
1227 }
1228 context->type = NATIVE;
1229 }
1230#endif /* !GLX */
1231
1232#ifdef CHROMIUM_THREADSAFE
1233 crUnlockMutex(&stub.mutex);
1234#endif
1235 }
1236
1237
1238 if (context->type == NATIVE) {
1239 /*
1240 * Native OpenGL MakeCurrent().
1241 */
1242#ifdef WINDOWS
1243 retVal = (GLboolean) stub.wsInterface.wglMakeCurrent( window->drawable, context->hglrc );
1244#elif defined(Darwin)
1245 // XXX \todo We need to differentiate between these two..
1246 retVal = ( stub.wsInterface.CGLSetSurface(context->cglc, window->connection, window->drawable, window->surface) == noErr );
1247 retVal = ( stub.wsInterface.CGLSetCurrentContext(context->cglc) == noErr );
1248#elif defined(GLX)
1249 retVal = (GLboolean) stub.wsInterface.glXMakeCurrent( window->dpy, window->drawable, context->glxContext );
1250#endif
1251 }
1252 else {
1253 /*
1254 * SPU chain MakeCurrent().
1255 */
1256 CRASSERT(context->type == CHROMIUM);
1257 CRASSERT(context->spuContext >= 0);
1258
1259 /*if (context->currentDrawable && context->currentDrawable != window)
1260 crDebug("Rebinding context %p to a different window", context);*/
1261
1262 if (window->type == NATIVE) {
1263 crWarning("Can't rebind a chromium context to a native window\n");
1264 retVal = 0;
1265 }
1266 else {
1267 if (window->spuWindow == -1)
1268 {
1269 /*crDebug("(2)stubMakeCurrent ctx=%p(%i) window=%p(%i)", context, context->spuContext, window, window->spuWindow);*/
1270 window->spuWindow = stub.spu->dispatch_table.VBoxWindowCreate(
1271#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
1272 context->spuConnection,
1273#else
1274 0,
1275#endif
1276 window->dpyName, context->visBits );
1277#ifdef CR_NEWWINTRACK
1278 window->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID(
1279# if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
1280 context->spuConnection
1281# else
1282 0
1283# endif
1284 );
1285#endif
1286 if (context->currentDrawable && context->currentDrawable->type==CHROMIUM
1287 && context->currentDrawable->pOwner==context)
1288 {
1289#ifdef WINDOWS
1290 if (context->currentDrawable->hWnd!=WindowFromDC(context->currentDrawable->drawable))
1291 {
1292 stubDestroyWindow(CR_CTX_CON(context), (GLint)context->currentDrawable->hWnd);
1293 }
1294#else
1295 Window root;
1296 int x, y;
1297 unsigned int border, depth, w, h;
1298
1299 XLOCK(context->currentDrawable->dpy);
1300 if (!XGetGeometry(context->currentDrawable->dpy, context->currentDrawable->drawable, &root, &x, &y, &w, &h, &border, &depth))
1301 {
1302 stubDestroyWindow(CR_CTX_CON(context), (GLint)context->currentDrawable->drawable);
1303 }
1304 XUNLOCK(context->currentDrawable->dpy);
1305#endif
1306
1307 }
1308 }
1309
1310 if (window->spuWindow != (GLint)window->drawable)
1311 stub.spu->dispatch_table.MakeCurrent( window->spuWindow, (GLint) window->drawable, context->spuContext );
1312 else
1313 stub.spu->dispatch_table.MakeCurrent( window->spuWindow, 0, /* native window handle */ context->spuContext );
1314
1315 retVal = 1;
1316 }
1317 }
1318
1319 window->type = context->type;
1320 window->pOwner = context;
1321 context->currentDrawable = window;
1322 stubSetCurrentContext(context);
1323
1324 if (retVal) {
1325 /* Now, if we've transitions from Chromium to native rendering, or
1326 * vice versa, we have to change all the OpenGL entrypoint pointers.
1327 */
1328 if (context->type == NATIVE) {
1329 /* Switch to native API */
1330 /*printf(" Switching to native API\n");*/
1331 stubSetDispatch(&stub.nativeDispatch);
1332 }
1333 else if (context->type == CHROMIUM) {
1334 /* Switch to stub (SPU) API */
1335 /*printf(" Switching to spu API\n");*/
1336 stubSetDispatch(&stub.spuDispatch);
1337 }
1338 else {
1339 /* no API switch needed */
1340 }
1341 }
1342
1343 if (!window->width && window->type == CHROMIUM) {
1344 /* One time window setup */
1345 int x, y;
1346 unsigned int winW, winH;
1347
1348 stubGetWindowGeometry( window, &x, &y, &winW, &winH );
1349
1350 /* If we're not using GLX/WGL (no app window) we'll always get
1351 * a width and height of zero here. In that case, skip the viewport
1352 * call since we're probably using a tilesort SPU with fake_window_dims
1353 * which the tilesort SPU will use for the viewport.
1354 */
1355 window->width = winW;
1356 window->height = winH;
1357#if defined(WINDOWS) && defined(VBOX_WITH_WDDM)
1358 if (stubIsWindowVisible(window))
1359#endif
1360 {
1361 if (stub.trackWindowSize)
1362 stub.spuDispatch.WindowSize( window->spuWindow, winW, winH );
1363 if (stub.trackWindowPos)
1364 stub.spuDispatch.WindowPosition(window->spuWindow, x, y);
1365 if (winW > 0 && winH > 0)
1366 stub.spu->dispatch_table.Viewport( 0, 0, winW, winH );
1367 }
1368#ifdef VBOX_WITH_WDDM
1369 if (stub.trackWindowVisibleRgn)
1370 stub.spu->dispatch_table.WindowVisibleRegion(window->spuWindow, 0, NULL);
1371#endif
1372 }
1373
1374 /* Update window mapping state.
1375 * Basically, this lets us hide render SPU windows which correspond
1376 * to unmapped application windows. Without this, "pertly" (for example)
1377 * opens *lots* of temporary windows which otherwise clutter the screen.
1378 */
1379 if (stub.trackWindowVisibility && window->type == CHROMIUM && window->drawable) {
1380 const int mapped = stubIsWindowVisible(window);
1381 if (mapped != window->mapped) {
1382 crDebug("Dispatched: WindowShow(%i, %i)", window->spuWindow, mapped);
1383 stub.spu->dispatch_table.WindowShow(window->spuWindow, mapped);
1384 window->mapped = mapped;
1385 }
1386 }
1387
1388 return retVal;
1389}
1390
1391void
1392stubDestroyContext( unsigned long contextId )
1393{
1394 ContextInfo *context;
1395
1396 if (!stub.contextTable) {
1397 return;
1398 }
1399
1400 /* the lock order is windowTable->contextTable (see wglMakeCurrent_prox, glXMakeCurrent)
1401 * this is why we need to take a windowTable lock since we will later do stub.windowTable access & locking */
1402 crHashtableLock(stub.windowTable);
1403 crHashtableLock(stub.contextTable);
1404
1405 context = (ContextInfo *) crHashtableSearch(stub.contextTable, contextId);
1406 if (context)
1407 stubDestroyContextLocked(context);
1408 else
1409 crError("No context.");
1410
1411#ifdef CHROMIUM_THREADSAFE
1412 if (stubGetCurrentContext() == context) {
1413 stubSetCurrentContext(NULL);
1414 }
1415
1416 VBoxTlsRefMarkDestroy(context);
1417 VBoxTlsRefRelease(context);
1418#else
1419 if (stubGetCurrentContext() == context) {
1420 stubSetCurrentContext(NULL);
1421 }
1422 stubContextFree(context);
1423#endif
1424 crHashtableUnlock(stub.contextTable);
1425 crHashtableUnlock(stub.windowTable);
1426}
1427
1428void
1429stubSwapBuffers(WindowInfo *window, GLint flags)
1430{
1431 if (!window)
1432 return;
1433
1434 /* Determine if this window is being rendered natively or through
1435 * Chromium.
1436 */
1437
1438 if (window->type == NATIVE) {
1439 /*printf("*** Swapping native window %d\n", (int) drawable);*/
1440#ifdef WINDOWS
1441 (void) stub.wsInterface.wglSwapBuffers( window->drawable );
1442#elif defined(Darwin)
1443 /* ...is this ok? */
1444/* stub.wsInterface.CGLFlushDrawable( context->cglc ); */
1445 crDebug("stubSwapBuffers: unable to swap (no context!)");
1446#elif defined(GLX)
1447 stub.wsInterface.glXSwapBuffers( window->dpy, window->drawable );
1448#endif
1449 }
1450 else if (window->type == CHROMIUM) {
1451 /* Let the SPU do the buffer swap */
1452 /*printf("*** Swapping chromium window %d\n", (int) drawable);*/
1453 if (stub.appDrawCursor) {
1454 int pos[2];
1455 GetCursorPosition(window, pos);
1456 stub.spu->dispatch_table.ChromiumParametervCR(GL_CURSOR_POSITION_CR, GL_INT, 2, pos);
1457 }
1458 stub.spu->dispatch_table.SwapBuffers( window->spuWindow, flags );
1459 }
1460 else {
1461 crDebug("Calling SwapBuffers on a window we haven't seen before (no-op).");
1462 }
1463}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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