From bba51d87cae93b9d30a07146aef3b0e16b2d377a Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Fri, 10 Jan 2014 13:55:23 -0500 Subject: [PATCH] Bug 958368 - Remove the code paths to load a custom Mesa/llvmpipe build instead of system OpenGL (sadface) - r=jgilbert --- content/canvas/src/WebGLContext.cpp | 11 +-- gfx/gl/GLContextGLX.h | 6 +- gfx/gl/GLContextProviderGLX.cpp | 126 +++++++++--------------- gfx/gl/GLContextProviderWGL.cpp | 142 +++++++++++----------------- gfx/gl/GLContextTypes.h | 3 +- gfx/gl/GLContextWGL.h | 7 +- gfx/gl/GLXLibrary.h | 16 +--- gfx/gl/WGLLibrary.h | 18 +--- gfx/thebes/gfxXlibSurface.cpp | 6 +- 9 files changed, 116 insertions(+), 219 deletions(-) diff --git a/content/canvas/src/WebGLContext.cpp b/content/canvas/src/WebGLContext.cpp index e23251b5e2c9..6041bdff10c5 100644 --- a/content/canvas/src/WebGLContext.cpp +++ b/content/canvas/src/WebGLContext.cpp @@ -439,8 +439,6 @@ WebGLContext::SetDimensions(int32_t width, int32_t height) #endif bool forceEnabled = Preferences::GetBool("webgl.force-enabled", false); - bool useMesaLlvmPipe = - Preferences::GetBool("gfx.prefer-mesa-llvmpipe", false); bool disabled = Preferences::GetBool("webgl.disabled", false); bool prefer16bit = @@ -533,7 +531,7 @@ WebGLContext::SetDimensions(int32_t width, int32_t height) #ifdef XP_WIN // allow forcing GL and not EGL/ANGLE - if (useMesaLlvmPipe || PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL")) { + if (PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL")) { preferEGL = false; useANGLE = false; useOpenGL = true; @@ -555,13 +553,10 @@ WebGLContext::SetDimensions(int32_t width, int32_t height) // try the default provider, whatever that is if (!gl && useOpenGL) { - gl::ContextFlags flag = useMesaLlvmPipe - ? gl::ContextFlagsMesaLLVMPipe - : gl::ContextFlagsNone; + gl::ContextFlags flag = gl::ContextFlagsNone; gl = gl::GLContextProvider::CreateOffscreen(size, caps, flag); if (gl && !InitAndValidateGL()) { - GenerateWarning("Error during %s initialization", - useMesaLlvmPipe ? "Mesa LLVMpipe" : "OpenGL"); + GenerateWarning("Error during OpenGL initialization"); return NS_ERROR_FAILURE; } } diff --git a/gfx/gl/GLContextGLX.h b/gfx/gl/GLContextGLX.h index 372a2bcdcde3..a67b3aeac2a7 100644 --- a/gfx/gl/GLContextGLX.h +++ b/gfx/gl/GLContextGLX.h @@ -13,8 +13,6 @@ namespace mozilla { namespace gl { -typedef GLXLibrary::LibraryType LibType; - class GLContextGLX : public GLContext { public: @@ -26,7 +24,6 @@ public: GLXDrawable drawable, GLXFBConfig cfg, bool deleteDrawable, - LibType libType = GLXLibrary::OPENGL_LIB, gfxXlibSurface* pixmap = nullptr); ~GLContextGLX(); @@ -63,8 +60,7 @@ private: GLXContext aContext, bool aDeleteDrawable, bool aDoubleBuffered, - gfxXlibSurface *aPixmap, - LibType libType); + gfxXlibSurface *aPixmap); GLXContext mContext; Display *mDisplay; diff --git a/gfx/gl/GLContextProviderGLX.cpp b/gfx/gl/GLContextProviderGLX.cpp index 0168d99b2937..1f9fa4c3f47e 100644 --- a/gfx/gl/GLContextProviderGLX.cpp +++ b/gfx/gl/GLContextProviderGLX.cpp @@ -43,18 +43,7 @@ using namespace mozilla::gfx; namespace mozilla { namespace gl { -GLXLibrary sGLXLibrary[GLXLibrary::LIBS_MAX]; -GLXLibrary& sDefGLXLib = sGLXLibrary[GLXLibrary::OPENGL_LIB]; - -static LibType gCurrLib = GLXLibrary::OPENGL_LIB; - -LibType -GLXLibrary::SelectLibrary(const ContextFlags& aFlags) -{ - return (aFlags & ContextFlagsMesaLLVMPipe) - ? GLXLibrary::MESA_LLVMPIPE_LIB - : GLXLibrary::OPENGL_LIB; -} +GLXLibrary sGLXLibrary; // Check that we have at least version aMajor.aMinor . bool @@ -72,7 +61,7 @@ HasExtension(const char* aExtensions, const char* aRequiredExtension) } bool -GLXLibrary::EnsureInitialized(LibType libType) +GLXLibrary::EnsureInitialized() { if (mInitialized) { return true; @@ -90,24 +79,15 @@ GLXLibrary::EnsureInitialized(LibType libType) if (!mOGLLibrary) { 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 + + // 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 #ifdef __OpenBSD__ - libGLfilename = "libGL.so"; + libGLfilename = "libGL.so"; #else - libGLfilename = "libGL.so.1"; + libGLfilename = "libGL.so.1"; #endif - break; - default: - MOZ_CRASH("Invalid GLX library type."); - } ScopedGfxFeatureReporter reporter(libGLfilename, forceFeatureReport); mOGLLibrary = PR_LoadLibrary(libGLfilename); @@ -266,7 +246,6 @@ GLXLibrary::EnsureInitialized(LibType libType) mClientIsMesa = clientVendor && DoesStringMatch(clientVendor, "Mesa"); mInitialized = true; - mLibType = libType; return true; } @@ -274,7 +253,7 @@ GLXLibrary::EnsureInitialized(LibType libType) bool GLXLibrary::SupportsTextureFromPixmap(gfxASurface* aSurface) { - if (!EnsureInitialized(mLibType)) { + if (!EnsureInitialized()) { return false; } @@ -333,7 +312,7 @@ GLXLibrary::CreatePixmap(gfxASurface* aSurface) for (int i = 0; i < numConfigs; i++) { int id = None; - sGLXLibrary[mLibType].xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &id); + sGLXLibrary.xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &id); Visual *visual; int depth; FindVisualAndDepth(display, id, &visual, &depth); @@ -390,8 +369,8 @@ GLXLibrary::CreatePixmap(gfxASurface* aSurface) // alpha or be unused, so just check that the number of alpha bits // matches. int size = 0; - sGLXLibrary[mLibType].xGetFBConfigAttrib(display, cfgs[i], - LOCAL_GLX_ALPHA_SIZE, &size); + sGLXLibrary.xGetFBConfigAttrib(display, cfgs[i], + LOCAL_GLX_ALPHA_SIZE, &size); if (size != alphaSize) { continue; } @@ -504,12 +483,12 @@ GLXLibrary::AfterGLXCall() } } -#define BEFORE_GLX_CALL do { \ - sGLXLibrary[gCurrLib].BeforeGLXCall(); \ +#define BEFORE_GLX_CALL do { \ + sGLXLibrary.BeforeGLXCall(); \ } while (0) -#define AFTER_GLX_CALL do { \ - sGLXLibrary[gCurrLib].AfterGLXCall(); \ +#define AFTER_GLX_CALL do { \ + sGLXLibrary.AfterGLXCall(); \ } while (0) #else @@ -551,7 +530,7 @@ GLXLibrary::xGetCurrentContext() GLXLibrary::xGetProcAddress(const char *procName) { BEFORE_GLX_CALL; - void* result = sGLXLibrary[gCurrLib].xGetProcAddressInternal(procName); + void* result = sGLXLibrary.xGetProcAddressInternal(procName); AFTER_GLX_CALL; return result; } @@ -751,10 +730,9 @@ GLContextGLX::CreateGLContext( GLXDrawable drawable, GLXFBConfig cfg, bool deleteDrawable, - LibType libType, gfxXlibSurface* pixmap) { - GLXLibrary& glx = sGLXLibrary[libType]; + GLXLibrary& glx = sGLXLibrary; int db = 0; int err = glx.xGetFBConfigAttrib(display, cfg, @@ -809,8 +787,7 @@ TRY_AGAIN_NO_SHARING: context, deleteDrawable, db, - pixmap, - libType); + pixmap); if (!glContext->Init()) error = true; } else { @@ -928,15 +905,14 @@ GLContextGLX::GLContextGLX( GLXContext aContext, bool aDeleteDrawable, bool aDoubleBuffered, - gfxXlibSurface *aPixmap, - LibType libType) + gfxXlibSurface *aPixmap) : GLContext(caps, shareContext, isOffscreen),//aDeleteDrawable ? true : false, aShareContext, ), mContext(aContext), mDisplay(aDisplay), mDrawable(aDrawable), mDeleteDrawable(aDeleteDrawable), mDoubleBuffered(aDoubleBuffered), - mGLX(&sGLXLibrary[libType]), + mGLX(&sGLXLibrary), mPixmap(aPixmap) { MOZ_ASSERT(mGLX); @@ -974,8 +950,7 @@ AreCompatibleVisuals(Visual *one, Visual *two) already_AddRefed GLContextProviderGLX::CreateForWindow(nsIWidget *aWidget) { - const LibType libType = GLXLibrary::OPENGL_LIB; - if (!sDefGLXLib.EnsureInitialized(libType)) { + if (!sGLXLibrary.EnsureInitialized()) { return nullptr; } @@ -992,20 +967,20 @@ GLContextProviderGLX::CreateForWindow(nsIWidget *aWidget) int numConfigs; ScopedXFree cfgs; - if (sDefGLXLib.IsATI() || - !sDefGLXLib.GLXVersionCheck(1, 3)) { + if (sGLXLibrary.IsATI() || + !sGLXLibrary.GLXVersionCheck(1, 3)) { const int attribs[] = { LOCAL_GLX_DOUBLEBUFFER, False, 0 }; - cfgs = sDefGLXLib.xChooseFBConfig(display, - xscreen, - attribs, - &numConfigs); + cfgs = sGLXLibrary.xChooseFBConfig(display, + xscreen, + attribs, + &numConfigs); } else { - cfgs = sDefGLXLib.xGetFBConfigs(display, - xscreen, - &numConfigs); + cfgs = sGLXLibrary.xGetFBConfigs(display, + xscreen, + &numConfigs); } if (!cfgs) { @@ -1031,11 +1006,11 @@ GLContextProviderGLX::CreateForWindow(nsIWidget *aWidget) for (int i = 0; i < numConfigs; i++) { int visid = None; - sDefGLXLib.xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &visid); + sGLXLibrary.xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &visid); if (!visid) { continue; } - if (sDefGLXLib.IsATI()) { + if (sGLXLibrary.IsATI()) { int depth; Visual *visual; FindVisualAndDepth(display, visid, &visual, &depth); @@ -1066,17 +1041,16 @@ GLContextProviderGLX::CreateForWindow(nsIWidget *aWidget) display, window, cfgs[matchIndex], - false, - libType); + false); return glContext.forget(); } static already_AddRefed -CreateOffscreenPixmapContext(const gfxIntSize& size, LibType libToUse) +CreateOffscreenPixmapContext(const gfxIntSize& size) { - GLXLibrary& glx = sGLXLibrary[libToUse]; - if (!glx.EnsureInitialized(libToUse)) { + GLXLibrary& glx = sGLXLibrary; + if (!glx.EnsureInitialized()) { return nullptr; } @@ -1170,9 +1144,7 @@ DONE_CREATING_PIXMAP: if (!error && // earlier recorded error !serverError) { - ContextFlags flag = libToUse == GLXLibrary::MESA_LLVMPIPE_LIB - ? ContextFlagsMesaLLVMPipe - : ContextFlagsNone; + ContextFlags flag = ContextFlagsNone; // We might have an alpha channel, but it doesn't matter. SurfaceCaps dummyCaps = SurfaceCaps::Any(); GLContextGLX* shareContext = GetGlobalContextGLX(flag); @@ -1184,7 +1156,6 @@ DONE_CREATING_PIXMAP: glxpixmap, cfgs[chosenIndex], true, - libToUse, xsurface); } @@ -1196,12 +1167,9 @@ GLContextProviderGLX::CreateOffscreen(const gfxIntSize& size, const SurfaceCaps& caps, ContextFlags flags) { - LibType libType = GLXLibrary::SelectLibrary(flags); - gCurrLib = libType; - gfxIntSize dummySize = gfxIntSize(16, 16); nsRefPtr glContext = - CreateOffscreenPixmapContext(dummySize, libType); + CreateOffscreenPixmapContext(dummySize); if (!glContext) return nullptr; @@ -1212,7 +1180,7 @@ GLContextProviderGLX::CreateOffscreen(const gfxIntSize& size, return glContext.forget(); } -static nsRefPtr gGlobalContext[GLXLibrary::LIBS_MAX]; +static nsRefPtr gGlobalContext; // TODO move that out of static initializaion static bool gUseContextSharing = getenv("MOZ_DISABLE_CONTEXT_SHARING_GLX") == 0; @@ -1224,23 +1192,21 @@ GLContextProviderGLX::GetGlobalContext(const ContextFlags aFlag) return nullptr; } - LibType libType = GLXLibrary::SelectLibrary(aFlag); - static bool triedToCreateContext[GLXLibrary::LIBS_MAX] = {false, false}; - if (!triedToCreateContext[libType] && !gGlobalContext[libType]) { - triedToCreateContext[libType] = true; + static bool triedToCreateContext = false; + if (!triedToCreateContext && !gGlobalContext) { + triedToCreateContext = true; gfxIntSize dummySize = gfxIntSize(16, 16); - gGlobalContext[libType] = CreateOffscreenPixmapContext(dummySize, libType); + gGlobalContext = CreateOffscreenPixmapContext(dummySize); } - return gGlobalContext[libType]; + return gGlobalContext; } void GLContextProviderGLX::Shutdown() { - for (int i = 0; i < GLXLibrary::LIBS_MAX; ++i) - gGlobalContext[i] = nullptr; + gGlobalContext = nullptr; } } /* namespace gl */ diff --git a/gfx/gl/GLContextProviderWGL.cpp b/gfx/gl/GLContextProviderWGL.cpp index 99089150869d..9a03c3d439c3 100644 --- a/gfx/gl/GLContextProviderWGL.cpp +++ b/gfx/gl/GLContextProviderWGL.cpp @@ -24,15 +24,7 @@ using namespace mozilla::gfx; namespace mozilla { namespace gl { -WGLLibrary sWGLLib[WGLLibrary::LIBS_MAX]; - -LibType -WGLLibrary::SelectLibrary(const ContextFlags& aFlags) -{ - return (aFlags & ContextFlagsMesaLLVMPipe) - ? WGLLibrary::MESA_LLVMPIPE_LIB - : WGLLibrary::OPENGL_LIB; -} +WGLLibrary sWGLLib; HWND WGLLibrary::CreateDummyWindow(HDC *aWindowDC) @@ -101,18 +93,16 @@ HasExtension(const char* aExtensions, const char* aRequiredExtension) } bool -WGLLibrary::EnsureInitialized(bool aUseMesaLlvmPipe) +WGLLibrary::EnsureInitialized() { if (mInitialized) return true; - mozilla::ScopedGfxFeatureReporter reporter("WGL", aUseMesaLlvmPipe); + mozilla::ScopedGfxFeatureReporter reporter("WGL"); - std::string libGLFilename = aUseMesaLlvmPipe - ? "mesallvmpipe.dll" - : "Opengl32.dll"; + std::string libGLFilename = "Opengl32.dll"; // SU_SPIES_DIRECTORY is for AMD CodeXL/gDEBugger - if (PR_GetEnv("SU_SPIES_DIRECTORY") && !aUseMesaLlvmPipe) { + if (PR_GetEnv("SU_SPIES_DIRECTORY")) { libGLFilename = std::string(PR_GetEnv("SU_SPIES_DIRECTORY")) + "\\opengl32.dll"; } @@ -233,10 +223,6 @@ WGLLibrary::EnsureInitialized(bool aUseMesaLlvmPipe) mInitialized = true; ContextFlags flag = ContextFlagsNone; - if (aUseMesaLlvmPipe) { - mLibType = WGLLibrary::MESA_LLVMPIPE_LIB; - flag = ContextFlagsMesaLLVMPipe; - } // Call this to create the global GLContext instance, // and to check for errors. Note that this must happen /after/ @@ -256,7 +242,6 @@ GLContextWGL::GLContextWGL( bool isOffscreen, HDC aDC, HGLRC aContext, - LibType aLibUsed, HWND aWindow) : GLContext(caps, sharedContext, isOffscreen), mDC(aDC), @@ -264,7 +249,6 @@ GLContextWGL::GLContextWGL( mWnd(aWindow), mPBuffer(nullptr), mPixelFormat(0), - mLibType(aLibUsed), mIsDoubleBuffered(false) { // See 899855 @@ -278,15 +262,13 @@ GLContextWGL::GLContextWGL( HANDLE aPbuffer, HDC aDC, HGLRC aContext, - int aPixelFormat, - LibType aLibUsed) + int aPixelFormat) : GLContext(caps, sharedContext, isOffscreen), mDC(aDC), mContext(aContext), mWnd(nullptr), mPBuffer(aPbuffer), mPixelFormat(aPixelFormat), - mLibType(aLibUsed), mIsDoubleBuffered(false) { // See 899855 @@ -297,10 +279,10 @@ GLContextWGL::~GLContextWGL() { MarkDestroyed(); - sWGLLib[mLibType].fDeleteContext(mContext); + sWGLLib.fDeleteContext(mContext); if (mPBuffer) - sWGLLib[mLibType].fDestroyPbuffer(mPBuffer); + sWGLLib.fDestroyPbuffer(mPBuffer); if (mWnd) DestroyWindow(mWnd); } @@ -312,7 +294,7 @@ GLContextWGL::Init() return false; // see bug 929506 comment 29. wglGetProcAddress requires a current context. - if (!sWGLLib[mLibType].fMakeCurrent(mDC, mContext)) + if (!sWGLLib.fMakeCurrent(mDC, mContext)) return false; SetupLookupFunction(); @@ -331,8 +313,8 @@ GLContextWGL::MakeCurrentImpl(bool aForce) // of its TLS slot, so no need to do our own tls slot. // You would think that wglMakeCurrent would avoid doing // work if mContext was already current, but not so much.. - if (aForce || sWGLLib[mLibType].fGetCurrentContext() != mContext) { - succeeded = sWGLLib[mLibType].fMakeCurrent(mDC, mContext); + if (aForce || sWGLLib.fGetCurrentContext() != mContext) { + succeeded = sWGLLib.fMakeCurrent(mDC, mContext); NS_ASSERTION(succeeded, "Failed to make GL context current!"); } @@ -341,7 +323,7 @@ GLContextWGL::MakeCurrentImpl(bool aForce) bool GLContextWGL::IsCurrent() { - return sWGLLib[mLibType].fGetCurrentContext() == mContext; + return sWGLLib.fGetCurrentContext() == mContext; } void @@ -357,7 +339,7 @@ GLContextWGL::IsDoubleBuffered() { bool GLContextWGL::SupportsRobustness() { - return sWGLLib[mLibType].HasRobustness(); + return sWGLLib.HasRobustness(); } bool @@ -375,19 +357,19 @@ GLContextWGL::SetupLookupFunction() // the right thing for some core functions. MOZ_ASSERT(mLibrary == nullptr); - mLibrary = sWGLLib[mLibType].GetOGLLibrary(); - mLookupFunc = (PlatformLookupFunction)sWGLLib[mLibType].fGetProcAddress; + mLibrary = sWGLLib.GetOGLLibrary(); + mLookupFunc = (PlatformLookupFunction)sWGLLib.fGetProcAddress; return true; } static bool -GetMaxSize(HDC hDC, int format, gfxIntSize& size, LibType aLibToUse) +GetMaxSize(HDC hDC, int format, gfxIntSize& size) { int query[] = {LOCAL_WGL_MAX_PBUFFER_WIDTH_ARB, LOCAL_WGL_MAX_PBUFFER_HEIGHT_ARB}; int result[2]; // (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, int *piValues) - if (!sWGLLib[aLibToUse].fGetPixelFormatAttribiv(hDC, format, 0, 2, query, result)) + if (!sWGLLib.fGetPixelFormatAttribiv(hDC, format, 0, 2, query, result)) return false; size.width = result[0]; @@ -397,11 +379,10 @@ GetMaxSize(HDC hDC, int format, gfxIntSize& size, LibType aLibToUse) static bool IsValidSizeForFormat(HDC hDC, int format, - const gfxIntSize& requested, - LibType aLibUsed) + const gfxIntSize& requested) { gfxIntSize max; - if (!GetMaxSize(hDC, format, max, aLibUsed)) + if (!GetMaxSize(hDC, format, max)) return true; if (requested.width > max.width) @@ -427,9 +408,7 @@ GetGlobalContextWGL(const ContextFlags aFlags = ContextFlagsNone) already_AddRefed GLContextProviderWGL::CreateForWindow(nsIWidget *aWidget) { - LibType libToUse = WGLLibrary::OPENGL_LIB; - - if (!sWGLLib[libToUse].EnsureInitialized(false)) { + if (!sWGLLib.EnsureInitialized()) { return nullptr; } @@ -441,29 +420,29 @@ GLContextProviderWGL::CreateForWindow(nsIWidget *aWidget) HDC dc = (HDC)aWidget->GetNativeData(NS_NATIVE_GRAPHIC); - SetPixelFormat(dc, sWGLLib[libToUse].GetWindowPixelFormat(), nullptr); + SetPixelFormat(dc, sWGLLib.GetWindowPixelFormat(), nullptr); HGLRC context; GLContextWGL *shareContext = GetGlobalContextWGL(); - if (sWGLLib[libToUse].HasRobustness()) { + if (sWGLLib.HasRobustness()) { int attribs[] = { LOCAL_WGL_CONTEXT_FLAGS_ARB, LOCAL_WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB, LOCAL_WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, LOCAL_WGL_LOSE_CONTEXT_ON_RESET_ARB, 0 }; - context = sWGLLib[libToUse].fCreateContextAttribs(dc, + context = sWGLLib.fCreateContextAttribs(dc, shareContext ? shareContext->Context() : nullptr, attribs); } else { - context = sWGLLib[libToUse].fCreateContext(dc); + context = sWGLLib.fCreateContext(dc); if (context && shareContext && - !sWGLLib[libToUse].fShareLists(shareContext->Context(), context)) + !sWGLLib.fShareLists(shareContext->Context(), context)) { printf_stderr("WGL context creation failed for window: wglShareLists returned false!"); - sWGLLib[libToUse].fDeleteContext(context); + sWGLLib.fDeleteContext(context); context = nullptr; } } @@ -477,8 +456,7 @@ GLContextProviderWGL::CreateForWindow(nsIWidget *aWidget) shareContext, false, dc, - context, - libToUse); + context); if (!glContext->Init()) { return nullptr; } @@ -490,10 +468,9 @@ GLContextProviderWGL::CreateForWindow(nsIWidget *aWidget) static already_AddRefed CreatePBufferOffscreenContext(const gfxIntSize& aSize, - LibType aLibToUse, GLContextWGL *aShareContext) { - WGLLibrary& wgl = sWGLLib[aLibToUse]; + WGLLibrary& wgl = sWGLLib; #define A1(_a,_x) do { _a.AppendElement(_x); } while(0) #define A2(_a,_x,_y) do { _a.AppendElement(_x); _a.AppendElement(_y); } while(0) @@ -531,7 +508,7 @@ CreatePBufferOffscreenContext(const gfxIntSize& aSize, // We don't care; just pick the first one. int chosenFormat = formats[0]; - if (!IsValidSizeForFormat(windowDC, chosenFormat, aSize, aLibToUse)) + if (!IsValidSizeForFormat(windowDC, chosenFormat, aSize)) return nullptr; HANDLE pbuffer = wgl.fCreatePbuffer(windowDC, chosenFormat, @@ -576,8 +553,7 @@ CreatePBufferOffscreenContext(const gfxIntSize& aSize, pbuffer, pbdc, context, - chosenFormat, - aLibToUse); + chosenFormat); return glContext.forget(); } @@ -591,30 +567,29 @@ CreateWindowOffscreenContext(ContextFlags aFlags) return nullptr; } - LibType libToUse = WGLLibrary::SelectLibrary(aFlags); HDC dc; - HWND win = sWGLLib[libToUse].CreateDummyWindow(&dc); + HWND win = sWGLLib.CreateDummyWindow(&dc); if (!win) { return nullptr; } - HGLRC context = sWGLLib[libToUse].fCreateContext(dc); - if (sWGLLib[libToUse].HasRobustness()) { + HGLRC context = sWGLLib.fCreateContext(dc); + if (sWGLLib.HasRobustness()) { int attribs[] = { LOCAL_WGL_CONTEXT_FLAGS_ARB, LOCAL_WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB, LOCAL_WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, LOCAL_WGL_LOSE_CONTEXT_ON_RESET_ARB, 0 }; - context = sWGLLib[libToUse].fCreateContextAttribs(dc, shareContext->Context(), attribs); + context = sWGLLib.fCreateContextAttribs(dc, shareContext->Context(), attribs); } else { - context = sWGLLib[libToUse].fCreateContext(dc); + context = sWGLLib.fCreateContext(dc); if (context && shareContext && - !sWGLLib[libToUse].fShareLists(shareContext->Context(), context)) + !sWGLLib.fShareLists(shareContext->Context(), context)) { NS_WARNING("wglShareLists failed!"); - sWGLLib[libToUse].fDeleteContext(context); + sWGLLib.fDeleteContext(context); DestroyWindow(win); return nullptr; } @@ -627,8 +602,7 @@ CreateWindowOffscreenContext(ContextFlags aFlags) SurfaceCaps caps = SurfaceCaps::ForRGBA(); nsRefPtr glContext = new GLContextWGL(caps, shareContext, true, - dc, context, - libToUse, win); + dc, context, win); return glContext.forget(); } @@ -638,9 +612,7 @@ GLContextProviderWGL::CreateOffscreen(const gfxIntSize& size, const SurfaceCaps& caps, ContextFlags flags) { - LibType libToUse = WGLLibrary::SelectLibrary(flags); - - if (!sWGLLib[libToUse].EnsureInitialized(libToUse == WGLLibrary::MESA_LLVMPIPE_LIB)) { + if (!sWGLLib.EnsureInitialized()) { return nullptr; } @@ -648,11 +620,11 @@ GLContextProviderWGL::CreateOffscreen(const gfxIntSize& size, // Always try to create a pbuffer context first, because we // want the context isolation. - if (sWGLLib[libToUse].fCreatePbuffer && - sWGLLib[libToUse].fChoosePixelFormat) + if (sWGLLib.fCreatePbuffer && + sWGLLib.fChoosePixelFormat) { gfxIntSize dummySize = gfxIntSize(16, 16); - glContext = CreatePBufferOffscreenContext(dummySize, libToUse, GetGlobalContextWGL()); + glContext = CreatePBufferOffscreenContext(dummySize, GetGlobalContextWGL()); } // If it failed, then create a window context and use a FBO. @@ -672,44 +644,40 @@ GLContextProviderWGL::CreateOffscreen(const gfxIntSize& size, return glContext.forget(); } -static nsRefPtr gGlobalContext[WGLLibrary::LIBS_MAX]; +static nsRefPtr gGlobalContext; GLContext * GLContextProviderWGL::GetGlobalContext(const ContextFlags flags) { - LibType libToUse = WGLLibrary::SelectLibrary(flags); - - if (!sWGLLib[libToUse].EnsureInitialized(libToUse == WGLLibrary::MESA_LLVMPIPE_LIB)) { + if (!sWGLLib.EnsureInitialized()) { return nullptr; } - static bool triedToCreateContext[WGLLibrary::LIBS_MAX] = {false, false}; + static bool triedToCreateContext = false; - if (!triedToCreateContext[libToUse] && !gGlobalContext[libToUse]) { - triedToCreateContext[libToUse] = true; + if (!triedToCreateContext && !gGlobalContext) { + triedToCreateContext = true; // conveniently, we already have what we need... SurfaceCaps dummyCaps = SurfaceCaps::Any(); - gGlobalContext[libToUse] = new GLContextWGL(dummyCaps, - nullptr, true, - sWGLLib[libToUse].GetWindowDC(), - sWGLLib[libToUse].GetWindowGLContext(), - libToUse); - if (!gGlobalContext[libToUse]->Init()) { + gGlobalContext = new GLContextWGL(dummyCaps, + nullptr, true, + sWGLLib.GetWindowDC(), + sWGLLib.GetWindowGLContext()); + if (!gGlobalContext->Init()) { NS_WARNING("Global context GLContext initialization failed?"); - gGlobalContext[libToUse] = nullptr; + gGlobalContext = nullptr; return nullptr; } } - return static_cast(gGlobalContext[libToUse]); + return static_cast(gGlobalContext); } void GLContextProviderWGL::Shutdown() { - for (int i = 0; i < WGLLibrary::LIBS_MAX; ++i) - gGlobalContext[i] = nullptr; + gGlobalContext = nullptr; } } /* namespace gl */ diff --git a/gfx/gl/GLContextTypes.h b/gfx/gl/GLContextTypes.h index 00e34c51c613..309614c583eb 100644 --- a/gfx/gl/GLContextTypes.h +++ b/gfx/gl/GLContextTypes.h @@ -32,8 +32,7 @@ enum SharedTextureBufferType { enum ContextFlags { ContextFlagsNone = 0x0, - ContextFlagsGlobal = 0x1, - ContextFlagsMesaLLVMPipe = 0x2 + ContextFlagsGlobal = 0x1 }; enum GLContextType { diff --git a/gfx/gl/GLContextWGL.h b/gfx/gl/GLContextWGL.h index 62bb4b7c29f5..bb2b7684e177 100644 --- a/gfx/gl/GLContextWGL.h +++ b/gfx/gl/GLContextWGL.h @@ -13,8 +13,6 @@ namespace mozilla { namespace gl { -typedef WGLLibrary::LibraryType LibType; - class GLContextWGL : public GLContext { public: @@ -24,7 +22,6 @@ public: bool isOffscreen, HDC aDC, HGLRC aContext, - LibType aLibUsed, HWND aWindow = nullptr); // From PBuffer @@ -34,8 +31,7 @@ public: HANDLE aPbuffer, HDC aDC, HGLRC aContext, - int aPixelFormat, - LibType aLibUsed); + int aPixelFormat); ~GLContextWGL(); @@ -74,7 +70,6 @@ protected: HWND mWnd; HANDLE mPBuffer; int mPixelFormat; - LibType mLibType; bool mIsDoubleBuffered; }; diff --git a/gfx/gl/GLXLibrary.h b/gfx/gl/GLXLibrary.h index 9fefb75e840c..4de60dd76861 100644 --- a/gfx/gl/GLXLibrary.h +++ b/gfx/gl/GLXLibrary.h @@ -35,7 +35,7 @@ public: mUseTextureFromPixmap(false), mDebug(false), mHasRobustness(false), mIsATI(false), mIsNVIDIA(false), mClientIsMesa(false), mGLXMajorVersion(0), - mGLXMinorVersion(0), mLibType(OPENGL_LIB), + mGLXMinorVersion(0), mOGLLibrary(nullptr) {} void xDestroyContext(Display* display, GLXContext context); @@ -43,13 +43,6 @@ public: GLXDrawable drawable, GLXContext context); - enum LibraryType - { - OPENGL_LIB = 0, - MESA_LLVMPIPE_LIB = 1, - LIBS_MAX - }; - GLXContext xGetCurrentContext(); static void* xGetProcAddress(const char *procName); GLXFBConfig* xChooseFBConfig(Display* display, @@ -102,7 +95,7 @@ public: Bool direct, const int* attrib_list); - bool EnsureInitialized(LibraryType libType); + bool EnsureInitialized(); GLXPixmap CreatePixmap(gfxASurface* aSurface); void DestroyPixmap(GLXPixmap aPixmap); @@ -114,7 +107,6 @@ public: bool SupportsTextureFromPixmap(gfxASurface* aSurface); bool IsATI() { return mIsATI; } bool GLXVersionCheck(int aMajor, int aMinor); - static LibraryType SelectLibrary(const ContextFlags& aFlags); private: @@ -221,13 +213,11 @@ private: bool mClientIsMesa; int mGLXMajorVersion; int mGLXMinorVersion; - LibraryType mLibType; PRLibrary *mOGLLibrary; }; // a global GLXLibrary instance -extern GLXLibrary sGLXLibrary[GLXLibrary::LIBS_MAX]; -extern GLXLibrary& sDefGLXLib; +extern GLXLibrary sGLXLibrary; } /* namespace gl */ } /* namespace mozilla */ diff --git a/gfx/gl/WGLLibrary.h b/gfx/gl/WGLLibrary.h index 1b807c714352..f26e57d50a53 100644 --- a/gfx/gl/WGLLibrary.h +++ b/gfx/gl/WGLLibrary.h @@ -21,17 +21,9 @@ public: mWindow (0), mWindowDC(0), mWindowGLContext(0), - mWindowPixelFormat (0), - mLibType(OPENGL_LIB) + mWindowPixelFormat (0) {} - enum LibraryType - { - OPENGL_LIB = 0, - MESA_LLVMPIPE_LIB = 1, - LIBS_MAX - }; - typedef HGLRC (GLAPIENTRY * PFNWGLCREATECONTEXTPROC) (HDC); PFNWGLCREATECONTEXTPROC fCreateContext; typedef BOOL (GLAPIENTRY * PFNWGLDELETECONTEXTPROC) (HGLRC); @@ -70,7 +62,7 @@ public: typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSPROC) (HDC hdc, HGLRC hShareContext, const int *attribList); PFNWGLCREATECONTEXTATTRIBSPROC fCreateContextAttribs; - bool EnsureInitialized(bool aUseMesaLlvmPipe); + bool EnsureInitialized(); HWND CreateDummyWindow(HDC *aWindowDC = nullptr); bool HasRobustness() const { return mHasRobustness; } @@ -79,9 +71,6 @@ public: HDC GetWindowDC() const {return mWindowDC; } HGLRC GetWindowGLContext() const {return mWindowGLContext; } int GetWindowPixelFormat() const { return mWindowPixelFormat; } - LibraryType GetLibraryType() const { return mLibType; } - static LibraryType SelectLibrary(const ContextFlags& aFlags); - PRLibrary *GetOGLLibrary() { return mOGLLibrary; } private: @@ -93,12 +82,11 @@ private: HDC mWindowDC; HGLRC mWindowGLContext; int mWindowPixelFormat; - LibraryType mLibType; }; // a global WGLLibrary instance -extern WGLLibrary sWGLLibrary[WGLLibrary::LIBS_MAX]; +extern WGLLibrary sWGLLibrary; } /* namespace gl */ } /* namespace mozilla */ diff --git a/gfx/thebes/gfxXlibSurface.cpp b/gfx/thebes/gfxXlibSurface.cpp index 611d26636b4e..4aea81b602f7 100644 --- a/gfx/thebes/gfxXlibSurface.cpp +++ b/gfx/thebes/gfxXlibSurface.cpp @@ -89,7 +89,7 @@ gfxXlibSurface::~gfxXlibSurface() { #if defined(GL_PROVIDER_GLX) if (mGLXPixmap) { - gl::sDefGLXLib.DestroyPixmap(mGLXPixmap); + gl::sGLXLibrary.DestroyPixmap(mGLXPixmap); } #endif // gfxASurface's destructor calls RecordMemoryFreed(). @@ -278,7 +278,7 @@ gfxXlibSurface::Finish() { #if defined(GL_PROVIDER_GLX) if (mGLXPixmap) { - gl::sDefGLXLib.DestroyPixmap(mGLXPixmap); + gl::sGLXLibrary.DestroyPixmap(mGLXPixmap); mGLXPixmap = None; } #endif @@ -598,7 +598,7 @@ gfxXlibSurface::GetGLXPixmap() NS_ASSERTION(CairoStatus() != CAIRO_STATUS_SURFACE_FINISHED, "GetGLXPixmap called after surface finished"); #endif - mGLXPixmap = gl::sDefGLXLib.CreatePixmap(this); + mGLXPixmap = gl::sGLXLibrary.CreatePixmap(this); } return mGLXPixmap; }