VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/glx.c@ 65661

Last change on this file since 65661 was 65572, checked in by vboxsync, 8 years ago

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

Fix glXChooseFBConfig not to bail out if GLX_BUFFER_SIZE is requested, as this is ignored according to the specification for RGBA rendering, which is the only type that we support. This lets glmark2 run for a bit until it exits due to a missing glGenerateMipmap symbol which is only core as of OpenGL 3.0. We get a number of assersions in CrFbEntryRegionsSet() on the host in-between: Assert(!hEntry->Flags.fInList).

  • Property svn:eol-style set to native
File size: 63.5 KB
Line 
1/* $Id: dri_drv.c 100879 2015-06-09 14:26:20Z bird $ */
2
3/** @file
4 * VBox OpenGL GLX implementation
5 */
6
7/*
8 * Copyright (C) 2009-2016 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 * --------------------------------------------------------------------
18 * Original copyright notice:
19 *
20 * Copyright (c) 2001, Stanford University
21 * All rights reserved
22 *
23 * See the file LICENSE.txt for information on redistributing this software.
24 */
25
26/* opengl_stub/glx.c */
27#include "chromium.h"
28#include "cr_error.h"
29#include "cr_spu.h"
30#include "cr_mem.h"
31#include "cr_string.h"
32#include "stub.h"
33#include "dri_glx.h"
34#include "GL/internal/glcore.h"
35#include "cr_glstate.h"
36
37#include <X11/Xregion.h>
38
39/* Force full pixmap update if there're more damaged regions than this number*/
40#define CR_MAX_DAMAGE_REGIONS_TRACKED 50
41
42/* Force "bigger" update (full or clip) if it's reducing number of regions updated
43 * but doesn't increase updated area more than given number
44 */
45#define CR_MIN_DAMAGE_PROFIT_SIZE 64*64
46
47/*@todo combine it in some other place*/
48/* Size of pack spu buffer - some delta for commands packing, see pack/packspu_config.c*/
49
50/** Ramshankar: Solaris compiz fix */
51#ifdef RT_OS_SOLARIS
52# define CR_MAX_TRANSFER_SIZE 20*1024*1024
53#else
54# define CR_MAX_TRANSFER_SIZE 4*1024*1024
55#endif
56
57/** For optimizing glXMakeCurrent */
58static Display *currentDisplay = NULL;
59static GLXDrawable currentDrawable = 0;
60static GLXDrawable currentReadDrawable = 0;
61
62/**
63 * Keep a list of structures which associates X visual IDs with
64 * Chromium visual bitmasks.
65 */
66struct VisualInfo {
67 Display *dpy;
68 int screen;
69 VisualID visualid;
70 int visBits;
71 struct VisualInfo *next;
72};
73
74static void stubXshmUpdateImageRect(Display *dpy, GLXDrawable draw, GLX_Pixmap_t *pGlxPixmap, XRectangle *pRect);
75static void stubQueryXDamageExtension(Display *dpy, ContextInfo *pContext);
76
77DECLEXPORT(XVisualInfo *)
78VBOXGLXTAG(glXChooseVisual)( Display *dpy, int screen, int *attribList )
79{
80 bool useRGBA = false;
81 int *attrib;
82 XVisualInfo searchvis, *pret;
83 int nvisuals;
84 stubInit();
85
86 for (attrib = attribList; *attrib != None; attrib++)
87 {
88 switch (*attrib)
89 {
90 case GLX_USE_GL:
91 /* ignored, this is mandatory */
92 break;
93
94 case GLX_BUFFER_SIZE:
95 /* this is for color-index visuals, which we don't support */
96 attrib++;
97 break;
98
99 case GLX_LEVEL:
100 if (attrib[1] != 0)
101 goto err_exit;
102 attrib++;
103 break;
104
105 case GLX_RGBA:
106 useRGBA = true;
107 break;
108
109 case GLX_STEREO:
110 goto err_exit;
111 /*
112 crWarning( "glXChooseVisual: stereo unsupported" );
113 return NULL;
114 */
115 break;
116
117 case GLX_AUX_BUFFERS:
118 if (attrib[1] != 0)
119 goto err_exit;
120 attrib++;
121 break;
122
123 case GLX_RED_SIZE:
124 case GLX_GREEN_SIZE:
125 case GLX_BLUE_SIZE:
126 if (attrib[1] > 8)
127 goto err_exit;
128 attrib++;
129 break;
130
131 case GLX_ALPHA_SIZE:
132 if (attrib[1] > 8)
133 goto err_exit;
134 attrib++;
135 break;
136
137 case GLX_DEPTH_SIZE:
138 if (attrib[1] > 24)
139 goto err_exit;
140 attrib++;
141 break;
142
143 case GLX_STENCIL_SIZE:
144 if (attrib[1] > 8)
145 goto err_exit;
146 attrib++;
147 break;
148
149 case GLX_ACCUM_RED_SIZE:
150 case GLX_ACCUM_GREEN_SIZE:
151 case GLX_ACCUM_BLUE_SIZE:
152 case GLX_ACCUM_ALPHA_SIZE:
153 if (attrib[1] > 16)
154 goto err_exit;
155 attrib++;
156 break;
157
158 case GLX_SAMPLE_BUFFERS_SGIS: /* aka GLX_SAMPLES_ARB */
159 if (attrib[1] > 0)
160 goto err_exit;
161 attrib++;
162 break;
163 case GLX_SAMPLES_SGIS: /* aka GLX_SAMPLES_ARB */
164 if (attrib[1] > 0)
165 goto err_exit;
166 attrib++;
167 break;
168
169 case GLX_DOUBLEBUFFER: /* @todo, check if we support it */
170 break;
171
172#ifdef GLX_VERSION_1_3
173 case GLX_X_VISUAL_TYPE:
174 case GLX_TRANSPARENT_TYPE_EXT:
175 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
176 case GLX_TRANSPARENT_RED_VALUE_EXT:
177 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
178 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
179 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
180 /* ignore */
181 crWarning("glXChooseVisual: ignoring attribute 0x%x", *attrib);
182 attrib++;
183 break;
184#endif
185
186 default:
187 crWarning( "glXChooseVisual: bad attrib=0x%x, ignoring", *attrib );
188 attrib++;
189 //return NULL;
190 }
191 }
192
193 if (!useRGBA)
194 return NULL;
195
196 XLOCK(dpy);
197 searchvis.visualid = XVisualIDFromVisual(DefaultVisual(dpy, screen));
198 pret = XGetVisualInfo(dpy, VisualIDMask, &searchvis, &nvisuals);
199 XUNLOCK(dpy);
200
201 if (nvisuals!=1) crWarning("glXChooseVisual: XGetVisualInfo returned %i visuals for %x", nvisuals, (unsigned int) searchvis.visualid);
202 if (pret)
203 crDebug("glXChooseVisual returned %x depth=%i", (unsigned int)pret->visualid, pret->depth);
204 return pret;
205
206err_exit:
207 crDebug("glXChooseVisual returning NULL, due to attrib=0x%x, next=0x%x", attrib[0], attrib[1]);
208 return NULL;
209}
210
211/**
212 ** There is a problem with glXCopyContext.
213 ** IRIX and Mesa both define glXCopyContext
214 ** to have the mask argument being a
215 ** GLuint. XFree 4 and oss.sgi.com
216 ** define it to be an unsigned long.
217 ** Solution: We don't support
218 ** glXCopyContext anyway so we'll just
219 ** \#ifdef out the code.
220 */
221DECLEXPORT(void)
222VBOXGLXTAG(glXCopyContext)( Display *dpy, GLXContext src, GLXContext dst,
223#if defined(AIX) || defined(PLAYSTATION2)
224GLuint mask
225#elif defined(SunOS)
226unsigned long mask
227#else
228unsigned long mask
229#endif
230)
231{
232 (void) dpy;
233 (void) src;
234 (void) dst;
235 (void) mask;
236 crWarning( "Unsupported GLX Call: glXCopyContext()" );
237}
238
239
240/**
241 * Get the display string for the given display pointer.
242 * Never return just ":0.0". In that case, prefix with our host name.
243 */
244static void
245stubGetDisplayString( Display *dpy, char *nameResult, int maxResult )
246{
247 const char *dpyName = DisplayString(dpy);
248 char host[1000];
249
250 host[0] = 0;
251 if (crStrlen(host) + crStrlen(dpyName) >= maxResult - 1)
252 {
253 /* return null string */
254 crWarning("Very long host / display name string in stubDisplayString!");
255 nameResult[0] = 0;
256 }
257 else
258 {
259 /* return host concatenated with dpyName */
260 crStrcpy(nameResult, host);
261 crStrcat(nameResult, dpyName);
262 }
263}
264
265
266
267DECLEXPORT(GLXContext)
268VBOXGLXTAG(glXCreateContext)(Display *dpy, XVisualInfo *vis, GLXContext share, Bool direct)
269{
270 char dpyName[MAX_DPY_NAME];
271 ContextInfo *context;
272 int visBits = CR_RGB_BIT | CR_DOUBLE_BIT | CR_DEPTH_BIT; /* default vis */
273
274 stubInit();
275
276 CRASSERT(stub.contextTable);
277
278 /*
279 {
280 int i, numExt;
281 char **list;
282
283 list = XListExtensions(dpy, &numExt);
284 crDebug("X extensions [%i]:", numExt);
285 for (i=0; i<numExt; ++i)
286 {
287 crDebug("%s", list[i]);
288 }
289 XFreeExtensionList(list);
290 }
291 */
292
293 stubGetDisplayString(dpy, dpyName, MAX_DPY_NAME);
294
295 context = stubNewContext(dpyName, visBits, UNDECIDED, (unsigned long) share);
296 if (!context)
297 return 0;
298
299 context->dpy = dpy;
300 context->visual = vis;
301 context->direct = direct;
302
303 stubQueryXDamageExtension(dpy, context);
304
305 return (GLXContext) context->id;
306}
307
308
309DECLEXPORT(void) VBOXGLXTAG(glXDestroyContext)( Display *dpy, GLXContext ctx )
310{
311 (void) dpy;
312 stubDestroyContext( (unsigned long) ctx );
313}
314
315typedef struct _stubFindPixmapParms_t {
316 ContextInfo *pCtx;
317 GLX_Pixmap_t *pGlxPixmap;
318 GLXDrawable draw;
319} stubFindPixmapParms_t;
320
321static void stubFindPixmapCB(unsigned long key, void *data1, void *data2)
322{
323 ContextInfo *pCtx = (ContextInfo *) data1;
324 stubFindPixmapParms_t *pParms = (stubFindPixmapParms_t *) data2;
325 GLX_Pixmap_t *pGlxPixmap = (GLX_Pixmap_t *) crHashtableSearch(pCtx->pGLXPixmapsHash, (unsigned int) pParms->draw);
326 (void)key;
327
328 if (pGlxPixmap)
329 {
330 pParms->pCtx = pCtx;
331 pParms->pGlxPixmap = pGlxPixmap;
332 }
333}
334
335DECLEXPORT(Bool) VBOXGLXTAG(glXMakeCurrent)( Display *dpy, GLXDrawable drawable, GLXContext ctx )
336{
337 ContextInfo *context;
338 WindowInfo *window;
339 Bool retVal;
340
341 /*crDebug("glXMakeCurrent(%p, 0x%x, 0x%x)", (void *) dpy, (int) drawable, (int) ctx);*/
342
343 /*check if passed drawable is GLXPixmap and not X Window*/
344 if (drawable)
345 {
346 GLX_Pixmap_t *pGlxPixmap = (GLX_Pixmap_t *) crHashtableSearch(stub.pGLXPixmapsHash, (unsigned int) drawable);
347
348 if (!pGlxPixmap)
349 {
350 stubFindPixmapParms_t parms;
351 parms.pGlxPixmap = NULL;
352 parms.draw = drawable;
353 crHashtableWalk(stub.contextTable, stubFindPixmapCB, &parms);
354 pGlxPixmap = parms.pGlxPixmap;
355 }
356
357 if (pGlxPixmap)
358 {
359 /*@todo*/
360 crWarning("Unimplemented glxMakeCurrent call with GLXPixmap passed, unexpected things might happen.");
361 }
362 }
363
364 if (ctx && drawable)
365 {
366 crHashtableLock(stub.windowTable);
367 crHashtableLock(stub.contextTable);
368
369 context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) ctx);
370 window = stubGetWindowInfo(dpy, drawable);
371
372 if (context && context->type == UNDECIDED) {
373 XLOCK(dpy);
374 XSync(dpy, 0); /* sync to force window creation on the server */
375 XUNLOCK(dpy);
376 }
377 }
378 else
379 {
380 dpy = NULL;
381 window = NULL;
382 context = NULL;
383 }
384
385 currentDisplay = dpy;
386 currentDrawable = drawable;
387
388 retVal = stubMakeCurrent(window, context);
389
390 if (ctx && drawable)
391 {
392 crHashtableUnlock(stub.contextTable);
393 crHashtableUnlock(stub.windowTable);
394 }
395
396 return retVal;
397}
398
399
400DECLEXPORT(GLXPixmap) VBOXGLXTAG(glXCreateGLXPixmap)( Display *dpy, XVisualInfo *vis, Pixmap pixmap )
401{
402 stubInit();
403 return VBOXGLXTAG(glXCreatePixmap)(dpy, (GLXFBConfig)vis->visualid, pixmap, NULL);
404}
405
406DECLEXPORT(void) VBOXGLXTAG(glXDestroyGLXPixmap)( Display *dpy, GLXPixmap pix )
407{
408 VBOXGLXTAG(glXDestroyPixmap)(dpy, pix);
409}
410
411DECLEXPORT(int) VBOXGLXTAG(glXGetConfig)( Display *dpy, XVisualInfo *vis, int attrib, int *value )
412{
413 (void)dpy;
414
415 if (!vis) {
416 /* SGI OpenGL Performer hits this */
417 crWarning("glXGetConfig called with NULL XVisualInfo");
418 return GLX_BAD_VISUAL;
419 }
420
421 stubInit();
422
423 *value = 0; /* For sanity */
424
425 switch ( attrib ) {
426
427 case GLX_USE_GL:
428 *value = vis->visualid == XVisualIDFromVisual(DefaultVisual(dpy, vis->screen));
429 break;
430
431 case GLX_BUFFER_SIZE:
432 *value = 32;
433 break;
434
435 case GLX_LEVEL:
436 *value = 0; /* for now */
437 break;
438
439 case GLX_RGBA:
440 *value = 1;
441 break;
442
443 case GLX_DOUBLEBUFFER:
444 *value = 1;
445 break;
446
447 case GLX_STEREO:
448 *value = 1;
449 break;
450
451 case GLX_AUX_BUFFERS:
452 *value = 0;
453 break;
454
455 case GLX_RED_SIZE:
456 *value = 8;
457 break;
458
459 case GLX_GREEN_SIZE:
460 *value = 8;
461 break;
462
463 case GLX_BLUE_SIZE:
464 *value = 8;
465 break;
466
467 case GLX_ALPHA_SIZE:
468 *value = 8;
469 break;
470
471 case GLX_DEPTH_SIZE:
472 *value = 24;
473 break;
474
475 case GLX_STENCIL_SIZE:
476 *value = 8;
477 break;
478
479 case GLX_ACCUM_RED_SIZE:
480 *value = 16;
481 break;
482
483 case GLX_ACCUM_GREEN_SIZE:
484 *value = 16;
485 break;
486
487 case GLX_ACCUM_BLUE_SIZE:
488 *value = 16;
489 break;
490
491 case GLX_ACCUM_ALPHA_SIZE:
492 *value = 16;
493 break;
494
495 case GLX_SAMPLE_BUFFERS_SGIS:
496 *value = 0; /* fix someday */
497 break;
498
499 case GLX_SAMPLES_SGIS:
500 *value = 0; /* fix someday */
501 break;
502
503 case GLX_VISUAL_CAVEAT_EXT:
504 *value = GLX_NONE_EXT;
505 break;
506#if defined(SunOS) || 1
507 /*
508 I don't think this is even a valid attribute for glxGetConfig.
509 No idea why this gets called under SunOS but we simply ignore it
510 -- jw
511 */
512 case GLX_X_VISUAL_TYPE:
513 crWarning ("Ignoring Unsupported GLX Call: glxGetConfig with attrib 0x%x", attrib);
514 break;
515#endif
516
517 case GLX_TRANSPARENT_TYPE:
518 *value = GLX_NONE_EXT;
519 break;
520 case GLX_TRANSPARENT_INDEX_VALUE:
521 *value = 0;
522 break;
523 case GLX_TRANSPARENT_RED_VALUE:
524 *value = 0;
525 break;
526 case GLX_TRANSPARENT_GREEN_VALUE:
527 *value = 0;
528 break;
529 case GLX_TRANSPARENT_BLUE_VALUE:
530 *value = 0;
531 break;
532 case GLX_TRANSPARENT_ALPHA_VALUE:
533 *value = 0;
534 break;
535 case GLX_DRAWABLE_TYPE:
536 *value = GLX_WINDOW_BIT;
537 break;
538 default:
539 crWarning( "Unsupported GLX Call: glXGetConfig with attrib 0x%x, ignoring...", attrib );
540 //return GLX_BAD_ATTRIBUTE;
541 *value = 0;
542 }
543
544 return 0;
545}
546
547DECLEXPORT(GLXContext) VBOXGLXTAG(glXGetCurrentContext)( void )
548{
549 ContextInfo *context = stubGetCurrentContext();
550 if (context)
551 return (GLXContext) context->id;
552 else
553 return (GLXContext) NULL;
554}
555
556DECLEXPORT(GLXDrawable) VBOXGLXTAG(glXGetCurrentDrawable)(void)
557{
558 return currentDrawable;
559}
560
561DECLEXPORT(Display *) VBOXGLXTAG(glXGetCurrentDisplay)(void)
562{
563 return currentDisplay;
564}
565
566DECLEXPORT(Bool) VBOXGLXTAG(glXIsDirect)(Display *dpy, GLXContext ctx)
567{
568 (void) dpy;
569 (void) ctx;
570 crDebug("->glXIsDirect");
571 return True;
572}
573
574DECLEXPORT(Bool) VBOXGLXTAG(glXQueryExtension)(Display *dpy, int *errorBase, int *eventBase)
575{
576 (void) dpy;
577 (void) errorBase;
578 (void) eventBase;
579 return 1; /* You BET we do... */
580}
581
582DECLEXPORT(Bool) VBOXGLXTAG(glXQueryVersion)( Display *dpy, int *major, int *minor )
583{
584 (void) dpy;
585 *major = 1;
586 *minor = 3;
587 return 1;
588}
589
590DECLEXPORT(void) VBOXGLXTAG(glXSwapBuffers)( Display *dpy, GLXDrawable drawable )
591{
592 WindowInfo *window = stubGetWindowInfo(dpy, drawable);
593 stubSwapBuffers( window, 0 );
594}
595
596DECLEXPORT(void) VBOXGLXTAG(glXUseXFont)( Font font, int first, int count, int listBase )
597{
598 ContextInfo *context = stubGetCurrentContext();
599 Display *dpy = context->dpy;
600 if (dpy) {
601 stubUseXFont( dpy, font, first, count, listBase );
602 }
603 else {
604 dpy = XOpenDisplay(NULL);
605 if (!dpy)
606 return;
607 stubUseXFont( dpy, font, first, count, listBase );
608 XCloseDisplay(dpy);
609 }
610}
611
612DECLEXPORT(void) VBOXGLXTAG(glXWaitGL)( void )
613{
614 static int first_call = 1;
615
616 if ( first_call )
617 {
618 crDebug( "Ignoring unsupported GLX call: glXWaitGL()" );
619 first_call = 0;
620 }
621}
622
623DECLEXPORT(void) VBOXGLXTAG(glXWaitX)( void )
624{
625 static int first_call = 1;
626
627 if ( first_call )
628 {
629 crDebug( "Ignoring unsupported GLX call: glXWaitX()" );
630 first_call = 0;
631 }
632}
633
634DECLEXPORT(const char *) VBOXGLXTAG(glXQueryExtensionsString)( Display *dpy, int screen )
635{
636 /* XXX maybe also advertise GLX_SGIS_multisample? */
637
638 static const char *retval = "GLX_ARB_multisample GLX_EXT_texture_from_pixmap GLX_SGIX_fbconfig GLX_ARB_get_proc_address";
639
640 (void) dpy;
641 (void) screen;
642
643 crDebug("->glXQueryExtensionsString");
644 return retval;
645}
646
647DECLEXPORT(const char *) VBOXGLXTAG(glXGetClientString)( Display *dpy, int name )
648{
649 const char *retval;
650 (void) dpy;
651 (void) name;
652
653 switch ( name ) {
654
655 case GLX_VENDOR:
656 retval = "Chromium";
657 break;
658
659 case GLX_VERSION:
660 retval = "1.3 Chromium";
661 break;
662
663 case GLX_EXTENSIONS:
664 /*@todo should be a screen not a name...but it's not used anyway*/
665 retval = glXQueryExtensionsString(dpy, name);
666 break;
667
668 default:
669 retval = NULL;
670 }
671
672 return retval;
673}
674
675DECLEXPORT(const char *) VBOXGLXTAG(glXQueryServerString)( Display *dpy, int screen, int name )
676{
677 const char *retval;
678 (void) dpy;
679 (void) screen;
680
681 switch ( name ) {
682
683 case GLX_VENDOR:
684 retval = "Chromium";
685 break;
686
687 case GLX_VERSION:
688 retval = "1.3 Chromium";
689 break;
690
691 case GLX_EXTENSIONS:
692 retval = glXQueryExtensionsString(dpy, screen);
693 break;
694
695 default:
696 retval = NULL;
697 }
698
699 return retval;
700}
701
702DECLEXPORT(CR_GLXFuncPtr) VBOXGLXTAG(glXGetProcAddressARB)( const GLubyte *name )
703{
704 return (CR_GLXFuncPtr) crGetProcAddress( (const char *) name );
705}
706
707DECLEXPORT(CR_GLXFuncPtr) VBOXGLXTAG(glXGetProcAddress)( const GLubyte *name )
708{
709 return (CR_GLXFuncPtr) crGetProcAddress( (const char *) name );
710}
711
712
713#if GLX_EXTRAS
714
715DECLEXPORT(GLXPbufferSGIX)
716VBOXGLXTAG(glXCreateGLXPbufferSGIX)(Display *dpy, GLXFBConfigSGIX config,
717 unsigned int width, unsigned int height,
718 int *attrib_list)
719{
720 (void) dpy;
721 (void) config;
722 (void) width;
723 (void) height;
724 (void) attrib_list;
725 crWarning("glXCreateGLXPbufferSGIX not implemented by Chromium");
726 return 0;
727}
728
729DECLEXPORT(void) VBOXGLXTAG(glXDestroyGLXPbufferSGIX)(Display *dpy, GLXPbuffer pbuf)
730{
731 (void) dpy;
732 (void) pbuf;
733 crWarning("glXDestroyGLXPbufferSGIX not implemented by Chromium");
734}
735
736DECLEXPORT(void) VBOXGLXTAG(glXSelectEventSGIX)(Display *dpy, GLXDrawable drawable, unsigned long mask)
737{
738 (void) dpy;
739 (void) drawable;
740 (void) mask;
741}
742
743DECLEXPORT(void) VBOXGLXTAG(glXGetSelectedEventSGIX)(Display *dpy, GLXDrawable drawable, unsigned long *mask)
744{
745 (void) dpy;
746 (void) drawable;
747 (void) mask;
748}
749
750DECLEXPORT(int) VBOXGLXTAG(glXQueryGLXPbufferSGIX)(Display *dpy, GLXPbuffer pbuf,
751 int attribute, unsigned int *value)
752{
753 (void) dpy;
754 (void) pbuf;
755 (void) attribute;
756 (void) value;
757 crWarning("glXQueryGLXPbufferSGIX not implemented by Chromium");
758 return 0;
759}
760
761DECLEXPORT(int) VBOXGLXTAG(glXGetFBConfigAttribSGIX)(Display *dpy, GLXFBConfig config,
762 int attribute, int *value)
763{
764 return VBOXGLXTAG(glXGetFBConfigAttrib)(dpy, config, attribute, value);
765}
766
767DECLEXPORT(GLXFBConfigSGIX *)
768VBOXGLXTAG(glXChooseFBConfigSGIX)(Display *dpy, int screen,
769 int *attrib_list, int *nelements)
770{
771 return VBOXGLXTAG(glXChooseFBConfig)(dpy, screen, attrib_list, nelements);
772}
773
774DECLEXPORT(GLXPixmap)
775VBOXGLXTAG(glXCreateGLXPixmapWithConfigSGIX)(Display *dpy,
776 GLXFBConfig config,
777 Pixmap pixmap)
778{
779 return VBOXGLXTAG(glXCreatePixmap)(dpy, config, pixmap, NULL);
780}
781
782DECLEXPORT(GLXContext)
783VBOXGLXTAG(glXCreateContextWithConfigSGIX)(Display *dpy, GLXFBConfig config,
784 int render_type,
785 GLXContext share_list,
786 Bool direct)
787{
788 if (render_type!=GLX_RGBA_TYPE_SGIX)
789 {
790 crWarning("glXCreateContextWithConfigSGIX: Unsupported render type %i", render_type);
791 return NULL;
792 }
793 else
794 {
795 XVisualInfo *vis;
796 GLXContext ret;
797
798 vis = VBOXGLXTAG(glXGetVisualFromFBConfigSGIX)(dpy, config);
799 if (!vis)
800 {
801 crWarning("glXCreateContextWithConfigSGIX: no visuals for %p", config);
802 return NULL;
803 }
804 ret = VBOXGLXTAG(glXCreateContext)(dpy, vis, share_list, direct);
805 XFree(vis);
806 return ret;
807 }
808}
809
810DECLEXPORT(XVisualInfo *)
811VBOXGLXTAG(glXGetVisualFromFBConfigSGIX)(Display *dpy,
812 GLXFBConfig config)
813{
814 return VBOXGLXTAG(glXGetVisualFromFBConfig)(dpy, config);
815}
816
817DECLEXPORT(GLXFBConfigSGIX)
818VBOXGLXTAG(glXGetFBConfigFromVisualSGIX)(Display *dpy, XVisualInfo *vis)
819{
820 if (!vis)
821 {
822 return NULL;
823 }
824 /*Note: Caller is supposed to call XFree on returned value, so can't just return (GLXFBConfig)vis->visualid*/
825 return (GLXFBConfigSGIX) VBOXGLXTAG(glXGetVisualFromFBConfig)(dpy, (GLXFBConfig)vis->visualid);
826}
827
828/*
829 * GLX 1.3 functions
830 */
831DECLEXPORT(GLXFBConfig *)
832VBOXGLXTAG(glXChooseFBConfig)(Display *dpy, int screen, ATTRIB_TYPE *attrib_list, int *nelements)
833{
834 ATTRIB_TYPE *attrib;
835 intptr_t fbconfig = 0;
836
837 stubInit();
838
839 if (!attrib_list)
840 {
841 return VBOXGLXTAG(glXGetFBConfigs)(dpy, screen, nelements);
842 }
843
844 for (attrib = attrib_list; *attrib != None; attrib++)
845 {
846 switch (*attrib)
847 {
848 case GLX_FBCONFIG_ID:
849 fbconfig = attrib[1];
850 attrib++;
851 break;
852
853 case GLX_BUFFER_SIZE:
854 /* this is ignored except for color-index visuals, which we don't support */
855 attrib++;
856 break;
857
858 case GLX_LEVEL:
859 if (attrib[1] != 0)
860 goto err_exit;
861 attrib++;
862 break;
863
864 case GLX_AUX_BUFFERS:
865 if (attrib[1] != 0)
866 goto err_exit;
867 attrib++;
868 break;
869
870 case GLX_DOUBLEBUFFER: /* @todo, check if we support it */
871 attrib++;
872 break;
873
874 case GLX_STEREO:
875 if (attrib[1] != 0)
876 goto err_exit;
877 attrib++;
878 break;
879
880 case GLX_RED_SIZE:
881 case GLX_GREEN_SIZE:
882 case GLX_BLUE_SIZE:
883 case GLX_ALPHA_SIZE:
884 if (attrib[1] > 8)
885 goto err_exit;
886 attrib++;
887 break;
888
889 case GLX_DEPTH_SIZE:
890 if (attrib[1] > 24)
891 goto err_exit;
892 attrib++;
893 break;
894
895 case GLX_STENCIL_SIZE:
896 if (attrib[1] > 8)
897 goto err_exit;
898 attrib++;
899 break;
900
901 case GLX_ACCUM_RED_SIZE:
902 case GLX_ACCUM_GREEN_SIZE:
903 case GLX_ACCUM_BLUE_SIZE:
904 case GLX_ACCUM_ALPHA_SIZE:
905 if (attrib[1] > 16)
906 goto err_exit;
907 attrib++;
908 break;
909
910 case GLX_X_RENDERABLE:
911 case GLX_CONFIG_CAVEAT:
912 attrib++;
913 break;
914
915 case GLX_RENDER_TYPE:
916 if (attrib[1]!=GLX_RGBA_BIT)
917 goto err_exit;
918 attrib++;
919 break;
920
921 case GLX_DRAWABLE_TYPE:
922 if ( !(attrib[1] & GLX_WINDOW_BIT)
923 && !(attrib[1] & GLX_PIXMAP_BIT))
924 goto err_exit;
925 attrib++;
926 break;
927
928 case GLX_X_VISUAL_TYPE:
929 case GLX_TRANSPARENT_TYPE_EXT:
930 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
931 case GLX_TRANSPARENT_RED_VALUE_EXT:
932 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
933 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
934 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
935 /* ignore */
936 crWarning("glXChooseVisual: ignoring attribute 0x%x", *attrib);
937 attrib++;
938 break;
939
940 break;
941 default:
942 crWarning( "glXChooseVisual: bad attrib=0x%x, ignoring", *attrib );
943 attrib++;
944 break;
945 }
946 }
947
948 if (fbconfig)
949 {
950 GLXFBConfig *pGLXFBConfigs;
951
952 *nelements = 1;
953 pGLXFBConfigs = (GLXFBConfig *) crAlloc(*nelements * sizeof(GLXFBConfig));
954 pGLXFBConfigs[0] = (GLXFBConfig)fbconfig;
955 return pGLXFBConfigs;
956 }
957 else
958 {
959 return VBOXGLXTAG(glXGetFBConfigs)(dpy, screen, nelements);
960 }
961
962err_exit:
963 crWarning("glXChooseFBConfig returning NULL, due to attrib=0x%x, next=0x%x", attrib[0], attrib[1]);
964 return NULL;
965}
966
967DECLEXPORT(GLXContext)
968VBOXGLXTAG(glXCreateNewContext)(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct)
969{
970 XVisualInfo *vis;
971
972 (void) dpy;
973 (void) config;
974 (void) render_type;
975 (void) share_list;
976 (void) direct;
977
978 if (render_type != GLX_RGBA_TYPE)
979 {
980 crWarning("glXCreateNewContext, unsupported render_type %x", render_type);
981 return NULL;
982 }
983
984 vis = VBOXGLXTAG(glXGetVisualFromFBConfig)(dpy, config);
985 return VBOXGLXTAG(glXCreateContext)(dpy, vis, share_list, direct);
986}
987
988DECLEXPORT(GLXPbuffer)
989VBOXGLXTAG(glXCreatePbuffer)(Display *dpy, GLXFBConfig config, ATTRIB_TYPE *attrib_list)
990{
991 (void) dpy;
992 (void) config;
993 (void) attrib_list;
994 crWarning("glXCreatePbuffer not implemented by Chromium");
995 return 0;
996}
997
998/* Note: there're examples where glxpixmaps are created without current context, so can't do much of the work here.
999 * Instead we'd do necessary initialization on first use of those pixmaps.
1000 */
1001DECLEXPORT(GLXPixmap)
1002VBOXGLXTAG(glXCreatePixmap)(Display *dpy, GLXFBConfig config, Pixmap pixmap, const ATTRIB_TYPE *attrib_list)
1003{
1004 ATTRIB_TYPE *attrib;
1005 GLX_Pixmap_t *pGlxPixmap;
1006 (void) dpy;
1007 (void) config;
1008
1009#if 0
1010 {
1011 int x, y;
1012 unsigned int w, h;
1013 unsigned int border;
1014 unsigned int depth;
1015 Window root;
1016
1017 crDebug("glXCreatePixmap called for %lu", pixmap);
1018
1019 XLOCK(dpy);
1020 if (!XGetGeometry(dpy, pixmap, &root, &x, &y, &w, &h, &border, &depth))
1021 {
1022 XSync(dpy, False);
1023 if (!XGetGeometry(dpy, pixmap, &root, &x, &y, &w, &h, &border, &depth))
1024 {
1025 crDebug("fail");
1026 }
1027 }
1028 crDebug("root: %lu, [%i,%i %u,%u]", root, x, y, w, h);
1029 XUNLOCK(dpy);
1030 }
1031#endif
1032
1033 pGlxPixmap = crCalloc(sizeof(GLX_Pixmap_t));
1034 if (!pGlxPixmap)
1035 {
1036 crWarning("glXCreatePixmap failed to allocate memory");
1037 return 0;
1038 }
1039
1040 pGlxPixmap->format = GL_RGBA;
1041 pGlxPixmap->target = GL_TEXTURE_2D;
1042
1043 if (attrib_list)
1044 {
1045 for (attrib = attrib_list; *attrib != None; attrib++)
1046 {
1047 switch (*attrib)
1048 {
1049 case GLX_TEXTURE_FORMAT_EXT:
1050 attrib++;
1051 switch (*attrib)
1052 {
1053 case GLX_TEXTURE_FORMAT_RGBA_EXT:
1054 pGlxPixmap->format = GL_RGBA;
1055 break;
1056 case GLX_TEXTURE_FORMAT_RGB_EXT:
1057 pGlxPixmap->format = GL_RGB;
1058 break;
1059 default:
1060 crDebug("Unexpected GLX_TEXTURE_FORMAT_EXT 0x%x", (unsigned int) *attrib);
1061 }
1062 break;
1063 case GLX_TEXTURE_TARGET_EXT:
1064 attrib++;
1065 switch (*attrib)
1066 {
1067 case GLX_TEXTURE_2D_EXT:
1068 pGlxPixmap->target = GL_TEXTURE_2D;
1069 break;
1070 case GLX_TEXTURE_RECTANGLE_EXT:
1071 pGlxPixmap->target = GL_TEXTURE_RECTANGLE_NV;
1072 break;
1073 default:
1074 crDebug("Unexpected GLX_TEXTURE_TARGET_EXT 0x%x", (unsigned int) *attrib);
1075 }
1076 break;
1077 default: attrib++;
1078 }
1079 }
1080 }
1081
1082 crHashtableAdd(stub.pGLXPixmapsHash, (unsigned int) pixmap, pGlxPixmap);
1083 return (GLXPixmap) pixmap;
1084}
1085
1086DECLEXPORT(GLXWindow)
1087VBOXGLXTAG(glXCreateWindow)(Display *dpy, GLXFBConfig config, Window win, ATTRIB_TYPE *attrib_list)
1088{
1089 GLXFBConfig *realcfg;
1090 int nconfigs;
1091 (void) config;
1092
1093 if (stub.wsInterface.glXGetFBConfigs)
1094 {
1095 realcfg = stub.wsInterface.glXGetFBConfigs(dpy, 0, &nconfigs);
1096 if (!realcfg || nconfigs<1)
1097 {
1098 crWarning("glXCreateWindow !realcfg || nconfigs<1");
1099 return 0;
1100 }
1101 else
1102 {
1103 return stub.wsInterface.glXCreateWindow(dpy, realcfg[0], win, attrib_list);
1104 }
1105 }
1106 else
1107 {
1108 if (attrib_list && *attrib_list!=None)
1109 {
1110 crWarning("Non empty attrib list in glXCreateWindow");
1111 return 0;
1112 }
1113 return (GLXWindow)win;
1114 }
1115}
1116
1117DECLEXPORT(void) VBOXGLXTAG(glXDestroyPbuffer)(Display *dpy, GLXPbuffer pbuf)
1118{
1119 (void) dpy;
1120 (void) pbuf;
1121 crWarning("glXDestroyPbuffer not implemented by Chromium");
1122}
1123
1124DECLEXPORT(void) VBOXGLXTAG(glXDestroyPixmap)(Display *dpy, GLXPixmap pixmap)
1125{
1126 stubFindPixmapParms_t parms;
1127
1128 if (crHashtableSearch(stub.pGLXPixmapsHash, (unsigned int) pixmap))
1129 {
1130 /*it's valid but never used glxpixmap, so simple free stored ptr*/
1131 crHashtableDelete(stub.pGLXPixmapsHash, (unsigned int) pixmap, crFree);
1132 return;
1133 }
1134 else
1135 {
1136 /*it's either invalid glxpixmap or one which was already initialized, so it's stored in appropriate ctx hash*/
1137 parms.pCtx = NULL;
1138 parms.pGlxPixmap = NULL;
1139 parms.draw = pixmap;
1140 crHashtableWalk(stub.contextTable, stubFindPixmapCB, &parms);
1141 }
1142
1143 if (!parms.pGlxPixmap)
1144 {
1145 crWarning("glXDestroyPixmap called for unknown glxpixmap 0x%x", (unsigned int) pixmap);
1146 return;
1147 }
1148
1149 XLOCK(dpy);
1150 if (parms.pGlxPixmap->gc)
1151 {
1152 XFreeGC(dpy, parms.pGlxPixmap->gc);
1153 }
1154
1155 if (parms.pGlxPixmap->hShmPixmap>0)
1156 {
1157 XFreePixmap(dpy, parms.pGlxPixmap->hShmPixmap);
1158 }
1159 XUNLOCK(dpy);
1160
1161 if (parms.pGlxPixmap->hDamage>0)
1162 {
1163 //crDebug("Destroy: Damage for drawable 0x%x, handle 0x%x", (unsigned int) pixmap, (unsigned int) parms.pGlxPixmap->damage);
1164 XDamageDestroy(dpy, parms.pGlxPixmap->hDamage);
1165 }
1166
1167 if (parms.pGlxPixmap->pDamageRegion)
1168 {
1169 XDestroyRegion(parms.pGlxPixmap->pDamageRegion);
1170 }
1171
1172 crHashtableDelete(parms.pCtx->pGLXPixmapsHash, (unsigned int) pixmap, crFree);
1173}
1174
1175DECLEXPORT(void) VBOXGLXTAG(glXDestroyWindow)(Display *dpy, GLXWindow win)
1176{
1177 (void) dpy;
1178 (void) win;
1179 /*crWarning("glXDestroyWindow not implemented by Chromium");*/
1180}
1181
1182DECLEXPORT(GLXDrawable) VBOXGLXTAG(glXGetCurrentReadDrawable)(void)
1183{
1184 return currentReadDrawable;
1185}
1186
1187DECLEXPORT(int) VBOXGLXTAG(glXGetFBConfigAttrib)(Display *dpy, GLXFBConfig config, int attribute, int *value)
1188{
1189 XVisualInfo * pVisual;
1190 const char * pExt;
1191
1192 pVisual = VBOXGLXTAG(glXGetVisualFromFBConfig)(dpy, config);
1193 if (!pVisual)
1194 {
1195 crWarning("glXGetFBConfigAttrib for %p, failed to get XVisualInfo", config);
1196 return GLX_BAD_ATTRIBUTE;
1197 }
1198 //crDebug("glXGetFBConfigAttrib 0x%x for 0x%x, visualid=0x%x, depth=%i", attribute, (int)config, (int)pVisual->visualid, pVisual->depth);
1199
1200
1201 switch (attribute)
1202 {
1203 case GLX_DRAWABLE_TYPE:
1204 *value = GLX_PIXMAP_BIT | GLX_WINDOW_BIT;
1205 break;
1206 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
1207 *value = GLX_TEXTURE_2D_BIT_EXT;
1208 pExt = (const char *) stub.spu->dispatch_table.GetString(GL_EXTENSIONS);
1209 if (crStrstr(pExt, "GL_NV_texture_rectangle")
1210 || crStrstr(pExt, "GL_ARB_texture_rectangle")
1211 || crStrstr(pExt, "GL_EXT_texture_rectangle"))
1212 {
1213 *value |= GLX_TEXTURE_RECTANGLE_BIT_EXT;
1214 }
1215 break;
1216 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
1217 *value = True;
1218 break;
1219 case GLX_BIND_TO_TEXTURE_RGB_EXT:
1220 *value = True;
1221 break;
1222 case GLX_DOUBLEBUFFER:
1223 //crDebug("attribute=GLX_DOUBLEBUFFER");
1224 *value = True;
1225 break;
1226 case GLX_Y_INVERTED_EXT:
1227 *value = True;
1228 break;
1229 case GLX_ALPHA_SIZE:
1230 //crDebug("attribute=GLX_ALPHA_SIZE");
1231 *value = 8;
1232 break;
1233 case GLX_BUFFER_SIZE:
1234 //crDebug("attribute=GLX_BUFFER_SIZE");
1235 *value = 32;
1236 break;
1237 case GLX_STENCIL_SIZE:
1238 //crDebug("attribute=GLX_STENCIL_SIZE");
1239 *value = 8;
1240 break;
1241 case GLX_DEPTH_SIZE:
1242 *value = 24;
1243 //crDebug("attribute=GLX_DEPTH_SIZE");
1244 break;
1245 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
1246 *value = 0;
1247 break;
1248 case GLX_RENDER_TYPE:
1249 //crDebug("attribute=GLX_RENDER_TYPE");
1250 *value = GLX_RGBA_BIT;
1251 break;
1252 case GLX_CONFIG_CAVEAT:
1253 //crDebug("attribute=GLX_CONFIG_CAVEAT");
1254 *value = GLX_NONE;
1255 break;
1256 case GLX_VISUAL_ID:
1257 //crDebug("attribute=GLX_VISUAL_ID");
1258 *value = pVisual->visualid;
1259 break;
1260 case GLX_FBCONFIG_ID:
1261 *value = pVisual->visualid; /*or config, though those are the same at the moment but this could change one day?*/
1262 break;
1263 case GLX_RED_SIZE:
1264 case GLX_GREEN_SIZE:
1265 case GLX_BLUE_SIZE:
1266 *value = 8;
1267 break;
1268 case GLX_LEVEL:
1269 *value = 0;
1270 break;
1271 case GLX_STEREO:
1272 *value = false;
1273 break;
1274 case GLX_AUX_BUFFERS:
1275 *value = 0;
1276 break;
1277 case GLX_ACCUM_RED_SIZE:
1278 case GLX_ACCUM_GREEN_SIZE:
1279 case GLX_ACCUM_BLUE_SIZE:
1280 case GLX_ACCUM_ALPHA_SIZE:
1281 *value = 0;
1282 break;
1283 case GLX_X_VISUAL_TYPE:
1284 *value = GLX_TRUE_COLOR;
1285 break;
1286 case GLX_TRANSPARENT_TYPE:
1287 *value = GLX_NONE;
1288 break;
1289 case GLX_SAMPLE_BUFFERS:
1290 case GLX_SAMPLES:
1291 *value = 1;
1292 break;
1293 case GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT:
1294 *value = 0;
1295 break;
1296 default:
1297 crDebug("glXGetFBConfigAttrib: unknown attribute=0x%x", attribute);
1298 XFree(pVisual);
1299 return GLX_BAD_ATTRIBUTE;
1300 }
1301
1302 XFree(pVisual);
1303 return Success;
1304}
1305
1306DECLEXPORT(GLXFBConfig *) VBOXGLXTAG(glXGetFBConfigs)(Display *dpy, int screen, int *nelements)
1307{
1308 int i;
1309
1310 GLXFBConfig *pGLXFBConfigs = crAlloc(sizeof(GLXFBConfig));
1311
1312 *nelements = 1;
1313 XLOCK(dpy);
1314 *pGLXFBConfigs = (GLXFBConfig) XVisualIDFromVisual(DefaultVisual(dpy, screen));
1315 XUNLOCK(dpy);
1316
1317 crDebug("glXGetFBConfigs returned %i configs", *nelements);
1318 for (i=0; i<*nelements; ++i)
1319 {
1320 crDebug("glXGetFBConfigs[%i]=0x%x", i, (unsigned)(uintptr_t) pGLXFBConfigs[i]);
1321 }
1322 return pGLXFBConfigs;
1323}
1324
1325DECLEXPORT(void) VBOXGLXTAG(glXGetSelectedEvent)(Display *dpy, GLXDrawable draw, unsigned long *event_mask)
1326{
1327 (void) dpy;
1328 (void) draw;
1329 (void) event_mask;
1330 crWarning("glXGetSelectedEvent not implemented by Chromium");
1331}
1332
1333DECLEXPORT(XVisualInfo *) VBOXGLXTAG(glXGetVisualFromFBConfig)(Display *dpy, GLXFBConfig config)
1334{
1335 (void) dpy;
1336 (void) config;
1337
1338 /*
1339 struct VisualInfo *v;
1340
1341 for (v = VisualInfoList; v; v = v->next) {
1342 if (v->dpy == dpy && v->visualid == (VisualID)config)
1343 {
1344 XVisualInfo temp, *pret;
1345 int nret;
1346
1347 temp.visualid = v->visualid;
1348 pret = XGetVisualInfo(dpy, VisualIDMask, &temp, &nret);
1349
1350 if (nret!=1) crWarning("XGetVisualInfo returned %i visuals", nret);
1351 crDebug("glXGetVisualFromFBConfig(cfg/visid==0x%x): depth=%i", (int) config, pret->depth);
1352 return pret;
1353 }
1354 }
1355 */
1356 {
1357 XVisualInfo temp, *pret;
1358 int nret;
1359
1360 temp.visualid = (VisualID)config;
1361 XLOCK(dpy);
1362 pret = XGetVisualInfo(dpy, VisualIDMask, &temp, &nret);
1363 XUNLOCK(dpy);
1364
1365 if (nret!=1)
1366 {
1367 crWarning("XGetVisualInfo returned %i visuals for %p", nret, config);
1368 /* Hack for glut based apps.
1369 We fail to patch first call to glXChooseFBConfigSGIX, which ends up in the mesa's fbconfigs being passed to this function later.
1370 */
1371 if (!nret && config)
1372 {
1373 temp.visualid = (VisualID) ((__GLcontextModes*)config)->visualID;
1374 XLOCK(dpy);
1375 pret = XGetVisualInfo(dpy, VisualIDMask, &temp, &nret);
1376 XUNLOCK(dpy);
1377 crWarning("Retry with %#x returned %i visuals", ((__GLcontextModes*)config)->visualID, nret);
1378 }
1379 }
1380 //crDebug("glXGetVisualFromFBConfig(cfg/visid==0x%x): depth=%i", (int) config, pret->depth);
1381//crDebug("here");
1382 return pret;
1383 }
1384
1385 crDebug("glXGetVisualFromFBConfig unknown fbconfig %p", config);
1386 return NULL;
1387}
1388
1389DECLEXPORT(Bool) VBOXGLXTAG(glXMakeContextCurrent)(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
1390{
1391 currentReadDrawable = read;
1392 return VBOXGLXTAG(glXMakeCurrent)(display, draw, ctx);
1393}
1394
1395DECLEXPORT(int) VBOXGLXTAG(glXQueryContext)(Display *dpy, GLXContext ctx, int attribute, int *value)
1396{
1397 (void) dpy;
1398 (void) ctx;
1399 (void) attribute;
1400 (void) value;
1401 crWarning("glXQueryContext not implemented by Chromium");
1402 return 0;
1403}
1404
1405DECLEXPORT(void) VBOXGLXTAG(glXQueryDrawable)(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value)
1406{
1407 (void) dpy;
1408 (void) draw;
1409 (void) attribute;
1410 (void) value;
1411 crWarning("glXQueryDrawable not implemented by Chromium");
1412}
1413
1414DECLEXPORT(void) VBOXGLXTAG(glXSelectEvent)(Display *dpy, GLXDrawable draw, unsigned long event_mask)
1415{
1416 (void) dpy;
1417 (void) draw;
1418 (void) event_mask;
1419 crWarning("glXSelectEvent not implemented by Chromium");
1420}
1421
1422#ifdef CR_EXT_texture_from_pixmap
1423/*typedef struct
1424{
1425 int x, y;
1426 unsigned int w, h, border, depth;
1427 Window root;
1428 void *data;
1429} pminfo;*/
1430
1431static void stubInitXSharedMemory(Display *dpy)
1432{
1433 int vma, vmi;
1434 Bool pixmaps;
1435
1436 if (stub.bShmInitFailed || stub.xshmSI.shmid>=0)
1437 return;
1438
1439 stub.bShmInitFailed = GL_TRUE;
1440
1441 /* Check for extension and pixmaps format */
1442 XLOCK(dpy);
1443 if (!XShmQueryExtension(dpy))
1444 {
1445 crWarning("No XSHM extension");
1446 XUNLOCK(dpy);
1447 return;
1448 }
1449
1450 if (!XShmQueryVersion(dpy, &vma, &vmi, &pixmaps) || !pixmaps)
1451 {
1452 crWarning("XSHM extension doesn't support pixmaps");
1453 XUNLOCK(dpy);
1454 return;
1455 }
1456
1457 if (XShmPixmapFormat(dpy)!=ZPixmap)
1458 {
1459 crWarning("XSHM extension doesn't support ZPixmap format");
1460 XUNLOCK(dpy);
1461 return;
1462 }
1463 XUNLOCK(dpy);
1464
1465 /* Alloc shared memory, so far using hardcoded value...could fail for bigger displays one day */
1466 stub.xshmSI.readOnly = false;
1467 stub.xshmSI.shmid = shmget(IPC_PRIVATE, 4*4096*2048, IPC_CREAT | 0600);
1468 if (stub.xshmSI.shmid<0)
1469 {
1470 crWarning("XSHM Failed to create shared segment");
1471 return;
1472 }
1473
1474 stub.xshmSI.shmaddr = (char*) shmat(stub.xshmSI.shmid, NULL, 0);
1475 if (stub.xshmSI.shmaddr==(void*)-1)
1476 {
1477 crWarning("XSHM Failed to attach shared segment");
1478 shmctl(stub.xshmSI.shmid, IPC_RMID, 0);
1479 return;
1480 }
1481
1482 XLOCK(dpy);
1483 if (!XShmAttach(dpy, &stub.xshmSI))
1484 {
1485 crWarning("XSHM Failed to attach shared segment to XServer");
1486 shmctl(stub.xshmSI.shmid, IPC_RMID, 0);
1487 shmdt(stub.xshmSI.shmaddr);
1488 XUNLOCK(dpy);
1489 return;
1490 }
1491 XUNLOCK(dpy);
1492
1493 stub.bShmInitFailed = GL_FALSE;
1494 crInfo("Using XSHM for GLX_EXT_texture_from_pixmap");
1495
1496 /*Anyway mark to be deleted when our process detaches it, in case of segfault etc*/
1497
1498/* Ramshankar: Solaris compiz fix */
1499#ifndef RT_OS_SOLARIS
1500 shmctl(stub.xshmSI.shmid, IPC_RMID, 0);
1501#endif
1502}
1503
1504void stubQueryXDamageExtension(Display *dpy, ContextInfo *pContext)
1505{
1506 int erb, vma, vmi;
1507
1508 CRASSERT(pContext);
1509
1510 if (pContext->damageQueryFailed)
1511 return;
1512
1513 pContext->damageQueryFailed = True;
1514
1515 if (!XDamageQueryExtension(dpy, &pContext->damageEventsBase, &erb)
1516 || !XDamageQueryVersion(dpy, &vma, &vmi))
1517 {
1518 crWarning("XDamage not found or old version (%i.%i), going to run *very* slow", vma, vmi);
1519 return;
1520 }
1521
1522 crDebug("XDamage %i.%i", vma, vmi);
1523 pContext->damageQueryFailed = False;
1524}
1525
1526static void stubFetchDamageOnDrawable(Display *dpy, GLX_Pixmap_t *pGlxPixmap)
1527{
1528 Damage damage = pGlxPixmap->hDamage;
1529
1530 if (damage)
1531 {
1532 XRectangle *returnRects;
1533 int nReturnRects;
1534
1535 /* Get the damage region as a server region */
1536 XserverRegion serverDamageRegion = XFixesCreateRegion (dpy, NULL, 0);
1537
1538 /* Unite damage region with server region and clear damage region */
1539 XDamageSubtract (dpy,
1540 damage,
1541 None, /* subtract all damage from this region */
1542 serverDamageRegion /* save in serverDamageRegion */);
1543
1544 /* Fetch damage rectangles */
1545 returnRects = XFixesFetchRegion (dpy, serverDamageRegion, &nReturnRects);
1546
1547 /* Delete region */
1548 XFixesDestroyRegion (dpy, serverDamageRegion);
1549
1550 if (pGlxPixmap->pDamageRegion)
1551 {
1552 /* If it's dirty and regions are empty, it marked for full update, so do nothing.*/
1553 if (!pGlxPixmap->bPixmapImageDirty || !XEmptyRegion(pGlxPixmap->pDamageRegion))
1554 {
1555 int i = 0;
1556 for (; i < nReturnRects; ++i)
1557 {
1558 if (CR_MAX_DAMAGE_REGIONS_TRACKED <= pGlxPixmap->pDamageRegion->numRects)
1559 {
1560 /* Mark for full update */
1561 EMPTY_REGION(pGlxPixmap->pDamageRegion);
1562 }
1563 else
1564 {
1565 /* Add to damage regions */
1566 XUnionRectWithRegion(&returnRects[i], pGlxPixmap->pDamageRegion, pGlxPixmap->pDamageRegion);
1567 }
1568 }
1569 }
1570 }
1571
1572 XFree(returnRects);
1573
1574 pGlxPixmap->bPixmapImageDirty = True;
1575 }
1576}
1577
1578static const CRPixelPackState defaultPacking =
1579{
1580 0, /*rowLength*/
1581 0, /*skipRows*/
1582 0, /*skipPixels*/
1583 1, /*alignment*/
1584 0, /*imageHeight*/
1585 0, /*skipImages*/
1586 GL_FALSE, /*swapBytes*/
1587 GL_FALSE /*lsbFirst*/
1588};
1589
1590static void stubGetUnpackState(CRPixelPackState *pUnpackState)
1591{
1592 stub.spu->dispatch_table.GetIntegerv(GL_UNPACK_ROW_LENGTH, &pUnpackState->rowLength);
1593 stub.spu->dispatch_table.GetIntegerv(GL_UNPACK_SKIP_ROWS, &pUnpackState->skipRows);
1594 stub.spu->dispatch_table.GetIntegerv(GL_UNPACK_SKIP_PIXELS, &pUnpackState->skipPixels);
1595 stub.spu->dispatch_table.GetIntegerv(GL_UNPACK_ALIGNMENT, &pUnpackState->alignment);
1596 stub.spu->dispatch_table.GetBooleanv(GL_UNPACK_SWAP_BYTES, &pUnpackState->swapBytes);
1597 stub.spu->dispatch_table.GetBooleanv(GL_UNPACK_LSB_FIRST, &pUnpackState->psLSBFirst);
1598}
1599
1600static void stubSetUnpackState(const CRPixelPackState *pUnpackState)
1601{
1602 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_ROW_LENGTH, pUnpackState->rowLength);
1603 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_SKIP_ROWS, pUnpackState->skipRows);
1604 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_SKIP_PIXELS, pUnpackState->skipPixels);
1605 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_ALIGNMENT, pUnpackState->alignment);
1606 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_SWAP_BYTES, pUnpackState->swapBytes);
1607 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_LSB_FIRST, pUnpackState->psLSBFirst);
1608}
1609
1610static GLX_Pixmap_t* stubInitGlxPixmap(GLX_Pixmap_t* pCreateInfoPixmap, Display *dpy, GLXDrawable draw, ContextInfo *pContext)
1611{
1612 int x, y;
1613 unsigned int w, h;
1614 unsigned int border;
1615 unsigned int depth;
1616 Window root;
1617 GLX_Pixmap_t *pGlxPixmap;
1618
1619 CRASSERT(pContext && pCreateInfoPixmap);
1620
1621 XLOCK(dpy);
1622 if (!XGetGeometry(dpy, (Pixmap)draw, &root, &x, &y, &w, &h, &border, &depth))
1623 {
1624 XSync(dpy, False);
1625 if (!XGetGeometry(dpy, (Pixmap)draw, &root, &x, &y, &w, &h, &border, &depth))
1626 {
1627 crWarning("stubInitGlxPixmap failed in call to XGetGeometry for 0x%x", (int) draw);
1628 XUNLOCK(dpy);
1629 return NULL;
1630 }
1631 }
1632
1633 pGlxPixmap = crAlloc(sizeof(GLX_Pixmap_t));
1634 if (!pGlxPixmap)
1635 {
1636 crWarning("stubInitGlxPixmap failed to allocate memory");
1637 XUNLOCK(dpy);
1638 return NULL;
1639 }
1640
1641 pGlxPixmap->x = x;
1642 pGlxPixmap->y = y;
1643 pGlxPixmap->w = w;
1644 pGlxPixmap->h = h;
1645 pGlxPixmap->border = border;
1646 pGlxPixmap->depth = depth;
1647 pGlxPixmap->root = root;
1648 pGlxPixmap->format = pCreateInfoPixmap->format;
1649 pGlxPixmap->target = pCreateInfoPixmap->target;
1650
1651 /* Try to allocate shared memory
1652 * As we're allocating huge chunk of memory, do it in this function, only if this extension is really used
1653 */
1654 if (!stub.bShmInitFailed && stub.xshmSI.shmid<0)
1655 {
1656 stubInitXSharedMemory(dpy);
1657 }
1658
1659 if (stub.xshmSI.shmid>=0)
1660 {
1661 XGCValues xgcv;
1662 xgcv.graphics_exposures = False;
1663 xgcv.subwindow_mode = IncludeInferiors;
1664 pGlxPixmap->gc = XCreateGC(dpy, (Pixmap)draw, GCGraphicsExposures|GCSubwindowMode, &xgcv);
1665
1666 pGlxPixmap->hShmPixmap = XShmCreatePixmap(dpy, pGlxPixmap->root, stub.xshmSI.shmaddr, &stub.xshmSI,
1667 pGlxPixmap->w, pGlxPixmap->h, pGlxPixmap->depth);
1668 }
1669 else
1670 {
1671 pGlxPixmap->gc = NULL;
1672 pGlxPixmap->hShmPixmap = 0;
1673 }
1674 XUNLOCK(dpy);
1675
1676 /* If there's damage extension, then get handle for damage events related to this pixmap */
1677 if (!pContext->damageQueryFailed)
1678 {
1679 pGlxPixmap->hDamage = XDamageCreate(dpy, (Pixmap)draw, XDamageReportNonEmpty);
1680 /*crDebug("Create: Damage for drawable 0x%x, handle 0x%x (level=%i)",
1681 (unsigned int) draw, (unsigned int) pGlxPixmap->damage, (int) XDamageReportRawRectangles);*/
1682 pGlxPixmap->pDamageRegion = XCreateRegion();
1683 if (!pGlxPixmap->pDamageRegion)
1684 {
1685 crWarning("stubInitGlxPixmap failed to create empty damage region for drawable 0x%x", (unsigned int) draw);
1686 }
1687
1688 /*We have never seen this pixmap before, so mark it as dirty for first use*/
1689 pGlxPixmap->bPixmapImageDirty = True;
1690 }
1691 else
1692 {
1693 pGlxPixmap->hDamage = 0;
1694 pGlxPixmap->pDamageRegion = NULL;
1695 }
1696
1697 /* glTexSubImage2D generates GL_INVALID_OP if texture array hasn't been defined by a call to glTexImage2D first.
1698 * It's fine for small textures which would be updated in stubXshmUpdateWholeImage, but we'd never call glTexImage2D for big ones.
1699 * Note that we're making empty texture by passing NULL as pixels pointer, so there's no overhead transferring data to host.*/
1700 if (CR_MAX_TRANSFER_SIZE < 4*pGlxPixmap->w*pGlxPixmap->h)
1701 {
1702 stub.spu->dispatch_table.TexImage2D(pGlxPixmap->target, 0, pGlxPixmap->format, pGlxPixmap->w, pGlxPixmap->h, 0,
1703 GL_BGRA, GL_UNSIGNED_BYTE, NULL);
1704 }
1705
1706 crHashtableAdd(pContext->pGLXPixmapsHash, (unsigned int) draw, pGlxPixmap);
1707 crHashtableDelete(stub.pGLXPixmapsHash, (unsigned int) draw, crFree);
1708
1709 return pGlxPixmap;
1710}
1711
1712static void stubXshmUpdateWholeImage(Display *dpy, GLXDrawable draw, GLX_Pixmap_t *pGlxPixmap)
1713{
1714 /* To limit the size of transferring buffer, split bigger texture into regions
1715 * which fit into connection buffer. Could be done in hgcm or packspu but implementation in this place allows to avoid
1716 * unnecessary memcpy.
1717 * This also workarounds guest driver failures when sending 6+mb texture buffers on linux.
1718 */
1719 if (CR_MAX_TRANSFER_SIZE < 4*pGlxPixmap->w*pGlxPixmap->h)
1720 {
1721 XRectangle rect;
1722
1723 rect.x = pGlxPixmap->x;
1724 rect.y = pGlxPixmap->y;
1725 rect.width = pGlxPixmap->w;
1726 rect.height = CR_MAX_TRANSFER_SIZE/(4*pGlxPixmap->w);
1727
1728 /*crDebug("Texture size too big, splitting in lower sized chunks. [%i,%i,%i,%i] (%i)",
1729 pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h, rect.height);*/
1730
1731 for (; (rect.y+rect.height)<=(pGlxPixmap->y+(int)pGlxPixmap->h); rect.y+=rect.height)
1732 {
1733 stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
1734 }
1735
1736 if (rect.y!=(pGlxPixmap->y+(int)pGlxPixmap->h))
1737 {
1738 rect.height=pGlxPixmap->h-rect.y;
1739 stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
1740 }
1741 }
1742 else
1743 {
1744 CRPixelPackState unpackState;
1745
1746 XLOCK(dpy);
1747 XCopyArea(dpy, (Pixmap)draw, pGlxPixmap->hShmPixmap, pGlxPixmap->gc,
1748 pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h, 0, 0);
1749 /* Have to make sure XCopyArea is processed */
1750 XSync(dpy, False);
1751 XUNLOCK(dpy);
1752
1753 stubGetUnpackState(&unpackState);
1754 stubSetUnpackState(&defaultPacking);
1755 stub.spu->dispatch_table.TexImage2D(pGlxPixmap->target, 0, pGlxPixmap->format, pGlxPixmap->w, pGlxPixmap->h, 0,
1756 GL_BGRA, GL_UNSIGNED_BYTE, stub.xshmSI.shmaddr);
1757 stubSetUnpackState(&unpackState);
1758 /*crDebug("Sync texture for drawable 0x%x(dmg handle 0x%x) [%i,%i,%i,%i]",
1759 (unsigned int) draw, (unsigned int)pGlxPixmap->hDamage,
1760 pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h);*/
1761 }
1762}
1763
1764static void stubXshmUpdateImageRect(Display *dpy, GLXDrawable draw, GLX_Pixmap_t *pGlxPixmap, XRectangle *pRect)
1765{
1766 /* See comment in stubXshmUpdateWholeImage */
1767 if (CR_MAX_TRANSFER_SIZE < 4*pRect->width*pRect->height)
1768 {
1769 XRectangle rect;
1770
1771 rect.x = pRect->x;
1772 rect.y = pRect->y;
1773 rect.width = pRect->width;
1774 rect.height = CR_MAX_TRANSFER_SIZE/(4*pRect->width);
1775
1776 /*crDebug("Region size too big, splitting in lower sized chunks. [%i,%i,%i,%i] (%i)",
1777 pRect->x, pRect->y, pRect->width, pRect->height, rect.height);*/
1778
1779 for (; (rect.y+rect.height)<=(pRect->y+pRect->height); rect.y+=rect.height)
1780 {
1781 stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
1782 }
1783
1784 if (rect.y!=(pRect->y+pRect->height))
1785 {
1786 rect.height=pRect->y+pRect->height-rect.y;
1787 stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
1788 }
1789 }
1790 else
1791 {
1792 CRPixelPackState unpackState;
1793
1794 XLOCK(dpy);
1795 XCopyArea(dpy, (Pixmap)draw, pGlxPixmap->hShmPixmap, pGlxPixmap->gc,
1796 pRect->x, pRect->y, pRect->width, pRect->height, 0, 0);
1797 /* Have to make sure XCopyArea is processed */
1798 XSync(dpy, False);
1799 XUNLOCK(dpy);
1800
1801 stubGetUnpackState(&unpackState);
1802 stubSetUnpackState(&defaultPacking);
1803 if (pRect->width!=pGlxPixmap->w)
1804 {
1805 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_ROW_LENGTH, pGlxPixmap->w);
1806 }
1807 stub.spu->dispatch_table.TexSubImage2D(pGlxPixmap->target, 0, pRect->x, pRect->y, pRect->width, pRect->height,
1808 GL_BGRA, GL_UNSIGNED_BYTE, stub.xshmSI.shmaddr);
1809 stubSetUnpackState(&unpackState);
1810
1811 /*crDebug("Region sync texture for drawable 0x%x(dmg handle 0x%x) [%i,%i,%i,%i]",
1812 (unsigned int) draw, (unsigned int)pGlxPixmap->hDamage,
1813 pRect->x, pRect->y, pRect->width, pRect->height);*/
1814 }
1815}
1816
1817#if 0
1818Bool checkevents(Display *display, XEvent *event, XPointer arg)
1819{
1820 //crDebug("got type: 0x%x", event->type);
1821 if (event->type==damage_evb+XDamageNotify)
1822 {
1823 ContextInfo *context = stubGetCurrentContext();
1824 XDamageNotifyEvent *e = (XDamageNotifyEvent *) event;
1825 /* we're interested in pixmaps only...and those have e->drawable set to 0 or other strange value for some odd reason
1826 * so have to walk glxpixmaps hashtable to find if we have damage event handle assigned to some pixmap
1827 */
1828 /*crDebug("Event: Damage for drawable 0x%x, handle 0x%x (level=%i) [%i,%i,%i,%i]",
1829 (unsigned int) e->drawable, (unsigned int) e->damage, (int) e->level,
1830 e->area.x, e->area.y, e->area.width, e->area.height);*/
1831 CRASSERT(context);
1832 crHashtableWalk(context->pGLXPixmapsHash, checkdamageCB, e);
1833 }
1834 return False;
1835}
1836#endif
1837
1838/*@todo check what error codes could we throw for failures here*/
1839DECLEXPORT(void) VBOXGLXTAG(glXBindTexImageEXT)(Display *dpy, GLXDrawable draw, int buffer, const int *attrib_list)
1840{
1841 ContextInfo *context = stubGetCurrentContext();
1842 GLX_Pixmap_t *pGlxPixmap;
1843 RT_NOREF(buffer, attrib_list);
1844
1845 if (!context)
1846 {
1847 crWarning("glXBindTexImageEXT called without current context");
1848 return;
1849 }
1850
1851 pGlxPixmap = (GLX_Pixmap_t *) crHashtableSearch(context->pGLXPixmapsHash, (unsigned int) draw);
1852 if (!pGlxPixmap)
1853 {
1854 pGlxPixmap = (GLX_Pixmap_t *) crHashtableSearch(stub.pGLXPixmapsHash, (unsigned int) draw);
1855 if (!pGlxPixmap)
1856 {
1857 crDebug("Unknown drawable 0x%x in glXBindTexImageEXT!", (unsigned int) draw);
1858 return;
1859 }
1860 pGlxPixmap = stubInitGlxPixmap(pGlxPixmap, dpy, draw, context);
1861 if (!pGlxPixmap)
1862 {
1863 crDebug("glXBindTexImageEXT failed to get pGlxPixmap");
1864 return;
1865 }
1866 }
1867
1868 /* If there's damage extension, then process incoming events as we need the information right now */
1869 if (!context->damageQueryFailed)
1870 {
1871 /* Sync connection */
1872 XLOCK(dpy);
1873 XSync(dpy, False);
1874 XUNLOCK(dpy);
1875
1876 stubFetchDamageOnDrawable(dpy, pGlxPixmap);
1877 }
1878
1879 /* No shared memory? Rollback to use slow x protocol then */
1880 if (stub.xshmSI.shmid<0)
1881 {
1882 /*@todo add damage support here too*/
1883 XImage *pxim;
1884 CRPixelPackState unpackState;
1885
1886 XLOCK(dpy);
1887 pxim = XGetImage(dpy, (Pixmap)draw, pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h, AllPlanes, ZPixmap);
1888 XUNLOCK(dpy);
1889 /*if (pxim)
1890 {
1891 if (!ptextable)
1892 {
1893 ptextable = crAllocHashtable();
1894 }
1895 pm = crHashtableSearch(ptextable, (unsigned int) draw);
1896 if (!pm)
1897 {
1898 pm = crCalloc(sizeof(pminfo));
1899 crHashtableAdd(ptextable, (unsigned int) draw, pm);
1900 }
1901 pm->w = w;
1902 pm->h = h;
1903 if (pm->data) crFree(pm->data);
1904 pm->data = crAlloc(4*w*h);
1905 crMemcpy(pm->data, (void*)(&(pxim->data[0])), 4*w*h);
1906 }*/
1907
1908 if (NULL==pxim)
1909 {
1910 crWarning("Failed, to get pixmap data for 0x%x", (unsigned int) draw);
1911 return;
1912 }
1913
1914 stubGetUnpackState(&unpackState);
1915 stubSetUnpackState(&defaultPacking);
1916 stub.spu->dispatch_table.TexImage2D(pGlxPixmap->target, 0, pGlxPixmap->format, pxim->width, pxim->height, 0,
1917 GL_BGRA, GL_UNSIGNED_BYTE, (void*)(&(pxim->data[0])));
1918 stubSetUnpackState(&unpackState);
1919 XDestroyImage(pxim);
1920 }
1921 else /* Use shm to get pixmap data */
1922 {
1923 /* Check if we have damage extension */
1924 if (!context->damageQueryFailed)
1925 {
1926 if (pGlxPixmap->bPixmapImageDirty)
1927 {
1928 /* Either we failed to allocate damage region or this pixmap is marked for full update */
1929 if (!pGlxPixmap->pDamageRegion || XEmptyRegion(pGlxPixmap->pDamageRegion))
1930 {
1931 /*crDebug("**FULL** update for 0x%x", (unsigned int)draw);*/
1932 stubXshmUpdateWholeImage(dpy, draw, pGlxPixmap);
1933 }
1934 else
1935 {
1936 long fullArea, damageArea=0, clipdamageArea, i;
1937 XRectangle damageClipBox;
1938
1939 fullArea = pGlxPixmap->w * pGlxPixmap->h;
1940 XClipBox(pGlxPixmap->pDamageRegion, &damageClipBox);
1941 clipdamageArea = damageClipBox.width * damageClipBox.height;
1942
1943 //crDebug("FullSize [%i,%i,%i,%i]", pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h);
1944 //crDebug("Clip [%i,%i,%i,%i]", damageClipBox.x, damageClipBox.y, damageClipBox.width, damageClipBox.height);
1945
1946 for (i=0; i<pGlxPixmap->pDamageRegion->numRects; ++i)
1947 {
1948 BoxPtr pBox = &pGlxPixmap->pDamageRegion->rects[i];
1949 damageArea += (pBox->x2-pBox->x1)*(pBox->y2-pBox->y1);
1950 //crDebug("Damage rect [%i,%i,%i,%i]", pBox->x1, pBox->y1, pBox->x2, pBox->y2);
1951 }
1952
1953 if (damageArea>clipdamageArea || clipdamageArea>fullArea)
1954 {
1955 crWarning("glXBindTexImageEXT, damage regions seems to be broken, forcing full update");
1956 /*crDebug("**FULL** update for 0x%x, numRect=%li, *FS*=%li, CS=%li, DS=%li",
1957 (unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
1958 stubXshmUpdateWholeImage(dpy, draw, pGlxPixmap);
1959 }
1960 else /*We have corect damage info*/
1961 {
1962 if (CR_MIN_DAMAGE_PROFIT_SIZE > (fullArea-damageArea))
1963 {
1964 /*crDebug("**FULL** update for 0x%x, numRect=%li, *FS*=%li, CS=%li, DS=%li",
1965 (unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
1966 stubXshmUpdateWholeImage(dpy, draw, pGlxPixmap);
1967 }
1968 else if (CR_MIN_DAMAGE_PROFIT_SIZE > (clipdamageArea-damageArea))
1969 {
1970 /*crDebug("**PARTIAL** update for 0x%x, numRect=%li, FS=%li, *CS*=%li, DS=%li",
1971 (unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
1972 stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &damageClipBox);
1973 }
1974 else
1975 {
1976 /*crDebug("**PARTIAL** update for 0x%x, numRect=*%li*, FS=%li, CS=%li, *DS*=%li",
1977 (unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
1978 for (i=0; i<pGlxPixmap->pDamageRegion->numRects; ++i)
1979 {
1980 XRectangle rect;
1981 BoxPtr pBox = &pGlxPixmap->pDamageRegion->rects[i];
1982
1983 rect.x = pBox->x1;
1984 rect.y = pBox->y1;
1985 rect.width = pBox->x2-pBox->x1;
1986 rect.height = pBox->y2-pBox->y1;
1987
1988 stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
1989 }
1990 }
1991 }
1992 }
1993
1994 /* Clean dirty flag and damage region */
1995 pGlxPixmap->bPixmapImageDirty = False;
1996 if (pGlxPixmap->pDamageRegion)
1997 EMPTY_REGION(pGlxPixmap->pDamageRegion);
1998 }
1999 }
2000 else
2001 {
2002 stubXshmUpdateWholeImage(dpy, draw, pGlxPixmap);
2003 }
2004 }
2005}
2006
2007DECLEXPORT(void) VBOXGLXTAG(glXReleaseTexImageEXT)(Display *dpy, GLXDrawable draw, int buffer)
2008{
2009 (void) dpy;
2010 (void) draw;
2011 (void) buffer;
2012 //crDebug("glXReleaseTexImageEXT 0x%x", (unsigned int)draw);
2013}
2014#endif
2015
2016#endif /* GLX_EXTRAS */
2017
2018
2019#ifdef GLX_SGIX_video_resize
2020/* more dummy funcs. These help when linking with older GLUTs */
2021
2022DECLEXPORT(int) VBOXGLXTAG(glXBindChannelToWindowSGIX)(Display *dpy, int scrn, int chan, Window w)
2023{
2024 (void) dpy;
2025 (void) scrn;
2026 (void) chan;
2027 (void) w;
2028 crDebug("glXBindChannelToWindowSGIX");
2029 return 0;
2030}
2031
2032DECLEXPORT(int) VBOXGLXTAG(glXChannelRectSGIX)(Display *dpy, int scrn, int chan, int x , int y, int w, int h)
2033{
2034 (void) dpy;
2035 (void) scrn;
2036 (void) chan;
2037 (void) x;
2038 (void) y;
2039 (void) w;
2040 (void) h;
2041 crDebug("glXChannelRectSGIX");
2042 return 0;
2043}
2044
2045DECLEXPORT(int) VBOXGLXTAG(glXQueryChannelRectSGIX)(Display *dpy, int scrn, int chan, int *x, int *y, int *w, int *h)
2046{
2047 (void) dpy;
2048 (void) scrn;
2049 (void) chan;
2050 (void) x;
2051 (void) y;
2052 (void) w;
2053 (void) h;
2054 crDebug("glXQueryChannelRectSGIX");
2055 return 0;
2056}
2057
2058DECLEXPORT(int) VBOXGLXTAG(glXQueryChannelDeltasSGIX)(Display *dpy, int scrn, int chan, int *dx, int *dy, int *dw, int *dh)
2059{
2060 (void) dpy;
2061 (void) scrn;
2062 (void) chan;
2063 (void) dx;
2064 (void) dy;
2065 (void) dw;
2066 (void) dh;
2067 crDebug("glXQueryChannelDeltasSGIX");
2068 return 0;
2069}
2070
2071DECLEXPORT(int) VBOXGLXTAG(glXChannelRectSyncSGIX)(Display *dpy, int scrn, int chan, GLenum synctype)
2072{
2073 (void) dpy;
2074 (void) scrn;
2075 (void) chan;
2076 (void) synctype;
2077 crDebug("glXChannelRectSyncSGIX");
2078 return 0;
2079}
2080
2081#endif /* GLX_SGIX_video_resize */
2082
2083#ifdef VBOXOGL_FAKEDRI
2084DECLEXPORT(const char *) VBOXGLXTAG(glXGetDriverConfig)(const char *driverName)
2085{
2086 return NULL;
2087}
2088
2089DECLEXPORT(void) VBOXGLXTAG(glXFreeMemoryMESA)(Display *dpy, int scrn, void *pointer)
2090{
2091 (void) dpy;
2092 (void) scrn;
2093 (void) pointer;
2094}
2095
2096DECLEXPORT(GLXContext) VBOXGLXTAG(glXImportContextEXT)(Display *dpy, GLXContextID contextID)
2097{
2098 (void) dpy;
2099 (void) contextID;
2100 return NULL;
2101}
2102
2103DECLEXPORT(GLXContextID) VBOXGLXTAG(glXGetContextIDEXT)(const GLXContext ctx)
2104{
2105 (void) ctx;
2106 return 0;
2107}
2108
2109DECLEXPORT(Bool) VBOXGLXTAG(glXMakeCurrentReadSGI)(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
2110{
2111 return VBOXGLXTAG(glXMakeContextCurrent)(display, draw, read, ctx);
2112}
2113
2114DECLEXPORT(const char *) VBOXGLXTAG(glXGetScreenDriver)(Display *dpy, int scrNum)
2115{
2116 static char *screendriver = "vboxvideo";
2117 return screendriver;
2118}
2119
2120DECLEXPORT(Display *) VBOXGLXTAG(glXGetCurrentDisplayEXT)(void)
2121{
2122 return VBOXGLXTAG(glXGetCurrentDisplay());
2123}
2124
2125DECLEXPORT(void) VBOXGLXTAG(glXFreeContextEXT)(Display *dpy, GLXContext ctx)
2126{
2127 VBOXGLXTAG(glXDestroyContext(dpy, ctx));
2128}
2129
2130/*Mesa internal*/
2131DECLEXPORT(int) VBOXGLXTAG(glXQueryContextInfoEXT)(Display *dpy, GLXContext ctx)
2132{
2133 (void) dpy;
2134 (void) ctx;
2135 return 0;
2136}
2137
2138DECLEXPORT(void *) VBOXGLXTAG(glXAllocateMemoryMESA)(Display *dpy, int scrn,
2139 size_t size, float readFreq,
2140 float writeFreq, float priority)
2141{
2142 (void) dpy;
2143 (void) scrn;
2144 (void) size;
2145 (void) readFreq;
2146 (void) writeFreq;
2147 (void) priority;
2148 return NULL;
2149}
2150
2151DECLEXPORT(GLuint) VBOXGLXTAG(glXGetMemoryOffsetMESA)(Display *dpy, int scrn, const void *pointer)
2152{
2153 (void) dpy;
2154 (void) scrn;
2155 (void) pointer;
2156 return 0;
2157}
2158
2159DECLEXPORT(GLXPixmap) VBOXGLXTAG(glXCreateGLXPixmapMESA)(Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap)
2160{
2161 (void) dpy;
2162 (void) visual;
2163 (void) pixmap;
2164 (void) cmap;
2165 return 0;
2166}
2167
2168#endif /*VBOXOGL_FAKEDRI*/
Note: See TracBrowser for help on using the repository browser.

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