glx.c revision 3746f380d2be457f44fd8893c320e21474bc0270
/* Copyright (c) 2001, Stanford University
* All rights reserved
*
* See the file LICENSE.txt for information on redistributing this software.
*/
/* opengl_stub/glx.c */
#include "chromium.h"
#include "cr_error.h"
#include "cr_spu.h"
#include "cr_mem.h"
#include "cr_string.h"
#include "stub.h"
#include "dri_glx.h"
#include "cr_glstate.h"
//#define VBOX_NO_NATIVEGL
/* Force full pixmap update if there're more damaged regions than this number*/
#define CR_MAX_DAMAGE_REGIONS_TRACKED 50
/* Force "bigger" update (full or clip) if it's reducing number of regions updated
* but doesn't increase updated area more than given number
*/
/*@todo combine it in some other place*/
/* Size of pack spu buffer - some delta for commands packing, see pack/packspu_config.c*/
/** Ramshankar: Solaris compiz fix */
#ifdef RT_OS_SOLARIS
#else
#endif
/** For optimizing glXMakeCurrent */
static GLXDrawable currentDrawable = 0;
static GLXDrawable currentReadDrawable = 0;
/**
* Keep a list of structures which associates X visual IDs with
* Chromium visual bitmasks.
*/
struct VisualInfo {
int screen;
int visBits;
struct VisualInfo *next;
};
static void stubXshmUpdateImageRect(Display *dpy, GLXDrawable draw, GLX_Pixmap_t *pGlxPixmap, XRectangle *pRect);
static void
{
struct VisualInfo *v;
for (v = VisualInfoList; v; v = v->next) {
return;
}
}
v->next = VisualInfoList;
VisualInfoList = v;
}
static struct VisualInfo *
{
struct VisualInfo *v;
for (v = VisualInfoList; v; v = v->next) {
return v;
}
return NULL;
}
/**
* Return string for a GLX error code
*/
static const char *glx_error_string(int err)
{
static const char *glxErrors[] = {
"none",
"GLX_BAD_SCREEN",
"GLX_BAD_ATTRIBUTE",
"GLX_NO_EXTENSION",
"GLX_BAD_VISUAL",
"GLX_BAD_CONTEXT",
"GLX_BAD_VALUE",
"GLX_BAD_ENUM"
};
}
else {
static char tmp[100];
return tmp;
}
}
/* Given an XVisualInfo structure, try to figure out what its
* OpenGL capabilities are, if we have a native OpenGL.
* Returns 0 if no information is available.
*/
static struct {
int gl_attrib;
char *attrib_name;
int match_vis_bits;
} attrib_map[] = {
};
#ifndef VBOX_NO_NATIVEGL /* Currently not used */
{
int visBits = 0;
unsigned int i;
/* We can only query the OpenGL capabilities if we actually
* have a native OpenGL underneath us. Without it, we can't
* get at all the actual OpenGL characteristics.
*/
if (!stub.haveNativeOpenGL) return 0;
/* If we don't have the GLX_USE_GL attribute, we've failed. */
if (return_val) {
crDebug("native glXGetConfig returned %d (%s) at %s line %d",
return 0;
}
if (value == 0) {
crDebug("visual ID 0x%x doesn't support OpenGL at %s line %d",
return 0;
}
for (i = 0; i < sizeof(attrib_map)/sizeof(attrib_map[0]); i++) {
if (return_val) {
crDebug("native glXGetConfig(%s) returned %d (%s) at %s line %d",
return 0;
}
switch(attrib_map[i].test) {
case TEST_TRUE:
if (value)
break;
case TEST_GREATER_0:
if (value > 0)
break;
default:
crWarning("illegal attribute map test for %s at %s line %d",
return 0;
}
}
return visBits;
}
#endif /* not 0 */
#ifndef VBOX_NO_NATIVEGL /* Old code */
{
int *attrib;
int visBits = 0;
stubInit();
{
switch (*attrib)
{
case GLX_USE_GL:
/* ignored, this is mandatory */
break;
case GLX_BUFFER_SIZE:
/* this is for color-index visuals, which we don't support */
attrib++;
break;
case GLX_LEVEL:
if (attrib[1] > 0)
attrib++;
break;
case GLX_RGBA:
visBits |= CR_RGB_BIT;
break;
case GLX_DOUBLEBUFFER:
visBits |= CR_DOUBLE_BIT;
break;
case GLX_STEREO:
visBits |= CR_STEREO_BIT;
/*
crWarning( "glXChooseVisual: stereo unsupported" );
return NULL;
*/
break;
case GLX_AUX_BUFFERS:
{
if (aux_buffers != 0)
{
crWarning("glXChooseVisual: aux_buffers=%d unsupported",
return NULL;
}
}
attrib++;
break;
case GLX_RED_SIZE:
case GLX_GREEN_SIZE:
case GLX_BLUE_SIZE:
if (attrib[1] > 0)
visBits |= CR_RGB_BIT;
attrib++;
break;
case GLX_ALPHA_SIZE:
if (attrib[1] > 0)
visBits |= CR_ALPHA_BIT;
attrib++;
break;
case GLX_DEPTH_SIZE:
if (attrib[1] > 0)
visBits |= CR_DEPTH_BIT;
attrib++;
break;
case GLX_STENCIL_SIZE:
if (attrib[1] > 0)
attrib++;
break;
case GLX_ACCUM_RED_SIZE:
case GLX_ACCUM_GREEN_SIZE:
case GLX_ACCUM_BLUE_SIZE:
case GLX_ACCUM_ALPHA_SIZE:
if (attrib[1] > 0)
visBits |= CR_ACCUM_BIT;
attrib++;
break;
case GLX_SAMPLE_BUFFERS_SGIS: /* aka GLX_SAMPLES_ARB */
if (attrib[1] > 0)
attrib++;
break;
case GLX_SAMPLES_SGIS: /* aka GLX_SAMPLES_ARB */
return NULL;
attrib++;
break;
#ifdef GLX_VERSION_1_3
case GLX_X_VISUAL_TYPE:
case GLX_TRANSPARENT_TYPE_EXT:
/* ignore */
attrib++;
break;
#endif
default:
return NULL;
}
}
{
/* normal layer, color index mode not supported */
crWarning( "glXChooseVisual: didn't request RGB visual?" );
return NULL;
}
/* try non-stereo */
visBits &= ~CR_STEREO_BIT;
}
if (vis) {
}
return vis;
}
#else /* not 0 */
{
bool useRGBA = false;
int *attrib;
int nvisuals;
stubInit();
{
switch (*attrib)
{
case GLX_USE_GL:
/* ignored, this is mandatory */
break;
case GLX_BUFFER_SIZE:
/* this is for color-index visuals, which we don't support */
attrib++;
break;
case GLX_LEVEL:
if (attrib[1] != 0)
goto err_exit;
attrib++;
break;
case GLX_RGBA:
useRGBA = true;
break;
case GLX_STEREO:
goto err_exit;
/*
crWarning( "glXChooseVisual: stereo unsupported" );
return NULL;
*/
break;
case GLX_AUX_BUFFERS:
if (attrib[1] != 0)
goto err_exit;
attrib++;
break;
case GLX_RED_SIZE:
case GLX_GREEN_SIZE:
case GLX_BLUE_SIZE:
goto err_exit;
attrib++;
break;
case GLX_ALPHA_SIZE:
goto err_exit;
attrib++;
break;
case GLX_DEPTH_SIZE:
goto err_exit;
attrib++;
break;
case GLX_STENCIL_SIZE:
goto err_exit;
attrib++;
break;
case GLX_ACCUM_RED_SIZE:
case GLX_ACCUM_GREEN_SIZE:
case GLX_ACCUM_BLUE_SIZE:
case GLX_ACCUM_ALPHA_SIZE:
goto err_exit;
attrib++;
break;
case GLX_SAMPLE_BUFFERS_SGIS: /* aka GLX_SAMPLES_ARB */
if (attrib[1] > 0)
goto err_exit;
attrib++;
break;
case GLX_SAMPLES_SGIS: /* aka GLX_SAMPLES_ARB */
if (attrib[1] > 0)
goto err_exit;
attrib++;
break;
case GLX_DOUBLEBUFFER: /* @todo, check if we support it */
break;
#ifdef GLX_VERSION_1_3
case GLX_X_VISUAL_TYPE:
case GLX_TRANSPARENT_TYPE_EXT:
/* ignore */
attrib++;
break;
#endif
default:
attrib++;
//return NULL;
}
}
if (!useRGBA)
return NULL;
if (nvisuals!=1) crWarning("glXChooseVisual: XGetVisualInfo returned %i visuals for %x", nvisuals, (unsigned int) searchvis.visualid);
if (pret)
return pret;
return NULL;
}
#endif
/**
** There is a problem with glXCopyContext.
** IRIX and Mesa both define glXCopyContext
** to have the mask argument being a
** GLuint. XFree 4 and oss.sgi.com
** define it to be an unsigned long.
** Solution: We don't support
** glXCopyContext anyway so we'll just
** #ifdef out the code.
*/
DECLEXPORT(void)
#if defined(AIX) || defined(PLAYSTATION2)
unsigned long mask )
#else
unsigned long mask )
#endif
{
(void) dpy;
(void) src;
(void) dst;
(void) mask;
crWarning( "Unsupported GLX Call: glXCopyContext()" );
}
/**
* Get the display string for the given display pointer.
* Never return just ":0.0". In that case, prefix with our host name.
*/
static void
{
char host[1000];
#ifndef VBOX_NO_NATIVEGL
if (dpyName[0] == ':')
{
}
else
#endif
{
host[0] = 0;
}
{
/* return null string */
crWarning("Very long host / display name string in stubDisplayString!");
nameResult[0] = 0;
}
else
{
/* return host concatenated with dpyName */
}
}
{
char dpyName[MAX_DPY_NAME];
int i, numExt;
stubInit();
/*
{
char **list;
list = XListExtensions(dpy, &numExt);
crDebug("X extensions [%i]:", numExt);
for (i=0; i<numExt; ++i)
{
crDebug("%s", list[i]);
}
XFreeExtensionList(list);
}
*/
#ifndef VBOX_NO_NATIVEGL /* We only care about the host capabilities, not the guest. */
if (stub.haveNativeOpenGL) {
/* If we have real GLX, compute the Chromium visual bitmask now.
* otherwise, we'll use the default desiredVisual bitmask.
*/
if (v) {
/*crDebug("%s visBits=0x%x", __FUNCTION__, visBits);*/
}
else {
/* For some reason, we haven't tested this visual
* before. This could be because the visual was found
* through a different display connection to the same
* display (as happens in GeoProbe), or through a
* connection to an external daemon that queries
* visuals. If we can query it directly, we can still
* find the proper visBits.
*/
if (newVisBits > 0) {
}
else {
crWarning("Application used unexpected and unqueryable visual id 0x%x; using default visbits", (int) vis->visual->visualid);
}
}
/*crDebug("ComputeVisBits(0x%x) = 0x%x", (int)vis->visual->visualid, visBits);*/
if (stub.force_pbuffers) {
crDebug("App faker: Forcing use of Pbuffers");
}
if (!v) {
}
}
}
else {
crDebug("No native OpenGL; cannot compute visbits");
}
#endif
if (!context)
return 0;
}
{
(void) dpy;
stubDestroyContext( (unsigned long) ctx );
}
typedef struct _stubFindPixmapParms_t {
{
GLX_Pixmap_t *pGlxPixmap = (GLX_Pixmap_t *) crHashtableSearch(pCtx->pGLXPixmapsHash, (unsigned int) pParms->draw);
if (pGlxPixmap)
{
}
}
{
/*crDebug("glXMakeCurrent(%p, 0x%x, 0x%x)", (void *) dpy, (int) drawable, (int) ctx);*/
/*check if passed drawable is GLXPixmap and not X Window*/
if (drawable)
{
GLX_Pixmap_t *pGlxPixmap = (GLX_Pixmap_t *) crHashtableSearch(stub.pGLXPixmapsHash, (unsigned int) drawable);
if (!pGlxPixmap)
{
}
if (pGlxPixmap)
{
/*@todo*/
crWarning("Unimplemented glxMakeCurrent call with GLXPixmap passed, unexpected things might happen.");
}
}
}
}
else {
}
return retVal;
}
DECLEXPORT(GLXPixmap) VBOXGLXTAG(glXCreateGLXPixmap)( Display *dpy, XVisualInfo *vis, Pixmap pixmap )
{
stubInit();
}
{
}
#ifndef VBOX_NO_NATIVEGL /* old code */
{
struct VisualInfo *v;
int visBits;
if (!vis) {
/* SGI OpenGL Performer hits this */
crWarning("glXGetConfig called with NULL XVisualInfo");
return GLX_BAD_VISUAL;
}
if (v) {
}
else {
visBits = 0;
}
stubInit();
/* try to satisfy this request with the native glXGetConfig() */
if (stub.haveNativeOpenGL)
{
int return_val;
{
if (return_val)
{
crDebug("faker native glXGetConfig returned %s",
}
return return_val;
}
}
/*
* If the GLX application chooses its visual via a bunch of calls to
* glXGetConfig, instead of by calling glXChooseVisual, we need to keep
* track of which attributes are queried to help satisfy context creation
* later.
*/
switch ( attrib ) {
case GLX_USE_GL:
*value = 1;
break;
case GLX_BUFFER_SIZE:
*value = 32;
break;
case GLX_LEVEL:
break;
case GLX_RGBA:
visBits |= CR_RGB_BIT;
*value = 1;
break;
case GLX_DOUBLEBUFFER:
*value = 1;
break;
case GLX_STEREO:
*value = 1;
break;
case GLX_AUX_BUFFERS:
*value = 0;
break;
case GLX_RED_SIZE:
*value = 8;
break;
case GLX_GREEN_SIZE:
*value = 8;
break;
case GLX_BLUE_SIZE:
*value = 8;
break;
case GLX_ALPHA_SIZE:
visBits |= CR_ALPHA_BIT;
break;
case GLX_DEPTH_SIZE:
visBits |= CR_DEPTH_BIT;
*value = 16;
break;
case GLX_STENCIL_SIZE:
*value = 8;
break;
case GLX_ACCUM_RED_SIZE:
visBits |= CR_ACCUM_BIT;
*value = 16;
break;
case GLX_ACCUM_GREEN_SIZE:
visBits |= CR_ACCUM_BIT;
*value = 16;
break;
case GLX_ACCUM_BLUE_SIZE:
visBits |= CR_ACCUM_BIT;
*value = 16;
break;
case GLX_ACCUM_ALPHA_SIZE:
visBits |= CR_ACCUM_BIT;
*value = 16;
break;
case GLX_SAMPLE_BUFFERS_SGIS:
*value = 0; /* fix someday */
break;
case GLX_SAMPLES_SGIS:
*value = 0; /* fix someday */
break;
case GLX_VISUAL_CAVEAT_EXT:
*value = GLX_NONE_EXT;
break;
#if defined(SunOS)
/*
I don't think this is even a valid attribute for glxGetConfig.
No idea why this gets called under SunOS but we simply ignore it
-- jw
*/
case GLX_X_VISUAL_TYPE:
break;
#endif
case GLX_TRANSPARENT_TYPE:
*value = GLX_NONE_EXT;
break;
*value = 0;
break;
*value = 0;
break;
*value = 0;
break;
*value = 0;
break;
*value = 0;
break;
default:
return GLX_BAD_ATTRIBUTE;
}
return 0;
}
#else /* not 0 */
{
if (!vis) {
/* SGI OpenGL Performer hits this */
crWarning("glXGetConfig called with NULL XVisualInfo");
return GLX_BAD_VISUAL;
}
stubInit();
*value = 0; /* For sanity */
switch ( attrib ) {
case GLX_USE_GL:
*value = 1;
break;
case GLX_BUFFER_SIZE:
*value = 32;
break;
case GLX_LEVEL:
*value = 0; /* for now */
break;
case GLX_RGBA:
*value = 1;
break;
case GLX_DOUBLEBUFFER:
*value = 1;
break;
case GLX_STEREO:
*value = 1;
break;
case GLX_AUX_BUFFERS:
*value = 0;
break;
case GLX_RED_SIZE:
*value = 8;
break;
case GLX_GREEN_SIZE:
*value = 8;
break;
case GLX_BLUE_SIZE:
*value = 8;
break;
case GLX_ALPHA_SIZE:
*value = 8;
break;
case GLX_DEPTH_SIZE:
*value = 16;
break;
case GLX_STENCIL_SIZE:
*value = 8;
break;
case GLX_ACCUM_RED_SIZE:
*value = 16;
break;
case GLX_ACCUM_GREEN_SIZE:
*value = 16;
break;
case GLX_ACCUM_BLUE_SIZE:
*value = 16;
break;
case GLX_ACCUM_ALPHA_SIZE:
*value = 16;
break;
case GLX_SAMPLE_BUFFERS_SGIS:
*value = 0; /* fix someday */
break;
case GLX_SAMPLES_SGIS:
*value = 0; /* fix someday */
break;
case GLX_VISUAL_CAVEAT_EXT:
*value = GLX_NONE_EXT;
break;
#if defined(SunOS) || 1
/*
I don't think this is even a valid attribute for glxGetConfig.
No idea why this gets called under SunOS but we simply ignore it
-- jw
*/
case GLX_X_VISUAL_TYPE:
break;
#endif
case GLX_TRANSPARENT_TYPE:
*value = GLX_NONE_EXT;
break;
*value = 0;
break;
*value = 0;
break;
*value = 0;
break;
*value = 0;
break;
*value = 0;
break;
case GLX_DRAWABLE_TYPE:
*value = GLX_WINDOW_BIT;
break;
default:
//return GLX_BAD_ATTRIBUTE;
*value = 0;
}
return 0;
}
#endif
{
if (stub.currentContext)
else
return (GLXContext) NULL;
}
{
return currentDrawable;
}
{
return currentDisplay;
}
{
(void) dpy;
(void) ctx;
crDebug("->glXIsDirect");
return True;
}
{
(void) dpy;
(void) errorBase;
(void) eventBase;
return 1; /* You BET we do... */
}
{
(void) dpy;
*major = 1;
*minor = 3;
return 1;
}
static XErrorHandler oldErrorHandler;
static unsigned char lastXError = Success;
static int
{
lastXError = e->error_code;
return 0;
}
{
stubSwapBuffers( window, 0 );
#ifdef VBOX_TEST_MEGOO
if (!stub.bXExtensionsChecked)
{
}
if (!stub.bHaveXComposite)
{
return;
}
{
Pixmap p;
if (attr.override_redirect)
{
return;
}
/*@todo this creates new pixmap for window every call*/
/*p = XCompositeNameWindowPixmap(dpy, window->drawable);*/
if (lastXError==Success)
{
int nvisuals;
int i, rowsize;
if (nvisuals!=1) crWarning("XGetVisualInfo returned %i visuals for %x", nvisuals, (unsigned int) searchvis.visualid);
stub.spu->dispatch_table.ReadPixels(0, 0, window->width, window->height, GL_RGBA, GL_UNSIGNED_BYTE, data);
/*y-invert image*/
{
}
image = XCreateImage(dpy, attr.visual, pret->depth, ZPixmap, 0, imgdata, window->width, window->height, 32, 0);
/*XFreePixmap(dpy, p);*/
}
}
#endif
}
#ifndef VBOX_NO_NATIVEGL
{
{
if (dpy) {
}
else {
if (!dpy)
return;
}
} else
}
#else /* not 0 */
{
if (dpy) {
}
else {
if (!dpy)
return;
}
}
#endif
{
static int first_call = 1;
if ( first_call )
{
crDebug( "Ignoring unsupported GLX call: glXWaitGL()" );
first_call = 0;
}
}
{
static int first_call = 1;
if ( first_call )
{
crDebug( "Ignoring unsupported GLX call: glXWaitX()" );
first_call = 0;
}
}
{
/* XXX maybe also advertise GLX_SGIS_multisample? */
static const char *retval = "GLX_ARB_multisample GLX_EXT_texture_from_pixmap GLX_SGIX_fbconfig GLX_ARB_get_proc_address";
(void) dpy;
(void) screen;
crDebug("->glXQueryExtensionsString");
return retval;
}
{
const char *retval;
(void) dpy;
(void) name;
switch ( name ) {
case GLX_VENDOR:
retval = "Chromium";
break;
case GLX_VERSION:
retval = "1.3 Chromium";
break;
case GLX_EXTENSIONS:
/*@todo should be a screen not a name...but it's not used anyway*/
break;
default:
}
return retval;
}
{
const char *retval;
(void) dpy;
(void) screen;
switch ( name ) {
case GLX_VENDOR:
retval = "Chromium";
break;
case GLX_VERSION:
retval = "1.3 Chromium";
break;
case GLX_EXTENSIONS:
break;
default:
}
return retval;
}
{
}
{
}
#if GLX_EXTRAS
int *attrib_list)
{
(void) dpy;
(void) config;
(void) width;
(void) height;
(void) attrib_list;
crWarning("glXCreateGLXPbufferSGIX not implemented by Chromium");
return 0;
}
{
(void) dpy;
(void) pbuf;
crWarning("glXDestroyGLXPbufferSGIX not implemented by Chromium");
}
DECLEXPORT(void) VBOXGLXTAG(glXSelectEventSGIX)(Display *dpy, GLXDrawable drawable, unsigned long mask)
{
(void) dpy;
(void) drawable;
(void) mask;
}
DECLEXPORT(void) VBOXGLXTAG(glXGetSelectedEventSGIX)(Display *dpy, GLXDrawable drawable, unsigned long *mask)
{
(void) dpy;
(void) drawable;
(void) mask;
}
{
(void) dpy;
(void) pbuf;
(void) attribute;
(void) value;
crWarning("glXQueryGLXPbufferSGIX not implemented by Chromium");
return 0;
}
{
}
int *attrib_list, int *nelements)
{
}
{
}
int render_type,
{
{
return NULL;
}
else
{
if (!vis)
{
return NULL;
}
return ret;
}
}
{
}
{
if (!vis)
{
return NULL;
}
/*Note: Caller is supposed to call XFree on returned value, so can't just return (GLXFBConfig)vis->visualid*/
}
/*
* GLX 1.3 functions
*/
{
stubInit();
if (!attrib_list)
{
}
{
switch (*attrib)
{
case GLX_FBCONFIG_ID:
attrib++;
break;
case GLX_BUFFER_SIZE:
/* this is for color-index visuals, which we don't support */
goto err_exit;
attrib++;
break;
case GLX_LEVEL:
if (attrib[1] != 0)
goto err_exit;
attrib++;
break;
case GLX_AUX_BUFFERS:
if (attrib[1] != 0)
goto err_exit;
attrib++;
break;
case GLX_DOUBLEBUFFER: /* @todo, check if we support it */
attrib++;
break;
case GLX_STEREO:
if (attrib[1] != 0)
goto err_exit;
attrib++;
break;
case GLX_RED_SIZE:
case GLX_GREEN_SIZE:
case GLX_BLUE_SIZE:
case GLX_ALPHA_SIZE:
goto err_exit;
attrib++;
break;
case GLX_DEPTH_SIZE:
goto err_exit;
attrib++;
break;
case GLX_STENCIL_SIZE:
goto err_exit;
attrib++;
break;
case GLX_ACCUM_RED_SIZE:
case GLX_ACCUM_GREEN_SIZE:
case GLX_ACCUM_BLUE_SIZE:
case GLX_ACCUM_ALPHA_SIZE:
goto err_exit;
attrib++;
break;
case GLX_X_RENDERABLE:
case GLX_CONFIG_CAVEAT:
attrib++;
break;
case GLX_RENDER_TYPE:
goto err_exit;
attrib++;
break;
case GLX_DRAWABLE_TYPE:
goto err_exit;
attrib++;
break;
case GLX_X_VISUAL_TYPE:
case GLX_TRANSPARENT_TYPE_EXT:
/* ignore */
attrib++;
break;
break;
default:
attrib++;
break;
}
}
if (fbconfig)
{
*nelements = 1;
return pGLXFBConfigs;
}
else
{
}
return NULL;
}
VBOXGLXTAG(glXCreateNewContext)(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct)
{
(void) dpy;
(void) config;
(void) render_type;
(void) share_list;
(void) direct;
if (render_type != GLX_RGBA_TYPE)
{
return NULL;
}
}
{
(void) dpy;
(void) config;
(void) attrib_list;
crWarning("glXCreatePbuffer not implemented by Chromium");
return 0;
}
/* Note: there're examples where glxpixmaps are created without current context, so can't do much of the work here.
* Instead we'd do necessary initialization on first use of those pixmaps.
*/
VBOXGLXTAG(glXCreatePixmap)(Display *dpy, GLXFBConfig config, Pixmap pixmap, const ATTRIB_TYPE *attrib_list)
{
(void) dpy;
(void) config;
#if 0
{
int x, y;
unsigned int w, h;
unsigned int border;
unsigned int depth;
{
{
crDebug("fail");
}
}
}
#endif
if (!pGlxPixmap)
{
crWarning("glXCreatePixmap failed to allocate memory");
return 0;
}
if (!pVis)
{
return 0;
}
if (attrib_list)
{
{
switch (*attrib)
{
case GLX_TEXTURE_FORMAT_EXT:
attrib++;
switch (*attrib)
{
break;
break;
default:
}
break;
case GLX_TEXTURE_TARGET_EXT:
attrib++;
switch (*attrib)
{
case GLX_TEXTURE_2D_EXT:
break;
break;
default:
}
break;
default: attrib++;
}
}
}
}
{
int nconfigs;
(void) config;
{
{
crWarning("glXCreateWindow !realcfg || nconfigs<1");
return 0;
}
else
{
}
}
else
{
{
crWarning("Non empty attrib list in glXCreateWindow");
return 0;
}
}
}
{
(void) dpy;
(void) pbuf;
crWarning("glXDestroyPbuffer not implemented by Chromium");
}
{
{
/*it's valid but never used glxpixmap, so simple free stored ptr*/
return;
}
else
{
/*it's either invalid glxpixmap or one which was already initialized, so it's stored in appropriate ctx hash*/
}
if (!parms.pGlxPixmap)
{
return;
}
{
}
{
}
{
//crDebug("Destroy: Damage for drawable 0x%x, handle 0x%x", (unsigned int) pixmap, (unsigned int) parms.pGlxPixmap->damage);
}
{
}
}
{
(void) dpy;
(void) win;
/*crWarning("glXDestroyWindow not implemented by Chromium");*/
}
{
return currentReadDrawable;
}
DECLEXPORT(int) VBOXGLXTAG(glXGetFBConfigAttrib)(Display *dpy, GLXFBConfig config, int attribute, int *value)
{
const char * pExt;
if (!pVisual)
{
return GLX_BAD_ATTRIBUTE;
}
//crDebug("glXGetFBConfigAttrib 0x%x for 0x%x, visualid=0x%x, depth=%i", attribute, (int)config, (int)pVisual->visualid, pVisual->depth);
switch (attribute)
{
case GLX_DRAWABLE_TYPE:
*value = GLX_PIXMAP_BIT;
break;
{
}
break;
break;
break;
case GLX_DOUBLEBUFFER:
//crDebug("attribute=GLX_DOUBLEBUFFER");
break;
case GLX_Y_INVERTED_EXT:
break;
case GLX_ALPHA_SIZE:
//crDebug("attribute=GLX_ALPHA_SIZE");
break;
case GLX_BUFFER_SIZE:
//crDebug("attribute=GLX_BUFFER_SIZE");
break;
case GLX_STENCIL_SIZE:
//crDebug("attribute=GLX_STENCIL_SIZE");
*value = 8;
break;
case GLX_DEPTH_SIZE:
*value = 16;
//crDebug("attribute=GLX_DEPTH_SIZE");
break;
*value = 0;
break;
case GLX_RENDER_TYPE:
//crDebug("attribute=GLX_RENDER_TYPE");
*value = GLX_RGBA_BIT;
break;
case GLX_CONFIG_CAVEAT:
//crDebug("attribute=GLX_CONFIG_CAVEAT");
break;
case GLX_VISUAL_ID:
//crDebug("attribute=GLX_VISUAL_ID");
break;
case GLX_FBCONFIG_ID:
*value = pVisual->visualid; /*or config, though those are the same at the moment but this could change one day?*/
break;
case GLX_RED_SIZE:
case GLX_GREEN_SIZE:
case GLX_BLUE_SIZE:
*value = 8;
break;
case GLX_LEVEL:
*value = 0;
break;
case GLX_STEREO:
*value = false;
break;
case GLX_AUX_BUFFERS:
*value = 0;
break;
case GLX_ACCUM_RED_SIZE:
case GLX_ACCUM_GREEN_SIZE:
case GLX_ACCUM_BLUE_SIZE:
case GLX_ACCUM_ALPHA_SIZE:
*value = 0;
break;
case GLX_X_VISUAL_TYPE:
*value = GLX_TRUE_COLOR;
break;
case GLX_TRANSPARENT_TYPE:
break;
case GLX_SAMPLE_BUFFERS:
case GLX_SAMPLES:
*value = 1;
break;
*value = 0;
break;
default:
return GLX_BAD_ATTRIBUTE;
}
return Success;
}
{
struct VisualInfo *v;
int i=0, cVisuals;
*nelements = 0;
/*
for (v = VisualInfoList; v; v = v->next) {
if (v->dpy == dpy && v->screen == screen)
++*nelements;
}
if (*nelements)
pGLXFBConfigs = crAlloc(*nelements * sizeof(GLXFBConfig));
for (v = VisualInfoList; v && i<*nelements; v = v->next) {
if (v->dpy == dpy && v->screen == screen)
pGLXFBConfigs[i++] = (GLXFBConfig) v->visualid;
}
*/
/*@todo doesn't really list all the common visuals, have to use some static list*/
if (*nelements)
for (i=0; i<*nelements; ++i)
{
}
for (i=0; i<*nelements; ++i)
{
}
return pGLXFBConfigs;
}
#else /* not 0 */
{
int i;
*nelements = 1;
for (i=0; i<*nelements; ++i)
{
}
return pGLXFBConfigs;
}
#endif
DECLEXPORT(void) VBOXGLXTAG(glXGetSelectedEvent)(Display *dpy, GLXDrawable draw, unsigned long *event_mask)
{
(void) dpy;
(void) draw;
(void) event_mask;
crWarning("glXGetSelectedEvent not implemented by Chromium");
}
{
(void) dpy;
(void) config;
struct VisualInfo *v;
/*
for (v = VisualInfoList; v; v = v->next) {
if (v->dpy == dpy && v->visualid == (VisualID)config)
{
XVisualInfo temp, *pret;
int nret;
temp.visualid = v->visualid;
pret = XGetVisualInfo(dpy, VisualIDMask, &temp, &nret);
if (nret!=1) crWarning("XGetVisualInfo returned %i visuals", nret);
return pret;
}
}
*/
{
int nret;
if (nret!=1)
{
/* Hack for glut based apps.
We fail to patch first call to glXChooseFBConfigSGIX, which ends up in the mesa's fbconfigs being passed to this function later.
*/
{
}
}
//crDebug("here");
return pret;
}
return NULL;
}
DECLEXPORT(Bool) VBOXGLXTAG(glXMakeContextCurrent)(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
{
}
DECLEXPORT(int) VBOXGLXTAG(glXQueryContext)(Display *dpy, GLXContext ctx, int attribute, int *value)
{
(void) dpy;
(void) ctx;
(void) attribute;
(void) value;
crWarning("glXQueryContext not implemented by Chromium");
return 0;
}
DECLEXPORT(void) VBOXGLXTAG(glXQueryDrawable)(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value)
{
(void) dpy;
(void) draw;
(void) attribute;
(void) value;
crWarning("glXQueryDrawable not implemented by Chromium");
}
DECLEXPORT(void) VBOXGLXTAG(glXSelectEvent)(Display *dpy, GLXDrawable draw, unsigned long event_mask)
{
(void) dpy;
(void) draw;
(void) event_mask;
crWarning("glXSelectEvent not implemented by Chromium");
}
#ifdef CR_EXT_texture_from_pixmap
/*typedef struct
{
int x, y;
unsigned int w, h, border, depth;
Window root;
void *data;
} pminfo;*/
{
return;
/* Check for extension and pixmaps format */
if (!XShmQueryExtension(dpy))
{
crWarning("No XSHM extension");
return;
}
{
crWarning("XSHM extension doesn't support pixmaps");
return;
}
{
crWarning("XSHM extension doesn't support ZPixmap format");
return;
}
/* Alloc shared memory, so far using hardcoded value...could fail for bigger displays one day */
{
crWarning("XSHM Failed to create shared segment");
return;
}
{
crWarning("XSHM Failed to attach shared segment");
return;
}
{
crWarning("XSHM Failed to attach shared segment to XServer");
return;
}
crInfo("Using XSHM for GLX_EXT_texture_from_pixmap");
/*Anyway mark to be deleted when our process detaches it, in case of segfault etc*/
/* Ramshankar: Solaris compiz fix */
#ifndef RT_OS_SOLARIS
#endif
}
{
return;
/* Open second xserver connection to make sure we'd receive all the xdamage messages
* and those wouldn't be eaten by application even queue */
{
return;
}
{
return;
}
}
{
{
/*crDebug("Event: Damage for pixmap 0x%lx(drawable 0x%x), handle 0x%x (level=%i) [%i,%i,%i,%i]",
key, (unsigned int) e->drawable, (unsigned int) e->damage, (int) e->level,
e->area.x, e->area.y, e->area.width, e->area.height);*/
if (pGlxPixmap->pDamageRegion)
{
/* If it's dirty and regions are empty, it marked for full update, so do nothing.*/
{
{
/* Mark for full update */
}
else
{
/* Add to damage regions */
}
}
}
}
}
static const CRPixelPackState defaultPacking =
{
0, /*rowLength*/
0, /*skipRows*/
0, /*skipPixels*/
1, /*alignment*/
0, /*imageHeight*/
0, /*skipImages*/
GL_FALSE, /*swapBytes*/
GL_FALSE /*lsbFirst*/
};
{
}
{
}
static GLX_Pixmap_t* stubInitGlxPixmap(GLX_Pixmap_t* pCreateInfoPixmap, Display *dpy, GLXDrawable draw, ContextInfo *pContext)
{
int x, y;
unsigned int w, h;
unsigned int border;
unsigned int depth;
{
{
return NULL;
}
}
if (!pGlxPixmap)
{
crWarning("stubInitGlxPixmap failed to allocate memory");
return NULL;
}
pGlxPixmap->x = x;
pGlxPixmap->y = y;
pGlxPixmap->w = w;
pGlxPixmap->h = h;
/* Try to allocate shared memory
* As we're allocating huge chunk of memory, do it in this function, only if this extension is really used
*/
{
}
{
}
else
{
pGlxPixmap->hShmPixmap = 0;
}
/* If there's damage extension, then get handle for damage events related to this pixmap */
{
/*crDebug("Create: Damage for drawable 0x%x, handle 0x%x (level=%i)",
(unsigned int) draw, (unsigned int) pGlxPixmap->damage, (int) XDamageReportRawRectangles);*/
if (!pGlxPixmap->pDamageRegion)
{
crWarning("stubInitGlxPixmap failed to create empty damage region for drawable 0x%x", (unsigned int) draw);
}
/*We have never seen this pixmap before, so mark it as dirty for first use*/
}
else
{
pGlxPixmap->hDamage = 0;
}
/* glTexSubImage2D generates GL_INVALID_OP if texture array hasn't been defined by a call to glTexImage2D first.
* It's fine for small textures which would be updated in stubXshmUpdateWholeImage, but we'd never call glTexImage2D for big ones.
* Note that we're making empty texture by passing NULL as pixels pointer, so there's no overhead transferring data to host.*/
{
stub.spu->dispatch_table.TexImage2D(pGlxPixmap->target, 0, pGlxPixmap->format, pGlxPixmap->w, pGlxPixmap->h, 0,
}
return pGlxPixmap;
}
{
/* To limit the size of transferring buffer, split bigger texture into regions
* which fit into connection buffer. Could be done in hgcm or packspu but implementation in this place allows to avoid
* unnecessary memcpy.
* This also workarounds guest driver failures when sending 6+mb texture buffers on linux.
*/
{
rect.x = pGlxPixmap->x;
rect.y = pGlxPixmap->y;
/*crDebug("Texture size too big, splitting in lower sized chunks. [%i,%i,%i,%i] (%i)",
pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h, rect.height);*/
{
}
{
}
}
else
{
/* Have to make sure XCopyArea is processed */
stub.spu->dispatch_table.TexImage2D(pGlxPixmap->target, 0, pGlxPixmap->format, pGlxPixmap->w, pGlxPixmap->h, 0,
/*crDebug("Sync texture for drawable 0x%x(dmg handle 0x%x) [%i,%i,%i,%i]",
(unsigned int) draw, (unsigned int)pGlxPixmap->hDamage,
pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h);*/
}
}
static void stubXshmUpdateImageRect(Display *dpy, GLXDrawable draw, GLX_Pixmap_t *pGlxPixmap, XRectangle *pRect)
{
/* See comment in stubXshmUpdateWholeImage */
{
/*crDebug("Region size too big, splitting in lower sized chunks. [%i,%i,%i,%i] (%i)",
pRect->x, pRect->y, pRect->width, pRect->height, rect.height);*/
{
}
{
}
}
else
{
/* Have to make sure XCopyArea is processed */
{
}
stub.spu->dispatch_table.TexSubImage2D(pGlxPixmap->target, 0, pRect->x, pRect->y, pRect->width, pRect->height,
/*crDebug("Region sync texture for drawable 0x%x(dmg handle 0x%x) [%i,%i,%i,%i]",
(unsigned int) draw, (unsigned int)pGlxPixmap->hDamage,
pRect->x, pRect->y, pRect->width, pRect->height);*/
}
}
#if 0
{
//crDebug("got type: 0x%x", event->type);
{
/* we're interested in pixmaps only...and those have e->drawable set to 0 or other strange value for some odd reason
* so have to walk glxpixmaps hashtable to find if we have damage event handle assigned to some pixmap
*/
/*crDebug("Event: Damage for drawable 0x%x, handle 0x%x (level=%i) [%i,%i,%i,%i]",
(unsigned int) e->drawable, (unsigned int) e->damage, (int) e->level,
e->area.x, e->area.y, e->area.width, e->area.height);*/
}
return False;
}
#endif
/*@todo check what error codes could we throw for failures here*/
DECLEXPORT(void) VBOXGLXTAG(glXBindTexImageEXT)(Display *dpy, GLXDrawable draw, int buffer, const int *attrib_list)
{
static int cnt=0;
if (!stub.currentContext)
{
crWarning("glXBindTexImageEXT called without current context");
return;
}
pGlxPixmap = (GLX_Pixmap_t *) crHashtableSearch(stub.currentContext->pGLXPixmapsHash, (unsigned int) draw);
if (!pGlxPixmap)
{
if (!pGlxPixmap)
{
return;
}
if (!pGlxPixmap)
{
crDebug("glXBindTexImageEXT failed to get pGlxPixmap");
return;
}
}
/* If there's damage extension, then process incoming events as we need the information right now */
{
/* Sync connections, note that order of syncs is important here.
* First make sure client commands are finished, then make sure we get all the damage events back*/
{
{
}
}
}
/* No shared memory? Rollback to use slow x protocol then */
{
/*@todo add damage support here too*/
pxim = XGetImage(dpy, (Pixmap)draw, pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h, AllPlanes, ZPixmap);
/*if (pxim)
{
if (!ptextable)
{
ptextable = crAllocHashtable();
}
pm = crHashtableSearch(ptextable, (unsigned int) draw);
if (!pm)
{
pm = crCalloc(sizeof(pminfo));
crHashtableAdd(ptextable, (unsigned int) draw, pm);
}
pm->w = w;
pm->h = h;
if (pm->data) crFree(pm->data);
pm->data = crAlloc(4*w*h);
crMemcpy(pm->data, (void*)(&(pxim->data[0])), 4*w*h);
}*/
{
return;
}
stub.spu->dispatch_table.TexImage2D(pGlxPixmap->target, 0, pGlxPixmap->format, pxim->width, pxim->height, 0,
}
else /* Use shm to get pixmap data */
{
/* Check if we have damage extension */
{
if (pGlxPixmap->bPixmapImageDirty)
{
/* Either we failed to allocate damage region or this pixmap is marked for full update */
{
/*crDebug("**FULL** update for 0x%x", (unsigned int)draw);*/
}
else
{
//crDebug("FullSize [%i,%i,%i,%i]", pGlxPixmap->x, pGlxPixmap->y, pGlxPixmap->w, pGlxPixmap->h);
//crDebug("Clip [%i,%i,%i,%i]", damageClipBox.x, damageClipBox.y, damageClipBox.width, damageClipBox.height);
{
//crDebug("Damage rect [%i,%i,%i,%i]", pBox->x1, pBox->y1, pBox->x2, pBox->y2);
}
{
crWarning("glXBindTexImageEXT, damage regions seems to be broken, forcing full update");
/*crDebug("**FULL** update for 0x%x, numRect=%li, *FS*=%li, CS=%li, DS=%li",
(unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
}
else /*We have corect damage info*/
{
{
/*crDebug("**FULL** update for 0x%x, numRect=%li, *FS*=%li, CS=%li, DS=%li",
(unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
}
{
/*crDebug("**PARTIAL** update for 0x%x, numRect=%li, FS=%li, *CS*=%li, DS=%li",
(unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
}
else
{
/*crDebug("**PARTIAL** update for 0x%x, numRect=*%li*, FS=%li, CS=%li, *DS*=%li",
(unsigned int)draw, pGlxPixmap->pDamageRegion->numRects, fullArea, clipdamageArea, damageArea);*/
{
}
}
}
}
/* Clean dirty flag and damage region */
if (pGlxPixmap->pDamageRegion)
}
}
else
{
}
}
}
{
(void) dpy;
(void) draw;
(void) buffer;
//crDebug("glXReleaseTexImageEXT 0x%x", (unsigned int)draw);
}
#endif
#endif /* GLX_EXTRAS */
#ifdef GLX_SGIX_video_resize
/* more dummy funcs. These help when linking with older GLUTs */
{
(void) dpy;
(void) scrn;
(void) chan;
(void) w;
crDebug("glXBindChannelToWindowSGIX");
return 0;
}
DECLEXPORT(int) VBOXGLXTAG(glXChannelRectSGIX)(Display *dpy, int scrn, int chan, int x , int y, int w, int h)
{
(void) dpy;
(void) scrn;
(void) chan;
(void) x;
(void) y;
(void) w;
(void) h;
crDebug("glXChannelRectSGIX");
return 0;
}
DECLEXPORT(int) VBOXGLXTAG(glXQueryChannelRectSGIX)(Display *dpy, int scrn, int chan, int *x, int *y, int *w, int *h)
{
(void) dpy;
(void) scrn;
(void) chan;
(void) x;
(void) y;
(void) w;
(void) h;
crDebug("glXQueryChannelRectSGIX");
return 0;
}
DECLEXPORT(int) VBOXGLXTAG(glXQueryChannelDeltasSGIX)(Display *dpy, int scrn, int chan, int *dx, int *dy, int *dw, int *dh)
{
(void) dpy;
(void) scrn;
(void) chan;
(void) dx;
(void) dy;
(void) dw;
(void) dh;
crDebug("glXQueryChannelDeltasSGIX");
return 0;
}
DECLEXPORT(int) VBOXGLXTAG(glXChannelRectSyncSGIX)(Display *dpy, int scrn, int chan, GLenum synctype)
{
(void) dpy;
(void) scrn;
(void) chan;
(void) synctype;
crDebug("glXChannelRectSyncSGIX");
return 0;
}
#endif /* GLX_SGIX_video_resize */
#ifdef VBOXOGL_FAKEDRI
{
return NULL;
}
{
(void) dpy;
(void) scrn;
(void) pointer;
}
{
(void) dpy;
(void) contextID;
return NULL;
}
{
(void) ctx;
return 0;
}
DECLEXPORT(Bool) VBOXGLXTAG(glXMakeCurrentReadSGI)(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
{
}
{
static char *screendriver = "vboxvideo";
return screendriver;
}
{
return VBOXGLXTAG(glXGetCurrentDisplay());
}
{
}
/*Mesa internal*/
{
(void) dpy;
(void) ctx;
return 0;
}
{
(void) dpy;
(void) scrn;
(void) size;
(void) readFreq;
(void) writeFreq;
(void) priority;
return NULL;
}
{
(void) dpy;
(void) scrn;
(void) pointer;
return 0;
}
DECLEXPORT(GLXPixmap) VBOXGLXTAG(glXCreateGLXPixmapMESA)(Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap)
{
(void) dpy;
(void) visual;
(void) pixmap;
(void) cmap;
return 0;
}
#endif /*VBOXOGL_FAKEDRI*/