VirtualBox

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

Last change on this file since 78795 was 78795, checked in by vboxsync, 6 years ago

Additions/common/crOpenGL/glx.c: Avoid a warning about bad/unknown attributes

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