2010-12-05 10:38:12 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-14 23:55:08 -07:00
|
|
|
|
2012-06-27 17:15:32 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2010-06-14 23:55:08 -07:00
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#define GET_NATIVE_WINDOW(aWidget) GDK_WINDOW_XID((GdkWindow *) aWidget->GetNativeData(NS_NATIVE_WINDOW))
|
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
|
|
|
#include <QWidget>
|
2012-03-22 16:24:40 -07:00
|
|
|
#define GET_NATIVE_WINDOW(aWidget) static_cast<QWidget*>(aWidget->GetNativeData(NS_NATIVE_SHELLWIDGET))->winId()
|
2010-06-14 23:55:08 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
2010-06-23 20:52:48 -07:00
|
|
|
#include "mozilla/X11Util.h"
|
|
|
|
|
2011-01-10 13:14:14 -08:00
|
|
|
#include "prenv.h"
|
2010-06-14 23:55:08 -07:00
|
|
|
#include "GLContextProvider.h"
|
2012-03-16 15:24:12 -07:00
|
|
|
#include "GLLibraryLoader.h"
|
2010-06-14 23:55:08 -07:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "GLXLibrary.h"
|
2010-07-18 22:01:14 -07:00
|
|
|
#include "gfxXlibSurface.h"
|
2010-07-01 09:30:38 -07:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxImageSurface.h"
|
2012-04-13 12:43:13 -07:00
|
|
|
#include "gfxPlatform.h"
|
2010-11-10 07:49:52 -08:00
|
|
|
#include "GLContext.h"
|
2011-04-07 16:58:08 -07:00
|
|
|
#include "gfxUtils.h"
|
2010-06-14 23:55:08 -07:00
|
|
|
|
2011-03-02 12:50:36 -08:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
|
|
|
|
2012-06-27 17:15:32 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2012-04-18 07:27:32 -07:00
|
|
|
#include "gfxPlatformGtk.h"
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2010-06-14 23:55:08 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
2012-09-06 17:16:30 -07:00
|
|
|
GLXLibrary sGLXLibrary[GLXLibrary::LIBS_MAX];
|
|
|
|
GLXLibrary& sDefGLXLib = sGLXLibrary[GLXLibrary::OPENGL_LIB];
|
|
|
|
|
|
|
|
typedef GLXLibrary::LibraryType LibType;
|
|
|
|
|
|
|
|
static LibType gCurrLib = GLXLibrary::OPENGL_LIB;
|
|
|
|
|
|
|
|
LibType
|
|
|
|
GLXLibrary::SelectLibrary(const GLContext::ContextFlags& aFlags)
|
|
|
|
{
|
|
|
|
return (aFlags & GLContext::ContextFlagsMesaLLVMPipe)
|
|
|
|
? GLXLibrary::MESA_LLVMPIPE_LIB
|
|
|
|
: GLXLibrary::OPENGL_LIB;
|
|
|
|
}
|
2010-11-10 07:49:52 -08:00
|
|
|
|
|
|
|
// Check that we have at least version aMajor.aMinor .
|
2012-09-06 17:16:30 -07:00
|
|
|
bool
|
|
|
|
GLXLibrary::GLXVersionCheck(int aMajor, int aMinor)
|
2010-11-10 07:49:52 -08:00
|
|
|
{
|
2012-09-06 17:16:30 -07:00
|
|
|
return aMajor < mGLXMajorVersion ||
|
|
|
|
(aMajor == mGLXMajorVersion && aMinor <= mGLXMinorVersion);
|
2010-11-10 07:49:52 -08:00
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2010-11-10 07:49:52 -08:00
|
|
|
static inline bool
|
|
|
|
HasExtension(const char* aExtensions, const char* aRequiredExtension)
|
|
|
|
{
|
|
|
|
return GLContext::ListHasExtension(
|
|
|
|
reinterpret_cast<const GLubyte*>(aExtensions), aRequiredExtension);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-02-13 15:26:24 -08:00
|
|
|
GLXLibrary::EnsureInitialized(LibType libType)
|
2010-06-14 23:55:08 -07:00
|
|
|
{
|
|
|
|
if (mInitialized) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 07:49:52 -08:00
|
|
|
// Don't repeatedly try to initialize.
|
|
|
|
if (mTriedInitializing) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-11-10 07:49:52 -08:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
mTriedInitializing = true;
|
2010-11-10 07:49:52 -08:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// Force enabling s3 texture compression. (Bug 774134)
|
2012-07-16 08:36:03 -07:00
|
|
|
PR_SetEnv("force_s3tc_enable=true");
|
|
|
|
|
2010-06-14 23:55:08 -07:00
|
|
|
if (!mOGLLibrary) {
|
2013-02-13 15:26:24 -08:00
|
|
|
const char* libGLfilename = nullptr;
|
|
|
|
bool forceFeatureReport = false;
|
|
|
|
switch (libType) {
|
|
|
|
case MESA_LLVMPIPE_LIB:
|
|
|
|
libGLfilename = "mesallvmpipe.so";
|
|
|
|
forceFeatureReport = true;
|
|
|
|
break;
|
|
|
|
case OPENGL_LIB:
|
|
|
|
// see e.g. bug 608526: it is intrinsically interesting to know whether we have dynamically linked to libGL.so.1
|
|
|
|
// because at least the NVIDIA implementation requires an executable stack, which causes mprotect calls,
|
|
|
|
// which trigger glibc bug http://sourceware.org/bugzilla/show_bug.cgi?id=12225
|
2011-10-25 05:48:39 -07:00
|
|
|
#ifdef __OpenBSD__
|
2013-02-13 15:26:24 -08:00
|
|
|
libGLfilename = "libGL.so";
|
2011-10-25 05:48:39 -07:00
|
|
|
#else
|
2013-02-13 15:26:24 -08:00
|
|
|
libGLfilename = "libGL.so.1";
|
2011-10-25 05:48:39 -07:00
|
|
|
#endif
|
2013-02-13 15:26:24 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_NOT_REACHED("Invalid GLX library type.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedGfxFeatureReporter reporter(libGLfilename, forceFeatureReport);
|
2011-03-02 12:50:36 -08:00
|
|
|
mOGLLibrary = PR_LoadLibrary(libGLfilename);
|
2010-06-14 23:55:08 -07:00
|
|
|
if (!mOGLLibrary) {
|
2011-03-02 12:50:36 -08:00
|
|
|
NS_WARNING("Couldn't load OpenGL shared library.");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
2011-03-02 12:50:36 -08:00
|
|
|
reporter.SetSuccessful();
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
|
|
|
|
2011-08-23 18:55:43 -07:00
|
|
|
if (PR_GetEnv("MOZ_GLX_DEBUG")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mDebug = true;
|
2011-08-23 18:55:43 -07:00
|
|
|
}
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols[] = {
|
2010-11-10 07:49:52 -08:00
|
|
|
/* functions that were in GLX 1.0 */
|
2011-08-23 18:55:43 -07:00
|
|
|
{ (PRFuncPtr*) &xDestroyContextInternal, { "glXDestroyContext", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xMakeCurrentInternal, { "glXMakeCurrent", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xSwapBuffersInternal, { "glXSwapBuffers", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xQueryVersionInternal, { "glXQueryVersion", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xGetCurrentContextInternal, { "glXGetCurrentContext", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xWaitGLInternal, { "glXWaitGL", NULL } },
|
2011-08-23 18:56:30 -07:00
|
|
|
{ (PRFuncPtr*) &xWaitXInternal, { "glXWaitX", NULL } },
|
2010-11-10 07:49:52 -08:00
|
|
|
/* functions introduced in GLX 1.1 */
|
2011-08-23 18:55:43 -07:00
|
|
|
{ (PRFuncPtr*) &xQueryExtensionsStringInternal, { "glXQueryExtensionsString", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xGetClientStringInternal, { "glXGetClientString", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xQueryServerStringInternal, { "glXQueryServerString", NULL } },
|
2010-11-10 07:49:52 -08:00
|
|
|
{ NULL, { NULL } }
|
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols13[] = {
|
2010-11-10 07:49:52 -08:00
|
|
|
/* functions introduced in GLX 1.3 */
|
2011-08-23 18:55:43 -07:00
|
|
|
{ (PRFuncPtr*) &xChooseFBConfigInternal, { "glXChooseFBConfig", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xGetFBConfigAttribInternal, { "glXGetFBConfigAttrib", NULL } },
|
2010-11-10 07:49:52 -08:00
|
|
|
// WARNING: xGetFBConfigs not set in symbols13_ext
|
2011-08-23 18:55:43 -07:00
|
|
|
{ (PRFuncPtr*) &xGetFBConfigsInternal, { "glXGetFBConfigs", NULL } },
|
2010-11-10 07:49:52 -08:00
|
|
|
// WARNING: symbols13_ext sets xCreateGLXPixmapWithConfig instead
|
2011-08-23 18:55:43 -07:00
|
|
|
{ (PRFuncPtr*) &xCreatePixmapInternal, { "glXCreatePixmap", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xDestroyPixmapInternal, { "glXDestroyPixmap", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xCreateNewContextInternal, { "glXCreateNewContext", NULL } },
|
2010-11-10 07:49:52 -08:00
|
|
|
{ NULL, { NULL } }
|
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols13_ext[] = {
|
2010-11-10 07:49:52 -08:00
|
|
|
/* extension equivalents for functions introduced in GLX 1.3 */
|
|
|
|
// GLX_SGIX_fbconfig extension
|
2011-08-23 18:55:43 -07:00
|
|
|
{ (PRFuncPtr*) &xChooseFBConfigInternal, { "glXChooseFBConfigSGIX", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xGetFBConfigAttribInternal, { "glXGetFBConfigAttribSGIX", NULL } },
|
2010-11-10 07:49:52 -08:00
|
|
|
// WARNING: no xGetFBConfigs equivalent in extensions
|
|
|
|
// WARNING: different from symbols13:
|
2011-08-23 18:55:43 -07:00
|
|
|
{ (PRFuncPtr*) &xCreateGLXPixmapWithConfigInternal, { "glXCreateGLXPixmapWithConfigSGIX", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xDestroyPixmapInternal, { "glXDestroyGLXPixmap", NULL } }, // not from ext
|
|
|
|
{ (PRFuncPtr*) &xCreateNewContextInternal, { "glXCreateContextWithConfigSGIX", NULL } },
|
2010-11-10 07:49:52 -08:00
|
|
|
{ NULL, { NULL } }
|
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols14[] = {
|
2010-11-10 07:49:52 -08:00
|
|
|
/* functions introduced in GLX 1.4 */
|
2011-08-23 18:55:43 -07:00
|
|
|
{ (PRFuncPtr*) &xGetProcAddressInternal, { "glXGetProcAddress", NULL } },
|
2010-11-10 07:49:52 -08:00
|
|
|
{ NULL, { NULL } }
|
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols14_ext[] = {
|
2010-11-10 07:49:52 -08:00
|
|
|
/* extension equivalents for functions introduced in GLX 1.4 */
|
|
|
|
// GLX_ARB_get_proc_address extension
|
2011-08-23 18:55:43 -07:00
|
|
|
{ (PRFuncPtr*) &xGetProcAddressInternal, { "glXGetProcAddressARB", NULL } },
|
2010-06-14 23:55:08 -07:00
|
|
|
{ NULL, { NULL } }
|
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols_texturefrompixmap[] = {
|
2011-08-23 18:55:43 -07:00
|
|
|
{ (PRFuncPtr*) &xBindTexImageInternal, { "glXBindTexImageEXT", NULL } },
|
|
|
|
{ (PRFuncPtr*) &xReleaseTexImageInternal, { "glXReleaseTexImageEXT", NULL } },
|
2011-04-07 16:58:07 -07:00
|
|
|
{ NULL, { NULL } }
|
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols_robustness[] = {
|
2011-10-26 13:00:44 -07:00
|
|
|
{ (PRFuncPtr*) &xCreateContextAttribsInternal, { "glXCreateContextAttribsARB", NULL } },
|
|
|
|
{ NULL, { NULL } }
|
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &symbols[0])) {
|
2010-06-14 23:55:08 -07:00
|
|
|
NS_WARNING("Couldn't find required entry point in OpenGL shared library");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 07:49:52 -08:00
|
|
|
Display *display = DefaultXDisplay();
|
|
|
|
int screen = DefaultScreen(display);
|
2011-02-11 15:11:30 -08:00
|
|
|
|
2012-09-06 17:16:30 -07:00
|
|
|
if (!xQueryVersion(display, &mGLXMajorVersion, &mGLXMinorVersion)) {
|
|
|
|
mGLXMajorVersion = 0;
|
|
|
|
mGLXMinorVersion = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-05-03 13:07:17 -07:00
|
|
|
}
|
2011-02-11 15:11:30 -08:00
|
|
|
|
2011-05-03 13:07:17 -07:00
|
|
|
if (!GLXVersionCheck(1, 1))
|
|
|
|
// Not possible to query for extensions.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-11-10 07:49:52 -08:00
|
|
|
|
2012-07-30 19:54:21 -07:00
|
|
|
const char *clientVendor = xGetClientString(display, GLX_VENDOR);
|
|
|
|
const char *serverVendor = xQueryServerString(display, screen, GLX_VENDOR);
|
|
|
|
const char *extensionsStr = xQueryExtensionsString(display, screen);
|
2011-05-22 16:04:22 -07:00
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct *sym13;
|
2010-11-10 07:49:52 -08:00
|
|
|
if (!GLXVersionCheck(1, 3)) {
|
2010-11-10 07:49:52 -08:00
|
|
|
// Even if we don't have 1.3, we might have equivalent extensions
|
|
|
|
// (as on the Intel X server).
|
|
|
|
if (!HasExtension(extensionsStr, "GLX_SGIX_fbconfig")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-11-10 07:49:52 -08:00
|
|
|
}
|
|
|
|
sym13 = symbols13_ext;
|
|
|
|
} else {
|
|
|
|
sym13 = symbols13;
|
|
|
|
}
|
2012-03-16 15:24:12 -07:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, sym13)) {
|
2010-11-10 07:49:52 -08:00
|
|
|
NS_WARNING("Couldn't find required entry point in OpenGL shared library");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-11-10 07:49:52 -08:00
|
|
|
}
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct *sym14;
|
2010-11-10 07:49:52 -08:00
|
|
|
if (!GLXVersionCheck(1, 4)) {
|
2010-11-10 07:49:52 -08:00
|
|
|
// Even if we don't have 1.4, we might have equivalent extensions
|
|
|
|
// (as on the Intel X server).
|
|
|
|
if (!HasExtension(extensionsStr, "GLX_ARB_get_proc_address")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-11-10 07:49:52 -08:00
|
|
|
}
|
|
|
|
sym14 = symbols14_ext;
|
|
|
|
} else {
|
|
|
|
sym14 = symbols14;
|
|
|
|
}
|
2012-03-16 15:24:12 -07:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, sym14)) {
|
2010-11-10 07:49:52 -08:00
|
|
|
NS_WARNING("Couldn't find required entry point in OpenGL shared library");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-11-10 07:49:52 -08:00
|
|
|
}
|
|
|
|
|
2011-04-07 16:58:07 -07:00
|
|
|
if (HasExtension(extensionsStr, "GLX_EXT_texture_from_pixmap") &&
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::LoadSymbols(mOGLLibrary, symbols_texturefrompixmap,
|
|
|
|
(GLLibraryLoader::PlatformLookupFunction)&xGetProcAddress))
|
2011-04-07 16:58:07 -07:00
|
|
|
{
|
2012-06-27 17:15:32 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2012-09-16 20:23:00 -07:00
|
|
|
mUseTextureFromPixmap = gfxPlatformGtk::GetPlatform()->UseXRender();
|
2012-04-18 07:27:32 -07:00
|
|
|
#else
|
|
|
|
mUseTextureFromPixmap = true;
|
|
|
|
#endif
|
2011-07-11 06:07:49 -07:00
|
|
|
} else {
|
2012-04-18 07:27:32 -07:00
|
|
|
mUseTextureFromPixmap = false;
|
2011-07-11 06:07:49 -07:00
|
|
|
NS_WARNING("Texture from pixmap disabled");
|
2011-04-07 16:58:07 -07:00
|
|
|
}
|
|
|
|
|
2011-11-18 19:57:29 -08:00
|
|
|
if (HasExtension(extensionsStr, "GLX_ARB_create_context_robustness") &&
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::LoadSymbols(mOGLLibrary, symbols_robustness)) {
|
2011-11-18 19:57:29 -08:00
|
|
|
mHasRobustness = true;
|
2011-10-26 13:00:44 -07:00
|
|
|
}
|
|
|
|
|
2012-09-06 17:16:30 -07:00
|
|
|
mIsATI = serverVendor && DoesStringMatch(serverVendor, "ATI");
|
|
|
|
mClientIsMesa = clientVendor && DoesStringMatch(clientVendor, "Mesa");
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mInitialized = true;
|
2013-02-13 15:26:24 -08:00
|
|
|
mLibType = libType;
|
2012-09-06 17:16:30 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-07-14 13:45:33 -07:00
|
|
|
GLXLibrary::SupportsTextureFromPixmap(gfxASurface* aSurface)
|
2011-04-07 16:58:07 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
if (!EnsureInitialized(mLibType)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-07-14 13:45:33 -07:00
|
|
|
}
|
|
|
|
|
2012-04-18 07:27:32 -07:00
|
|
|
if (aSurface->GetType() != gfxASurface::SurfaceTypeXlib || !mUseTextureFromPixmap) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-04-07 16:58:07 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2011-07-14 13:45:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
GLXPixmap
|
|
|
|
GLXLibrary::CreatePixmap(gfxASurface* aSurface)
|
|
|
|
{
|
|
|
|
if (!SupportsTextureFromPixmap(aSurface)) {
|
2012-07-30 19:54:21 -07:00
|
|
|
return None;
|
2011-04-07 16:58:07 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 19:54:21 -07:00
|
|
|
gfxXlibSurface *xs = static_cast<gfxXlibSurface*>(aSurface);
|
|
|
|
const XRenderPictFormat *format = xs->XRenderFormat();
|
|
|
|
if (!format || format->type != PictTypeDirect) {
|
|
|
|
return None;
|
|
|
|
}
|
2012-08-19 21:21:37 -07:00
|
|
|
const XRenderDirectFormat& direct = format->direct;
|
|
|
|
int alphaSize;
|
|
|
|
PR_FLOOR_LOG2(alphaSize, direct.alphaMask + 1);
|
|
|
|
NS_ASSERTION((1 << alphaSize) - 1 == direct.alphaMask,
|
|
|
|
"Unexpected render format with non-adjacent alpha bits");
|
2012-07-30 19:54:21 -07:00
|
|
|
|
2011-04-07 16:58:07 -07:00
|
|
|
int attribs[] = { GLX_DOUBLEBUFFER, False,
|
|
|
|
GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
|
2012-08-19 21:21:37 -07:00
|
|
|
GLX_ALPHA_SIZE, alphaSize,
|
|
|
|
(alphaSize ? GLX_BIND_TO_TEXTURE_RGBA_EXT
|
2012-07-30 19:54:21 -07:00
|
|
|
: GLX_BIND_TO_TEXTURE_RGB_EXT), True,
|
2012-08-06 18:22:23 -07:00
|
|
|
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
2011-04-07 16:58:07 -07:00
|
|
|
None };
|
|
|
|
|
2012-07-30 19:54:21 -07:00
|
|
|
int numConfigs = 0;
|
|
|
|
Display *display = xs->XDisplay();
|
2011-04-07 16:58:07 -07:00
|
|
|
int xscreen = DefaultScreen(display);
|
|
|
|
|
2012-07-30 19:54:21 -07:00
|
|
|
ScopedXFree<GLXFBConfig> cfgs(xChooseFBConfig(display,
|
|
|
|
xscreen,
|
|
|
|
attribs,
|
|
|
|
&numConfigs));
|
|
|
|
|
2012-08-19 21:21:07 -07:00
|
|
|
// Find an fbconfig that matches the pixel format used on the Pixmap.
|
2012-07-30 19:54:21 -07:00
|
|
|
int matchIndex = -1;
|
|
|
|
unsigned long redMask =
|
|
|
|
static_cast<unsigned long>(direct.redMask) << direct.red;
|
|
|
|
unsigned long greenMask =
|
|
|
|
static_cast<unsigned long>(direct.greenMask) << direct.green;
|
|
|
|
unsigned long blueMask =
|
|
|
|
static_cast<unsigned long>(direct.blueMask) << direct.blue;
|
2012-08-19 21:21:07 -07:00
|
|
|
// This is true if the Pixmap has bits for alpha or unused bits.
|
|
|
|
bool haveNonColorBits =
|
|
|
|
~(redMask | greenMask | blueMask) != -1UL << format->depth;
|
2012-07-30 19:54:21 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < numConfigs; i++) {
|
2012-08-19 21:21:07 -07:00
|
|
|
int id = None;
|
2012-09-06 17:16:30 -07:00
|
|
|
sGLXLibrary[mLibType].xGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &id);
|
2012-08-19 21:21:07 -07:00
|
|
|
Visual *visual;
|
|
|
|
int depth;
|
|
|
|
FindVisualAndDepth(display, id, &visual, &depth);
|
|
|
|
if (!visual ||
|
|
|
|
visual->c_class != TrueColor ||
|
|
|
|
visual->red_mask != redMask ||
|
|
|
|
visual->green_mask != greenMask ||
|
|
|
|
visual->blue_mask != blueMask ) {
|
2012-07-30 19:54:21 -07:00
|
|
|
continue;
|
|
|
|
}
|
2011-04-07 16:58:07 -07:00
|
|
|
|
2012-08-19 21:21:07 -07:00
|
|
|
// Historically Xlib Visuals did not try to represent an alpha channel
|
|
|
|
// and there was no means to use an alpha channel on a Pixmap. The
|
|
|
|
// Xlib Visual from the fbconfig was not intended to have any
|
|
|
|
// information about alpha bits.
|
|
|
|
//
|
|
|
|
// Since then, RENDER has added formats for 32 bit depth Pixmaps.
|
|
|
|
// Some of these formats have bits for alpha and some have unused
|
|
|
|
// bits.
|
|
|
|
//
|
|
|
|
// Then the Composite extension added a 32 bit depth Visual intended
|
|
|
|
// for Windows with an alpha channel, so bits not in the visual color
|
|
|
|
// masks were expected to be treated as alpha bits.
|
|
|
|
//
|
|
|
|
// Usually GLX counts only color bits in the Visual depth, but the
|
|
|
|
// depth of Composite's ARGB Visual includes alpha bits. However,
|
|
|
|
// bits not in the color masks are not necessarily alpha bits because
|
|
|
|
// sometimes (NVIDIA) 32 bit Visuals are added for fbconfigs with 32
|
|
|
|
// bit BUFFER_SIZE but zero alpha bits and 24 color bits (NVIDIA
|
|
|
|
// again).
|
|
|
|
//
|
|
|
|
// This checks that the depth matches in one of the two ways.
|
|
|
|
if (depth != format->depth && depth != format->depth - alphaSize) {
|
2012-07-30 19:54:21 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-19 21:21:07 -07:00
|
|
|
// If all bits of the Pixmap are color bits and the Pixmap depth
|
|
|
|
// matches the depth of the fbconfig visual, then we can assume that
|
|
|
|
// the driver will do whatever is necessary to ensure that any
|
|
|
|
// GLXPixmap alpha bits are treated as set. We can skip the
|
|
|
|
// ALPHA_SIZE check in this situation. We need to skip this check for
|
|
|
|
// situations (ATI) where there are no fbconfigs without alpha bits.
|
|
|
|
//
|
|
|
|
// glXChooseFBConfig should prefer configs with smaller
|
|
|
|
// GLX_BUFFER_SIZE, so we should still get zero alpha bits if
|
|
|
|
// available, except perhaps with NVIDIA drivers where buffer size is
|
|
|
|
// not the specified sum of the component sizes.
|
|
|
|
if (haveNonColorBits) {
|
|
|
|
// There are bits in the Pixmap format that haven't been matched
|
|
|
|
// against the fbconfig visual. These bits could either represent
|
|
|
|
// alpha or be unused, so just check that the number of alpha bits
|
|
|
|
// matches.
|
|
|
|
int size = 0;
|
2012-09-06 17:16:30 -07:00
|
|
|
sGLXLibrary[mLibType].xGetFBConfigAttrib(display, cfgs[i],
|
|
|
|
GLX_ALPHA_SIZE, &size);
|
2012-08-19 21:21:07 -07:00
|
|
|
if (size != alphaSize) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 19:54:21 -07:00
|
|
|
matchIndex = i;
|
2012-08-19 21:21:07 -07:00
|
|
|
break;
|
2012-07-30 19:54:21 -07:00
|
|
|
}
|
|
|
|
if (matchIndex == -1) {
|
|
|
|
NS_WARNING("[GLX] Couldn't find a FBConfig matching Pixmap format");
|
|
|
|
return None;
|
|
|
|
}
|
2011-04-07 16:58:07 -07:00
|
|
|
|
|
|
|
int pixmapAttribs[] = { GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
|
2012-07-30 19:54:21 -07:00
|
|
|
GLX_TEXTURE_FORMAT_EXT,
|
2012-08-19 21:21:37 -07:00
|
|
|
(alphaSize ? GLX_TEXTURE_FORMAT_RGBA_EXT
|
2012-07-30 19:54:21 -07:00
|
|
|
: GLX_TEXTURE_FORMAT_RGB_EXT),
|
2011-04-07 16:58:07 -07:00
|
|
|
None};
|
|
|
|
|
|
|
|
GLXPixmap glxpixmap = xCreatePixmap(display,
|
2012-07-30 19:54:21 -07:00
|
|
|
cfgs[matchIndex],
|
2011-04-07 16:58:07 -07:00
|
|
|
xs->XDrawable(),
|
|
|
|
pixmapAttribs);
|
|
|
|
|
|
|
|
return glxpixmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::DestroyPixmap(GLXPixmap aPixmap)
|
|
|
|
{
|
2012-04-18 07:27:32 -07:00
|
|
|
if (!mUseTextureFromPixmap) {
|
2011-04-07 16:58:07 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Display *display = DefaultXDisplay();
|
|
|
|
xDestroyPixmap(display, aPixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::BindTexImage(GLXPixmap aPixmap)
|
|
|
|
{
|
2012-04-18 07:27:32 -07:00
|
|
|
if (!mUseTextureFromPixmap) {
|
2011-04-07 16:58:07 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Display *display = DefaultXDisplay();
|
|
|
|
// Make sure all X drawing to the surface has finished before binding to a texture.
|
2012-09-06 17:16:30 -07:00
|
|
|
if (mClientIsMesa) {
|
2012-07-30 19:54:21 -07:00
|
|
|
// Using XSync instead of Mesa's glXWaitX, because its glxWaitX is a
|
|
|
|
// noop when direct rendering unless the current drawable is a
|
|
|
|
// single-buffer window.
|
|
|
|
FinishX(display);
|
|
|
|
} else {
|
|
|
|
xWaitX();
|
|
|
|
}
|
2011-04-07 16:58:07 -07:00
|
|
|
xBindTexImage(display, aPixmap, GLX_FRONT_LEFT_EXT, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::ReleaseTexImage(GLXPixmap aPixmap)
|
|
|
|
{
|
2012-04-18 07:27:32 -07:00
|
|
|
if (!mUseTextureFromPixmap) {
|
2011-04-07 16:58:07 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Display *display = DefaultXDisplay();
|
|
|
|
xReleaseTexImage(display, aPixmap, GLX_FRONT_LEFT_EXT);
|
|
|
|
}
|
|
|
|
|
2011-08-23 18:55:43 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
static int (*sOldErrorHandler)(Display *, XErrorEvent *);
|
|
|
|
ScopedXErrorHandler::ErrorEvent sErrorEvent;
|
|
|
|
static int GLXErrorHandler(Display *display, XErrorEvent *ev)
|
|
|
|
{
|
|
|
|
if (!sErrorEvent.mError.error_code) {
|
|
|
|
sErrorEvent.mError = *ev;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::BeforeGLXCall()
|
|
|
|
{
|
|
|
|
if (mDebug) {
|
|
|
|
sOldErrorHandler = XSetErrorHandler(GLXErrorHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::AfterGLXCall()
|
|
|
|
{
|
|
|
|
if (mDebug) {
|
2012-07-30 19:54:21 -07:00
|
|
|
FinishX(DefaultXDisplay());
|
2011-08-23 18:55:43 -07:00
|
|
|
if (sErrorEvent.mError.error_code) {
|
|
|
|
char buffer[2048];
|
|
|
|
XGetErrorText(DefaultXDisplay(), sErrorEvent.mError.error_code, buffer, sizeof(buffer));
|
|
|
|
printf_stderr("X ERROR: %s (%i) - Request: %i.%i, Serial: %i",
|
|
|
|
buffer,
|
|
|
|
sErrorEvent.mError.error_code,
|
|
|
|
sErrorEvent.mError.request_code,
|
|
|
|
sErrorEvent.mError.minor_code,
|
|
|
|
sErrorEvent.mError.serial);
|
|
|
|
NS_ABORT();
|
|
|
|
}
|
|
|
|
XSetErrorHandler(sOldErrorHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BEFORE_GLX_CALL do { \
|
2012-09-06 17:16:30 -07:00
|
|
|
sGLXLibrary[gCurrLib].BeforeGLXCall(); \
|
2011-08-23 18:55:43 -07:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define AFTER_GLX_CALL do { \
|
2012-09-06 17:16:30 -07:00
|
|
|
sGLXLibrary[gCurrLib].AfterGLXCall(); \
|
2011-08-23 18:55:43 -07:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define BEFORE_GLX_CALL do { } while(0)
|
|
|
|
#define AFTER_GLX_CALL do { } while(0)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::xDestroyContext(Display* display, GLXContext context)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
xDestroyContextInternal(display, context);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
GLXLibrary::xMakeCurrent(Display* display,
|
|
|
|
GLXDrawable drawable,
|
|
|
|
GLXContext context)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
Bool result = xMakeCurrentInternal(display, drawable, context);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLXContext
|
|
|
|
GLXLibrary::xGetCurrentContext()
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXContext result = xGetCurrentContextInternal();
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void*
|
|
|
|
GLXLibrary::xGetProcAddress(const char *procName)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
2012-09-06 17:16:30 -07:00
|
|
|
void* result = sGLXLibrary[gCurrLib].xGetProcAddressInternal(procName);
|
2011-08-23 18:55:43 -07:00
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLXFBConfig*
|
|
|
|
GLXLibrary::xChooseFBConfig(Display* display,
|
|
|
|
int screen,
|
|
|
|
const int *attrib_list,
|
|
|
|
int *nelements)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXFBConfig* result = xChooseFBConfigInternal(display, screen, attrib_list, nelements);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLXFBConfig*
|
|
|
|
GLXLibrary::xGetFBConfigs(Display* display,
|
|
|
|
int screen,
|
|
|
|
int *nelements)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXFBConfig* result = xGetFBConfigsInternal(display, screen, nelements);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLXContext
|
|
|
|
GLXLibrary::xCreateNewContext(Display* display,
|
|
|
|
GLXFBConfig config,
|
|
|
|
int render_type,
|
|
|
|
GLXContext share_list,
|
|
|
|
Bool direct)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXContext result = xCreateNewContextInternal(display, config,
|
|
|
|
render_type,
|
|
|
|
share_list, direct);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
GLXLibrary::xGetFBConfigAttrib(Display *display,
|
|
|
|
GLXFBConfig config,
|
|
|
|
int attribute,
|
|
|
|
int *value)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
int result = xGetFBConfigAttribInternal(display, config,
|
|
|
|
attribute, value);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::xSwapBuffers(Display *display, GLXDrawable drawable)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
xSwapBuffersInternal(display, drawable);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
GLXLibrary::xQueryExtensionsString(Display *display,
|
|
|
|
int screen)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
const char *result = xQueryExtensionsStringInternal(display, screen);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
GLXLibrary::xGetClientString(Display *display,
|
|
|
|
int screen)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
const char *result = xGetClientStringInternal(display, screen);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
GLXLibrary::xQueryServerString(Display *display,
|
|
|
|
int screen, int name)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
const char *result = xQueryServerStringInternal(display, screen, name);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLXPixmap
|
|
|
|
GLXLibrary::xCreatePixmap(Display *display,
|
|
|
|
GLXFBConfig config,
|
|
|
|
Pixmap pixmap,
|
|
|
|
const int *attrib_list)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXPixmap result = xCreatePixmapInternal(display, config,
|
|
|
|
pixmap, attrib_list);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLXPixmap
|
|
|
|
GLXLibrary::xCreateGLXPixmapWithConfig(Display *display,
|
|
|
|
GLXFBConfig config,
|
|
|
|
Pixmap pixmap)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXPixmap result = xCreateGLXPixmapWithConfigInternal(display, config, pixmap);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::xDestroyPixmap(Display *display, GLXPixmap pixmap)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
xDestroyPixmapInternal(display, pixmap);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
GLXLibrary::xQueryVersion(Display *display,
|
|
|
|
int *major,
|
|
|
|
int *minor)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
Bool result = xQueryVersionInternal(display, major, minor);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::xBindTexImage(Display *display,
|
|
|
|
GLXDrawable drawable,
|
|
|
|
int buffer,
|
|
|
|
const int *attrib_list)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
xBindTexImageInternal(display, drawable, buffer, attrib_list);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::xReleaseTexImage(Display *display,
|
|
|
|
GLXDrawable drawable,
|
|
|
|
int buffer)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
xReleaseTexImageInternal(display, drawable, buffer);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::xWaitGL()
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
xWaitGLInternal();
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
}
|
|
|
|
|
2011-08-23 18:56:30 -07:00
|
|
|
void
|
|
|
|
GLXLibrary::xWaitX()
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
xWaitXInternal();
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
}
|
|
|
|
|
2011-10-26 13:00:44 -07:00
|
|
|
GLXContext
|
|
|
|
GLXLibrary::xCreateContextAttribs(Display* display,
|
|
|
|
GLXFBConfig config,
|
|
|
|
GLXContext share_list,
|
|
|
|
Bool direct,
|
|
|
|
const int* attrib_list)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXContext result = xCreateContextAttribsInternal(display,
|
|
|
|
config,
|
|
|
|
share_list,
|
|
|
|
direct,
|
|
|
|
attrib_list);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-06-14 23:55:08 -07:00
|
|
|
class GLContextGLX : public GLContext
|
|
|
|
{
|
|
|
|
public:
|
2010-06-23 20:52:48 -07:00
|
|
|
static already_AddRefed<GLContextGLX>
|
2013-02-13 15:26:24 -08:00
|
|
|
CreateGLContext(const SurfaceCaps& caps,
|
|
|
|
GLContextGLX* shareContext,
|
|
|
|
bool isOffscreen,
|
|
|
|
Display* display,
|
2010-07-18 22:01:14 -07:00
|
|
|
GLXDrawable drawable,
|
|
|
|
GLXFBConfig cfg,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool deleteDrawable,
|
2013-02-13 15:26:24 -08:00
|
|
|
LibType libType = GLXLibrary::OPENGL_LIB,
|
|
|
|
gfxXlibSurface* pixmap = nullptr)
|
2010-06-14 23:55:08 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
GLXLibrary& glx = sGLXLibrary[libType];
|
|
|
|
|
|
|
|
int db = 0;
|
|
|
|
int err = glx.xGetFBConfigAttrib(display, cfg,
|
|
|
|
GLX_DOUBLEBUFFER, &db);
|
2010-06-18 16:17:00 -07:00
|
|
|
if (GLX_BAD_ATTRIBUTE != err) {
|
|
|
|
#ifdef DEBUG
|
2012-06-11 08:25:06 -07:00
|
|
|
if (DebugMode()) {
|
|
|
|
printf("[GLX] FBConfig is %sdouble-buffered\n", db ? "" : "not ");
|
|
|
|
}
|
2010-06-18 16:17:00 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
GLXContext context;
|
2010-12-06 03:34:34 -08:00
|
|
|
nsRefPtr<GLContextGLX> glContext;
|
2011-02-11 15:11:30 -08:00
|
|
|
bool error;
|
2010-12-06 03:34:34 -08:00
|
|
|
|
|
|
|
ScopedXErrorHandler xErrorHandler;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
TRY_AGAIN_NO_SHARING:
|
|
|
|
|
2011-02-11 15:11:30 -08:00
|
|
|
error = false;
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
GLXContext glxContext = shareContext ? shareContext->mContext : NULL;
|
|
|
|
if (glx.HasRobustness()) {
|
2011-10-26 13:00:44 -07:00
|
|
|
int attrib_list[] = {
|
|
|
|
LOCAL_GL_CONTEXT_FLAGS_ARB, LOCAL_GL_CONTEXT_ROBUST_ACCESS_BIT_ARB,
|
|
|
|
LOCAL_GL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, LOCAL_GL_LOSE_CONTEXT_ON_RESET_ARB,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
context = glx.xCreateContextAttribs(
|
|
|
|
display,
|
|
|
|
cfg,
|
|
|
|
glxContext,
|
|
|
|
True,
|
|
|
|
attrib_list);
|
2011-10-26 13:00:44 -07:00
|
|
|
} else {
|
2013-02-13 15:26:24 -08:00
|
|
|
context = glx.xCreateNewContext(
|
|
|
|
display,
|
|
|
|
cfg,
|
|
|
|
GLX_RGBA_TYPE,
|
|
|
|
glxContext,
|
|
|
|
True);
|
2011-10-26 13:00:44 -07:00
|
|
|
}
|
2010-06-14 23:55:08 -07:00
|
|
|
|
2010-12-06 03:34:34 -08:00
|
|
|
if (context) {
|
2013-02-13 15:26:24 -08:00
|
|
|
glContext = new GLContextGLX(caps,
|
|
|
|
shareContext,
|
|
|
|
isOffscreen,
|
|
|
|
display,
|
|
|
|
drawable,
|
|
|
|
context,
|
|
|
|
deleteDrawable,
|
|
|
|
db,
|
|
|
|
pixmap,
|
|
|
|
libType);
|
2010-12-06 03:34:34 -08:00
|
|
|
if (!glContext->Init())
|
|
|
|
error = true;
|
|
|
|
} else {
|
|
|
|
error = true;
|
|
|
|
}
|
2010-06-14 23:55:08 -07:00
|
|
|
|
2011-02-11 15:11:30 -08:00
|
|
|
error |= xErrorHandler.SyncAndGetError(display);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
if (shareContext) {
|
2012-07-30 07:20:58 -07:00
|
|
|
shareContext = nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
goto TRY_AGAIN_NO_SHARING;
|
|
|
|
}
|
2010-06-14 23:55:08 -07:00
|
|
|
|
2011-02-11 15:11:30 -08:00
|
|
|
NS_WARNING("Failed to create GLXContext!");
|
2012-07-30 07:20:58 -07:00
|
|
|
glContext = nullptr; // note: this must be done while the graceful X error handler is set,
|
2011-02-11 15:11:30 -08:00
|
|
|
// because glxMakeCurrent can give a GLXBadDrawable error
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
|
|
|
|
2010-06-23 20:52:48 -07:00
|
|
|
return glContext.forget();
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
~GLContextGLX()
|
|
|
|
{
|
2010-09-21 12:41:24 -07:00
|
|
|
MarkDestroyed();
|
2010-08-06 22:09:18 -07:00
|
|
|
|
2011-06-17 08:49:27 -07:00
|
|
|
// see bug 659842 comment 76
|
2011-06-17 18:42:31 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool success =
|
|
|
|
#endif
|
2013-02-13 15:26:24 -08:00
|
|
|
mGLX->xMakeCurrent(mDisplay, None, nullptr);
|
2011-06-17 08:49:27 -07:00
|
|
|
NS_ABORT_IF_FALSE(success,
|
|
|
|
"glXMakeCurrent failed to release GL context before we call glXDestroyContext!");
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
mGLX->xDestroyContext(mDisplay, mContext);
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
if (mDeleteDrawable) {
|
2013-02-13 15:26:24 -08:00
|
|
|
mGLX->xDestroyPixmap(mDisplay, mDrawable);
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
2010-06-14 23:55:08 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
GLContextType GetContextType() {
|
|
|
|
return ContextTypeGLX;
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Init()
|
2010-06-14 23:55:08 -07:00
|
|
|
{
|
|
|
|
MakeCurrent();
|
|
|
|
SetupLookupFunction();
|
2011-10-17 07:59:28 -07:00
|
|
|
if (!InitWithPrefix("gl", true)) {
|
|
|
|
return false;
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
|
|
|
|
2012-04-04 18:44:55 -07:00
|
|
|
if (!IsExtensionSupported(EXT_framebuffer_object))
|
2012-03-12 15:10:38 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
InitFramebuffers();
|
|
|
|
|
|
|
|
return true;
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
|
|
|
|
2012-05-12 16:23:56 -07:00
|
|
|
bool MakeCurrentImpl(bool aForce = false)
|
2010-06-14 23:55:08 -07:00
|
|
|
{
|
2012-05-12 16:23:56 -07:00
|
|
|
bool succeeded = true;
|
|
|
|
|
|
|
|
// With the ATI FGLRX driver, glxMakeCurrent is very slow even when the context doesn't change.
|
|
|
|
// (This is not the case with other drivers such as NVIDIA).
|
|
|
|
// So avoid calling it more than necessary. Since GLX documentation says that:
|
|
|
|
// "glXGetCurrentContext returns client-side information.
|
|
|
|
// It does not make a round trip to the server."
|
|
|
|
// I assume that it's not worth using our own TLS slot here.
|
2013-02-13 15:26:24 -08:00
|
|
|
if (aForce || mGLX->xGetCurrentContext() != mContext) {
|
|
|
|
succeeded = mGLX->xMakeCurrent(mDisplay, mDrawable, mContext);
|
2012-05-12 16:23:56 -07:00
|
|
|
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
|
|
|
}
|
2010-09-20 10:19:30 -07:00
|
|
|
|
2010-06-14 23:55:08 -07:00
|
|
|
return succeeded;
|
|
|
|
}
|
|
|
|
|
2012-08-21 20:30:20 -07:00
|
|
|
virtual bool IsCurrent() {
|
2013-02-13 15:26:24 -08:00
|
|
|
return mGLX->xGetCurrentContext() == mContext;
|
2012-08-21 20:30:20 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SetupLookupFunction()
|
2010-06-14 23:55:08 -07:00
|
|
|
{
|
2011-08-23 18:55:43 -07:00
|
|
|
mLookupFunc = (PlatformLookupFunction)&GLXLibrary::xGetProcAddress;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void *GetNativeData(NativeDataType aType)
|
|
|
|
{
|
|
|
|
switch(aType) {
|
|
|
|
case NativeGLContext:
|
|
|
|
return mContext;
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
case NativeThebesSurface:
|
|
|
|
return mPixmap;
|
2010-06-14 23:55:08 -07:00
|
|
|
|
|
|
|
default:
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsDoubleBuffered()
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
|
|
|
return mDoubleBuffered;
|
|
|
|
}
|
|
|
|
|
2011-11-18 19:57:29 -08:00
|
|
|
bool SupportsRobustness()
|
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
return mGLX->HasRobustness();
|
2011-11-18 19:57:29 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SwapBuffers()
|
2010-06-18 16:17:00 -07:00
|
|
|
{
|
2010-07-18 22:01:14 -07:00
|
|
|
if (!mDoubleBuffered)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2013-02-13 15:26:24 -08:00
|
|
|
mGLX->xSwapBuffers(mDisplay, mDrawable);
|
|
|
|
mGLX->xWaitGL();
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-18 16:17:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool TextureImageSupportsGetBackingSurface()
|
2011-04-07 16:58:08 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
return mGLX->UseTextureFromPixmap();
|
2011-04-07 16:58:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual already_AddRefed<TextureImage>
|
|
|
|
CreateTextureImage(const nsIntSize& aSize,
|
|
|
|
TextureImage::ContentType aContentType,
|
|
|
|
GLenum aWrapMode,
|
2012-05-09 13:55:31 -07:00
|
|
|
TextureImage::Flags aFlags = TextureImage::NoFlags);
|
2011-04-07 16:58:08 -07:00
|
|
|
|
2010-06-14 23:55:08 -07:00
|
|
|
private:
|
2010-07-18 22:01:14 -07:00
|
|
|
friend class GLContextProviderGLX;
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
GLContextGLX(const SurfaceCaps& caps,
|
|
|
|
GLContext* shareContext,
|
|
|
|
bool isOffscreen,
|
2010-07-18 22:01:14 -07:00
|
|
|
Display *aDisplay,
|
|
|
|
GLXDrawable aDrawable,
|
|
|
|
GLXContext aContext,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDeleteDrawable,
|
|
|
|
bool aDoubleBuffered,
|
2012-09-06 17:16:30 -07:00
|
|
|
gfxXlibSurface *aPixmap,
|
2013-02-13 15:26:24 -08:00
|
|
|
LibType libType)
|
|
|
|
: GLContext(caps, shareContext, isOffscreen),//aDeleteDrawable ? true : false, aShareContext, ),
|
2010-07-18 22:01:14 -07:00
|
|
|
mContext(aContext),
|
|
|
|
mDisplay(aDisplay),
|
|
|
|
mDrawable(aDrawable),
|
|
|
|
mDeleteDrawable(aDeleteDrawable),
|
|
|
|
mDoubleBuffered(aDoubleBuffered),
|
2013-02-13 15:26:24 -08:00
|
|
|
mLibType(libType),
|
|
|
|
mGLX(&sGLXLibrary[libType]),
|
|
|
|
mPixmap(aPixmap)
|
2012-09-06 17:16:30 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
MOZ_ASSERT(mGLX);
|
2012-09-06 17:16:30 -07:00
|
|
|
}
|
2010-06-14 23:55:08 -07:00
|
|
|
|
|
|
|
GLXContext mContext;
|
|
|
|
Display *mDisplay;
|
2010-07-18 22:01:14 -07:00
|
|
|
GLXDrawable mDrawable;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDeleteDrawable;
|
|
|
|
bool mDoubleBuffered;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2012-09-06 17:16:30 -07:00
|
|
|
LibType mLibType;
|
2013-02-13 15:26:24 -08:00
|
|
|
GLXLibrary* mGLX;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
nsRefPtr<gfxXlibSurface> mPixmap;
|
2010-06-14 23:55:08 -07:00
|
|
|
};
|
|
|
|
|
2011-04-07 16:58:08 -07:00
|
|
|
class TextureImageGLX : public TextureImage
|
|
|
|
{
|
|
|
|
friend already_AddRefed<TextureImage>
|
|
|
|
GLContextGLX::CreateTextureImage(const nsIntSize&,
|
|
|
|
ContentType,
|
|
|
|
GLenum,
|
2012-05-09 13:55:31 -07:00
|
|
|
TextureImage::Flags);
|
2011-04-07 16:58:08 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~TextureImageGLX()
|
|
|
|
{
|
|
|
|
mGLContext->MakeCurrent();
|
|
|
|
mGLContext->fDeleteTextures(1, &mTexture);
|
2012-09-06 17:16:30 -07:00
|
|
|
sGLXLib.DestroyPixmap(mPixmap);
|
2011-04-07 16:58:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual gfxASurface* BeginUpdate(nsIntRegion& aRegion)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mInUpdate = true;
|
2011-04-07 16:58:08 -07:00
|
|
|
return mUpdateSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void EndUpdate()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mInUpdate = false;
|
2011-04-07 16:58:08 -07:00
|
|
|
}
|
|
|
|
|
2011-07-06 11:00:47 -07:00
|
|
|
|
|
|
|
virtual bool DirectUpdate(gfxASurface* aSurface, const nsIntRegion& aRegion, const nsIntPoint& aFrom)
|
2011-04-07 16:58:08 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(mUpdateSurface);
|
|
|
|
gfxUtils::ClipToRegion(ctx, aRegion);
|
2011-07-06 11:00:47 -07:00
|
|
|
ctx->SetSource(aSurface, aFrom);
|
2011-04-07 16:58:08 -07:00
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
ctx->Paint();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void BindTexture(GLenum aTextureUnit)
|
|
|
|
{
|
|
|
|
mGLContext->fActiveTexture(aTextureUnit);
|
2011-07-06 11:00:47 -07:00
|
|
|
mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
|
2012-09-06 17:16:30 -07:00
|
|
|
sGLXLib.BindTexImage(mPixmap);
|
2011-04-12 00:36:13 -07:00
|
|
|
mGLContext->fActiveTexture(LOCAL_GL_TEXTURE0);
|
2011-04-07 16:58:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ReleaseTexture()
|
|
|
|
{
|
2012-09-06 17:16:30 -07:00
|
|
|
sGLXLib.ReleaseTexImage(mPixmap);
|
2011-04-07 16:58:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual already_AddRefed<gfxASurface> GetBackingSurface()
|
|
|
|
{
|
2011-09-16 13:22:44 -07:00
|
|
|
nsRefPtr<gfxASurface> copy = mUpdateSurface;
|
|
|
|
return copy.forget();
|
2011-04-07 16:58:08 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool InUpdate() const { return mInUpdate; }
|
2011-04-07 16:58:08 -07:00
|
|
|
|
2011-07-06 11:00:47 -07:00
|
|
|
virtual GLuint GetTextureID() {
|
|
|
|
return mTexture;
|
2012-07-16 07:59:15 -07:00
|
|
|
}
|
2011-07-06 11:00:47 -07:00
|
|
|
|
2011-04-07 16:58:08 -07:00
|
|
|
private:
|
|
|
|
TextureImageGLX(GLuint aTexture,
|
|
|
|
const nsIntSize& aSize,
|
|
|
|
GLenum aWrapMode,
|
|
|
|
ContentType aContentType,
|
|
|
|
GLContext* aContext,
|
|
|
|
gfxASurface* aSurface,
|
2012-05-09 13:55:31 -07:00
|
|
|
GLXPixmap aPixmap,
|
2012-09-11 05:59:34 -07:00
|
|
|
TextureImage::Flags aFlags,
|
|
|
|
LibType aLibType)
|
2012-05-09 13:55:31 -07:00
|
|
|
: TextureImage(aSize, aWrapMode, aContentType, aFlags)
|
2011-04-07 16:58:08 -07:00
|
|
|
, mGLContext(aContext)
|
|
|
|
, mUpdateSurface(aSurface)
|
|
|
|
, mPixmap(aPixmap)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mInUpdate(false)
|
2011-07-06 11:00:47 -07:00
|
|
|
, mTexture(aTexture)
|
2012-09-06 17:16:30 -07:00
|
|
|
, sGLXLib(sGLXLibrary[aLibType])
|
2011-04-07 16:58:08 -07:00
|
|
|
{
|
|
|
|
if (aSurface->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA) {
|
|
|
|
mShaderType = gl::RGBALayerProgramType;
|
|
|
|
} else {
|
|
|
|
mShaderType = gl::RGBXLayerProgramType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GLContext* mGLContext;
|
|
|
|
nsRefPtr<gfxASurface> mUpdateSurface;
|
|
|
|
GLXPixmap mPixmap;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mInUpdate;
|
2011-07-06 11:00:47 -07:00
|
|
|
GLuint mTexture;
|
2012-09-06 17:16:30 -07:00
|
|
|
GLXLibrary& sGLXLib;
|
2011-10-05 11:20:33 -07:00
|
|
|
|
|
|
|
virtual void ApplyFilter()
|
|
|
|
{
|
|
|
|
mGLContext->ApplyFilterToBoundTexture(mFilter);
|
|
|
|
}
|
2011-04-07 16:58:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
already_AddRefed<TextureImage>
|
|
|
|
GLContextGLX::CreateTextureImage(const nsIntSize& aSize,
|
|
|
|
TextureImage::ContentType aContentType,
|
|
|
|
GLenum aWrapMode,
|
2012-05-09 13:55:31 -07:00
|
|
|
TextureImage::Flags aFlags)
|
2011-04-07 16:58:08 -07:00
|
|
|
{
|
|
|
|
if (!TextureImageSupportsGetBackingSurface()) {
|
|
|
|
return GLContext::CreateTextureImage(aSize,
|
|
|
|
aContentType,
|
|
|
|
aWrapMode,
|
2012-05-09 13:55:31 -07:00
|
|
|
aFlags);
|
2011-04-07 16:58:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Display *display = DefaultXDisplay();
|
|
|
|
int xscreen = DefaultScreen(display);
|
2012-05-25 21:38:17 -07:00
|
|
|
gfxASurface::gfxImageFormat imageFormat = gfxPlatform::GetPlatform()->OptimalFormatForContent(aContentType);
|
2011-04-07 16:58:08 -07:00
|
|
|
|
|
|
|
XRenderPictFormat* xrenderFormat =
|
|
|
|
gfxXlibSurface::FindRenderFormat(display, imageFormat);
|
|
|
|
NS_ASSERTION(xrenderFormat, "Could not find a render format for our display!");
|
|
|
|
|
|
|
|
|
|
|
|
nsRefPtr<gfxXlibSurface> surface =
|
|
|
|
gfxXlibSurface::Create(ScreenOfDisplay(display, xscreen),
|
|
|
|
xrenderFormat,
|
|
|
|
gfxIntSize(aSize.width, aSize.height));
|
|
|
|
NS_ASSERTION(surface, "Failed to create xlib surface!");
|
|
|
|
|
|
|
|
if (aContentType == gfxASurface::CONTENT_COLOR_ALPHA) {
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(surface);
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_CLEAR);
|
|
|
|
ctx->Paint();
|
|
|
|
}
|
|
|
|
|
|
|
|
MakeCurrent();
|
2013-02-13 15:26:24 -08:00
|
|
|
GLXPixmap pixmap = mGLX->CreatePixmap(surface);
|
2011-04-07 16:58:08 -07:00
|
|
|
NS_ASSERTION(pixmap, "Failed to create pixmap!");
|
|
|
|
|
|
|
|
GLuint texture;
|
|
|
|
fGenTextures(1, &texture);
|
|
|
|
|
|
|
|
fActiveTexture(LOCAL_GL_TEXTURE0);
|
|
|
|
fBindTexture(LOCAL_GL_TEXTURE_2D, texture);
|
|
|
|
|
|
|
|
nsRefPtr<TextureImageGLX> teximage =
|
2012-09-06 17:16:30 -07:00
|
|
|
new TextureImageGLX(texture, aSize, aWrapMode, aContentType,
|
|
|
|
this, surface, pixmap, aFlags, mLibType);
|
2011-04-07 16:58:08 -07:00
|
|
|
|
2012-05-09 13:55:31 -07:00
|
|
|
GLint texfilter = aFlags & TextureImage::UseNearestFilter ? LOCAL_GL_NEAREST : LOCAL_GL_LINEAR;
|
2011-04-07 16:58:08 -07:00
|
|
|
fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, texfilter);
|
|
|
|
fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, texfilter);
|
|
|
|
fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, aWrapMode);
|
|
|
|
fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, aWrapMode);
|
|
|
|
|
|
|
|
return teximage.forget();
|
|
|
|
}
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
static GLContextGLX *
|
2012-09-06 17:16:30 -07:00
|
|
|
GetGlobalContextGLX(const GLContext::ContextFlags aFlags = GLContext::ContextFlagsNone)
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
2012-09-06 17:16:30 -07:00
|
|
|
return static_cast<GLContextGLX*>(GLContextProviderGLX::GetGlobalContext(aFlags));
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2012-08-19 21:21:59 -07:00
|
|
|
AreCompatibleVisuals(Visual *one, Visual *two)
|
2010-06-18 16:17:00 -07:00
|
|
|
{
|
|
|
|
if (one->c_class != two->c_class) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-18 16:17:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (one->red_mask != two->red_mask ||
|
|
|
|
one->green_mask != two->green_mask ||
|
|
|
|
one->blue_mask != two->blue_mask) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-18 16:17:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (one->bits_per_rgb != two->bits_per_rgb) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-18 16:17:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-18 16:17:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-14 23:55:08 -07:00
|
|
|
already_AddRefed<GLContext>
|
2010-07-18 22:01:14 -07:00
|
|
|
GLContextProviderGLX::CreateForWindow(nsIWidget *aWidget)
|
2010-06-14 23:55:08 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
const LibType libType = GLXLibrary::OPENGL_LIB;
|
|
|
|
if (!sDefGLXLib.EnsureInitialized(libType)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-18 16:17:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Currently, we take whatever Visual the window already has, and
|
|
|
|
// try to create an fbconfig for that visual. This isn't
|
|
|
|
// necessarily what we want in the long run; an fbconfig may not
|
|
|
|
// be available for the existing visual, or if it is, the GL
|
|
|
|
// performance might be suboptimal. But using the existing visual
|
|
|
|
// is a relatively safe intermediate step.
|
|
|
|
|
|
|
|
Display *display = (Display*)aWidget->GetNativeData(NS_NATIVE_DISPLAY);
|
|
|
|
int xscreen = DefaultScreen(display);
|
|
|
|
Window window = GET_NATIVE_WINDOW(aWidget);
|
|
|
|
|
|
|
|
int numConfigs;
|
2010-06-23 20:52:48 -07:00
|
|
|
ScopedXFree<GLXFBConfig> cfgs;
|
2012-09-06 17:16:30 -07:00
|
|
|
if (sDefGLXLib.IsATI() ||
|
|
|
|
!sDefGLXLib.GLXVersionCheck(1, 3)) {
|
2010-06-18 16:17:00 -07:00
|
|
|
const int attribs[] = {
|
|
|
|
GLX_DOUBLEBUFFER, False,
|
|
|
|
0
|
|
|
|
};
|
2012-09-06 17:16:30 -07:00
|
|
|
cfgs = sDefGLXLib.xChooseFBConfig(display,
|
|
|
|
xscreen,
|
|
|
|
attribs,
|
|
|
|
&numConfigs);
|
2010-06-18 16:17:00 -07:00
|
|
|
} else {
|
2012-09-06 17:16:30 -07:00
|
|
|
cfgs = sDefGLXLib.xGetFBConfigs(display,
|
|
|
|
xscreen,
|
|
|
|
&numConfigs);
|
2010-06-18 16:17:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cfgs) {
|
|
|
|
NS_WARNING("[GLX] glXGetFBConfigs() failed");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-18 16:17:00 -07:00
|
|
|
}
|
|
|
|
NS_ASSERTION(numConfigs > 0, "No FBConfigs found!");
|
|
|
|
|
|
|
|
// XXX the visual ID is almost certainly the GLX_FBCONFIG_ID, so
|
|
|
|
// we could probably do this first and replace the glXGetFBConfigs
|
|
|
|
// with glXChooseConfigs. Docs are sparklingly clear as always.
|
|
|
|
XWindowAttributes widgetAttrs;
|
|
|
|
if (!XGetWindowAttributes(display, window, &widgetAttrs)) {
|
|
|
|
NS_WARNING("[GLX] XGetWindowAttributes() failed");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-18 16:17:00 -07:00
|
|
|
}
|
|
|
|
const VisualID widgetVisualID = XVisualIDFromVisual(widgetAttrs.visual);
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("[GLX] widget has VisualID 0x%lx\n", widgetVisualID);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int matchIndex = -1;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2010-06-18 16:17:00 -07:00
|
|
|
for (int i = 0; i < numConfigs; i++) {
|
2012-08-19 21:21:59 -07:00
|
|
|
int visid = None;
|
2012-09-06 17:16:30 -07:00
|
|
|
sDefGLXLib.xGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &visid);
|
2012-08-19 21:21:59 -07:00
|
|
|
if (!visid) {
|
2010-06-22 17:24:52 -07:00
|
|
|
continue;
|
|
|
|
}
|
2012-09-06 17:16:30 -07:00
|
|
|
if (sDefGLXLib.IsATI()) {
|
2012-08-19 21:21:59 -07:00
|
|
|
int depth;
|
|
|
|
Visual *visual;
|
|
|
|
FindVisualAndDepth(display, visid, &visual, &depth);
|
|
|
|
if (depth == widgetAttrs.depth &&
|
|
|
|
AreCompatibleVisuals(widgetAttrs.visual, visual)) {
|
2010-06-18 16:17:00 -07:00
|
|
|
matchIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-19 21:21:59 -07:00
|
|
|
if (widgetVisualID == static_cast<VisualID>(visid)) {
|
2010-06-18 16:17:00 -07:00
|
|
|
matchIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matchIndex == -1) {
|
|
|
|
NS_WARNING("[GLX] Couldn't find a FBConfig matching widget visual");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-18 16:17:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
GLContextGLX *shareContext = GetGlobalContextGLX();
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
SurfaceCaps caps = SurfaceCaps::Any();
|
|
|
|
nsRefPtr<GLContextGLX> glContext = GLContextGLX::CreateGLContext(caps,
|
|
|
|
shareContext,
|
|
|
|
false,
|
2010-07-18 22:01:14 -07:00
|
|
|
display,
|
2010-06-18 16:17:00 -07:00
|
|
|
window,
|
|
|
|
cfgs[matchIndex],
|
2012-09-06 17:16:30 -07:00
|
|
|
false,
|
2013-02-13 15:26:24 -08:00
|
|
|
libType);
|
2012-03-12 15:10:38 -07:00
|
|
|
|
2010-06-23 20:52:48 -07:00
|
|
|
return glContext.forget();
|
2010-06-14 23:55:08 -07:00
|
|
|
}
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
static already_AddRefed<GLContextGLX>
|
2013-02-13 15:26:24 -08:00
|
|
|
CreateOffscreenPixmapContext(const gfxIntSize& size, LibType libToUse)
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
GLXLibrary& glx = sGLXLibrary[libToUse];
|
|
|
|
if (!glx.EnsureInitialized(libToUse)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Display *display = DefaultXDisplay();
|
|
|
|
int xscreen = DefaultScreen(display);
|
|
|
|
|
|
|
|
int attribs[] = {
|
|
|
|
GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
|
|
|
|
GLX_X_RENDERABLE, True,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
int numConfigs = 0;
|
|
|
|
|
|
|
|
ScopedXFree<GLXFBConfig> cfgs;
|
2013-02-13 15:26:24 -08:00
|
|
|
cfgs = glx.xChooseFBConfig(display,
|
|
|
|
xscreen,
|
|
|
|
attribs,
|
|
|
|
&numConfigs);
|
2010-07-18 22:01:14 -07:00
|
|
|
if (!cfgs) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
MOZ_ASSERT(numConfigs > 0,
|
|
|
|
"glXChooseFBConfig() failed to match our requested format and violated its spec!");
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2012-08-19 21:21:59 -07:00
|
|
|
int visid = None;
|
2010-12-05 10:38:12 -08:00
|
|
|
int chosenIndex = 0;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < numConfigs; ++i) {
|
2012-08-19 21:21:59 -07:00
|
|
|
int dtype;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
if (glx.xGetFBConfigAttrib(display, cfgs[i], GLX_DRAWABLE_TYPE, &dtype) != Success
|
2010-07-18 22:01:14 -07:00
|
|
|
|| !(dtype & GLX_PIXMAP_BIT))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-13 15:26:24 -08:00
|
|
|
if (glx.xGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &visid) != Success
|
2010-07-18 22:01:14 -07:00
|
|
|
|| visid == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-19 21:21:59 -07:00
|
|
|
chosenIndex = i;
|
|
|
|
break;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2012-08-19 21:21:59 -07:00
|
|
|
if (!visid) {
|
2010-07-18 22:01:14 -07:00
|
|
|
NS_WARNING("glXChooseFBConfig() didn't give us any configs with visuals!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2012-08-19 21:21:59 -07:00
|
|
|
Visual *visual;
|
|
|
|
int depth;
|
|
|
|
FindVisualAndDepth(display, visid, &visual, &depth);
|
2010-12-06 03:34:34 -08:00
|
|
|
ScopedXErrorHandler xErrorHandler;
|
2011-01-07 02:54:19 -08:00
|
|
|
GLXPixmap glxpixmap = 0;
|
2010-12-06 03:34:34 -08:00
|
|
|
bool error = false;
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
gfxIntSize dummySize(16, 16);
|
2010-07-18 22:01:14 -07:00
|
|
|
nsRefPtr<gfxXlibSurface> xsurface = gfxXlibSurface::Create(DefaultScreenOfDisplay(display),
|
2012-08-19 21:21:59 -07:00
|
|
|
visual,
|
2013-02-13 15:26:24 -08:00
|
|
|
dummySize);
|
2010-07-18 22:01:14 -07:00
|
|
|
if (xsurface->CairoStatus() != 0) {
|
2010-12-06 03:34:34 -08:00
|
|
|
error = true;
|
|
|
|
goto DONE_CREATING_PIXMAP;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 07:49:52 -08:00
|
|
|
// Handle slightly different signature between glXCreatePixmap and
|
|
|
|
// its pre-GLX-1.3 extension equivalent (though given the ABI, we
|
|
|
|
// might not need to).
|
2013-02-13 15:26:24 -08:00
|
|
|
if (glx.GLXVersionCheck(1, 3)) {
|
|
|
|
glxpixmap = glx.xCreatePixmap(display,
|
2012-09-06 17:16:30 -07:00
|
|
|
cfgs[chosenIndex],
|
|
|
|
xsurface->XDrawable(),
|
|
|
|
NULL);
|
2010-11-10 07:49:52 -08:00
|
|
|
} else {
|
2013-02-13 15:26:24 -08:00
|
|
|
glxpixmap = glx.xCreateGLXPixmapWithConfig(display,
|
2012-09-06 17:16:30 -07:00
|
|
|
cfgs[chosenIndex],
|
|
|
|
xsurface->
|
|
|
|
XDrawable());
|
2010-11-10 07:49:52 -08:00
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
if (glxpixmap == 0) {
|
2010-12-06 03:34:34 -08:00
|
|
|
error = true;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2010-12-06 03:34:34 -08:00
|
|
|
DONE_CREATING_PIXMAP:
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2010-12-06 03:34:34 -08:00
|
|
|
nsRefPtr<GLContextGLX> glContext;
|
|
|
|
bool serverError = xErrorHandler.SyncAndGetError(display);
|
|
|
|
|
|
|
|
if (!error && // earlier recorded error
|
|
|
|
!serverError)
|
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
GLContext::ContextFlags flag = libToUse == GLXLibrary::MESA_LLVMPIPE_LIB
|
|
|
|
? GLContext::ContextFlagsMesaLLVMPipe
|
|
|
|
: GLContext::ContextFlagsNone;
|
|
|
|
// We might have an alpha channel, but it doesn't matter.
|
|
|
|
SurfaceCaps dummyCaps = SurfaceCaps::Any();
|
|
|
|
GLContextGLX* shareContext = GetGlobalContextGLX(flag);
|
|
|
|
|
|
|
|
glContext = GLContextGLX::CreateGLContext(dummyCaps,
|
|
|
|
shareContext,
|
|
|
|
true,
|
|
|
|
display,
|
|
|
|
glxpixmap,
|
|
|
|
cfgs[chosenIndex],
|
|
|
|
false,
|
|
|
|
libToUse,
|
|
|
|
xsurface);
|
2010-12-06 03:34:34 -08:00
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
2010-06-14 23:55:08 -07:00
|
|
|
already_AddRefed<GLContext>
|
2013-02-13 15:26:24 -08:00
|
|
|
GLContextProviderGLX::CreateOffscreen(const gfxIntSize& size,
|
|
|
|
const SurfaceCaps& caps,
|
|
|
|
ContextFlags flags)
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
LibType libType = GLXLibrary::SelectLibrary(flags);
|
|
|
|
gCurrLib = libType;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
gfxIntSize dummySize = gfxIntSize(16, 16);
|
|
|
|
nsRefPtr<GLContextGLX> glContext =
|
|
|
|
CreateOffscreenPixmapContext(dummySize, libType);
|
2013-02-20 07:01:20 -08:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
if (!glContext)
|
2013-02-20 07:01:20 -08:00
|
|
|
return nullptr;
|
2013-02-21 11:54:25 -08:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
if (!glContext->InitOffscreen(size, caps))
|
2013-02-21 11:54:25 -08:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
2012-09-06 17:16:30 -07:00
|
|
|
static nsRefPtr<GLContext> gGlobalContext[GLXLibrary::LIBS_MAX];
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
GLContext*
|
2012-09-06 17:16:30 -07:00
|
|
|
GLContextProviderGLX::GetGlobalContext(const ContextFlags aFlag)
|
2010-06-23 02:24:31 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
LibType libType = GLXLibrary::SelectLibrary(aFlag);
|
2012-09-06 17:16:30 -07:00
|
|
|
static bool triedToCreateContext[GLXLibrary::LIBS_MAX] = {false, false};
|
2013-02-13 15:26:24 -08:00
|
|
|
if (!triedToCreateContext[libType] && !gGlobalContext[libType]) {
|
|
|
|
triedToCreateContext[libType] = true;
|
|
|
|
|
|
|
|
gfxIntSize dummySize = gfxIntSize(16, 16);
|
|
|
|
gGlobalContext[libType] = CreateOffscreenPixmapContext(dummySize, libType);
|
|
|
|
if (gGlobalContext[libType])
|
|
|
|
gGlobalContext[libType]->SetIsGlobalSharedContext(true);
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
return gGlobalContext[libType];
|
2010-06-23 02:24:31 -07:00
|
|
|
}
|
|
|
|
|
2010-07-19 21:05:42 -07:00
|
|
|
void
|
|
|
|
GLContextProviderGLX::Shutdown()
|
|
|
|
{
|
2012-09-06 17:16:30 -07:00
|
|
|
for (int i = 0; i < GLXLibrary::LIBS_MAX; ++i)
|
|
|
|
gGlobalContext[i] = nullptr;
|
2010-07-19 21:05:42 -07:00
|
|
|
}
|
|
|
|
|
2010-06-14 23:55:08 -07:00
|
|
|
} /* namespace gl */
|
|
|
|
} /* namespace mozilla */
|
2011-08-23 18:55:43 -07:00
|
|
|
|