Bug 1276708 - Add gfxConfig feature for GLX surface sharing. r?jrmuizel draft
authorAndrew Comminos <andrew@comminos.com>
Thu, 02 Jun 2016 17:20:02 -0400
changeset 374824 0e55ffef62bade31c2e861619428cc98473e6c6d
parent 374820 68af9cd00e00ca9b5b24df326afe64af547d09ca
child 522694 198aa044419f9d631ed2460b53dfbeb7cc7e4537
push id20089
push userbmo:andrew@comminos.com
push dateThu, 02 Jun 2016 21:38:25 +0000
reviewersjrmuizel
bugs1276708
milestone49.0a1
Bug 1276708 - Add gfxConfig feature for GLX surface sharing. r?jrmuizel MozReview-Commit-ID: DKf8hbiJ1gA
gfx/config/gfxFeature.h
gfx/gl/GLContextProviderGLX.cpp
gfx/gl/GLScreenBuffer.cpp
gfx/gl/SharedSurfaceGLX.cpp
--- a/gfx/config/gfxFeature.h
+++ b/gfx/config/gfxFeature.h
@@ -15,17 +15,18 @@ namespace mozilla {
 namespace gfx {
 
 #define GFX_FEATURE_MAP(_)                                                        \
   /* Name,                        Type,         Description */                    \
   _(HW_COMPOSITING,               Feature,      "Compositing")                    \
   _(D3D11_COMPOSITING,            Feature,      "Direct3D11 Compositing")         \
   _(D3D9_COMPOSITING,             Feature,      "Direct3D9 Compositing")          \
   _(DIRECT2D,                     Feature,      "Direct2D")                       \
-  _(D3D11_HW_ANGLE,               Feature,      "Direct3D11 hardware ANGLE")               \
+  _(D3D11_HW_ANGLE,               Feature,      "Direct3D11 hardware ANGLE")      \
+  _(GLX_SURFACE_SHARING,          Feature,      "GLX surface sharing")            \
   /* Add new entries above this comment */
 
 enum class Feature : uint32_t {
 #define MAKE_ENUM(name, type, desc) name,
   GFX_FEATURE_MAP(MAKE_ENUM)
 #undef MAKE_ENUM
   NumValues
 };
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -27,16 +27,17 @@
 #include "gfxContext.h"
 #include "gfxEnv.h"
 #include "gfxPlatform.h"
 #include "GLContextGLX.h"
 #include "gfxUtils.h"
 #include "gfx2DGlue.h"
 #include "GLScreenBuffer.h"
 #include "gfxPrefs.h"
+#include "gfxConfig.h"
 
 #include "gfxCrashReporterUtils.h"
 
 #ifdef MOZ_WIDGET_GTK
 #include "gfxPlatformGtk.h"
 #endif
 
 namespace mozilla {
@@ -219,24 +220,34 @@ GLXLibrary::EnsureInitialized()
     } else {
         sym14 = symbols14;
     }
     if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, sym14)) {
         NS_WARNING("Couldn't find required entry point in OpenGL shared library");
         return false;
     }
 
+    FeatureState& surfaceSharing = gfxConfig::GetFeature(gfx::Feature::GLX_SURFACE_SHARING);
+    surfaceSharing.EnableByDefault();
+    // TODO: as data presents itself, blacklist this feature on broken
+    //       configurations using client and server vendor strings, as well as
+    //       the GL renderer string.
+
     if (HasExtension(extensionsStr, "GLX_EXT_texture_from_pixmap") &&
         GLLibraryLoader::LoadSymbols(mOGLLibrary, symbols_texturefrompixmap,
                                          (GLLibraryLoader::PlatformLookupFunction)&xGetProcAddress))
     {
         mUseTextureFromPixmap = gfxPrefs::UseGLXTextureFromPixmap();
+        if (!mUseTextureFromPixmap)
+            surfaceSharing.UserDisable("GLX_EXT_texture_from_pixmap disabled by pref.");
     } else {
         mUseTextureFromPixmap = false;
         NS_WARNING("Texture from pixmap disabled");
+        surfaceSharing.Disable(gfx::FeatureStatus::Blocked,
+                               "GLX_EXT_texture_from_pixmap unavailable.");
     }
 
     if (HasExtension(extensionsStr, "GLX_ARB_create_context") &&
         HasExtension(extensionsStr, "GLX_ARB_create_context_profile") &&
         GLLibraryLoader::LoadSymbols(mOGLLibrary, symbols_createcontext,
                                      (GLLibraryLoader::PlatformLookupFunction)&xGetProcAddress))
     {
         mHasCreateContextAttribs = true;
--- a/gfx/gl/GLScreenBuffer.cpp
+++ b/gfx/gl/GLScreenBuffer.cpp
@@ -9,16 +9,17 @@
 #include "CompositorTypes.h"
 #include "GLContext.h"
 #include "GLBlitHelper.h"
 #include "GLReadTexImageHelper.h"
 #include "SharedSurfaceEGL.h"
 #include "SharedSurfaceGL.h"
 #include "ScopedGLHelpers.h"
 #include "gfx2DGlue.h"
+#include "gfxConfig.h"
 #include "../layers/ipc/ShadowLayers.h"
 #include "mozilla/layers/CompositableForwarder.h"
 #include "mozilla/layers/TextureClientSharedSurface.h"
 
 #ifdef XP_WIN
 #include "SharedSurfaceANGLE.h"         // for SurfaceFactory_ANGLEShareHandle
 #include "SharedSurfaceD3D11Interop.h"  // for SurfaceFactory_D3D11Interop
 #include "gfxWindowsPlatform.h"
@@ -76,17 +77,17 @@ GLScreenBuffer::CreateFactory(GLContext*
     if (!gfxPrefs::WebGLForceLayersReadback()) {
         switch (forwarder->GetCompositorBackendType()) {
             case mozilla::layers::LayersBackend::LAYERS_OPENGL: {
 #if defined(XP_MACOSX)
                 factory = SurfaceFactory_IOSurface::Create(gl, caps, forwarder, flags);
 #elif defined(MOZ_WIDGET_GONK)
                 factory = MakeUnique<SurfaceFactory_Gralloc>(gl, caps, forwarder, flags);
 #elif defined(GL_PROVIDER_GLX)
-                if (sGLXLibrary.UseTextureFromPixmap())
+                if (gfx::gfxConfig::IsEnabled(gfx::Feature::GLX_SURFACE_SHARING))
                   factory = SurfaceFactory_GLXDrawable::Create(gl, caps, forwarder, flags);
 #elif defined(MOZ_WIDGET_UIKIT)
                 factory = MakeUnique<SurfaceFactory_GLTexture>(mGLContext, caps, forwarder, mFlags);
 #else
                 if (gl->GetContextType() == GLContextType::EGL) {
                     if (XRE_IsParentProcess()) {
                         factory = SurfaceFactory_EGLImage::Create(gl, caps, forwarder, flags);
                     }
--- a/gfx/gl/SharedSurfaceGLX.cpp
+++ b/gfx/gl/SharedSurfaceGLX.cpp
@@ -8,28 +8,30 @@
 #include "GLXLibrary.h"
 #include "GLContextProvider.h"
 #include "GLContextGLX.h"
 #include "GLScreenBuffer.h"
 #include "mozilla/gfx/SourceSurfaceCairo.h"
 #include "mozilla/layers/LayersSurfaces.h"
 #include "mozilla/layers/ISurfaceAllocator.h"
 #include "mozilla/X11Util.h"
+#include "gfxConfig.h"
 
 namespace mozilla {
 namespace gl {
 
 /* static */
 UniquePtr<SharedSurface_GLXDrawable>
 SharedSurface_GLXDrawable::Create(GLContext* prodGL,
                                   const SurfaceCaps& caps,
                                   const gfx::IntSize& size,
                                   bool deallocateClient,
                                   bool inSameProcess)
 {
+    MOZ_RELEASE_ASSERT(gfx::gfxConfig::IsEnabled(gfx::Feature::GLX_SURFACE_SHARING));
     GLContextGLX* glxContext = GLContextGLX::Cast(prodGL);
     RefPtr<GLXSurface> surf = glxContext->CreateCompatibleSurface(size);
     if (!surf)
         return nullptr;
 
     if (!deallocateClient) {
         surf->ReleasePixmap();
         surf->ReleaseGLXPixmap();