VirtualBox

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

Last change on this file since 70344 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 61.5 KB
Line 
1/* $Id: glx.c 69500 2017-10-28 15:14:05Z vboxsync $ */
2/** @file
3 * VBox OpenGL GLX implementation
4 */
5
6/*
7 * Copyright (C) 2009-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. 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_X_VISUAL_TYPE:
932 case GLX_TRANSPARENT_TYPE_EXT:
933 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
934 case GLX_TRANSPARENT_RED_VALUE_EXT:
935 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
936 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
937 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
938 /* ignore */
939 crWarning("glXChooseVisual: ignoring attribute 0x%x", *attrib);
940 attrib++;
941 break;
942
943 break;
944 default:
945 crWarning( "glXChooseVisual: bad attrib=0x%x, ignoring", *attrib );
946 attrib++;
947 break;
948 }
949 }
950
951 if (fbconfig)
952 {
953 GLXFBConfig *pGLXFBConfigs;
954
955 *nelements = 1;
956 pGLXFBConfigs = (GLXFBConfig *) crAlloc(*nelements * sizeof(GLXFBConfig));
957 pGLXFBConfigs[0] = (GLXFBConfig)fbconfig;
958 return pGLXFBConfigs;
959 }
960 else
961 {
962 return VBOXGLXTAG(glXGetFBConfigs)(dpy, screen, nelements);
963 }
964
965err_exit:
966 crWarning("glXChooseFBConfig returning NULL, due to attrib=0x%x, next=0x%x", attrib[0], attrib[1]);
967 return NULL;
968}
969
970DECLEXPORT(GLXContext)
971VBOXGLXTAG(glXCreateNewContext)(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct)
972{
973 (void) dpy;
974 (void) config;
975 (void) render_type;
976 (void) share_list;
977 (void) direct;
978
979 if (render_type != GLX_RGBA_TYPE)
980 {
981 crWarning("glXCreateNewContext, unsupported render_type %x", render_type);
982 return NULL;
983 }
984
985 return VBOXGLXTAG(glXCreateContext)(dpy, NULL, 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, 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 switch (attribute)
1193 {
1194 case GLX_DRAWABLE_TYPE:
1195 *value = GLX_PIXMAP_BIT | GLX_WINDOW_BIT;
1196 break;
1197 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
1198 *value = GLX_TEXTURE_2D_BIT_EXT;
1199 pExt = (const char *) stub.spu->dispatch_table.GetString(GL_EXTENSIONS);
1200 if (crStrstr(pExt, "GL_NV_texture_rectangle")
1201 || crStrstr(pExt, "GL_ARB_texture_rectangle")
1202 || crStrstr(pExt, "GL_EXT_texture_rectangle"))
1203 {
1204 *value |= GLX_TEXTURE_RECTANGLE_BIT_EXT;
1205 }
1206 break;
1207 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
1208 *value = True;
1209 break;
1210 case GLX_BIND_TO_TEXTURE_RGB_EXT:
1211 *value = True;
1212 break;
1213 case GLX_DOUBLEBUFFER:
1214 //crDebug("attribute=GLX_DOUBLEBUFFER");
1215 *value = True;
1216 break;
1217 case GLX_Y_INVERTED_EXT:
1218 *value = True;
1219 break;
1220 case GLX_ALPHA_SIZE:
1221 //crDebug("attribute=GLX_ALPHA_SIZE");
1222 *value = 8;
1223 break;
1224 case GLX_BUFFER_SIZE:
1225 //crDebug("attribute=GLX_BUFFER_SIZE");
1226 *value = 32;
1227 break;
1228 case GLX_STENCIL_SIZE:
1229 //crDebug("attribute=GLX_STENCIL_SIZE");
1230 *value = 8;
1231 break;
1232 case GLX_DEPTH_SIZE:
1233 *value = 24;
1234 //crDebug("attribute=GLX_DEPTH_SIZE");
1235 break;
1236 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
1237 *value = 0;
1238 break;
1239 case GLX_RENDER_TYPE:
1240 //crDebug("attribute=GLX_RENDER_TYPE");
1241 *value = GLX_RGBA_BIT;
1242 break;
1243 case GLX_CONFIG_CAVEAT:
1244 //crDebug("attribute=GLX_CONFIG_CAVEAT");
1245 *value = GLX_NONE;
1246 break;
1247 case GLX_VISUAL_ID:
1248 //crDebug("attribute=GLX_VISUAL_ID");
1249 pVisual = visualInfoFromFBConfig(dpy, config);
1250 if (!pVisual)
1251 {
1252 crWarning("glXGetFBConfigAttrib for %p, failed to get XVisualInfo", config);
1253 return GLX_BAD_ATTRIBUTE;
1254 }
1255 *value = pVisual->visualid;
1256 XFree(pVisual);
1257 break;
1258 case GLX_FBCONFIG_ID:
1259 *value = (int)(intptr_t)config;
1260 break;
1261 case GLX_RED_SIZE:
1262 case GLX_GREEN_SIZE:
1263 case GLX_BLUE_SIZE:
1264 *value = 8;
1265 break;
1266 case GLX_LEVEL:
1267 *value = 0;
1268 break;
1269 case GLX_STEREO:
1270 *value = false;
1271 break;
1272 case GLX_AUX_BUFFERS:
1273 *value = 0;
1274 break;
1275 case GLX_ACCUM_RED_SIZE:
1276 case GLX_ACCUM_GREEN_SIZE:
1277 case GLX_ACCUM_BLUE_SIZE:
1278 case GLX_ACCUM_ALPHA_SIZE:
1279 *value = 0;
1280 break;
1281 case GLX_X_VISUAL_TYPE:
1282 *value = GLX_TRUE_COLOR;
1283 break;
1284 case GLX_TRANSPARENT_TYPE:
1285 *value = GLX_NONE;
1286 break;
1287 case GLX_SAMPLE_BUFFERS:
1288 case GLX_SAMPLES:
1289 *value = 1;
1290 break;
1291 case GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT:
1292 *value = 0;
1293 break;
1294 default:
1295 crDebug("glXGetFBConfigAttrib: unknown attribute=0x%x", attribute);
1296 return GLX_BAD_ATTRIBUTE;
1297 }
1298
1299 return Success;
1300}
1301
1302DECLEXPORT(GLXFBConfig *) VBOXGLXTAG(glXGetFBConfigs)(Display *dpy, int screen, int *nelements)
1303{
1304 int i;
1305
1306 GLXFBConfig *pGLXFBConfigs = crAlloc(sizeof(GLXFBConfig));
1307
1308 *nelements = 1;
1309 XLOCK(dpy);
1310 *pGLXFBConfigs = defaultFBConfigForScreen(dpy, screen);
1311 XUNLOCK(dpy);
1312
1313 crDebug("glXGetFBConfigs returned %i configs", *nelements);
1314 for (i=0; i<*nelements; ++i)
1315 {
1316 crDebug("glXGetFBConfigs[%i]=0x%x", i, (unsigned)(uintptr_t) pGLXFBConfigs[i]);
1317 }
1318 return pGLXFBConfigs;
1319}
1320
1321DECLEXPORT(void) VBOXGLXTAG(glXGetSelectedEvent)(Display *dpy, GLXDrawable draw, unsigned long *event_mask)
1322{
1323 (void) dpy;
1324 (void) draw;
1325 (void) event_mask;
1326 crWarning("glXGetSelectedEvent not implemented by Chromium");
1327}
1328
1329DECLEXPORT(XVisualInfo *) VBOXGLXTAG(glXGetVisualFromFBConfig)(Display *dpy, GLXFBConfig config)
1330{
1331 return visualInfoFromFBConfig(dpy, config);
1332}
1333
1334DECLEXPORT(Bool) VBOXGLXTAG(glXMakeContextCurrent)(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
1335{
1336 currentReadDrawable = read;
1337 return VBOXGLXTAG(glXMakeCurrent)(display, draw, ctx);
1338}
1339
1340DECLEXPORT(int) VBOXGLXTAG(glXQueryContext)(Display *dpy, GLXContext ctx, int attribute, int *value)
1341{
1342 (void) dpy;
1343 (void) ctx;
1344 (void) attribute;
1345 (void) value;
1346 crWarning("glXQueryContext not implemented by Chromium");
1347 return 0;
1348}
1349
1350DECLEXPORT(void) VBOXGLXTAG(glXQueryDrawable)(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value)
1351{
1352 (void) dpy;
1353 (void) draw;
1354 (void) attribute;
1355 (void) value;
1356 crWarning("glXQueryDrawable not implemented by Chromium");
1357}
1358
1359DECLEXPORT(void) VBOXGLXTAG(glXSelectEvent)(Display *dpy, GLXDrawable draw, unsigned long event_mask)
1360{
1361 (void) dpy;
1362 (void) draw;
1363 (void) event_mask;
1364 crWarning("glXSelectEvent not implemented by Chromium");
1365}
1366
1367#ifdef CR_EXT_texture_from_pixmap
1368/*typedef struct
1369{
1370 int x, y;
1371 unsigned int w, h, border, depth;
1372 Window root;
1373 void *data;
1374} pminfo;*/
1375
1376static void stubInitXSharedMemory(Display *dpy)
1377{
1378 int vma, vmi;
1379 Bool pixmaps;
1380
1381 if (stub.bShmInitFailed || stub.xshmSI.shmid>=0)
1382 return;
1383
1384 stub.bShmInitFailed = GL_TRUE;
1385
1386 /* Check for extension and pixmaps format */
1387 XLOCK(dpy);
1388 if (!XShmQueryExtension(dpy))
1389 {
1390 crWarning("No XSHM extension");
1391 XUNLOCK(dpy);
1392 return;
1393 }
1394
1395 if (!XShmQueryVersion(dpy, &vma, &vmi, &pixmaps) || !pixmaps)
1396 {
1397 crWarning("XSHM extension doesn't support pixmaps");
1398 XUNLOCK(dpy);
1399 return;
1400 }
1401
1402 if (XShmPixmapFormat(dpy)!=ZPixmap)
1403 {
1404 crWarning("XSHM extension doesn't support ZPixmap format");
1405 XUNLOCK(dpy);
1406 return;
1407 }
1408 XUNLOCK(dpy);
1409
1410 /* Alloc shared memory, so far using hardcoded value...could fail for bigger displays one day */
1411 stub.xshmSI.readOnly = false;
1412 stub.xshmSI.shmid = shmget(IPC_PRIVATE, 4*4096*2048, IPC_CREAT | 0600);
1413 if (stub.xshmSI.shmid<0)
1414 {
1415 crWarning("XSHM Failed to create shared segment");
1416 return;
1417 }
1418
1419 stub.xshmSI.shmaddr = (char*) shmat(stub.xshmSI.shmid, NULL, 0);
1420 if (stub.xshmSI.shmaddr==(void*)-1)
1421 {
1422 crWarning("XSHM Failed to attach shared segment");
1423 shmctl(stub.xshmSI.shmid, IPC_RMID, 0);
1424 return;
1425 }
1426
1427 XLOCK(dpy);
1428 if (!XShmAttach(dpy, &stub.xshmSI))
1429 {
1430 crWarning("XSHM Failed to attach shared segment to XServer");
1431 shmctl(stub.xshmSI.shmid, IPC_RMID, 0);
1432 shmdt(stub.xshmSI.shmaddr);
1433 XUNLOCK(dpy);
1434 return;
1435 }
1436 XUNLOCK(dpy);
1437
1438 stub.bShmInitFailed = GL_FALSE;
1439 crInfo("Using XSHM for GLX_EXT_texture_from_pixmap");
1440
1441 /*Anyway mark to be deleted when our process detaches it, in case of segfault etc*/
1442
1443/* Ramshankar: Solaris compiz fix */
1444#ifndef RT_OS_SOLARIS
1445 shmctl(stub.xshmSI.shmid, IPC_RMID, 0);
1446#endif
1447}
1448
1449void stubQueryXDamageExtension(Display *dpy, ContextInfo *pContext)
1450{
1451 int erb, vma, vmi;
1452
1453 CRASSERT(pContext);
1454
1455 if (pContext->damageQueryFailed)
1456 return;
1457
1458 pContext->damageQueryFailed = True;
1459
1460 if (!XDamageQueryExtension(dpy, &pContext->damageEventsBase, &erb)
1461 || !XDamageQueryVersion(dpy, &vma, &vmi))
1462 {
1463 crWarning("XDamage not found or old version (%i.%i), going to run *very* slow", vma, vmi);
1464 return;
1465 }
1466
1467 crDebug("XDamage %i.%i", vma, vmi);
1468 pContext->damageQueryFailed = False;
1469}
1470
1471static void stubFetchDamageOnDrawable(Display *dpy, GLX_Pixmap_t *pGlxPixmap)
1472{
1473 Damage damage = pGlxPixmap->hDamage;
1474
1475 if (damage)
1476 {
1477 XRectangle *returnRects;
1478 int nReturnRects;
1479
1480 /* Get the damage region as a server region */
1481 XserverRegion serverDamageRegion = XFixesCreateRegion (dpy, NULL, 0);
1482
1483 /* Unite damage region with server region and clear damage region */
1484 XDamageSubtract (dpy,
1485 damage,
1486 None, /* subtract all damage from this region */
1487 serverDamageRegion /* save in serverDamageRegion */);
1488
1489 /* Fetch damage rectangles */
1490 returnRects = XFixesFetchRegion (dpy, serverDamageRegion, &nReturnRects);
1491
1492 /* Delete region */
1493 XFixesDestroyRegion (dpy, serverDamageRegion);
1494
1495 if (pGlxPixmap->pDamageRegion)
1496 {
1497 /* If it's dirty and regions are empty, it marked for full update, so do nothing.*/
1498 if (!pGlxPixmap->bPixmapImageDirty || !XEmptyRegion(pGlxPixmap->pDamageRegion))
1499 {
1500 int i = 0;
1501 for (; i < nReturnRects; ++i)
1502 {
1503 if (CR_MAX_DAMAGE_REGIONS_TRACKED <= pGlxPixmap->pDamageRegion->numRects)
1504 {
1505 /* Mark for full update */
1506 EMPTY_REGION(pGlxPixmap->pDamageRegion);
1507 }
1508 else
1509 {
1510 /* Add to damage regions */
1511 XUnionRectWithRegion(&returnRects[i], pGlxPixmap->pDamageRegion, pGlxPixmap->pDamageRegion);
1512 }
1513 }
1514 }
1515 }
1516
1517 XFree(returnRects);
1518
1519 pGlxPixmap->bPixmapImageDirty = True;
1520 }
1521}
1522
1523static const CRPixelPackState defaultPacking =
1524{
1525 0, /*rowLength*/
1526 0, /*skipRows*/
1527 0, /*skipPixels*/
1528 1, /*alignment*/
1529 0, /*imageHeight*/
1530 0, /*skipImages*/
1531 GL_FALSE, /*swapBytes*/
1532 GL_FALSE /*lsbFirst*/
1533};
1534
1535static void stubGetUnpackState(CRPixelPackState *pUnpackState)
1536{
1537 stub.spu->dispatch_table.GetIntegerv(GL_UNPACK_ROW_LENGTH, &pUnpackState->rowLength);
1538 stub.spu->dispatch_table.GetIntegerv(GL_UNPACK_SKIP_ROWS, &pUnpackState->skipRows);
1539 stub.spu->dispatch_table.GetIntegerv(GL_UNPACK_SKIP_PIXELS, &pUnpackState->skipPixels);
1540 stub.spu->dispatch_table.GetIntegerv(GL_UNPACK_ALIGNMENT, &pUnpackState->alignment);
1541 stub.spu->dispatch_table.GetBooleanv(GL_UNPACK_SWAP_BYTES, &pUnpackState->swapBytes);
1542 stub.spu->dispatch_table.GetBooleanv(GL_UNPACK_LSB_FIRST, &pUnpackState->psLSBFirst);
1543}
1544
1545static void stubSetUnpackState(const CRPixelPackState *pUnpackState)
1546{
1547 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_ROW_LENGTH, pUnpackState->rowLength);
1548 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_SKIP_ROWS, pUnpackState->skipRows);
1549 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_SKIP_PIXELS, pUnpackState->skipPixels);
1550 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_ALIGNMENT, pUnpackState->alignment);
1551 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_SWAP_BYTES, pUnpackState->swapBytes);
1552 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_LSB_FIRST, pUnpackState->psLSBFirst);
1553}
1554
1555static GLX_Pixmap_t* stubInitGlxPixmap(GLX_Pixmap_t* pCreateInfoPixmap, Display *dpy, GLXDrawable draw, ContextInfo *pContext)
1556{
1557 int x, y;
1558 unsigned int w, h;
1559 unsigned int border;
1560 unsigned int depth;
1561 Window root;
1562 GLX_Pixmap_t *pGlxPixmap;
1563
1564 CRASSERT(pContext && pCreateInfoPixmap);
1565
1566 XLOCK(dpy);
1567 if (!XGetGeometry(dpy, (Pixmap)draw, &root, &x, &y, &w, &h, &border, &depth))
1568 {
1569 XSync(dpy, False);
1570 if (!XGetGeometry(dpy, (Pixmap)draw, &root, &x, &y, &w, &h, &border, &depth))
1571 {
1572 crWarning("stubInitGlxPixmap failed in call to XGetGeometry for 0x%x", (int) draw);
1573 XUNLOCK(dpy);
1574 return NULL;
1575 }
1576 }
1577
1578 pGlxPixmap = crAlloc(sizeof(GLX_Pixmap_t));
1579 if (!pGlxPixmap)
1580 {
1581 crWarning("stubInitGlxPixmap failed to allocate memory");
1582 XUNLOCK(dpy);
1583 return NULL;
1584 }
1585
1586 pGlxPixmap->x = x;
1587 pGlxPixmap->y = y;
1588 pGlxPixmap->w = w;
1589 pGlxPixmap->h = h;
1590 pGlxPixmap->border = border;
1591 pGlxPixmap->depth = depth;
1592 pGlxPixmap->root = root;
1593 pGlxPixmap->format = pCreateInfoPixmap->format;
1594 pGlxPixmap->target = pCreateInfoPixmap->target;
1595
1596 /* Try to allocate shared memory
1597 * As we're allocating huge chunk of memory, do it in this function, only if this extension is really used
1598 */
1599 if (!stub.bShmInitFailed && stub.xshmSI.shmid<0)
1600 {
1601 stubInitXSharedMemory(dpy);
1602 }
1603
1604 if (stub.xshmSI.shmid>=0)
1605 {
1606 XGCValues xgcv;
1607 xgcv.graphics_exposures = False;
1608 xgcv.subwindow_mode = IncludeInferiors;
1609 pGlxPixmap->gc = XCreateGC(dpy, (Pixmap)draw, GCGraphicsExposures|GCSubwindowMode, &xgcv);
1610
1611 pGlxPixmap->hShmPixmap = XShmCreatePixmap(dpy, pGlxPixmap->root, stub.xshmSI.shmaddr, &stub.xshmSI,
1612 pGlxPixmap->w, pGlxPixmap->h, pGlxPixmap->depth);
1613 }
1614 else
1615 {
1616 pGlxPixmap->gc = NULL;
1617 pGlxPixmap->hShmPixmap = 0;
1618 }
1619 XUNLOCK(dpy);
1620
1621 /* If there's damage extension, then get handle for damage events related to this pixmap */
1622 if (!pContext->damageQueryFailed)
1623 {
1624 pGlxPixmap->hDamage = XDamageCreate(dpy, (Pixmap)draw, XDamageReportNonEmpty);
1625 /*crDebug("Create: Damage for drawable 0x%x, handle 0x%x (level=%i)",
1626 (unsigned int) draw, (unsigned int) pGlxPixmap->damage, (int) XDamageReportRawRectangles);*/
1627 pGlxPixmap->pDamageRegion = XCreateRegion();
1628 if (!pGlxPixmap->pDamageRegion)
1629 {
1630 crWarning("stubInitGlxPixmap failed to create empty damage region for drawable 0x%x", (unsigned int) draw);
1631 }
1632
1633 /*We have never seen this pixmap before, so mark it as dirty for first use*/
1634 pGlxPixmap->bPixmapImageDirty = True;
1635 }
1636 else
1637 {
1638 pGlxPixmap->hDamage = 0;
1639 pGlxPixmap->pDamageRegion = NULL;
1640 }
1641
1642 /* glTexSubImage2D generates GL_INVALID_OP if texture array hasn't been defined by a call to glTexImage2D first.
1643 * It's fine for small textures which would be updated in stubXshmUpdateWholeImage, but we'd never call glTexImage2D for big ones.
1644 * Note that we're making empty texture by passing NULL as pixels pointer, so there's no overhead transferring data to host.*/
1645 if (CR_MAX_TRANSFER_SIZE < 4*pGlxPixmap->w*pGlxPixmap->h)
1646 {
1647 stub.spu->dispatch_table.TexImage2D(pGlxPixmap->target, 0, pGlxPixmap->format, pGlxPixmap->w, pGlxPixmap->h, 0,
1648 GL_BGRA, GL_UNSIGNED_BYTE, NULL);
1649 }
1650
1651 crHashtableAdd(pContext->pGLXPixmapsHash, (unsigned int) draw, pGlxPixmap);
1652 crHashtableDelete(stub.pGLXPixmapsHash, (unsigned int) draw, crFree);
1653
1654 return pGlxPixmap;
1655}
1656
1657static void stubXshmUpdateWholeImage(Display *dpy, GLXDrawable draw, GLX_Pixmap_t *pGlxPixmap)
1658{
1659 /* To limit the size of transferring buffer, split bigger texture into regions
1660 * which fit into connection buffer. Could be done in hgcm or packspu but implementation in this place allows to avoid
1661 * unnecessary memcpy.
1662 * This also workarounds guest driver failures when sending 6+mb texture buffers on linux.
1663 */
1664 if (CR_MAX_TRANSFER_SIZE < 4*pGlxPixmap->w*pGlxPixmap->h)
1665 {
1666 XRectangle rect;
1667
1668 rect.x = pGlxPixmap->x;
1669 rect.y = pGlxPixmap->y;
1670 rect.width = pGlxPixmap->w;
1671 rect.height = CR_MAX_TRANSFER_SIZE/(4*pGlxPixmap->w);
1672
1673 /*crDebug("Texture size too big, splitting in lower sized chunks. [%i,%i,%i,%i] (%i)",
1674 pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h, rect.height);*/
1675
1676 for (; (rect.y+rect.height)<=(pGlxPixmap->y+(int)pGlxPixmap->h); rect.y+=rect.height)
1677 {
1678 stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
1679 }
1680
1681 if (rect.y!=(pGlxPixmap->y+(int)pGlxPixmap->h))
1682 {
1683 rect.height=pGlxPixmap->h-rect.y;
1684 stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
1685 }
1686 }
1687 else
1688 {
1689 CRPixelPackState unpackState;
1690
1691 XLOCK(dpy);
1692 XCopyArea(dpy, (Pixmap)draw, pGlxPixmap->hShmPixmap, pGlxPixmap->gc,
1693 pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h, 0, 0);
1694 /* Have to make sure XCopyArea is processed */
1695 XSync(dpy, False);
1696 XUNLOCK(dpy);
1697
1698 stubGetUnpackState(&unpackState);
1699 stubSetUnpackState(&defaultPacking);
1700 stub.spu->dispatch_table.TexImage2D(pGlxPixmap->target, 0, pGlxPixmap->format, pGlxPixmap->w, pGlxPixmap->h, 0,
1701 GL_BGRA, GL_UNSIGNED_BYTE, stub.xshmSI.shmaddr);
1702 stubSetUnpackState(&unpackState);
1703 /*crDebug("Sync texture for drawable 0x%x(dmg handle 0x%x) [%i,%i,%i,%i]",
1704 (unsigned int) draw, (unsigned int)pGlxPixmap->hDamage,
1705 pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h);*/
1706 }
1707}
1708
1709static void stubXshmUpdateImageRect(Display *dpy, GLXDrawable draw, GLX_Pixmap_t *pGlxPixmap, XRectangle *pRect)
1710{
1711 /* See comment in stubXshmUpdateWholeImage */
1712 if (CR_MAX_TRANSFER_SIZE < 4*pRect->width*pRect->height)
1713 {
1714 XRectangle rect;
1715
1716 rect.x = pRect->x;
1717 rect.y = pRect->y;
1718 rect.width = pRect->width;
1719 rect.height = CR_MAX_TRANSFER_SIZE/(4*pRect->width);
1720
1721 /*crDebug("Region size too big, splitting in lower sized chunks. [%i,%i,%i,%i] (%i)",
1722 pRect->x, pRect->y, pRect->width, pRect->height, rect.height);*/
1723
1724 for (; (rect.y+rect.height)<=(pRect->y+pRect->height); rect.y+=rect.height)
1725 {
1726 stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
1727 }
1728
1729 if (rect.y!=(pRect->y+pRect->height))
1730 {
1731 rect.height=pRect->y+pRect->height-rect.y;
1732 stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
1733 }
1734 }
1735 else
1736 {
1737 CRPixelPackState unpackState;
1738
1739 XLOCK(dpy);
1740 XCopyArea(dpy, (Pixmap)draw, pGlxPixmap->hShmPixmap, pGlxPixmap->gc,
1741 pRect->x, pRect->y, pRect->width, pRect->height, 0, 0);
1742 /* Have to make sure XCopyArea is processed */
1743 XSync(dpy, False);
1744 XUNLOCK(dpy);
1745
1746 stubGetUnpackState(&unpackState);
1747 stubSetUnpackState(&defaultPacking);
1748 if (pRect->width!=pGlxPixmap->w)
1749 {
1750 stub.spu->dispatch_table.PixelStorei(GL_UNPACK_ROW_LENGTH, pGlxPixmap->w);
1751 }
1752 stub.spu->dispatch_table.TexSubImage2D(pGlxPixmap->target, 0, pRect->x, pRect->y, pRect->width, pRect->height,
1753 GL_BGRA, GL_UNSIGNED_BYTE, stub.xshmSI.shmaddr);
1754 stubSetUnpackState(&unpackState);
1755
1756 /*crDebug("Region sync texture for drawable 0x%x(dmg handle 0x%x) [%i,%i,%i,%i]",
1757 (unsigned int) draw, (unsigned int)pGlxPixmap->hDamage,
1758 pRect->x, pRect->y, pRect->width, pRect->height);*/
1759 }
1760}
1761
1762#if 0
1763Bool checkevents(Display *display, XEvent *event, XPointer arg)
1764{
1765 //crDebug("got type: 0x%x", event->type);
1766 if (event->type==damage_evb+XDamageNotify)
1767 {
1768 ContextInfo *context = stubGetCurrentContext();
1769 XDamageNotifyEvent *e = (XDamageNotifyEvent *) event;
1770 /* we're interested in pixmaps only...and those have e->drawable set to 0 or other strange value for some odd reason
1771 * so have to walk glxpixmaps hashtable to find if we have damage event handle assigned to some pixmap
1772 */
1773 /*crDebug("Event: Damage for drawable 0x%x, handle 0x%x (level=%i) [%i,%i,%i,%i]",
1774 (unsigned int) e->drawable, (unsigned int) e->damage, (int) e->level,
1775 e->area.x, e->area.y, e->area.width, e->area.height);*/
1776 CRASSERT(context);
1777 crHashtableWalk(context->pGLXPixmapsHash, checkdamageCB, e);
1778 }
1779 return False;
1780}
1781#endif
1782
1783/** @todo check what error codes could we throw for failures here*/
1784DECLEXPORT(void) VBOXGLXTAG(glXBindTexImageEXT)(Display *dpy, GLXDrawable draw, int buffer, const int *attrib_list)
1785{
1786 ContextInfo *context = stubGetCurrentContext();
1787 GLX_Pixmap_t *pGlxPixmap;
1788 RT_NOREF(buffer, attrib_list);
1789
1790 if (!context)
1791 {
1792 crWarning("glXBindTexImageEXT called without current context");
1793 return;
1794 }
1795
1796 pGlxPixmap = (GLX_Pixmap_t *) crHashtableSearch(context->pGLXPixmapsHash, (unsigned int) draw);
1797 if (!pGlxPixmap)
1798 {
1799 pGlxPixmap = (GLX_Pixmap_t *) crHashtableSearch(stub.pGLXPixmapsHash, (unsigned int) draw);
1800 if (!pGlxPixmap)
1801 {
1802 crDebug("Unknown drawable 0x%x in glXBindTexImageEXT!", (unsigned int) draw);
1803 return;
1804 }
1805 pGlxPixmap = stubInitGlxPixmap(pGlxPixmap, dpy, draw, context);
1806 if (!pGlxPixmap)
1807 {
1808 crDebug("glXBindTexImageEXT failed to get pGlxPixmap");
1809 return;
1810 }
1811 }
1812
1813 /* If there's damage extension, then process incoming events as we need the information right now */
1814 if (!context->damageQueryFailed)
1815 {
1816 /* Sync connection */
1817 XLOCK(dpy);
1818 XSync(dpy, False);
1819 XUNLOCK(dpy);
1820
1821 stubFetchDamageOnDrawable(dpy, pGlxPixmap);
1822 }
1823
1824 /* No shared memory? Rollback to use slow x protocol then */
1825 if (stub.xshmSI.shmid<0)
1826 {
1827 /** @todo add damage support here too*/
1828 XImage *pxim;
1829 CRPixelPackState unpackState;
1830
1831 XLOCK(dpy);
1832 pxim = XGetImage(dpy, (Pixmap)draw, pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h, AllPlanes, ZPixmap);
1833 XUNLOCK(dpy);
1834 /*if (pxim)
1835 {
1836 if (!ptextable)
1837 {
1838 ptextable = crAllocHashtable();
1839 }
1840 pm = crHashtableSearch(ptextable, (unsigned int) draw);
1841 if (!pm)
1842 {
1843 pm = crCalloc(sizeof(pminfo));
1844 crHashtableAdd(ptextable, (unsigned int) draw, pm);
1845 }
1846 pm->w = w;
1847 pm->h = h;
1848 if (pm->data) crFree(pm->data);
1849 pm->data = crAlloc(4*w*h);
1850 crMemcpy(pm->data, (void*)(&(pxim->data[0])), 4*w*h);
1851 }*/
1852
1853 if (NULL==pxim)
1854 {
1855 crWarning("Failed, to get pixmap data for 0x%x", (unsigned int) draw);
1856 return;
1857 }
1858
1859 stubGetUnpackState(&unpackState);
1860 stubSetUnpackState(&defaultPacking);
1861 stub.spu->dispatch_table.TexImage2D(pGlxPixmap->target, 0, pGlxPixmap->format, pxim->width, pxim->height, 0,
1862 GL_BGRA, GL_UNSIGNED_BYTE, (void*)(&(pxim->data[0])));
1863 stubSetUnpackState(&unpackState);
1864 XDestroyImage(pxim);
1865 }
1866 else /* Use shm to get pixmap data */
1867 {
1868 /* Check if we have damage extension */
1869 if (!context->damageQueryFailed)
1870 {
1871 if (pGlxPixmap->bPixmapImageDirty)
1872 {
1873 /* Either we failed to allocate damage region or this pixmap is marked for full update */
1874 if (!pGlxPixmap->pDamageRegion || XEmptyRegion(pGlxPixmap->pDamageRegion))
1875 {
1876 /*crDebug("**FULL** update for 0x%x", (unsigned int)draw);*/
1877 stubXshmUpdateWholeImage(dpy, draw, pGlxPixmap);
1878 }
1879 else
1880 {
1881 long fullArea, damageArea=0, clipdamageArea, i;
1882 XRectangle damageClipBox;
1883
1884 fullArea = pGlxPixmap->w * pGlxPixmap->h;
1885 XClipBox(pGlxPixmap->pDamageRegion, &damageClipBox);
1886 clipdamageArea = damageClipBox.width * damageClipBox.height;
1887
1888 //crDebug("FullSize [%i,%i,%i,%i]", pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h);
1889 //crDebug("Clip [%i,%i,%i,%i]", damageClipBox.x, damageClipBox.y, damageClipBox.width, damageClipBox.height);
1890
1891 for (i=0; i<pGlxPixmap->pDamageRegion->numRects; ++i)
1892 {
1893 BoxPtr pBox = &pGlxPixmap->pDamageRegion->rects[i];
1894 damageArea += (pBox->x2-pBox->x1)*(pBox->y2-pBox->y1);
1895 //crDebug("Damage rect [%i,%i,%i,%i]", pBox->x1, pBox->y1, pBox->x2, pBox->y2);
1896 }
1897
1898 if (damageArea>clipdamageArea || clipdamageArea>fullArea)
1899 {
1900 crWarning("glXBindTexImageEXT, damage regions seems to be broken, forcing full update");
1901 /*crDebug("**FULL** update for 0x%x, numRect=%li, *FS*=%li, CS=%li, DS=%li",
1902 (unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
1903 stubXshmUpdateWholeImage(dpy, draw, pGlxPixmap);
1904 }
1905 else /*We have corect damage info*/
1906 {
1907 if (CR_MIN_DAMAGE_PROFIT_SIZE > (fullArea-damageArea))
1908 {
1909 /*crDebug("**FULL** update for 0x%x, numRect=%li, *FS*=%li, CS=%li, DS=%li",
1910 (unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
1911 stubXshmUpdateWholeImage(dpy, draw, pGlxPixmap);
1912 }
1913 else if (CR_MIN_DAMAGE_PROFIT_SIZE > (clipdamageArea-damageArea))
1914 {
1915 /*crDebug("**PARTIAL** update for 0x%x, numRect=%li, FS=%li, *CS*=%li, DS=%li",
1916 (unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
1917 stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &damageClipBox);
1918 }
1919 else
1920 {
1921 /*crDebug("**PARTIAL** update for 0x%x, numRect=*%li*, FS=%li, CS=%li, *DS*=%li",
1922 (unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
1923 for (i=0; i<pGlxPixmap->pDamageRegion->numRects; ++i)
1924 {
1925 XRectangle rect;
1926 BoxPtr pBox = &pGlxPixmap->pDamageRegion->rects[i];
1927
1928 rect.x = pBox->x1;
1929 rect.y = pBox->y1;
1930 rect.width = pBox->x2-pBox->x1;
1931 rect.height = pBox->y2-pBox->y1;
1932
1933 stubXshmUpdateImageRect(dpy, draw, pGlxPixmap, &rect);
1934 }
1935 }
1936 }
1937 }
1938
1939 /* Clean dirty flag and damage region */
1940 pGlxPixmap->bPixmapImageDirty = False;
1941 if (pGlxPixmap->pDamageRegion)
1942 EMPTY_REGION(pGlxPixmap->pDamageRegion);
1943 }
1944 }
1945 else
1946 {
1947 stubXshmUpdateWholeImage(dpy, draw, pGlxPixmap);
1948 }
1949 }
1950}
1951
1952DECLEXPORT(void) VBOXGLXTAG(glXReleaseTexImageEXT)(Display *dpy, GLXDrawable draw, int buffer)
1953{
1954 (void) dpy;
1955 (void) draw;
1956 (void) buffer;
1957 //crDebug("glXReleaseTexImageEXT 0x%x", (unsigned int)draw);
1958}
1959#endif
1960
1961#endif /* GLX_EXTRAS */
1962
1963
1964#ifdef GLX_SGIX_video_resize
1965/* more dummy funcs. These help when linking with older GLUTs */
1966
1967DECLEXPORT(int) VBOXGLXTAG(glXBindChannelToWindowSGIX)(Display *dpy, int scrn, int chan, Window w)
1968{
1969 (void) dpy;
1970 (void) scrn;
1971 (void) chan;
1972 (void) w;
1973 crDebug("glXBindChannelToWindowSGIX");
1974 return 0;
1975}
1976
1977DECLEXPORT(int) VBOXGLXTAG(glXChannelRectSGIX)(Display *dpy, int scrn, int chan, int x , int y, int w, int h)
1978{
1979 (void) dpy;
1980 (void) scrn;
1981 (void) chan;
1982 (void) x;
1983 (void) y;
1984 (void) w;
1985 (void) h;
1986 crDebug("glXChannelRectSGIX");
1987 return 0;
1988}
1989
1990DECLEXPORT(int) VBOXGLXTAG(glXQueryChannelRectSGIX)(Display *dpy, int scrn, int chan, int *x, int *y, int *w, int *h)
1991{
1992 (void) dpy;
1993 (void) scrn;
1994 (void) chan;
1995 (void) x;
1996 (void) y;
1997 (void) w;
1998 (void) h;
1999 crDebug("glXQueryChannelRectSGIX");
2000 return 0;
2001}
2002
2003DECLEXPORT(int) VBOXGLXTAG(glXQueryChannelDeltasSGIX)(Display *dpy, int scrn, int chan, int *dx, int *dy, int *dw, int *dh)
2004{
2005 (void) dpy;
2006 (void) scrn;
2007 (void) chan;
2008 (void) dx;
2009 (void) dy;
2010 (void) dw;
2011 (void) dh;
2012 crDebug("glXQueryChannelDeltasSGIX");
2013 return 0;
2014}
2015
2016DECLEXPORT(int) VBOXGLXTAG(glXChannelRectSyncSGIX)(Display *dpy, int scrn, int chan, GLenum synctype)
2017{
2018 (void) dpy;
2019 (void) scrn;
2020 (void) chan;
2021 (void) synctype;
2022 crDebug("glXChannelRectSyncSGIX");
2023 return 0;
2024}
2025
2026#endif /* GLX_SGIX_video_resize */
2027
2028#ifdef VBOXOGL_FAKEDRI
2029DECLEXPORT(const char *) VBOXGLXTAG(glXGetDriverConfig)(const char *driverName)
2030{
2031 return NULL;
2032}
2033
2034DECLEXPORT(void) VBOXGLXTAG(glXFreeMemoryMESA)(Display *dpy, int scrn, void *pointer)
2035{
2036 (void) dpy;
2037 (void) scrn;
2038 (void) pointer;
2039}
2040
2041DECLEXPORT(GLXContext) VBOXGLXTAG(glXImportContextEXT)(Display *dpy, GLXContextID contextID)
2042{
2043 (void) dpy;
2044 (void) contextID;
2045 return NULL;
2046}
2047
2048DECLEXPORT(GLXContextID) VBOXGLXTAG(glXGetContextIDEXT)(const GLXContext ctx)
2049{
2050 (void) ctx;
2051 return 0;
2052}
2053
2054DECLEXPORT(Bool) VBOXGLXTAG(glXMakeCurrentReadSGI)(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
2055{
2056 return VBOXGLXTAG(glXMakeContextCurrent)(display, draw, read, ctx);
2057}
2058
2059DECLEXPORT(const char *) VBOXGLXTAG(glXGetScreenDriver)(Display *dpy, int scrNum)
2060{
2061 static char *screendriver = "vboxvideo";
2062 return screendriver;
2063}
2064
2065DECLEXPORT(Display *) VBOXGLXTAG(glXGetCurrentDisplayEXT)(void)
2066{
2067 return VBOXGLXTAG(glXGetCurrentDisplay());
2068}
2069
2070DECLEXPORT(void) VBOXGLXTAG(glXFreeContextEXT)(Display *dpy, GLXContext ctx)
2071{
2072 VBOXGLXTAG(glXDestroyContext(dpy, ctx));
2073}
2074
2075/*Mesa internal*/
2076DECLEXPORT(int) VBOXGLXTAG(glXQueryContextInfoEXT)(Display *dpy, GLXContext ctx)
2077{
2078 (void) dpy;
2079 (void) ctx;
2080 return 0;
2081}
2082
2083DECLEXPORT(void *) VBOXGLXTAG(glXAllocateMemoryMESA)(Display *dpy, int scrn,
2084 size_t size, float readFreq,
2085 float writeFreq, float priority)
2086{
2087 (void) dpy;
2088 (void) scrn;
2089 (void) size;
2090 (void) readFreq;
2091 (void) writeFreq;
2092 (void) priority;
2093 return NULL;
2094}
2095
2096DECLEXPORT(GLuint) VBOXGLXTAG(glXGetMemoryOffsetMESA)(Display *dpy, int scrn, const void *pointer)
2097{
2098 (void) dpy;
2099 (void) scrn;
2100 (void) pointer;
2101 return 0;
2102}
2103
2104DECLEXPORT(GLXPixmap) VBOXGLXTAG(glXCreateGLXPixmapMESA)(Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap)
2105{
2106 (void) dpy;
2107 (void) visual;
2108 (void) pixmap;
2109 (void) cmap;
2110 return 0;
2111}
2112
2113#endif /*VBOXOGL_FAKEDRI*/
Note: See TracBrowser for help on using the repository browser.

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