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>
|
|
|
|
|
2013-11-12 16:22:38 -08:00
|
|
|
#include "mozilla/MathAlgorithms.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
|
2013-09-04 05:14:52 -07:00
|
|
|
GLXLibrary::SelectLibrary(const ContextFlags& aFlags)
|
2012-09-06 17:16:30 -07:00
|
|
|
{
|
2013-09-04 05:14:52 -07:00
|
|
|
return (aFlags & ContextFlagsMesaLLVMPipe)
|
2012-09-06 17:16:30 -07:00
|
|
|
? GLXLibrary::MESA_LLVMPIPE_LIB
|
|
|
|
: GLXLibrary::OPENGL_LIB;
|
|
|
|
}
|
2010-11-10 07:49:52 -08:00
|
|
|
|
|
|
|
// Check that we have at least version aMajor.aMinor .
|
2013-12-08 20:07:18 -08:00
|
|
|
bool
|
2012-09-06 17:16:30 -07:00
|
|
|
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:
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("Invalid GLX library type.");
|
2013-02-13 15:26:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr*) &xDestroyContextInternal, { "glXDestroyContext", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xMakeCurrentInternal, { "glXMakeCurrent", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xSwapBuffersInternal, { "glXSwapBuffers", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xQueryVersionInternal, { "glXQueryVersion", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xGetCurrentContextInternal, { "glXGetCurrentContext", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xWaitGLInternal, { "glXWaitGL", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xWaitXInternal, { "glXWaitX", nullptr } },
|
2010-11-10 07:49:52 -08:00
|
|
|
/* functions introduced in GLX 1.1 */
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr*) &xQueryExtensionsStringInternal, { "glXQueryExtensionsString", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xGetClientStringInternal, { "glXGetClientString", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xQueryServerStringInternal, { "glXQueryServerString", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-11-10 07:49:52 -08:00
|
|
|
};
|
|
|
|
|
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 */
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr*) &xChooseFBConfigInternal, { "glXChooseFBConfig", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xGetFBConfigAttribInternal, { "glXGetFBConfigAttrib", nullptr } },
|
2010-11-10 07:49:52 -08:00
|
|
|
// WARNING: xGetFBConfigs not set in symbols13_ext
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr*) &xGetFBConfigsInternal, { "glXGetFBConfigs", nullptr } },
|
2010-11-10 07:49:52 -08:00
|
|
|
// WARNING: symbols13_ext sets xCreateGLXPixmapWithConfig instead
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr*) &xCreatePixmapInternal, { "glXCreatePixmap", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xDestroyPixmapInternal, { "glXDestroyPixmap", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xCreateNewContextInternal, { "glXCreateNewContext", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-11-10 07:49:52 -08:00
|
|
|
};
|
|
|
|
|
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
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr*) &xChooseFBConfigInternal, { "glXChooseFBConfigSGIX", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xGetFBConfigAttribInternal, { "glXGetFBConfigAttribSGIX", nullptr } },
|
2010-11-10 07:49:52 -08:00
|
|
|
// WARNING: no xGetFBConfigs equivalent in extensions
|
|
|
|
// WARNING: different from symbols13:
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr*) &xCreateGLXPixmapWithConfigInternal, { "glXCreateGLXPixmapWithConfigSGIX", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xDestroyPixmapInternal, { "glXDestroyGLXPixmap", nullptr } }, // not from ext
|
|
|
|
{ (PRFuncPtr*) &xCreateNewContextInternal, { "glXCreateContextWithConfigSGIX", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-11-10 07:49:52 -08:00
|
|
|
};
|
|
|
|
|
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 */
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr*) &xGetProcAddressInternal, { "glXGetProcAddress", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-11-10 07:49:52 -08:00
|
|
|
};
|
|
|
|
|
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
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr*) &xGetProcAddressInternal, { "glXGetProcAddressARB", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-06-14 23:55:08 -07:00
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols_texturefrompixmap[] = {
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr*) &xBindTexImageInternal, { "glXBindTexImageEXT", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xReleaseTexImageInternal, { "glXReleaseTexImageEXT", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2011-04-07 16:58:07 -07:00
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols_robustness[] = {
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr*) &xCreateContextAttribsInternal, { "glXCreateContextAttribsARB", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2011-10-26 13:00:44 -07:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2013-11-18 05:08:24 -08:00
|
|
|
const char *clientVendor = xGetClientString(display, LOCAL_GLX_VENDOR);
|
|
|
|
const char *serverVendor = xQueryServerString(display, screen, LOCAL_GLX_VENDOR);
|
2012-07-30 19:54:21 -07:00
|
|
|
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") &&
|
2013-12-08 20:07:18 -08:00
|
|
|
GLLibraryLoader::LoadSymbols(mOGLLibrary, symbols_texturefrompixmap,
|
2012-03-16 15:24:12 -07:00
|
|
|
(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");
|
2013-08-20 05:30:26 -07:00
|
|
|
mIsNVIDIA = serverVendor && DoesStringMatch(serverVendor, "NVIDIA Corporation");
|
2012-09-06 17:16:30 -07:00
|
|
|
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
|
|
|
}
|
2013-12-08 20:07:18 -08:00
|
|
|
|
2013-09-24 13:45:13 -07:00
|
|
|
if (aSurface->GetType() != gfxSurfaceTypeXlib || !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
|
|
|
}
|
|
|
|
|
2013-12-08 20:07:18 -08:00
|
|
|
GLXPixmap
|
2011-07-14 13:45:33 -07:00
|
|
|
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;
|
2013-11-12 16:22:38 -08:00
|
|
|
int alphaSize = FloorLog2(direct.alphaMask + 1);
|
2012-08-19 21:21:37 -07:00
|
|
|
NS_ASSERTION((1 << alphaSize) - 1 == direct.alphaMask,
|
|
|
|
"Unexpected render format with non-adjacent alpha bits");
|
2012-07-30 19:54:21 -07:00
|
|
|
|
2013-11-18 05:08:24 -08:00
|
|
|
int attribs[] = { LOCAL_GLX_DOUBLEBUFFER, False,
|
|
|
|
LOCAL_GLX_DRAWABLE_TYPE, LOCAL_GLX_PIXMAP_BIT,
|
|
|
|
LOCAL_GLX_ALPHA_SIZE, alphaSize,
|
|
|
|
(alphaSize ? LOCAL_GLX_BIND_TO_TEXTURE_RGBA_EXT
|
|
|
|
: LOCAL_GLX_BIND_TO_TEXTURE_RGB_EXT), True,
|
|
|
|
LOCAL_GLX_RENDER_TYPE, LOCAL_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));
|
|
|
|
|
2013-12-08 20:07:18 -08: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;
|
2013-11-18 05:08:24 -08:00
|
|
|
sGLXLibrary[mLibType].xGetFBConfigAttrib(display, cfgs[i], LOCAL_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.
|
2013-08-20 05:30:26 -07:00
|
|
|
// NVIDIA now forces format->depth == depth so only the first way
|
|
|
|
// is checked for NVIDIA
|
|
|
|
if (depth != format->depth &&
|
|
|
|
(mIsNVIDIA || 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
|
2013-11-18 05:08:24 -08:00
|
|
|
// LOCAL_GLX_BUFFER_SIZE, so we should still get zero alpha bits if
|
2012-08-19 21:21:07 -07:00
|
|
|
// 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],
|
2013-11-18 05:08:24 -08:00
|
|
|
LOCAL_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) {
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
// GLX can't handle A8 surfaces, so this is not really unexpected. The
|
|
|
|
// caller should deal with this situation.
|
|
|
|
NS_WARN_IF_FALSE(format->depth == 8,
|
|
|
|
"[GLX] Couldn't find a FBConfig matching Pixmap format");
|
2012-07-30 19:54:21 -07:00
|
|
|
return None;
|
|
|
|
}
|
2011-04-07 16:58:07 -07:00
|
|
|
|
2013-11-18 05:08:24 -08:00
|
|
|
int pixmapAttribs[] = { LOCAL_GLX_TEXTURE_TARGET_EXT, LOCAL_GLX_TEXTURE_2D_EXT,
|
|
|
|
LOCAL_GLX_TEXTURE_FORMAT_EXT,
|
|
|
|
(alphaSize ? LOCAL_GLX_TEXTURE_FORMAT_RGBA_EXT
|
|
|
|
: LOCAL_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)
|
2013-12-08 20:07:18 -08:00
|
|
|
{
|
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();
|
|
|
|
}
|
2013-11-18 05:08:24 -08:00
|
|
|
xBindTexImage(display, aPixmap, LOCAL_GLX_FRONT_LEFT_EXT, nullptr);
|
2011-04-07 16:58:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2013-11-18 05:08:24 -08:00
|
|
|
xReleaseTexImage(display, aPixmap, LOCAL_GLX_FRONT_LEFT_EXT);
|
2011-04-07 16:58:07 -07:00
|
|
|
}
|
|
|
|
|
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)
|
2013-12-08 20:07:18 -08:00
|
|
|
|
2011-08-23 18:55:43 -07:00
|
|
|
#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
|
2013-12-08 20:07:18 -08:00
|
|
|
|
|
|
|
void
|
2011-08-23 18:55:43 -07:00
|
|
|
GLXLibrary::xDestroyContext(Display* display, GLXContext context)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
xDestroyContextInternal(display, context);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
}
|
|
|
|
|
2013-12-08 20:07:18 -08:00
|
|
|
Bool
|
|
|
|
GLXLibrary::xMakeCurrent(Display* display,
|
|
|
|
GLXDrawable drawable,
|
2011-08-23 18:55:43 -07:00
|
|
|
GLXContext context)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
Bool result = xMakeCurrentInternal(display, drawable, context);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-12-08 20:07:18 -08:00
|
|
|
GLXContext
|
2011-08-23 18:55:43 -07:00
|
|
|
GLXLibrary::xGetCurrentContext()
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXContext result = xGetCurrentContextInternal();
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-12-08 20:07:18 -08:00
|
|
|
/* static */ void*
|
2011-08-23 18:55:43 -07:00
|
|
|
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*
|
2013-12-08 20:07:18 -08:00
|
|
|
GLXLibrary::xChooseFBConfig(Display* display,
|
|
|
|
int screen,
|
|
|
|
const int *attrib_list,
|
2011-08-23 18:55:43 -07:00
|
|
|
int *nelements)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXFBConfig* result = xChooseFBConfigInternal(display, screen, attrib_list, nelements);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-12-08 20:07:18 -08:00
|
|
|
GLXFBConfig*
|
|
|
|
GLXLibrary::xGetFBConfigs(Display* display,
|
|
|
|
int screen,
|
2011-08-23 18:55:43 -07:00
|
|
|
int *nelements)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXFBConfig* result = xGetFBConfigsInternal(display, screen, nelements);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
2013-12-08 20:07:18 -08:00
|
|
|
|
2011-08-23 18:55:43 -07:00
|
|
|
GLXContext
|
2013-12-08 20:07:18 -08:00
|
|
|
GLXLibrary::xCreateNewContext(Display* display,
|
|
|
|
GLXFBConfig config,
|
|
|
|
int render_type,
|
|
|
|
GLXContext share_list,
|
2011-08-23 18:55:43 -07:00
|
|
|
Bool direct)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
2013-12-08 20:07:18 -08:00
|
|
|
GLXContext result = xCreateNewContextInternal(display, config,
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
render_type,
|
|
|
|
share_list, direct);
|
2011-08-23 18:55:43 -07:00
|
|
|
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
|
2013-12-08 20:07:18 -08:00
|
|
|
GLXLibrary::xCreatePixmap(Display *display,
|
2011-08-23 18:55:43 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-12-08 20:07:18 -08:00
|
|
|
void
|
2011-08-23 18:55:43 -07:00
|
|
|
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
|
2013-12-08 20:07:18 -08:00
|
|
|
GLXLibrary::xCreateContextAttribs(Display* display,
|
|
|
|
GLXFBConfig config,
|
|
|
|
GLXContext share_list,
|
2011-10-26 13:00:44 -07:00
|
|
|
Bool direct,
|
|
|
|
const int* attrib_list)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
2013-12-08 20:07:18 -08:00
|
|
|
GLXContext result = xCreateContextAttribsInternal(display,
|
|
|
|
config,
|
|
|
|
share_list,
|
2011-10-26 13:00:44 -07:00
|
|
|
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,
|
2013-11-18 05:08:24 -08:00
|
|
|
LOCAL_GLX_DOUBLEBUFFER, &db);
|
|
|
|
if (LOCAL_GLX_BAD_ATTRIBUTE != err) {
|
2010-06-18 16:17:00 -07:00
|
|
|
#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-07-20 01:48:55 -07:00
|
|
|
GLXContext glxContext = shareContext ? shareContext->mContext : nullptr;
|
2013-02-13 15:26:24 -08:00
|
|
|
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,
|
2013-11-18 05:08:24 -08:00
|
|
|
LOCAL_GLX_RGBA_TYPE,
|
2013-02-13 15:26:24 -08:00
|
|
|
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
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
2013-12-08 20:07:18 -08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
mGLX(&sGLXLibrary[libType]),
|
|
|
|
mPixmap(aPixmap)
|
2012-09-06 17:16:30 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
MOZ_ASSERT(mGLX);
|
2013-08-01 16:43:27 -07:00
|
|
|
// See 899855
|
|
|
|
SetProfileVersion(ContextProfile::OpenGLCompatibility, 200);
|
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
|
|
|
|
|
|
|
GLXLibrary* mGLX;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
nsRefPtr<gfxXlibSurface> mPixmap;
|
2010-06-14 23:55:08 -07:00
|
|
|
};
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
static GLContextGLX *
|
2013-09-04 05:14:52 -07:00
|
|
|
GetGlobalContextGLX(const ContextFlags aFlags = 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.
|
|
|
|
|
2013-12-08 20:07:18 -08:00
|
|
|
Display *display = (Display*)aWidget->GetNativeData(NS_NATIVE_DISPLAY);
|
2010-06-18 16:17:00 -07:00
|
|
|
int xscreen = DefaultScreen(display);
|
|
|
|
Window window = GET_NATIVE_WINDOW(aWidget);
|
|
|
|
|
|
|
|
int numConfigs;
|
2010-06-23 20:52:48 -07:00
|
|
|
ScopedXFree<GLXFBConfig> cfgs;
|
2013-12-08 20:07:18 -08:00
|
|
|
if (sDefGLXLib.IsATI() ||
|
2012-09-06 17:16:30 -07:00
|
|
|
!sDefGLXLib.GLXVersionCheck(1, 3)) {
|
2010-06-18 16:17:00 -07:00
|
|
|
const int attribs[] = {
|
2013-11-18 05:08:24 -08:00
|
|
|
LOCAL_GLX_DOUBLEBUFFER, False,
|
2010-06-18 16:17:00 -07:00
|
|
|
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!");
|
|
|
|
|
2013-11-18 05:08:24 -08:00
|
|
|
// XXX the visual ID is almost certainly the LOCAL_GLX_FBCONFIG_ID, so
|
2010-06-18 16:17:00 -07:00
|
|
|
// 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;
|
2013-11-18 05:08:24 -08:00
|
|
|
sDefGLXLib.xGetFBConfigAttrib(display, cfgs[i], LOCAL_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[] = {
|
2013-11-18 05:08:24 -08:00
|
|
|
LOCAL_GLX_DRAWABLE_TYPE, LOCAL_GLX_PIXMAP_BIT,
|
|
|
|
LOCAL_GLX_X_RENDERABLE, True,
|
2010-07-18 22:01:14 -07:00
|
|
|
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-11-18 05:08:24 -08:00
|
|
|
if (glx.xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_DRAWABLE_TYPE, &dtype) != Success
|
|
|
|
|| !(dtype & LOCAL_GLX_PIXMAP_BIT))
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-18 05:08:24 -08:00
|
|
|
if (glx.xGetFBConfigAttrib(display, cfgs[i], LOCAL_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(),
|
2013-07-20 01:48:55 -07:00
|
|
|
nullptr);
|
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-09-04 05:14:52 -07:00
|
|
|
ContextFlags flag = libToUse == GLXLibrary::MESA_LLVMPIPE_LIB
|
|
|
|
? ContextFlagsMesaLLVMPipe
|
|
|
|
: ContextFlagsNone;
|
2013-02-13 15:26:24 -08:00
|
|
|
// 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],
|
2013-06-16 19:03:12 -07:00
|
|
|
true,
|
2013-02-13 15:26:24 -08:00
|
|
|
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];
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
// TODO move that out of static initializaion
|
|
|
|
static bool gUseContextSharing = getenv("MOZ_DISABLE_CONTEXT_SHARING_GLX") == 0;
|
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
|
|
|
{
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
// TODO: get GLX context sharing to work well with multiple threads
|
|
|
|
if (!gUseContextSharing) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|