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
|
---|
40 | stubCheckMultithread( 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
|
---|
65 | stubSetDispatch( 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 |
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Create a new _Chromium_ window, not GLX, WGL or CGL.
|
---|
93 | * Called by crWindowCreate() only.
|
---|
94 | */
|
---|
95 | GLint
|
---|
96 | stubNewWindow( const char *dpyName, GLint visBits )
|
---|
97 | {
|
---|
98 | WindowInfo *winInfo;
|
---|
99 | GLint spuWin, size[2];
|
---|
100 |
|
---|
101 | spuWin = stub.spu->dispatch_table.WindowCreate( dpyName, visBits );
|
---|
102 | if (spuWin < 0) {
|
---|
103 | return -1;
|
---|
104 | }
|
---|
105 |
|
---|
106 | winInfo = (WindowInfo *) crCalloc(sizeof(WindowInfo));
|
---|
107 | if (!winInfo) {
|
---|
108 | stub.spu->dispatch_table.WindowDestroy(spuWin);
|
---|
109 | return -1;
|
---|
110 | }
|
---|
111 |
|
---|
112 | winInfo->type = CHROMIUM;
|
---|
113 |
|
---|
114 | /* Ask the head SPU for the initial window size */
|
---|
115 | size[0] = size[1] = 0;
|
---|
116 | stub.spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, size);
|
---|
117 | if (size[0] == 0 && size[1] == 0) {
|
---|
118 | /* use some reasonable defaults */
|
---|
119 | size[0] = size[1] = 512;
|
---|
120 | }
|
---|
121 | winInfo->width = size[0];
|
---|
122 | winInfo->height = size[1];
|
---|
123 | winInfo->mapped = 1;
|
---|
124 |
|
---|
125 | if (!dpyName)
|
---|
126 | dpyName = "";
|
---|
127 |
|
---|
128 | crStrncpy(winInfo->dpyName, dpyName, MAX_DPY_NAME);
|
---|
129 | winInfo->dpyName[MAX_DPY_NAME-1] = 0;
|
---|
130 |
|
---|
131 | /* Use spuWin as the hash table index and GLX/WGL handle */
|
---|
132 | #ifdef WINDOWS
|
---|
133 | winInfo->drawable = (HDC) spuWin;
|
---|
134 | winInfo->hVisibleRegion = INVALID_HANDLE_VALUE;
|
---|
135 | #elif defined(Darwin)
|
---|
136 | winInfo->drawable = (CGSWindowID) spuWin;
|
---|
137 | #elif defined(GLX)
|
---|
138 | winInfo->drawable = (GLXDrawable) spuWin;
|
---|
139 | winInfo->pVisibleRegions = NULL;
|
---|
140 | winInfo->cVisibleRegions = 0;
|
---|
141 | #endif
|
---|
142 | #ifdef CR_NEWWINTRACK
|
---|
143 | winInfo->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID();
|
---|
144 | #endif
|
---|
145 | winInfo->spuWindow = spuWin;
|
---|
146 |
|
---|
147 | crHashtableAdd(stub.windowTable, (unsigned int) spuWin, winInfo);
|
---|
148 |
|
---|
149 | return spuWin;
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | GLboolean
|
---|
154 | stubIsWindowVisible(WindowInfo *win)
|
---|
155 | {
|
---|
156 | #if defined(WINDOWS)
|
---|
157 | return GL_TRUE;
|
---|
158 | #elif defined(Darwin)
|
---|
159 | return GL_TRUE;
|
---|
160 | #elif defined(GLX)
|
---|
161 | Display *dpy = stubGetWindowDisplay(win);
|
---|
162 | if (dpy)
|
---|
163 | {
|
---|
164 | XWindowAttributes attr;
|
---|
165 | XLOCK(dpy);
|
---|
166 | XGetWindowAttributes(dpy, win->drawable, &attr);
|
---|
167 | XUNLOCK(dpy);
|
---|
168 | return (attr.map_state != IsUnmapped);
|
---|
169 | }
|
---|
170 | else {
|
---|
171 | /* probably created by crWindowCreate() */
|
---|
172 | return win->mapped;
|
---|
173 | }
|
---|
174 | #endif
|
---|
175 | }
|
---|
176 |
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * Given a Windows HDC or GLX Drawable, return the corresponding
|
---|
180 | * WindowInfo structure. Create a new one if needed.
|
---|
181 | */
|
---|
182 | WindowInfo *
|
---|
183 | #ifdef WINDOWS
|
---|
184 | stubGetWindowInfo( HDC drawable )
|
---|
185 | #elif defined(Darwin)
|
---|
186 | stubGetWindowInfo( CGSWindowID drawable )
|
---|
187 | #elif defined(GLX)
|
---|
188 | stubGetWindowInfo( Display *dpy, GLXDrawable drawable )
|
---|
189 | #endif
|
---|
190 | {
|
---|
191 | #ifndef WINDOWS
|
---|
192 | WindowInfo *winInfo = (WindowInfo *) crHashtableSearch(stub.windowTable, (unsigned int) drawable);
|
---|
193 | #else
|
---|
194 | WindowInfo *winInfo;
|
---|
195 | HWND hwnd;
|
---|
196 | hwnd = WindowFromDC(drawable);
|
---|
197 |
|
---|
198 | if (!hwnd)
|
---|
199 | {
|
---|
200 | return NULL;
|
---|
201 | }
|
---|
202 |
|
---|
203 | winInfo = (WindowInfo *) crHashtableSearch(stub.windowTable, (unsigned int) hwnd);
|
---|
204 | #endif
|
---|
205 | if (!winInfo) {
|
---|
206 | winInfo = (WindowInfo *) crCalloc(sizeof(WindowInfo));
|
---|
207 | if (!winInfo)
|
---|
208 | return NULL;
|
---|
209 | #ifdef GLX
|
---|
210 | crStrncpy(winInfo->dpyName, DisplayString(dpy), MAX_DPY_NAME);
|
---|
211 | winInfo->dpyName[MAX_DPY_NAME-1] = 0;
|
---|
212 | winInfo->dpy = dpy;
|
---|
213 | winInfo->pVisibleRegions = NULL;
|
---|
214 | #elif defined(Darwin)
|
---|
215 | winInfo->connection = _CGSDefaultConnection(); // store our connection as default
|
---|
216 | #elif defined(WINDOWS)
|
---|
217 | winInfo->hVisibleRegion = INVALID_HANDLE_VALUE;
|
---|
218 | winInfo->hWnd = hwnd;
|
---|
219 | #endif
|
---|
220 | winInfo->drawable = drawable;
|
---|
221 | winInfo->type = UNDECIDED;
|
---|
222 | winInfo->spuWindow = -1;
|
---|
223 | winInfo->mapped = -1; /* don't know */
|
---|
224 | winInfo->pOwner = NULL;
|
---|
225 | #ifdef CR_NEWWINTRACK
|
---|
226 | winInfo->u32ClientID = -1;
|
---|
227 | #endif
|
---|
228 | #ifndef WINDOWS
|
---|
229 | crHashtableAdd(stub.windowTable, (unsigned int) drawable, winInfo);
|
---|
230 | #else
|
---|
231 | crHashtableAdd(stub.windowTable, (unsigned int) hwnd, winInfo);
|
---|
232 | #endif
|
---|
233 | }
|
---|
234 | return winInfo;
|
---|
235 | }
|
---|
236 |
|
---|
237 |
|
---|
238 | /**
|
---|
239 | * Allocate a new ContextInfo object, initialize it, put it into the
|
---|
240 | * context hash table. If type==CHROMIUM, call the head SPU's
|
---|
241 | * CreateContext() function too.
|
---|
242 | */
|
---|
243 | ContextInfo *
|
---|
244 | stubNewContext( const char *dpyName, GLint visBits, ContextType type,
|
---|
245 | unsigned long shareCtx )
|
---|
246 | {
|
---|
247 | GLint spuContext = -1, spuShareCtx = 0;
|
---|
248 | ContextInfo *context;
|
---|
249 |
|
---|
250 | if (shareCtx > 0) {
|
---|
251 | /* translate shareCtx to a SPU context ID */
|
---|
252 | context = (ContextInfo *)
|
---|
253 | crHashtableSearch(stub.contextTable, shareCtx);
|
---|
254 | if (context)
|
---|
255 | spuShareCtx = context->spuContext;
|
---|
256 | }
|
---|
257 |
|
---|
258 | if (type == CHROMIUM) {
|
---|
259 | spuContext
|
---|
260 | = stub.spu->dispatch_table.CreateContext(dpyName, visBits, spuShareCtx);
|
---|
261 | if (spuContext < 0)
|
---|
262 | return NULL;
|
---|
263 | }
|
---|
264 |
|
---|
265 | context = crCalloc(sizeof(ContextInfo));
|
---|
266 | if (!context) {
|
---|
267 | stub.spu->dispatch_table.DestroyContext(spuContext);
|
---|
268 | return NULL;
|
---|
269 | }
|
---|
270 |
|
---|
271 | if (!dpyName)
|
---|
272 | dpyName = "";
|
---|
273 |
|
---|
274 | context->id = stub.freeContextNumber++;
|
---|
275 | context->type = type;
|
---|
276 | context->spuContext = spuContext;
|
---|
277 | context->visBits = visBits;
|
---|
278 | context->currentDrawable = NULL;
|
---|
279 | crStrncpy(context->dpyName, dpyName, MAX_DPY_NAME);
|
---|
280 | context->dpyName[MAX_DPY_NAME-1] = 0;
|
---|
281 |
|
---|
282 | #if defined(GLX) || defined(DARWIN)
|
---|
283 | context->share = (ContextInfo *)
|
---|
284 | crHashtableSearch(stub.contextTable, (unsigned long) shareCtx);
|
---|
285 | #endif
|
---|
286 |
|
---|
287 | #ifdef GLX
|
---|
288 | context->pGLXPixmapsHash = crAllocHashtable();
|
---|
289 | context->damageInitFailed = GL_FALSE;
|
---|
290 | context->damageDpy = NULL;
|
---|
291 | context->damageEventsBase = 0;
|
---|
292 | #endif
|
---|
293 |
|
---|
294 | crHashtableAdd(stub.contextTable, context->id, (void *) context);
|
---|
295 |
|
---|
296 | return context;
|
---|
297 | }
|
---|
298 |
|
---|
299 |
|
---|
300 | #ifdef Darwin
|
---|
301 |
|
---|
302 | #define SET_ATTR(l,i,a) ( (l)[(i)++] = (a) )
|
---|
303 | #define SET_ATTR_V(l,i,a,v) ( SET_ATTR(l,i,a), SET_ATTR(l,i,v) )
|
---|
304 |
|
---|
305 | void stubSetPFA( ContextInfo *ctx, CGLPixelFormatAttribute *attribs, int size, GLint *num ) {
|
---|
306 | GLuint visual = ctx->visBits;
|
---|
307 | int i = 0;
|
---|
308 |
|
---|
309 | CRASSERT(visual & CR_RGB_BIT);
|
---|
310 |
|
---|
311 | SET_ATTR_V(attribs, i, kCGLPFAColorSize, 8);
|
---|
312 |
|
---|
313 | if( visual & CR_DEPTH_BIT )
|
---|
314 | SET_ATTR_V(attribs, i, kCGLPFADepthSize, 16);
|
---|
315 |
|
---|
316 | if( visual & CR_ACCUM_BIT )
|
---|
317 | SET_ATTR_V(attribs, i, kCGLPFAAccumSize, 1);
|
---|
318 |
|
---|
319 | if( visual & CR_STENCIL_BIT )
|
---|
320 | SET_ATTR_V(attribs, i, kCGLPFAStencilSize, 1);
|
---|
321 |
|
---|
322 | if( visual & CR_ALPHA_BIT )
|
---|
323 | SET_ATTR_V(attribs, i, kCGLPFAAlphaSize, 1);
|
---|
324 |
|
---|
325 | if( visual & CR_DOUBLE_BIT )
|
---|
326 | SET_ATTR(attribs, i, kCGLPFADoubleBuffer);
|
---|
327 |
|
---|
328 | if( visual & CR_STEREO_BIT )
|
---|
329 | SET_ATTR(attribs, i, kCGLPFAStereo);
|
---|
330 |
|
---|
331 | /* SET_ATTR_V(attribs, i, kCGLPFASampleBuffers, 1);
|
---|
332 | SET_ATTR_V(attribs, i, kCGLPFASamples, 0);
|
---|
333 | SET_ATTR_V(attribs, i, kCGLPFADisplayMask, 0); */
|
---|
334 | SET_ATTR(attribs, i, kCGLPFABackingStore);
|
---|
335 | SET_ATTR(attribs, i, kCGLPFAWindow);
|
---|
336 | SET_ATTR_V(attribs, i, kCGLPFADisplayMask, ctx->disp_mask);
|
---|
337 |
|
---|
338 | SET_ATTR(attribs, i, 0);
|
---|
339 |
|
---|
340 | *num = i;
|
---|
341 | }
|
---|
342 |
|
---|
343 | #endif
|
---|
344 |
|
---|
345 | /**
|
---|
346 | * This creates a native GLX/WGL context.
|
---|
347 | */
|
---|
348 | static GLboolean
|
---|
349 | InstantiateNativeContext( WindowInfo *window, ContextInfo *context )
|
---|
350 | {
|
---|
351 | #ifdef WINDOWS
|
---|
352 | context->hglrc = stub.wsInterface.wglCreateContext( window->drawable );
|
---|
353 | return context->hglrc ? GL_TRUE : GL_FALSE;
|
---|
354 | #elif defined(Darwin)
|
---|
355 | CGLContextObj shareCtx = NULL;
|
---|
356 | CGLPixelFormatObj pix;
|
---|
357 | long npix;
|
---|
358 |
|
---|
359 | CGLPixelFormatAttribute attribs[16];
|
---|
360 | GLint ind = 0;
|
---|
361 |
|
---|
362 | if( context->share ) {
|
---|
363 | if( context->cglc != context->share->cglc ) {
|
---|
364 | crWarning("CGLCreateContext() is trying to share a non-existant "
|
---|
365 | "CGL context. Setting share context to zero.");
|
---|
366 | shareCtx = 0;
|
---|
367 | }
|
---|
368 | else
|
---|
369 | shareCtx = context->cglc;
|
---|
370 | }
|
---|
371 |
|
---|
372 | stubSetPFA( context, attribs, 16, &ind );
|
---|
373 |
|
---|
374 | stub.wsInterface.CGLChoosePixelFormat( attribs, &pix, &npix );
|
---|
375 | stub.wsInterface.CGLCreateContext( pix, shareCtx, &context->cglc );
|
---|
376 | if( !context->cglc )
|
---|
377 | crError("InstantiateNativeContext: Couldn't Create the context!");
|
---|
378 |
|
---|
379 | stub.wsInterface.CGLDestroyPixelFormat( pix );
|
---|
380 |
|
---|
381 | if( context->parambits ) {
|
---|
382 | /* Set the delayed parameters */
|
---|
383 | if( context->parambits & VISBIT_SWAP_RECT )
|
---|
384 | stub.wsInterface.CGLSetParameter( context->cglc, kCGLCPSwapRectangle, context->swap_rect );
|
---|
385 |
|
---|
386 | if( context->parambits & VISBIT_SWAP_INTERVAL )
|
---|
387 | stub.wsInterface.CGLSetParameter( context->cglc, kCGLCPSwapInterval, &(context->swap_interval) );
|
---|
388 |
|
---|
389 | if( context->parambits & VISBIT_CLIENT_STORAGE )
|
---|
390 | stub.wsInterface.CGLSetParameter( context->cglc, kCGLCPClientStorage, (long*)&(context->client_storage) );
|
---|
391 |
|
---|
392 | context->parambits = 0;
|
---|
393 | }
|
---|
394 |
|
---|
395 | return context->cglc ? GL_TRUE : GL_FALSE;
|
---|
396 | #elif defined(GLX)
|
---|
397 | GLXContext shareCtx = 0;
|
---|
398 |
|
---|
399 | /* sort out context sharing here */
|
---|
400 | if (context->share) {
|
---|
401 | if (context->glxContext != context->share->glxContext) {
|
---|
402 | crWarning("glXCreateContext() is trying to share a non-existant "
|
---|
403 | "GLX context. Setting share context to zero.");
|
---|
404 | shareCtx = 0;
|
---|
405 | }
|
---|
406 | else {
|
---|
407 | shareCtx = context->glxContext;
|
---|
408 | }
|
---|
409 | }
|
---|
410 |
|
---|
411 | context->glxContext = stub.wsInterface.glXCreateContext( window->dpy,
|
---|
412 | context->visual, shareCtx, context->direct );
|
---|
413 |
|
---|
414 | return context->glxContext ? GL_TRUE : GL_FALSE;
|
---|
415 | #endif
|
---|
416 | }
|
---|
417 |
|
---|
418 |
|
---|
419 | /**
|
---|
420 | * Utility functions to get window size and titlebar text.
|
---|
421 | */
|
---|
422 | #ifdef WINDOWS
|
---|
423 |
|
---|
424 | void
|
---|
425 | stubGetWindowGeometry( const WindowInfo *window, int *x, int *y,
|
---|
426 | unsigned int *w, unsigned int *h )
|
---|
427 | {
|
---|
428 | RECT rect;
|
---|
429 | HWND hwnd;
|
---|
430 |
|
---|
431 | if (!window->drawable) {
|
---|
432 | *w = *h = 0;
|
---|
433 | return;
|
---|
434 | }
|
---|
435 |
|
---|
436 | hwnd = WindowFromDC( window->drawable );
|
---|
437 |
|
---|
438 | if (!hwnd) {
|
---|
439 | *w = 0;
|
---|
440 | *h = 0;
|
---|
441 | }
|
---|
442 | else {
|
---|
443 | GetClientRect( hwnd, &rect );
|
---|
444 | *w = rect.right - rect.left;
|
---|
445 | *h = rect.bottom - rect.top;
|
---|
446 | ClientToScreen( hwnd, (LPPOINT) &rect );
|
---|
447 | *x = rect.left;
|
---|
448 | *y = rect.top;
|
---|
449 | }
|
---|
450 | }
|
---|
451 |
|
---|
452 | static void
|
---|
453 | GetWindowTitle( const WindowInfo *window, char *title )
|
---|
454 | {
|
---|
455 | HWND hwnd;
|
---|
456 | /* XXX - we don't handle recurseUp */
|
---|
457 | hwnd = WindowFromDC( window->drawable );
|
---|
458 | if (hwnd)
|
---|
459 | GetWindowText(hwnd, title, 100);
|
---|
460 | else
|
---|
461 | title[0] = 0;
|
---|
462 | }
|
---|
463 |
|
---|
464 | static void
|
---|
465 | GetCursorPosition(WindowInfo *window, int pos[2])
|
---|
466 | {
|
---|
467 | RECT rect;
|
---|
468 | POINT point;
|
---|
469 | GLint size[2], x, y;
|
---|
470 | unsigned int NativeHeight, NativeWidth, ChromiumHeight, ChromiumWidth;
|
---|
471 | float WidthRatio, HeightRatio;
|
---|
472 | static int DebugFlag = 0;
|
---|
473 |
|
---|
474 | // apparently the "window" parameter passed to this
|
---|
475 | // function contains the native window information
|
---|
476 | HWND NATIVEhwnd = WindowFromDC( window->drawable );
|
---|
477 |
|
---|
478 | // get the native window's height and width
|
---|
479 | stubGetWindowGeometry(window, &x, &y, &NativeWidth, &NativeHeight);
|
---|
480 |
|
---|
481 | // get the spu window's height and width
|
---|
482 | stub.spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, window->spuWindow, GL_INT, 2, size);
|
---|
483 | ChromiumWidth = size[0];
|
---|
484 | ChromiumHeight = size[1];
|
---|
485 |
|
---|
486 | // get the ratio of the size of the native window to the cr window
|
---|
487 | WidthRatio = (float)ChromiumWidth / (float)NativeWidth;
|
---|
488 | HeightRatio = (float)ChromiumHeight / (float)NativeHeight;
|
---|
489 |
|
---|
490 | // output some debug information at the beginning
|
---|
491 | if(DebugFlag)
|
---|
492 | {
|
---|
493 | DebugFlag = 0;
|
---|
494 | crDebug("Native Window Handle = %d", NATIVEhwnd);
|
---|
495 | crDebug("Native Width = %i", NativeWidth);
|
---|
496 | crDebug("Native Height = %i", NativeHeight);
|
---|
497 | crDebug("Chromium Width = %i", ChromiumWidth);
|
---|
498 | crDebug("Chromium Height = %i", ChromiumHeight);
|
---|
499 | }
|
---|
500 |
|
---|
501 | if (NATIVEhwnd)
|
---|
502 | {
|
---|
503 | GetClientRect( NATIVEhwnd, &rect );
|
---|
504 | GetCursorPos (&point);
|
---|
505 |
|
---|
506 | // make sure these coordinates are relative to the native window,
|
---|
507 | // not the whole desktop
|
---|
508 | ScreenToClient(NATIVEhwnd, &point);
|
---|
509 |
|
---|
510 | // calculate the new position of the virtual cursor
|
---|
511 | pos[0] = (int)(point.x * WidthRatio);
|
---|
512 | pos[1] = (int)((NativeHeight - point.y) * HeightRatio);
|
---|
513 | }
|
---|
514 | else
|
---|
515 | {
|
---|
516 | pos[0] = 0;
|
---|
517 | pos[1] = 0;
|
---|
518 | }
|
---|
519 | }
|
---|
520 |
|
---|
521 | #elif defined(Darwin)
|
---|
522 |
|
---|
523 | extern OSStatus CGSGetScreenRectForWindow( CGSConnectionID cid, CGSWindowID wid, float *outRect );
|
---|
524 | extern OSStatus CGSGetWindowBounds( CGSConnectionID cid, CGSWindowID wid, float *bounds );
|
---|
525 |
|
---|
526 | void
|
---|
527 | stubGetWindowGeometry( const WindowInfo *window, int *x, int *y, unsigned int *w, unsigned int *h )
|
---|
528 | {
|
---|
529 | float rect[4];
|
---|
530 |
|
---|
531 | if( !window ||
|
---|
532 | !window->connection ||
|
---|
533 | !window->drawable ||
|
---|
534 | CGSGetWindowBounds( window->connection, window->drawable, rect ) != noErr )
|
---|
535 | {
|
---|
536 | *x = *y = 0;
|
---|
537 | *w = *h = 0;
|
---|
538 | } else {
|
---|
539 | *x = (int) rect[0];
|
---|
540 | *y = (int) rect[1];
|
---|
541 | *w = (int) rect[2];
|
---|
542 | *h = (int) rect[3];
|
---|
543 | }
|
---|
544 | }
|
---|
545 |
|
---|
546 |
|
---|
547 | static void
|
---|
548 | GetWindowTitle( const WindowInfo *window, char *title )
|
---|
549 | {
|
---|
550 | /* XXX \todo Darwin window Title */
|
---|
551 | title[0] = '\0';
|
---|
552 | }
|
---|
553 |
|
---|
554 |
|
---|
555 | static void
|
---|
556 | GetCursorPosition( const WindowInfo *window, int pos[2] )
|
---|
557 | {
|
---|
558 | Point mouse_pos;
|
---|
559 | float window_rect[4];
|
---|
560 |
|
---|
561 | GetMouse( &mouse_pos );
|
---|
562 | CGSGetScreenRectForWindow( window->connection, window->drawable, window_rect );
|
---|
563 |
|
---|
564 | pos[0] = mouse_pos.h - (int) window_rect[0];
|
---|
565 | pos[1] = (int) window_rect[3] - (mouse_pos.v - (int) window_rect[1]);
|
---|
566 |
|
---|
567 | /*crDebug( "%i %i", pos[0], pos[1] );*/
|
---|
568 | }
|
---|
569 |
|
---|
570 | #elif defined(GLX)
|
---|
571 |
|
---|
572 | void
|
---|
573 | stubGetWindowGeometry(WindowInfo *window, int *x, int *y, unsigned int *w, unsigned int *h)
|
---|
574 | {
|
---|
575 | Window root, child;
|
---|
576 | unsigned int border, depth;
|
---|
577 | Display *dpy;
|
---|
578 |
|
---|
579 | dpy = stubGetWindowDisplay(window);
|
---|
580 |
|
---|
581 | //@todo: Performing those checks is expensive operation, especially for simple apps with high FPS.
|
---|
582 | // Disabling those tripples glxgears fps, thus using xevens instead of per frame polling is much more preffered.
|
---|
583 | //@todo: Check similiar on windows guests, though doubtfull as there're no XSync like calls on windows.
|
---|
584 | if (window && dpy)
|
---|
585 | {
|
---|
586 | XLOCK(dpy);
|
---|
587 | }
|
---|
588 |
|
---|
589 | if (!window
|
---|
590 | || !dpy
|
---|
591 | || !window->drawable
|
---|
592 | || !XGetGeometry(dpy, window->drawable, &root, x, y, w, h, &border, &depth)
|
---|
593 | || !XTranslateCoordinates(dpy, window->drawable, root, 0, 0, x, y, &child))
|
---|
594 | {
|
---|
595 | crWarning("Failed to get windows geometry for %p, try xwininfo", window);
|
---|
596 | *x = *y = 0;
|
---|
597 | *w = *h = 0;
|
---|
598 | }
|
---|
599 |
|
---|
600 | if (window && dpy)
|
---|
601 | {
|
---|
602 | XUNLOCK(dpy);
|
---|
603 | }
|
---|
604 | }
|
---|
605 |
|
---|
606 | static char *
|
---|
607 | GetWindowTitleHelper( Display *dpy, Window window, GLboolean recurseUp )
|
---|
608 | {
|
---|
609 | while (1) {
|
---|
610 | char *name;
|
---|
611 | if (!XFetchName(dpy, window, &name))
|
---|
612 | return NULL;
|
---|
613 | if (name[0]) {
|
---|
614 | return name;
|
---|
615 | }
|
---|
616 | else if (recurseUp) {
|
---|
617 | /* This window has no name, try the parent */
|
---|
618 | Status stat;
|
---|
619 | Window root, parent, *children;
|
---|
620 | unsigned int numChildren;
|
---|
621 | stat = XQueryTree( dpy, window, &root, &parent,
|
---|
622 | &children, &numChildren );
|
---|
623 | if (!stat || window == root)
|
---|
624 | return NULL;
|
---|
625 | if (children)
|
---|
626 | XFree(children);
|
---|
627 | window = parent;
|
---|
628 | }
|
---|
629 | else {
|
---|
630 | XFree(name);
|
---|
631 | return NULL;
|
---|
632 | }
|
---|
633 | }
|
---|
634 | }
|
---|
635 |
|
---|
636 | static void
|
---|
637 | GetWindowTitle( const WindowInfo *window, char *title )
|
---|
638 | {
|
---|
639 | char *t = GetWindowTitleHelper(window->dpy, window->drawable, GL_TRUE);
|
---|
640 | if (t) {
|
---|
641 | crStrcpy(title, t);
|
---|
642 | XFree(t);
|
---|
643 | }
|
---|
644 | else {
|
---|
645 | title[0] = 0;
|
---|
646 | }
|
---|
647 | }
|
---|
648 |
|
---|
649 |
|
---|
650 | /**
|
---|
651 | *Return current cursor position in local window coords.
|
---|
652 | */
|
---|
653 | static void
|
---|
654 | GetCursorPosition(WindowInfo *window, int pos[2] )
|
---|
655 | {
|
---|
656 | int rootX, rootY;
|
---|
657 | Window root, child;
|
---|
658 | unsigned int mask;
|
---|
659 | int x, y;
|
---|
660 |
|
---|
661 | XLOCK(window->dpy);
|
---|
662 |
|
---|
663 | Bool q = XQueryPointer(window->dpy, window->drawable, &root, &child,
|
---|
664 | &rootX, &rootY, &pos[0], &pos[1], &mask);
|
---|
665 | if (q) {
|
---|
666 | unsigned int w, h;
|
---|
667 | stubGetWindowGeometry( window, &x, &y, &w, &h );
|
---|
668 | /* invert Y */
|
---|
669 | pos[1] = (int) h - pos[1] - 1;
|
---|
670 | }
|
---|
671 | else {
|
---|
672 | pos[0] = pos[1] = 0;
|
---|
673 | }
|
---|
674 |
|
---|
675 | XUNLOCK(window->dpy);
|
---|
676 | }
|
---|
677 |
|
---|
678 | #endif
|
---|
679 |
|
---|
680 |
|
---|
681 | /**
|
---|
682 | * This function is called by MakeCurrent() and determines whether or
|
---|
683 | * not a new rendering context should be bound to Chromium or the native
|
---|
684 | * OpenGL.
|
---|
685 | * \return GL_FALSE if native OpenGL should be used, or GL_TRUE if Chromium
|
---|
686 | * should be used.
|
---|
687 | */
|
---|
688 | static GLboolean
|
---|
689 | stubCheckUseChromium( WindowInfo *window )
|
---|
690 | {
|
---|
691 | int x, y;
|
---|
692 | unsigned int w, h;
|
---|
693 |
|
---|
694 | /* If the provided window is CHROMIUM, we're clearly intended
|
---|
695 | * to create a CHROMIUM context.
|
---|
696 | */
|
---|
697 | if (window->type == CHROMIUM)
|
---|
698 | return GL_TRUE;
|
---|
699 |
|
---|
700 | if (stub.ignoreFreeglutMenus) {
|
---|
701 | const char *glutMenuTitle = "freeglut menu";
|
---|
702 | char title[1000];
|
---|
703 | GetWindowTitle(window, title);
|
---|
704 | if (crStrcmp(title, glutMenuTitle) == 0) {
|
---|
705 | crDebug("GL faker: Ignoring freeglut menu window");
|
---|
706 | return GL_FALSE;
|
---|
707 | }
|
---|
708 | }
|
---|
709 |
|
---|
710 | /* If the user's specified a window count for Chromium, see if
|
---|
711 | * this window satisfies that criterium.
|
---|
712 | */
|
---|
713 | stub.matchChromiumWindowCounter++;
|
---|
714 | if (stub.matchChromiumWindowCount > 0) {
|
---|
715 | if (stub.matchChromiumWindowCounter != stub.matchChromiumWindowCount) {
|
---|
716 | crDebug("Using native GL, app window doesn't meet match_window_count");
|
---|
717 | return GL_FALSE;
|
---|
718 | }
|
---|
719 | }
|
---|
720 |
|
---|
721 | /* If the user's specified a window list to ignore, see if this
|
---|
722 | * window satisfies that criterium.
|
---|
723 | */
|
---|
724 | if (stub.matchChromiumWindowID) {
|
---|
725 | GLuint i;
|
---|
726 |
|
---|
727 | for (i = 0; i <= stub.numIgnoreWindowID; i++) {
|
---|
728 | if (stub.matchChromiumWindowID[i] == stub.matchChromiumWindowCounter) {
|
---|
729 | crDebug("Ignore window ID %d, using native GL", stub.matchChromiumWindowID[i]);
|
---|
730 | return GL_FALSE;
|
---|
731 | }
|
---|
732 | }
|
---|
733 | }
|
---|
734 |
|
---|
735 | /* If the user's specified a minimum window size for Chromium, see if
|
---|
736 | * this window satisfies that criterium.
|
---|
737 | */
|
---|
738 | if (stub.minChromiumWindowWidth > 0 &&
|
---|
739 | stub.minChromiumWindowHeight > 0) {
|
---|
740 | stubGetWindowGeometry( window, &x, &y, &w, &h );
|
---|
741 | if (w >= stub.minChromiumWindowWidth &&
|
---|
742 | h >= stub.minChromiumWindowHeight) {
|
---|
743 |
|
---|
744 | /* Check for maximum sized window now too */
|
---|
745 | if (stub.maxChromiumWindowWidth &&
|
---|
746 | stub.maxChromiumWindowHeight) {
|
---|
747 | if (w < stub.maxChromiumWindowWidth &&
|
---|
748 | h < stub.maxChromiumWindowHeight)
|
---|
749 | return GL_TRUE;
|
---|
750 | else
|
---|
751 | return GL_FALSE;
|
---|
752 | }
|
---|
753 |
|
---|
754 | return GL_TRUE;
|
---|
755 | }
|
---|
756 | crDebug("Using native GL, app window doesn't meet minimum_window_size");
|
---|
757 | return GL_FALSE;
|
---|
758 | }
|
---|
759 | else if (stub.matchWindowTitle) {
|
---|
760 | /* If the user's specified a window title for Chromium, see if this
|
---|
761 | * window satisfies that criterium.
|
---|
762 | */
|
---|
763 | GLboolean wildcard = GL_FALSE;
|
---|
764 | char title[1000];
|
---|
765 | char *titlePattern;
|
---|
766 | int len;
|
---|
767 | /* check for leading '*' wildcard */
|
---|
768 | if (stub.matchWindowTitle[0] == '*') {
|
---|
769 | titlePattern = crStrdup( stub.matchWindowTitle + 1 );
|
---|
770 | wildcard = GL_TRUE;
|
---|
771 | }
|
---|
772 | else {
|
---|
773 | titlePattern = crStrdup( stub.matchWindowTitle );
|
---|
774 | }
|
---|
775 | /* check for trailing '*' wildcard */
|
---|
776 | len = crStrlen(titlePattern);
|
---|
777 | if (len > 0 && titlePattern[len - 1] == '*') {
|
---|
778 | titlePattern[len - 1] = '\0'; /* terminate here */
|
---|
779 | wildcard = GL_TRUE;
|
---|
780 | }
|
---|
781 |
|
---|
782 | GetWindowTitle( window, title );
|
---|
783 | if (title[0]) {
|
---|
784 | if (wildcard) {
|
---|
785 | if (crStrstr(title, titlePattern)) {
|
---|
786 | crFree(titlePattern);
|
---|
787 | return GL_TRUE;
|
---|
788 | }
|
---|
789 | }
|
---|
790 | else if (crStrcmp(title, titlePattern) == 0) {
|
---|
791 | crFree(titlePattern);
|
---|
792 | return GL_TRUE;
|
---|
793 | }
|
---|
794 | }
|
---|
795 | crFree(titlePattern);
|
---|
796 | crDebug("Using native GL, app window title doesn't match match_window_title string (\"%s\" != \"%s\")", title, stub.matchWindowTitle);
|
---|
797 | return GL_FALSE;
|
---|
798 | }
|
---|
799 |
|
---|
800 | /* Window title and size don't matter */
|
---|
801 | CRASSERT(stub.minChromiumWindowWidth == 0);
|
---|
802 | CRASSERT(stub.minChromiumWindowHeight == 0);
|
---|
803 | CRASSERT(stub.matchWindowTitle == NULL);
|
---|
804 |
|
---|
805 | /* User hasn't specified a width/height or window title.
|
---|
806 | * We'll use chromium for this window (and context) if no other is.
|
---|
807 | */
|
---|
808 |
|
---|
809 | return GL_TRUE; /* use Chromium! */
|
---|
810 | }
|
---|
811 |
|
---|
812 | static void stubWindowCheckOwnerCB(unsigned long key, void *data1, void *data2)
|
---|
813 | {
|
---|
814 | WindowInfo *pWindow = (WindowInfo *) data1;
|
---|
815 | ContextInfo *pCtx = (ContextInfo *) data2;
|
---|
816 |
|
---|
817 | if (pWindow->pOwner == pCtx)
|
---|
818 | {
|
---|
819 | #ifdef WINDOWS
|
---|
820 | /* Note: can't use WindowFromDC(context->pOwnWindow->drawable) here
|
---|
821 | because GL context is already released from DC and actual guest window
|
---|
822 | could be destroyed.
|
---|
823 | */
|
---|
824 | crWindowDestroy((GLint)pWindow->hWnd);
|
---|
825 | #else
|
---|
826 | crWindowDestroy((GLint)pWindow->drawable);
|
---|
827 | #endif
|
---|
828 | }
|
---|
829 | }
|
---|
830 |
|
---|
831 | GLboolean
|
---|
832 | stubMakeCurrent( WindowInfo *window, ContextInfo *context )
|
---|
833 | {
|
---|
834 | GLboolean retVal;
|
---|
835 |
|
---|
836 | /*
|
---|
837 | * Get WindowInfo and ContextInfo pointers.
|
---|
838 | */
|
---|
839 |
|
---|
840 | if (!context || !window) {
|
---|
841 | if (stub.currentContext)
|
---|
842 | stub.currentContext->currentDrawable = NULL;
|
---|
843 | if (context)
|
---|
844 | context->currentDrawable = NULL;
|
---|
845 | stub.currentContext = NULL;
|
---|
846 | return GL_TRUE; /* OK */
|
---|
847 | }
|
---|
848 |
|
---|
849 | #ifdef CHROMIUM_THREADSAFE
|
---|
850 | stubCheckMultithread();
|
---|
851 | #endif
|
---|
852 |
|
---|
853 | if (context->type == UNDECIDED) {
|
---|
854 | /* Here's where we really create contexts */
|
---|
855 | #ifdef CHROMIUM_THREADSAFE
|
---|
856 | crLockMutex(&stub.mutex);
|
---|
857 | #endif
|
---|
858 |
|
---|
859 | if (stubCheckUseChromium(window)) {
|
---|
860 | /*
|
---|
861 | * Create a Chromium context.
|
---|
862 | */
|
---|
863 | #if defined(GLX) || defined(DARWIN)
|
---|
864 | GLint spuShareCtx = context->share ? context->share->spuContext : 0;
|
---|
865 | #else
|
---|
866 | GLint spuShareCtx = 0;
|
---|
867 | #endif
|
---|
868 |
|
---|
869 | CRASSERT(stub.spu);
|
---|
870 | CRASSERT(stub.spu->dispatch_table.CreateContext);
|
---|
871 | context->type = CHROMIUM;
|
---|
872 |
|
---|
873 | context->spuContext
|
---|
874 | = stub.spu->dispatch_table.CreateContext( context->dpyName,
|
---|
875 | context->visBits,
|
---|
876 | spuShareCtx );
|
---|
877 | if (window->spuWindow == -1)
|
---|
878 | {
|
---|
879 | /*crDebug("(1)stubMakeCurrent ctx=%p(%i) window=%p(%i)", context, context->spuContext, window, window->spuWindow);*/
|
---|
880 | window->spuWindow = stub.spu->dispatch_table.WindowCreate( window->dpyName, context->visBits );
|
---|
881 | #ifdef CR_NEWWINTRACK
|
---|
882 | window->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID();
|
---|
883 | #endif
|
---|
884 |
|
---|
885 | }
|
---|
886 | }
|
---|
887 | else {
|
---|
888 | /*
|
---|
889 | * Create a native OpenGL context.
|
---|
890 | */
|
---|
891 | if (!InstantiateNativeContext(window, context))
|
---|
892 | {
|
---|
893 | #ifdef CHROMIUM_THREADSAFE
|
---|
894 | crUnlockMutex(&stub.mutex);
|
---|
895 | #endif
|
---|
896 | return 0; /* false */
|
---|
897 | }
|
---|
898 | context->type = NATIVE;
|
---|
899 | }
|
---|
900 |
|
---|
901 | #ifdef CHROMIUM_THREADSAFE
|
---|
902 | crUnlockMutex(&stub.mutex);
|
---|
903 | #endif
|
---|
904 | }
|
---|
905 |
|
---|
906 |
|
---|
907 | if (context->type == NATIVE) {
|
---|
908 | /*
|
---|
909 | * Native OpenGL MakeCurrent().
|
---|
910 | */
|
---|
911 | #ifdef WINDOWS
|
---|
912 | retVal = (GLboolean) stub.wsInterface.wglMakeCurrent( window->drawable, context->hglrc );
|
---|
913 | #elif defined(Darwin)
|
---|
914 | // XXX \todo We need to differentiate between these two..
|
---|
915 | retVal = ( stub.wsInterface.CGLSetSurface(context->cglc, window->connection, window->drawable, window->surface) == noErr );
|
---|
916 | retVal = ( stub.wsInterface.CGLSetCurrentContext(context->cglc) == noErr );
|
---|
917 | #elif defined(GLX)
|
---|
918 | retVal = (GLboolean) stub.wsInterface.glXMakeCurrent( window->dpy, window->drawable, context->glxContext );
|
---|
919 | #endif
|
---|
920 | }
|
---|
921 | else {
|
---|
922 | /*
|
---|
923 | * SPU chain MakeCurrent().
|
---|
924 | */
|
---|
925 | CRASSERT(context->type == CHROMIUM);
|
---|
926 | CRASSERT(context->spuContext >= 0);
|
---|
927 |
|
---|
928 | /*if (context->currentDrawable && context->currentDrawable != window)
|
---|
929 | crDebug("Rebinding context %p to a different window", context);*/
|
---|
930 |
|
---|
931 | if (window->type == NATIVE) {
|
---|
932 | crWarning("Can't rebind a chromium context to a native window\n");
|
---|
933 | retVal = 0;
|
---|
934 | }
|
---|
935 | else {
|
---|
936 | if (window->spuWindow == -1)
|
---|
937 | {
|
---|
938 | /*crDebug("(2)stubMakeCurrent ctx=%p(%i) window=%p(%i)", context, context->spuContext, window, window->spuWindow);*/
|
---|
939 | window->spuWindow = stub.spu->dispatch_table.WindowCreate( window->dpyName, context->visBits );
|
---|
940 | if (context->currentDrawable && context->currentDrawable->type==CHROMIUM
|
---|
941 | && context->currentDrawable->pOwner==context)
|
---|
942 | {
|
---|
943 | #ifdef WINDOWS
|
---|
944 | if (!WindowFromDC(context->currentDrawable->drawable))
|
---|
945 | {
|
---|
946 | crWindowDestroy((GLint)context->currentDrawable->hWnd);
|
---|
947 | }
|
---|
948 | #else
|
---|
949 | Window root;
|
---|
950 | int x, y;
|
---|
951 | unsigned int border, depth, w, h;
|
---|
952 |
|
---|
953 | XLOCK(context->currentDrawable->dpy);
|
---|
954 | if (!XGetGeometry(context->currentDrawable->dpy, context->currentDrawable->drawable, &root, &x, &y, &w, &h, &border, &depth))
|
---|
955 | {
|
---|
956 | crWindowDestroy((GLint)context->currentDrawable->drawable);
|
---|
957 | }
|
---|
958 | XUNLOCK(context->currentDrawable->dpy);
|
---|
959 | #endif
|
---|
960 |
|
---|
961 | }
|
---|
962 | }
|
---|
963 |
|
---|
964 | if (window->spuWindow != (GLint)window->drawable)
|
---|
965 | stub.spu->dispatch_table.MakeCurrent( window->spuWindow, (GLint) window->drawable, context->spuContext );
|
---|
966 | else
|
---|
967 | stub.spu->dispatch_table.MakeCurrent( window->spuWindow, 0, /* native window handle */ context->spuContext );
|
---|
968 |
|
---|
969 | retVal = 1;
|
---|
970 | }
|
---|
971 | }
|
---|
972 |
|
---|
973 | window->type = context->type;
|
---|
974 | window->pOwner = context;
|
---|
975 | context->currentDrawable = window;
|
---|
976 | stub.currentContext = context;
|
---|
977 |
|
---|
978 | if (retVal) {
|
---|
979 | /* Now, if we've transitions from Chromium to native rendering, or
|
---|
980 | * vice versa, we have to change all the OpenGL entrypoint pointers.
|
---|
981 | */
|
---|
982 | if (context->type == NATIVE) {
|
---|
983 | /* Switch to native API */
|
---|
984 | /*printf(" Switching to native API\n");*/
|
---|
985 | stubSetDispatch(&stub.nativeDispatch);
|
---|
986 | }
|
---|
987 | else if (context->type == CHROMIUM) {
|
---|
988 | /* Switch to stub (SPU) API */
|
---|
989 | /*printf(" Switching to spu API\n");*/
|
---|
990 | stubSetDispatch(&stub.spuDispatch);
|
---|
991 | }
|
---|
992 | else {
|
---|
993 | /* no API switch needed */
|
---|
994 | }
|
---|
995 | }
|
---|
996 |
|
---|
997 | if (!window->width && window->type == CHROMIUM) {
|
---|
998 | /* One time window setup */
|
---|
999 | int x, y;
|
---|
1000 | unsigned int winW, winH;
|
---|
1001 |
|
---|
1002 | stubGetWindowGeometry( window, &x, &y, &winW, &winH );
|
---|
1003 |
|
---|
1004 | /* If we're not using GLX/WGL (no app window) we'll always get
|
---|
1005 | * a width and height of zero here. In that case, skip the viewport
|
---|
1006 | * call since we're probably using a tilesort SPU with fake_window_dims
|
---|
1007 | * which the tilesort SPU will use for the viewport.
|
---|
1008 | */
|
---|
1009 | window->width = winW;
|
---|
1010 | window->height = winH;
|
---|
1011 | if (stub.trackWindowSize)
|
---|
1012 | stub.spuDispatch.WindowSize( window->spuWindow, winW, winH );
|
---|
1013 | if (stub.trackWindowPos)
|
---|
1014 | stub.spuDispatch.WindowPosition(window->spuWindow, x, y);
|
---|
1015 | if (winW > 0 && winH > 0)
|
---|
1016 | stub.spu->dispatch_table.Viewport( 0, 0, winW, winH );
|
---|
1017 | #ifdef VBOX_WITH_WDDM
|
---|
1018 | stub.spu->dispatch_table.WindowVisibleRegion(window->spuWindow, 0, NULL);
|
---|
1019 | #endif
|
---|
1020 | }
|
---|
1021 |
|
---|
1022 | /* Update window mapping state.
|
---|
1023 | * Basically, this lets us hide render SPU windows which correspond
|
---|
1024 | * to unmapped application windows. Without this, perfly (for example)
|
---|
1025 | * opens *lots* of temporary windows which otherwise clutter the screen.
|
---|
1026 | */
|
---|
1027 | if (stub.trackWindowVisibility && window->type == CHROMIUM && window->drawable) {
|
---|
1028 | const int mapped = stubIsWindowVisible(window);
|
---|
1029 | if (mapped != window->mapped) {
|
---|
1030 | crDebug("Dispatched: WindowShow(%i, %i)", window->spuWindow, mapped);
|
---|
1031 | stub.spu->dispatch_table.WindowShow(window->spuWindow, mapped);
|
---|
1032 | window->mapped = mapped;
|
---|
1033 | }
|
---|
1034 | }
|
---|
1035 |
|
---|
1036 | return retVal;
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | void
|
---|
1040 | stubDestroyContext( unsigned long contextId )
|
---|
1041 | {
|
---|
1042 | ContextInfo *context;
|
---|
1043 |
|
---|
1044 | if (!stub.contextTable) {
|
---|
1045 | return;
|
---|
1046 | }
|
---|
1047 | context = (ContextInfo *) crHashtableSearch(stub.contextTable, contextId);
|
---|
1048 |
|
---|
1049 | CRASSERT(context);
|
---|
1050 |
|
---|
1051 | if (context->type == NATIVE) {
|
---|
1052 | #ifdef WINDOWS
|
---|
1053 | stub.wsInterface.wglDeleteContext( context->hglrc );
|
---|
1054 | #elif defined(Darwin)
|
---|
1055 | stub.wsInterface.CGLDestroyContext( context->cglc );
|
---|
1056 | #elif defined(GLX)
|
---|
1057 | stub.wsInterface.glXDestroyContext( context->dpy, context->glxContext );
|
---|
1058 | #endif
|
---|
1059 | }
|
---|
1060 | else if (context->type == CHROMIUM) {
|
---|
1061 | /* Have pack SPU or tilesort SPU, etc. destroy the context */
|
---|
1062 | CRASSERT(context->spuContext >= 0);
|
---|
1063 | stub.spu->dispatch_table.DestroyContext( context->spuContext );
|
---|
1064 | crHashtableWalk(stub.windowTable, stubWindowCheckOwnerCB, context);
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 | if (stub.currentContext == context) {
|
---|
1068 | stub.currentContext = NULL;
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | #ifdef GLX
|
---|
1072 | crFreeHashtable(context->pGLXPixmapsHash, crFree);
|
---|
1073 | if (context->damageDpy)
|
---|
1074 | {
|
---|
1075 | XCloseDisplay(context->damageDpy);
|
---|
1076 | }
|
---|
1077 | #endif
|
---|
1078 |
|
---|
1079 | crMemZero(context, sizeof(ContextInfo)); /* just to be safe */
|
---|
1080 | crHashtableDelete(stub.contextTable, contextId, crFree);
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 |
|
---|
1084 | void
|
---|
1085 | stubSwapBuffers(WindowInfo *window, GLint flags)
|
---|
1086 | {
|
---|
1087 | if (!window)
|
---|
1088 | return;
|
---|
1089 |
|
---|
1090 | /* Determine if this window is being rendered natively or through
|
---|
1091 | * Chromium.
|
---|
1092 | */
|
---|
1093 |
|
---|
1094 | if (window->type == NATIVE) {
|
---|
1095 | /*printf("*** Swapping native window %d\n", (int) drawable);*/
|
---|
1096 | #ifdef WINDOWS
|
---|
1097 | (void) stub.wsInterface.wglSwapBuffers( window->drawable );
|
---|
1098 | #elif defined(Darwin)
|
---|
1099 | /* ...is this ok? */
|
---|
1100 | /* stub.wsInterface.CGLFlushDrawable( context->cglc ); */
|
---|
1101 | crDebug("stubSwapBuffers: unable to swap (no context!)");
|
---|
1102 | #elif defined(GLX)
|
---|
1103 | stub.wsInterface.glXSwapBuffers( window->dpy, window->drawable );
|
---|
1104 | #endif
|
---|
1105 | }
|
---|
1106 | else if (window->type == CHROMIUM) {
|
---|
1107 | /* Let the SPU do the buffer swap */
|
---|
1108 | /*printf("*** Swapping chromium window %d\n", (int) drawable);*/
|
---|
1109 | if (stub.appDrawCursor) {
|
---|
1110 | int pos[2];
|
---|
1111 | GetCursorPosition(window, pos);
|
---|
1112 | stub.spu->dispatch_table.ChromiumParametervCR(GL_CURSOR_POSITION_CR, GL_INT, 2, pos);
|
---|
1113 | }
|
---|
1114 | stub.spu->dispatch_table.SwapBuffers( window->spuWindow, flags );
|
---|
1115 | }
|
---|
1116 | else {
|
---|
1117 | crDebug("Calling SwapBuffers on a window we haven't seen before (no-op).");
|
---|
1118 | }
|
---|
1119 | }
|
---|