2010-12-05 18:38:12 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00: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-15 06:55:08 +00:00
|
|
|
|
2012-06-28 00:15:32 +00:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2010-06-15 06:55:08 +00: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)
|
2014-02-21 02:08:50 +00:00
|
|
|
#define GET_NATIVE_WINDOW(aWidget) (Window)(aWidget->GetNativeData(NS_NATIVE_SHAREABLE_WINDOW))
|
2010-06-15 06:55:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
2013-11-13 00:22:38 +00:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2010-06-24 03:52:48 +00:00
|
|
|
#include "mozilla/X11Util.h"
|
|
|
|
|
2011-01-10 21:14:14 +00:00
|
|
|
#include "prenv.h"
|
2010-06-15 06:55:08 +00:00
|
|
|
#include "GLContextProvider.h"
|
2012-03-16 22:24:12 +00:00
|
|
|
#include "GLLibraryLoader.h"
|
2010-06-15 06:55:08 +00:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "GLXLibrary.h"
|
2010-07-19 05:01:14 +00:00
|
|
|
#include "gfxXlibSurface.h"
|
2010-07-01 16:30:38 +00:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxImageSurface.h"
|
2012-04-13 19:43:13 +00:00
|
|
|
#include "gfxPlatform.h"
|
2014-01-07 20:02:18 +00:00
|
|
|
#include "GLContextGLX.h"
|
2011-04-07 23:58:08 +00:00
|
|
|
#include "gfxUtils.h"
|
2014-01-01 19:47:19 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2010-06-15 06:55:08 +00:00
|
|
|
|
2011-03-02 20:50:36 +00:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
|
|
|
|
2012-06-28 00:15:32 +00:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2012-04-18 14:27:32 +00:00
|
|
|
#include "gfxPlatformGtk.h"
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2010-06-15 06:55:08 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
GLXLibrary sGLXLibrary;
|
2010-11-10 15:49:52 +00:00
|
|
|
|
|
|
|
// Check that we have at least version aMajor.aMinor .
|
2013-12-09 04:07:18 +00:00
|
|
|
bool
|
2012-09-07 00:16:30 +00:00
|
|
|
GLXLibrary::GLXVersionCheck(int aMajor, int aMinor)
|
2010-11-10 15:49:52 +00:00
|
|
|
{
|
2012-09-07 00:16:30 +00:00
|
|
|
return aMajor < mGLXMajorVersion ||
|
|
|
|
(aMajor == mGLXMajorVersion && aMinor <= mGLXMinorVersion);
|
2010-11-10 15:49:52 +00:00
|
|
|
}
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2010-11-10 15:49:52 +00:00
|
|
|
static inline bool
|
|
|
|
HasExtension(const char* aExtensions, const char* aRequiredExtension)
|
|
|
|
{
|
|
|
|
return GLContext::ListHasExtension(
|
|
|
|
reinterpret_cast<const GLubyte*>(aExtensions), aRequiredExtension);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-01-10 18:55:23 +00:00
|
|
|
GLXLibrary::EnsureInitialized()
|
2010-06-15 06:55:08 +00:00
|
|
|
{
|
|
|
|
if (mInitialized) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-06-15 06:55:08 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:49:52 +00:00
|
|
|
// Don't repeatedly try to initialize.
|
|
|
|
if (mTriedInitializing) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-11-10 15:49:52 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
mTriedInitializing = true;
|
2010-11-10 15:49:52 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
// Force enabling s3 texture compression. (Bug 774134)
|
2012-07-16 15:36:03 +00:00
|
|
|
PR_SetEnv("force_s3tc_enable=true");
|
|
|
|
|
2010-06-15 06:55:08 +00:00
|
|
|
if (!mOGLLibrary) {
|
2013-02-13 23:26:24 +00:00
|
|
|
const char* libGLfilename = nullptr;
|
|
|
|
bool forceFeatureReport = false;
|
2014-01-10 18:55:23 +00:00
|
|
|
|
|
|
|
// 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 12:48:39 +00:00
|
|
|
#ifdef __OpenBSD__
|
2014-01-10 18:55:23 +00:00
|
|
|
libGLfilename = "libGL.so";
|
2011-10-25 12:48:39 +00:00
|
|
|
#else
|
2014-01-10 18:55:23 +00:00
|
|
|
libGLfilename = "libGL.so.1";
|
2011-10-25 12:48:39 +00:00
|
|
|
#endif
|
2013-02-13 23:26:24 +00:00
|
|
|
|
|
|
|
ScopedGfxFeatureReporter reporter(libGLfilename, forceFeatureReport);
|
2011-03-02 20:50:36 +00:00
|
|
|
mOGLLibrary = PR_LoadLibrary(libGLfilename);
|
2010-06-15 06:55:08 +00:00
|
|
|
if (!mOGLLibrary) {
|
2011-03-02 20:50:36 +00:00
|
|
|
NS_WARNING("Couldn't load OpenGL shared library.");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-06-15 06:55:08 +00:00
|
|
|
}
|
2011-03-02 20:50:36 +00:00
|
|
|
reporter.SetSuccessful();
|
2010-06-15 06:55:08 +00:00
|
|
|
}
|
|
|
|
|
2011-08-24 01:55:43 +00:00
|
|
|
if (PR_GetEnv("MOZ_GLX_DEBUG")) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mDebug = true;
|
2011-08-24 01:55:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols[] = {
|
2010-11-10 15:49:52 +00:00
|
|
|
/* functions that were in GLX 1.0 */
|
2013-07-20 08:48:55 +00: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 15:49:52 +00:00
|
|
|
/* functions introduced in GLX 1.1 */
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &xQueryExtensionsStringInternal, { "glXQueryExtensionsString", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xGetClientStringInternal, { "glXGetClientString", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xQueryServerStringInternal, { "glXQueryServerString", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-11-10 15:49:52 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols13[] = {
|
2010-11-10 15:49:52 +00:00
|
|
|
/* functions introduced in GLX 1.3 */
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &xChooseFBConfigInternal, { "glXChooseFBConfig", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xGetFBConfigAttribInternal, { "glXGetFBConfigAttrib", nullptr } },
|
2010-11-10 15:49:52 +00:00
|
|
|
// WARNING: xGetFBConfigs not set in symbols13_ext
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &xGetFBConfigsInternal, { "glXGetFBConfigs", nullptr } },
|
2010-11-10 15:49:52 +00:00
|
|
|
// WARNING: symbols13_ext sets xCreateGLXPixmapWithConfig instead
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &xCreatePixmapInternal, { "glXCreatePixmap", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xDestroyPixmapInternal, { "glXDestroyPixmap", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xCreateNewContextInternal, { "glXCreateNewContext", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-11-10 15:49:52 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols13_ext[] = {
|
2010-11-10 15:49:52 +00:00
|
|
|
/* extension equivalents for functions introduced in GLX 1.3 */
|
|
|
|
// GLX_SGIX_fbconfig extension
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &xChooseFBConfigInternal, { "glXChooseFBConfigSGIX", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xGetFBConfigAttribInternal, { "glXGetFBConfigAttribSGIX", nullptr } },
|
2010-11-10 15:49:52 +00:00
|
|
|
// WARNING: no xGetFBConfigs equivalent in extensions
|
|
|
|
// WARNING: different from symbols13:
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &xCreateGLXPixmapWithConfigInternal, { "glXCreateGLXPixmapWithConfigSGIX", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xDestroyPixmapInternal, { "glXDestroyGLXPixmap", nullptr } }, // not from ext
|
|
|
|
{ (PRFuncPtr*) &xCreateNewContextInternal, { "glXCreateContextWithConfigSGIX", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-11-10 15:49:52 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols14[] = {
|
2010-11-10 15:49:52 +00:00
|
|
|
/* functions introduced in GLX 1.4 */
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &xGetProcAddressInternal, { "glXGetProcAddress", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-11-10 15:49:52 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols14_ext[] = {
|
2010-11-10 15:49:52 +00:00
|
|
|
/* extension equivalents for functions introduced in GLX 1.4 */
|
|
|
|
// GLX_ARB_get_proc_address extension
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &xGetProcAddressInternal, { "glXGetProcAddressARB", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-06-15 06:55:08 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols_texturefrompixmap[] = {
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &xBindTexImageInternal, { "glXBindTexImageEXT", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &xReleaseTexImageInternal, { "glXReleaseTexImageEXT", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2011-04-07 23:58:07 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct symbols_robustness[] = {
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &xCreateContextAttribsInternal, { "glXCreateContextAttribsARB", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2011-10-26 20:00:44 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &symbols[0])) {
|
2010-06-15 06:55:08 +00:00
|
|
|
NS_WARNING("Couldn't find required entry point in OpenGL shared library");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-06-15 06:55:08 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:49:52 +00:00
|
|
|
Display *display = DefaultXDisplay();
|
|
|
|
int screen = DefaultScreen(display);
|
2011-02-11 23:11:30 +00:00
|
|
|
|
2012-09-07 00:16:30 +00:00
|
|
|
if (!xQueryVersion(display, &mGLXMajorVersion, &mGLXMinorVersion)) {
|
|
|
|
mGLXMajorVersion = 0;
|
|
|
|
mGLXMinorVersion = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-05-03 20:07:17 +00:00
|
|
|
}
|
2011-02-11 23:11:30 +00:00
|
|
|
|
2011-05-03 20:07:17 +00:00
|
|
|
if (!GLXVersionCheck(1, 1))
|
|
|
|
// Not possible to query for extensions.
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-11-10 15:49:52 +00:00
|
|
|
|
2013-11-18 13:08:24 +00:00
|
|
|
const char *clientVendor = xGetClientString(display, LOCAL_GLX_VENDOR);
|
|
|
|
const char *serverVendor = xQueryServerString(display, screen, LOCAL_GLX_VENDOR);
|
2012-07-31 02:54:21 +00:00
|
|
|
const char *extensionsStr = xQueryExtensionsString(display, screen);
|
2011-05-22 23:04:22 +00:00
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct *sym13;
|
2010-11-10 15:49:52 +00:00
|
|
|
if (!GLXVersionCheck(1, 3)) {
|
2010-11-10 15:49:52 +00: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 14:59:28 +00:00
|
|
|
return false;
|
2010-11-10 15:49:52 +00:00
|
|
|
}
|
|
|
|
sym13 = symbols13_ext;
|
|
|
|
} else {
|
|
|
|
sym13 = symbols13;
|
|
|
|
}
|
2012-03-16 22:24:12 +00:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, sym13)) {
|
2010-11-10 15:49:52 +00:00
|
|
|
NS_WARNING("Couldn't find required entry point in OpenGL shared library");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-11-10 15:49:52 +00:00
|
|
|
}
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct *sym14;
|
2010-11-10 15:49:52 +00:00
|
|
|
if (!GLXVersionCheck(1, 4)) {
|
2010-11-10 15:49:52 +00: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 14:59:28 +00:00
|
|
|
return false;
|
2010-11-10 15:49:52 +00:00
|
|
|
}
|
|
|
|
sym14 = symbols14_ext;
|
|
|
|
} else {
|
|
|
|
sym14 = symbols14;
|
|
|
|
}
|
2012-03-16 22:24:12 +00:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, sym14)) {
|
2010-11-10 15:49:52 +00:00
|
|
|
NS_WARNING("Couldn't find required entry point in OpenGL shared library");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-11-10 15:49:52 +00:00
|
|
|
}
|
|
|
|
|
2011-04-07 23:58:07 +00:00
|
|
|
if (HasExtension(extensionsStr, "GLX_EXT_texture_from_pixmap") &&
|
2013-12-09 04:07:18 +00:00
|
|
|
GLLibraryLoader::LoadSymbols(mOGLLibrary, symbols_texturefrompixmap,
|
2012-03-16 22:24:12 +00:00
|
|
|
(GLLibraryLoader::PlatformLookupFunction)&xGetProcAddress))
|
2011-04-07 23:58:07 +00:00
|
|
|
{
|
2012-06-28 00:15:32 +00:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2012-09-17 03:23:00 +00:00
|
|
|
mUseTextureFromPixmap = gfxPlatformGtk::GetPlatform()->UseXRender();
|
2012-04-18 14:27:32 +00:00
|
|
|
#else
|
|
|
|
mUseTextureFromPixmap = true;
|
|
|
|
#endif
|
2011-07-11 13:07:49 +00:00
|
|
|
} else {
|
2012-04-18 14:27:32 +00:00
|
|
|
mUseTextureFromPixmap = false;
|
2011-07-11 13:07:49 +00:00
|
|
|
NS_WARNING("Texture from pixmap disabled");
|
2011-04-07 23:58:07 +00:00
|
|
|
}
|
|
|
|
|
2011-11-19 03:57:29 +00:00
|
|
|
if (HasExtension(extensionsStr, "GLX_ARB_create_context_robustness") &&
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::LoadSymbols(mOGLLibrary, symbols_robustness)) {
|
2011-11-19 03:57:29 +00:00
|
|
|
mHasRobustness = true;
|
2011-10-26 20:00:44 +00:00
|
|
|
}
|
|
|
|
|
2012-09-07 00:16:30 +00:00
|
|
|
mIsATI = serverVendor && DoesStringMatch(serverVendor, "ATI");
|
2013-08-20 12:30:26 +00:00
|
|
|
mIsNVIDIA = serverVendor && DoesStringMatch(serverVendor, "NVIDIA Corporation");
|
2012-09-07 00:16:30 +00:00
|
|
|
mClientIsMesa = clientVendor && DoesStringMatch(clientVendor, "Mesa");
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mInitialized = true;
|
2012-09-07 00:16:30 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-06-15 06:55:08 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2011-07-14 20:45:33 +00:00
|
|
|
GLXLibrary::SupportsTextureFromPixmap(gfxASurface* aSurface)
|
2011-04-07 23:58:07 +00:00
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
if (!EnsureInitialized()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-07-14 20:45:33 +00:00
|
|
|
}
|
2013-12-09 04:07:18 +00:00
|
|
|
|
2014-01-23 18:26:40 +00:00
|
|
|
if (aSurface->GetType() != gfxSurfaceType::Xlib || !mUseTextureFromPixmap) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-04-07 23:58:07 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2011-07-14 20:45:33 +00:00
|
|
|
}
|
|
|
|
|
2013-12-09 04:07:18 +00:00
|
|
|
GLXPixmap
|
2011-07-14 20:45:33 +00:00
|
|
|
GLXLibrary::CreatePixmap(gfxASurface* aSurface)
|
|
|
|
{
|
|
|
|
if (!SupportsTextureFromPixmap(aSurface)) {
|
2012-07-31 02:54:21 +00:00
|
|
|
return None;
|
2011-04-07 23:58:07 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 02:54:21 +00:00
|
|
|
gfxXlibSurface *xs = static_cast<gfxXlibSurface*>(aSurface);
|
|
|
|
const XRenderPictFormat *format = xs->XRenderFormat();
|
|
|
|
if (!format || format->type != PictTypeDirect) {
|
|
|
|
return None;
|
|
|
|
}
|
2012-08-20 04:21:37 +00:00
|
|
|
const XRenderDirectFormat& direct = format->direct;
|
2013-11-13 00:22:38 +00:00
|
|
|
int alphaSize = FloorLog2(direct.alphaMask + 1);
|
2012-08-20 04:21:37 +00:00
|
|
|
NS_ASSERTION((1 << alphaSize) - 1 == direct.alphaMask,
|
|
|
|
"Unexpected render format with non-adjacent alpha bits");
|
2012-07-31 02:54:21 +00:00
|
|
|
|
2013-11-18 13:08:24 +00: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 23:58:07 +00:00
|
|
|
None };
|
|
|
|
|
2012-07-31 02:54:21 +00:00
|
|
|
int numConfigs = 0;
|
|
|
|
Display *display = xs->XDisplay();
|
2011-04-07 23:58:07 +00:00
|
|
|
int xscreen = DefaultScreen(display);
|
|
|
|
|
2012-07-31 02:54:21 +00:00
|
|
|
ScopedXFree<GLXFBConfig> cfgs(xChooseFBConfig(display,
|
|
|
|
xscreen,
|
|
|
|
attribs,
|
|
|
|
&numConfigs));
|
|
|
|
|
2013-12-09 04:07:18 +00:00
|
|
|
// Find an fbconfig that matches the pixel format used on the Pixmap.
|
2012-07-31 02:54:21 +00: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-20 04:21:07 +00:00
|
|
|
// This is true if the Pixmap has bits for alpha or unused bits.
|
|
|
|
bool haveNonColorBits =
|
|
|
|
~(redMask | greenMask | blueMask) != -1UL << format->depth;
|
2012-07-31 02:54:21 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < numConfigs; i++) {
|
2012-08-20 04:21:07 +00:00
|
|
|
int id = None;
|
2014-01-10 18:55:23 +00:00
|
|
|
sGLXLibrary.xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &id);
|
2012-08-20 04:21:07 +00: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-31 02:54:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-04-07 23:58:07 +00:00
|
|
|
|
2012-08-20 04:21:07 +00: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 12:30:26 +00: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-31 02:54:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-20 04:21:07 +00: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 13:08:24 +00:00
|
|
|
// LOCAL_GLX_BUFFER_SIZE, so we should still get zero alpha bits if
|
2012-08-20 04:21:07 +00: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;
|
2014-01-10 18:55:23 +00:00
|
|
|
sGLXLibrary.xGetFBConfigAttrib(display, cfgs[i],
|
|
|
|
LOCAL_GLX_ALPHA_SIZE, &size);
|
2012-08-20 04:21:07 +00:00
|
|
|
if (size != alphaSize) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 02:54:21 +00:00
|
|
|
matchIndex = i;
|
2012-08-20 04:21:07 +00:00
|
|
|
break;
|
2012-07-31 02:54:21 +00: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 09:20:52 +00: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-31 02:54:21 +00:00
|
|
|
return None;
|
|
|
|
}
|
2011-04-07 23:58:07 +00:00
|
|
|
|
2013-11-18 13:08:24 +00: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 23:58:07 +00:00
|
|
|
None};
|
|
|
|
|
|
|
|
GLXPixmap glxpixmap = xCreatePixmap(display,
|
2012-07-31 02:54:21 +00:00
|
|
|
cfgs[matchIndex],
|
2011-04-07 23:58:07 +00:00
|
|
|
xs->XDrawable(),
|
|
|
|
pixmapAttribs);
|
|
|
|
|
|
|
|
return glxpixmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::DestroyPixmap(GLXPixmap aPixmap)
|
|
|
|
{
|
2012-04-18 14:27:32 +00:00
|
|
|
if (!mUseTextureFromPixmap) {
|
2011-04-07 23:58:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Display *display = DefaultXDisplay();
|
|
|
|
xDestroyPixmap(display, aPixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::BindTexImage(GLXPixmap aPixmap)
|
2013-12-09 04:07:18 +00:00
|
|
|
{
|
2012-04-18 14:27:32 +00:00
|
|
|
if (!mUseTextureFromPixmap) {
|
2011-04-07 23:58:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Display *display = DefaultXDisplay();
|
|
|
|
// Make sure all X drawing to the surface has finished before binding to a texture.
|
2012-09-07 00:16:30 +00:00
|
|
|
if (mClientIsMesa) {
|
2012-07-31 02:54:21 +00: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 13:08:24 +00:00
|
|
|
xBindTexImage(display, aPixmap, LOCAL_GLX_FRONT_LEFT_EXT, nullptr);
|
2011-04-07 23:58:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLXLibrary::ReleaseTexImage(GLXPixmap aPixmap)
|
|
|
|
{
|
2012-04-18 14:27:32 +00:00
|
|
|
if (!mUseTextureFromPixmap) {
|
2011-04-07 23:58:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Display *display = DefaultXDisplay();
|
2013-11-18 13:08:24 +00:00
|
|
|
xReleaseTexImage(display, aPixmap, LOCAL_GLX_FRONT_LEFT_EXT);
|
2011-04-07 23:58:07 +00:00
|
|
|
}
|
|
|
|
|
2011-08-24 01:55:43 +00: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-31 02:54:21 +00:00
|
|
|
FinishX(DefaultXDisplay());
|
2011-08-24 01:55:43 +00: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
#define BEFORE_GLX_CALL do { \
|
|
|
|
sGLXLibrary.BeforeGLXCall(); \
|
2011-08-24 01:55:43 +00:00
|
|
|
} while (0)
|
2013-12-09 04:07:18 +00:00
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
#define AFTER_GLX_CALL do { \
|
|
|
|
sGLXLibrary.AfterGLXCall(); \
|
2011-08-24 01:55:43 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define BEFORE_GLX_CALL do { } while(0)
|
|
|
|
#define AFTER_GLX_CALL do { } while(0)
|
|
|
|
|
|
|
|
#endif
|
2013-12-09 04:07:18 +00:00
|
|
|
|
|
|
|
void
|
2011-08-24 01:55:43 +00:00
|
|
|
GLXLibrary::xDestroyContext(Display* display, GLXContext context)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
xDestroyContextInternal(display, context);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
}
|
|
|
|
|
2013-12-09 04:07:18 +00:00
|
|
|
Bool
|
|
|
|
GLXLibrary::xMakeCurrent(Display* display,
|
|
|
|
GLXDrawable drawable,
|
2011-08-24 01:55:43 +00:00
|
|
|
GLXContext context)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
Bool result = xMakeCurrentInternal(display, drawable, context);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-12-09 04:07:18 +00:00
|
|
|
GLXContext
|
2011-08-24 01:55:43 +00:00
|
|
|
GLXLibrary::xGetCurrentContext()
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXContext result = xGetCurrentContextInternal();
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-12-09 04:07:18 +00:00
|
|
|
/* static */ void*
|
2011-08-24 01:55:43 +00:00
|
|
|
GLXLibrary::xGetProcAddress(const char *procName)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
2014-01-10 18:55:23 +00:00
|
|
|
void* result = sGLXLibrary.xGetProcAddressInternal(procName);
|
2011-08-24 01:55:43 +00:00
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLXFBConfig*
|
2013-12-09 04:07:18 +00:00
|
|
|
GLXLibrary::xChooseFBConfig(Display* display,
|
|
|
|
int screen,
|
|
|
|
const int *attrib_list,
|
2011-08-24 01:55:43 +00:00
|
|
|
int *nelements)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXFBConfig* result = xChooseFBConfigInternal(display, screen, attrib_list, nelements);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-12-09 04:07:18 +00:00
|
|
|
GLXFBConfig*
|
|
|
|
GLXLibrary::xGetFBConfigs(Display* display,
|
|
|
|
int screen,
|
2011-08-24 01:55:43 +00:00
|
|
|
int *nelements)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
GLXFBConfig* result = xGetFBConfigsInternal(display, screen, nelements);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
2013-12-09 04:07:18 +00:00
|
|
|
|
2011-08-24 01:55:43 +00:00
|
|
|
GLXContext
|
2013-12-09 04:07:18 +00:00
|
|
|
GLXLibrary::xCreateNewContext(Display* display,
|
|
|
|
GLXFBConfig config,
|
|
|
|
int render_type,
|
|
|
|
GLXContext share_list,
|
2011-08-24 01:55:43 +00:00
|
|
|
Bool direct)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
2013-12-09 04:07:18 +00: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 09:20:52 +00:00
|
|
|
render_type,
|
|
|
|
share_list, direct);
|
2011-08-24 01:55:43 +00: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-09 04:07:18 +00:00
|
|
|
GLXLibrary::xCreatePixmap(Display *display,
|
2011-08-24 01:55:43 +00: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-09 04:07:18 +00:00
|
|
|
void
|
2011-08-24 01:55:43 +00:00
|
|
|
GLXLibrary::xWaitGL()
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
xWaitGLInternal();
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
}
|
|
|
|
|
2011-08-24 01:56:30 +00:00
|
|
|
void
|
|
|
|
GLXLibrary::xWaitX()
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
|
|
|
xWaitXInternal();
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
}
|
|
|
|
|
2011-10-26 20:00:44 +00:00
|
|
|
GLXContext
|
2013-12-09 04:07:18 +00:00
|
|
|
GLXLibrary::xCreateContextAttribs(Display* display,
|
|
|
|
GLXFBConfig config,
|
|
|
|
GLXContext share_list,
|
2011-10-26 20:00:44 +00:00
|
|
|
Bool direct,
|
|
|
|
const int* attrib_list)
|
|
|
|
{
|
|
|
|
BEFORE_GLX_CALL;
|
2013-12-09 04:07:18 +00:00
|
|
|
GLXContext result = xCreateContextAttribsInternal(display,
|
|
|
|
config,
|
|
|
|
share_list,
|
2011-10-26 20:00:44 +00:00
|
|
|
direct,
|
|
|
|
attrib_list);
|
|
|
|
AFTER_GLX_CALL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
already_AddRefed<GLContextGLX>
|
|
|
|
GLContextGLX::CreateGLContext(
|
|
|
|
const SurfaceCaps& caps,
|
|
|
|
GLContextGLX* shareContext,
|
|
|
|
bool isOffscreen,
|
|
|
|
Display* display,
|
|
|
|
GLXDrawable drawable,
|
|
|
|
GLXFBConfig cfg,
|
|
|
|
bool deleteDrawable,
|
|
|
|
gfxXlibSurface* pixmap)
|
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
GLXLibrary& glx = sGLXLibrary;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
|
|
|
int db = 0;
|
|
|
|
int err = glx.xGetFBConfigAttrib(display, cfg,
|
|
|
|
LOCAL_GLX_DOUBLEBUFFER, &db);
|
|
|
|
if (LOCAL_GLX_BAD_ATTRIBUTE != err) {
|
2010-06-18 23:17:00 +00:00
|
|
|
#ifdef DEBUG
|
2014-01-07 20:02:18 +00:00
|
|
|
if (DebugMode()) {
|
|
|
|
printf("[GLX] FBConfig is %sdouble-buffered\n", db ? "" : "not ");
|
2010-06-18 23:17:00 +00:00
|
|
|
}
|
2014-01-07 20:02:18 +00:00
|
|
|
#endif
|
|
|
|
}
|
2010-06-18 23:17:00 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
GLXContext context;
|
|
|
|
nsRefPtr<GLContextGLX> glContext;
|
|
|
|
bool error;
|
2010-12-06 11:34:34 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
ScopedXErrorHandler xErrorHandler;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
TRY_AGAIN_NO_SHARING:
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
error = false;
|
|
|
|
|
|
|
|
GLXContext glxContext = shareContext ? shareContext->mContext : nullptr;
|
|
|
|
if (glx.HasRobustness()) {
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
context = glx.xCreateContextAttribs(
|
|
|
|
display,
|
|
|
|
cfg,
|
|
|
|
glxContext,
|
|
|
|
True,
|
|
|
|
attrib_list);
|
|
|
|
} else {
|
|
|
|
context = glx.xCreateNewContext(
|
|
|
|
display,
|
|
|
|
cfg,
|
|
|
|
LOCAL_GLX_RGBA_TYPE,
|
|
|
|
glxContext,
|
|
|
|
True);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context) {
|
|
|
|
glContext = new GLContextGLX(caps,
|
|
|
|
shareContext,
|
|
|
|
isOffscreen,
|
|
|
|
display,
|
|
|
|
drawable,
|
|
|
|
context,
|
|
|
|
deleteDrawable,
|
|
|
|
db,
|
2014-01-10 18:55:23 +00:00
|
|
|
pixmap);
|
2014-01-07 20:02:18 +00:00
|
|
|
if (!glContext->Init())
|
2010-12-06 11:34:34 +00:00
|
|
|
error = true;
|
2014-01-07 20:02:18 +00:00
|
|
|
} else {
|
|
|
|
error = true;
|
|
|
|
}
|
2011-02-11 23:11:30 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
error |= xErrorHandler.SyncAndGetError(display);
|
2010-06-15 06:55:08 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
if (error) {
|
|
|
|
if (shareContext) {
|
|
|
|
shareContext = nullptr;
|
|
|
|
goto TRY_AGAIN_NO_SHARING;
|
2010-06-15 06:55:08 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
NS_WARNING("Failed to create GLXContext!");
|
|
|
|
glContext = nullptr; // note: this must be done while the graceful X error handler is set,
|
|
|
|
// because glxMakeCurrent can give a GLXBadDrawable error
|
2010-06-15 06:55:08 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
GLContextGLX::~GLContextGLX()
|
|
|
|
{
|
|
|
|
MarkDestroyed();
|
2010-08-07 05:09:18 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
// see bug 659842 comment 76
|
2011-06-18 01:42:31 +00:00
|
|
|
#ifdef DEBUG
|
2014-01-07 20:02:18 +00:00
|
|
|
bool success =
|
2011-06-18 01:42:31 +00:00
|
|
|
#endif
|
2014-01-07 20:02:18 +00:00
|
|
|
mGLX->xMakeCurrent(mDisplay, None, nullptr);
|
|
|
|
NS_ABORT_IF_FALSE(success,
|
|
|
|
"glXMakeCurrent failed to release GL context before we call glXDestroyContext!");
|
2011-06-17 15:49:27 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
mGLX->xDestroyContext(mDisplay, mContext);
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
if (mDeleteDrawable) {
|
|
|
|
mGLX->xDestroyPixmap(mDisplay, mDrawable);
|
2010-06-15 06:55:08 +00:00
|
|
|
}
|
2014-01-07 20:02:18 +00:00
|
|
|
}
|
2010-06-15 06:55:08 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextGLX::Init()
|
|
|
|
{
|
|
|
|
SetupLookupFunction();
|
|
|
|
if (!InitWithPrefix("gl", true)) {
|
|
|
|
return false;
|
2010-06-15 06:55:08 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
if (!IsExtensionSupported(EXT_framebuffer_object))
|
|
|
|
return false;
|
2010-09-20 17:19:30 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-06-15 06:55:08 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextGLX::MakeCurrentImpl(bool aForce)
|
|
|
|
{
|
|
|
|
bool succeeded = true;
|
2012-08-22 03:30:20 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
// 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.
|
|
|
|
if (aForce || mGLX->xGetCurrentContext() != mContext) {
|
|
|
|
succeeded = mGLX->xMakeCurrent(mDisplay, mDrawable, mContext);
|
|
|
|
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
2010-06-15 06:55:08 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
return succeeded;
|
|
|
|
}
|
2013-12-09 04:07:18 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextGLX::IsCurrent() {
|
|
|
|
return mGLX->xGetCurrentContext() == mContext;
|
|
|
|
}
|
2010-06-15 06:55:08 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextGLX::SetupLookupFunction()
|
|
|
|
{
|
|
|
|
mLookupFunc = (PlatformLookupFunction)&GLXLibrary::xGetProcAddress;
|
|
|
|
return true;
|
|
|
|
}
|
2010-06-15 06:55:08 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextGLX::IsDoubleBuffered()
|
|
|
|
{
|
|
|
|
return mDoubleBuffered;
|
|
|
|
}
|
2010-06-15 06:55:08 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextGLX::SupportsRobustness()
|
|
|
|
{
|
|
|
|
return mGLX->HasRobustness();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GLContextGLX::SwapBuffers()
|
|
|
|
{
|
|
|
|
if (!mDoubleBuffered)
|
|
|
|
return false;
|
|
|
|
mGLX->xSwapBuffers(mDisplay, mDrawable);
|
|
|
|
mGLX->xWaitGL();
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-13 23:26:24 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
GLContextGLX::GLContextGLX(
|
|
|
|
const SurfaceCaps& caps,
|
|
|
|
GLContext* shareContext,
|
|
|
|
bool isOffscreen,
|
|
|
|
Display *aDisplay,
|
|
|
|
GLXDrawable aDrawable,
|
|
|
|
GLXContext aContext,
|
|
|
|
bool aDeleteDrawable,
|
|
|
|
bool aDoubleBuffered,
|
2014-01-10 18:55:23 +00:00
|
|
|
gfxXlibSurface *aPixmap)
|
2014-01-07 20:02:18 +00:00
|
|
|
: GLContext(caps, shareContext, isOffscreen),//aDeleteDrawable ? true : false, aShareContext, ),
|
|
|
|
mContext(aContext),
|
|
|
|
mDisplay(aDisplay),
|
|
|
|
mDrawable(aDrawable),
|
|
|
|
mDeleteDrawable(aDeleteDrawable),
|
|
|
|
mDoubleBuffered(aDoubleBuffered),
|
2014-01-10 18:55:23 +00:00
|
|
|
mGLX(&sGLXLibrary),
|
2014-01-07 20:02:18 +00:00
|
|
|
mPixmap(aPixmap)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mGLX);
|
|
|
|
// See 899855
|
|
|
|
SetProfileVersion(ContextProfile::OpenGLCompatibility, 200);
|
|
|
|
}
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2010-06-15 06:55:08 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
static GLContextGLX *
|
2014-01-10 18:55:23 +00:00
|
|
|
GetGlobalContextGLX()
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
return static_cast<GLContextGLX*>(GLContextProviderGLX::GetGlobalContext());
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2012-08-20 04:21:59 +00:00
|
|
|
AreCompatibleVisuals(Visual *one, Visual *two)
|
2010-06-18 23:17:00 +00:00
|
|
|
{
|
|
|
|
if (one->c_class != two->c_class) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-06-18 23:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (one->red_mask != two->red_mask ||
|
|
|
|
one->green_mask != two->green_mask ||
|
|
|
|
one->blue_mask != two->blue_mask) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-06-18 23:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (one->bits_per_rgb != two->bits_per_rgb) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-06-18 23:17:00 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-06-18 23:17:00 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 06:55:08 +00:00
|
|
|
already_AddRefed<GLContext>
|
2010-07-19 05:01:14 +00:00
|
|
|
GLContextProviderGLX::CreateForWindow(nsIWidget *aWidget)
|
2010-06-15 06:55:08 +00:00
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
if (!sGLXLibrary.EnsureInitialized()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-06-18 23:17:00 +00: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-09 04:07:18 +00:00
|
|
|
Display *display = (Display*)aWidget->GetNativeData(NS_NATIVE_DISPLAY);
|
2010-06-18 23:17:00 +00:00
|
|
|
int xscreen = DefaultScreen(display);
|
|
|
|
Window window = GET_NATIVE_WINDOW(aWidget);
|
|
|
|
|
|
|
|
int numConfigs;
|
2010-06-24 03:52:48 +00:00
|
|
|
ScopedXFree<GLXFBConfig> cfgs;
|
2014-01-10 18:55:23 +00:00
|
|
|
if (sGLXLibrary.IsATI() ||
|
|
|
|
!sGLXLibrary.GLXVersionCheck(1, 3)) {
|
2010-06-18 23:17:00 +00:00
|
|
|
const int attribs[] = {
|
2013-11-18 13:08:24 +00:00
|
|
|
LOCAL_GLX_DOUBLEBUFFER, False,
|
2010-06-18 23:17:00 +00:00
|
|
|
0
|
|
|
|
};
|
2014-01-10 18:55:23 +00:00
|
|
|
cfgs = sGLXLibrary.xChooseFBConfig(display,
|
|
|
|
xscreen,
|
|
|
|
attribs,
|
|
|
|
&numConfigs);
|
2010-06-18 23:17:00 +00:00
|
|
|
} else {
|
2014-01-10 18:55:23 +00:00
|
|
|
cfgs = sGLXLibrary.xGetFBConfigs(display,
|
|
|
|
xscreen,
|
|
|
|
&numConfigs);
|
2010-06-18 23:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cfgs) {
|
|
|
|
NS_WARNING("[GLX] glXGetFBConfigs() failed");
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-06-18 23:17:00 +00:00
|
|
|
}
|
|
|
|
NS_ASSERTION(numConfigs > 0, "No FBConfigs found!");
|
|
|
|
|
2013-11-18 13:08:24 +00:00
|
|
|
// XXX the visual ID is almost certainly the LOCAL_GLX_FBCONFIG_ID, so
|
2010-06-18 23:17:00 +00: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 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-06-18 23:17:00 +00:00
|
|
|
}
|
|
|
|
const VisualID widgetVisualID = XVisualIDFromVisual(widgetAttrs.visual);
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("[GLX] widget has VisualID 0x%lx\n", widgetVisualID);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int matchIndex = -1;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2010-06-18 23:17:00 +00:00
|
|
|
for (int i = 0; i < numConfigs; i++) {
|
2012-08-20 04:21:59 +00:00
|
|
|
int visid = None;
|
2014-01-10 18:55:23 +00:00
|
|
|
sGLXLibrary.xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &visid);
|
2012-08-20 04:21:59 +00:00
|
|
|
if (!visid) {
|
2010-06-23 00:24:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-01-10 18:55:23 +00:00
|
|
|
if (sGLXLibrary.IsATI()) {
|
2012-08-20 04:21:59 +00:00
|
|
|
int depth;
|
|
|
|
Visual *visual;
|
|
|
|
FindVisualAndDepth(display, visid, &visual, &depth);
|
|
|
|
if (depth == widgetAttrs.depth &&
|
|
|
|
AreCompatibleVisuals(widgetAttrs.visual, visual)) {
|
2010-06-18 23:17:00 +00:00
|
|
|
matchIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-20 04:21:59 +00:00
|
|
|
if (widgetVisualID == static_cast<VisualID>(visid)) {
|
2010-06-18 23:17:00 +00:00
|
|
|
matchIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matchIndex == -1) {
|
|
|
|
NS_WARNING("[GLX] Couldn't find a FBConfig matching widget visual");
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-06-18 23:17:00 +00:00
|
|
|
}
|
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
GLContextGLX *shareContext = GetGlobalContextGLX();
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
SurfaceCaps caps = SurfaceCaps::Any();
|
|
|
|
nsRefPtr<GLContextGLX> glContext = GLContextGLX::CreateGLContext(caps,
|
|
|
|
shareContext,
|
|
|
|
false,
|
2010-07-19 05:01:14 +00:00
|
|
|
display,
|
2010-06-18 23:17:00 +00:00
|
|
|
window,
|
|
|
|
cfgs[matchIndex],
|
2014-01-10 18:55:23 +00:00
|
|
|
false);
|
2012-03-12 22:10:38 +00:00
|
|
|
|
2010-06-24 03:52:48 +00:00
|
|
|
return glContext.forget();
|
2010-06-15 06:55:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
static already_AddRefed<GLContextGLX>
|
2014-01-10 18:55:23 +00:00
|
|
|
CreateOffscreenPixmapContext(const gfxIntSize& size)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
GLXLibrary& glx = sGLXLibrary;
|
|
|
|
if (!glx.EnsureInitialized()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Display *display = DefaultXDisplay();
|
|
|
|
int xscreen = DefaultScreen(display);
|
|
|
|
|
|
|
|
int attribs[] = {
|
2013-11-18 13:08:24 +00:00
|
|
|
LOCAL_GLX_DRAWABLE_TYPE, LOCAL_GLX_PIXMAP_BIT,
|
|
|
|
LOCAL_GLX_X_RENDERABLE, True,
|
2010-07-19 05:01:14 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
int numConfigs = 0;
|
|
|
|
|
|
|
|
ScopedXFree<GLXFBConfig> cfgs;
|
2013-02-13 23:26:24 +00:00
|
|
|
cfgs = glx.xChooseFBConfig(display,
|
|
|
|
xscreen,
|
|
|
|
attribs,
|
|
|
|
&numConfigs);
|
2010-07-19 05:01:14 +00:00
|
|
|
if (!cfgs) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
MOZ_ASSERT(numConfigs > 0,
|
|
|
|
"glXChooseFBConfig() failed to match our requested format and violated its spec!");
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2012-08-20 04:21:59 +00:00
|
|
|
int visid = None;
|
2010-12-05 18:38:12 +00:00
|
|
|
int chosenIndex = 0;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < numConfigs; ++i) {
|
2012-08-20 04:21:59 +00:00
|
|
|
int dtype;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2013-11-18 13:08:24 +00:00
|
|
|
if (glx.xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_DRAWABLE_TYPE, &dtype) != Success
|
|
|
|
|| !(dtype & LOCAL_GLX_PIXMAP_BIT))
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-18 13:08:24 +00:00
|
|
|
if (glx.xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &visid) != Success
|
2010-07-19 05:01:14 +00:00
|
|
|
|| visid == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-20 04:21:59 +00:00
|
|
|
chosenIndex = i;
|
|
|
|
break;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 04:21:59 +00:00
|
|
|
if (!visid) {
|
2010-07-19 05:01:14 +00:00
|
|
|
NS_WARNING("glXChooseFBConfig() didn't give us any configs with visuals!");
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 04:21:59 +00:00
|
|
|
Visual *visual;
|
|
|
|
int depth;
|
|
|
|
FindVisualAndDepth(display, visid, &visual, &depth);
|
2010-12-06 11:34:34 +00:00
|
|
|
ScopedXErrorHandler xErrorHandler;
|
2011-01-07 10:54:19 +00:00
|
|
|
GLXPixmap glxpixmap = 0;
|
2010-12-06 11:34:34 +00:00
|
|
|
bool error = false;
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
gfxIntSize dummySize(16, 16);
|
2010-07-19 05:01:14 +00:00
|
|
|
nsRefPtr<gfxXlibSurface> xsurface = gfxXlibSurface::Create(DefaultScreenOfDisplay(display),
|
2012-08-20 04:21:59 +00:00
|
|
|
visual,
|
2013-02-13 23:26:24 +00:00
|
|
|
dummySize);
|
2010-07-19 05:01:14 +00:00
|
|
|
if (xsurface->CairoStatus() != 0) {
|
2010-12-06 11:34:34 +00:00
|
|
|
error = true;
|
|
|
|
goto DONE_CREATING_PIXMAP;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:49:52 +00: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 23:26:24 +00:00
|
|
|
if (glx.GLXVersionCheck(1, 3)) {
|
|
|
|
glxpixmap = glx.xCreatePixmap(display,
|
2012-09-07 00:16:30 +00:00
|
|
|
cfgs[chosenIndex],
|
|
|
|
xsurface->XDrawable(),
|
2013-07-20 08:48:55 +00:00
|
|
|
nullptr);
|
2010-11-10 15:49:52 +00:00
|
|
|
} else {
|
2013-02-13 23:26:24 +00:00
|
|
|
glxpixmap = glx.xCreateGLXPixmapWithConfig(display,
|
2012-09-07 00:16:30 +00:00
|
|
|
cfgs[chosenIndex],
|
|
|
|
xsurface->
|
|
|
|
XDrawable());
|
2010-11-10 15:49:52 +00:00
|
|
|
}
|
2010-07-19 05:01:14 +00:00
|
|
|
if (glxpixmap == 0) {
|
2010-12-06 11:34:34 +00:00
|
|
|
error = true;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 11:34:34 +00:00
|
|
|
DONE_CREATING_PIXMAP:
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2010-12-06 11:34:34 +00:00
|
|
|
nsRefPtr<GLContextGLX> glContext;
|
|
|
|
bool serverError = xErrorHandler.SyncAndGetError(display);
|
|
|
|
|
|
|
|
if (!error && // earlier recorded error
|
|
|
|
!serverError)
|
|
|
|
{
|
2013-02-13 23:26:24 +00:00
|
|
|
// We might have an alpha channel, but it doesn't matter.
|
|
|
|
SurfaceCaps dummyCaps = SurfaceCaps::Any();
|
2014-01-10 18:55:23 +00:00
|
|
|
GLContextGLX* shareContext = GetGlobalContextGLX();
|
2013-02-13 23:26:24 +00:00
|
|
|
|
|
|
|
glContext = GLContextGLX::CreateGLContext(dummyCaps,
|
|
|
|
shareContext,
|
|
|
|
true,
|
|
|
|
display,
|
|
|
|
glxpixmap,
|
|
|
|
cfgs[chosenIndex],
|
2013-06-17 02:03:12 +00:00
|
|
|
true,
|
2013-02-13 23:26:24 +00:00
|
|
|
xsurface);
|
2010-12-06 11:34:34 +00:00
|
|
|
}
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
2010-06-15 06:55:08 +00:00
|
|
|
already_AddRefed<GLContext>
|
2013-02-13 23:26:24 +00:00
|
|
|
GLContextProviderGLX::CreateOffscreen(const gfxIntSize& size,
|
2014-01-10 18:55:23 +00:00
|
|
|
const SurfaceCaps& caps)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2013-02-13 23:26:24 +00:00
|
|
|
gfxIntSize dummySize = gfxIntSize(16, 16);
|
|
|
|
nsRefPtr<GLContextGLX> glContext =
|
2014-01-10 18:55:23 +00:00
|
|
|
CreateOffscreenPixmapContext(dummySize);
|
2013-02-20 15:01:20 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
if (!glContext)
|
2013-02-20 15:01:20 +00:00
|
|
|
return nullptr;
|
2013-02-21 19:54:25 +00:00
|
|
|
|
2014-01-01 19:47:19 +00:00
|
|
|
if (!glContext->InitOffscreen(ToIntSize(size), caps))
|
2013-02-21 19:54:25 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
static nsRefPtr<GLContext> gGlobalContext;
|
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 09:20:52 +00:00
|
|
|
// TODO move that out of static initializaion
|
|
|
|
static bool gUseContextSharing = getenv("MOZ_DISABLE_CONTEXT_SHARING_GLX") == 0;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
GLContext*
|
2014-01-10 18:55:23 +00:00
|
|
|
GLContextProviderGLX::GetGlobalContext()
|
2010-06-23 09:24:31 +00: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 09:20:52 +00:00
|
|
|
// TODO: get GLX context sharing to work well with multiple threads
|
|
|
|
if (!gUseContextSharing) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
static bool triedToCreateContext = false;
|
|
|
|
if (!triedToCreateContext && !gGlobalContext) {
|
|
|
|
triedToCreateContext = true;
|
2013-02-13 23:26:24 +00:00
|
|
|
|
|
|
|
gfxIntSize dummySize = gfxIntSize(16, 16);
|
2014-01-10 18:55:23 +00:00
|
|
|
gGlobalContext = CreateOffscreenPixmapContext(dummySize);
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
return gGlobalContext;
|
2010-06-23 09:24:31 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 04:05:42 +00:00
|
|
|
void
|
|
|
|
GLContextProviderGLX::Shutdown()
|
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
gGlobalContext = nullptr;
|
2010-07-20 04:05:42 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 06:55:08 +00:00
|
|
|
} /* namespace gl */
|
|
|
|
} /* namespace mozilla */
|
2011-08-24 01:55:43 +00:00
|
|
|
|