Bug 1464037 - Replace GL_PROVIDER_GLX by MOZ_X11 to build X11 dependent code, r?lsalzman draft
authorMartin Stransky <stransky@redhat.com>
Thu, 24 May 2018 14:06:31 +0200
changeset 800039 84530804511ee01465b40483deacae62b43deeca
parent 800025 94d7f0e1c4d0390450028972cfeb65e0550b9892
push id111239
push userstransky@redhat.com
push dateFri, 25 May 2018 19:30:05 +0000
reviewerslsalzman
bugs1464037
milestone62.0a1
Bug 1464037 - Replace GL_PROVIDER_GLX by MOZ_X11 to build X11 dependent code, r?lsalzman In order to have useful Wayland builds we need ability to switch between GL backends run-time - to use EGL backend for Wayland and GLX backend for X11. GL_PROVIDER_GLX is used exclusively for GLX GL backend, so let's replace GL_PROVIDER_GLX build-time check by more general MOZ_X11 check which determines X11 dependent code and it's valid for both X11 and Wayland builds. MozReview-Commit-ID: HYobrHveoaP
gfx/gl/GLScreenBuffer.cpp
gfx/layers/client/TextureClient.cpp
gfx/layers/composite/X11TextureHost.cpp
gfx/layers/ipc/ShadowLayerUtilsX11.cpp
gfx/layers/opengl/X11TextureSourceOGL.cpp
gfx/layers/opengl/X11TextureSourceOGL.h
gfx/thebes/gfxPlatformGtk.cpp
gfx/thebes/gfxPlatformGtk.h
gfx/thebes/gfxXlibSurface.cpp
gfx/thebes/gfxXlibSurface.h
--- a/gfx/gl/GLScreenBuffer.cpp
+++ b/gfx/gl/GLScreenBuffer.cpp
@@ -24,17 +24,17 @@
 #include "SharedSurfaceD3D11Interop.h"  // for SurfaceFactory_D3D11Interop
 #include "mozilla/gfx/DeviceManagerDx.h"
 #endif
 
 #ifdef XP_MACOSX
 #include "SharedSurfaceIO.h"
 #endif
 
-#ifdef GL_PROVIDER_GLX
+#ifdef MOZ_X11
 #include "GLXLibrary.h"
 #include "SharedSurfaceGLX.h"
 #endif
 
 namespace mozilla {
 namespace gl {
 
 using gfx::SurfaceFormat;
@@ -78,17 +78,17 @@ GLScreenBuffer::CreateFactory(GLContext*
     const bool useD3D = !gfxPrefs::WebGLForceLayersReadback() &&
                         (backend == layers::LayersBackend::LAYERS_D3D11 ||
                         (backend == layers::LayersBackend::LAYERS_WR && useANGLE));
 
     UniquePtr<SurfaceFactory> factory = nullptr;
     if (useGl) {
 #if defined(XP_MACOSX)
         factory = SurfaceFactory_IOSurface::Create(gl, caps, ipcChannel, flags);
-#elif defined(GL_PROVIDER_GLX)
+#elif defined(MOZ_X11)
         if (sGLXLibrary.UseTextureFromPixmap())
             factory = SurfaceFactory_GLXDrawable::Create(gl, caps, ipcChannel, flags);
 #elif defined(MOZ_WIDGET_UIKIT)
         factory = MakeUnique<SurfaceFactory_GLTexture>(mGLContext, caps, ipcChannel, mFlags);
 #elif defined(MOZ_WIDGET_ANDROID)
         if (XRE_IsParentProcess() && !gfxPrefs::WebGLSurfaceTextureEnabled()) {
             factory = SurfaceFactory_EGLImage::Create(gl, caps, ipcChannel, flags);
         } else {
@@ -114,17 +114,17 @@ GLScreenBuffer::CreateFactory(GLContext*
         }
 
         if (!factory && gfxPrefs::WebGLDXGLEnabled()) {
             factory = SurfaceFactory_D3D11Interop::Create(gl, caps, ipcChannel, flags);
         }
 #endif
     }
 
-#ifdef GL_PROVIDER_GLX
+#ifdef MOZ_X11
     if (!factory && sGLXLibrary.UseTextureFromPixmap()) {
         factory = SurfaceFactory_GLXDrawable::Create(gl, caps, ipcChannel, flags);
     }
 #endif
 
     return factory;
 }
 
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -40,20 +40,18 @@
 #include "mozilla/gfx/DeviceManagerDx.h"
 #include "mozilla/layers/TextureD3D11.h"
 #include "mozilla/layers/TextureDIB.h"
 #include "gfxWindowsPlatform.h"
 #include "gfx2DGlue.h"
 #endif
 #ifdef MOZ_X11
 #include "mozilla/layers/TextureClientX11.h"
-#ifdef GL_PROVIDER_GLX
 #include "GLXLibrary.h"
 #endif
-#endif
 
 #ifdef XP_MACOSX
 #include "mozilla/layers/MacIOSurfaceTextureClientOGL.h"
 #endif
 
 #if 0
 #define RECYCLE_LOG(...) printf_stderr(__VA_ARGS__)
 #else
@@ -1122,26 +1120,24 @@ TextureClient::CreateForDrawing(TextureF
     gfxPlatform::GetPlatform()->ScreenReferenceSurface()->GetType();
 
   if (!data && aLayersBackend == LayersBackend::LAYERS_BASIC &&
       moz2DBackend == gfx::BackendType::CAIRO &&
       type == gfxSurfaceType::Xlib)
   {
     data = X11TextureData::Create(aSize, aFormat, aTextureFlags, aAllocator);
   }
-#ifdef GL_PROVIDER_GLX
   if (!data && aLayersBackend == LayersBackend::LAYERS_OPENGL &&
       type == gfxSurfaceType::Xlib &&
       aFormat != SurfaceFormat::A8 &&
       gl::sGLXLibrary.UseTextureFromPixmap())
   {
     data = X11TextureData::Create(aSize, aFormat, aTextureFlags, aAllocator);
   }
 #endif
-#endif
 
 #ifdef XP_MACOSX
   if (!data && gfxPrefs::UseIOSurfaceTextures()) {
     data = MacIOSurfaceTextureData::Create(aSize, aFormat, moz2DBackend);
   }
 #endif
 
 #ifdef MOZ_WIDGET_ANDROID
--- a/gfx/layers/composite/X11TextureHost.cpp
+++ b/gfx/layers/composite/X11TextureHost.cpp
@@ -2,20 +2,18 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/. */
 
 #include "X11TextureHost.h"
 #include "mozilla/layers/BasicCompositor.h"
 #include "mozilla/layers/X11TextureSourceBasic.h"
-#ifdef GL_PROVIDER_GLX
 #include "mozilla/layers/CompositorOGL.h"
 #include "mozilla/layers/X11TextureSourceOGL.h"
-#endif
 #include "gfxXlibSurface.h"
 #include "gfx2DGlue.h"
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gfx;
 
@@ -38,22 +36,20 @@ X11TextureHost::Lock()
   }
 
   if (!mTextureSource) {
     switch (mCompositor->GetBackendType()) {
       case LayersBackend::LAYERS_BASIC:
         mTextureSource =
           new X11TextureSourceBasic(mCompositor->AsBasicCompositor(), mSurface);
         break;
-#ifdef GL_PROVIDER_GLX
       case LayersBackend::LAYERS_OPENGL:
         mTextureSource =
           new X11TextureSourceOGL(mCompositor->AsCompositorOGL(), mSurface);
         break;
-#endif
       default:
         return false;
     }
   }
 
   return true;
 }
 
@@ -73,21 +69,19 @@ X11TextureHost::SetTextureSourceProvider
 
 SurfaceFormat
 X11TextureHost::GetFormat() const
 {
   if (!mSurface) {
     return SurfaceFormat::UNKNOWN;
   }
   gfxContentType type = mSurface->GetContentType();
-#ifdef GL_PROVIDER_GLX
   if (mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL) {
     return X11TextureSourceOGL::ContentTypeToSurfaceFormat(type);
   }
-#endif
   return X11TextureSourceBasic::ContentTypeToSurfaceFormat(type);
 }
 
 IntSize
 X11TextureHost::GetSize() const
 {
   if (!mSurface) {
     return IntSize();
--- a/gfx/layers/ipc/ShadowLayerUtilsX11.cpp
+++ b/gfx/layers/ipc/ShadowLayerUtilsX11.cpp
@@ -69,21 +69,19 @@ SurfaceDescriptorX11::SurfaceDescriptorX
 {
   const XRenderPictFormat *pictFormat = aSurf->XRenderFormat();
   if (pictFormat) {
     mFormat = pictFormat->id;
   } else {
     mFormat = cairo_xlib_surface_get_visual(aSurf->CairoSurface())->visualid;
   }
 
-#ifdef GL_PROVIDER_GLX
   if (aForwardGLX) {
     mGLXPixmap = aSurf->GetGLXPixmap();
   }
-#endif
 }
 
 SurfaceDescriptorX11::SurfaceDescriptorX11(Drawable aDrawable, XID aFormatID,
                                            const gfx::IntSize& aSize)
   : mId(aDrawable)
   , mFormat(aFormatID)
   , mSize(aSize)
   , mGLXPixmap(X11None)
@@ -104,20 +102,18 @@ SurfaceDescriptorX11::OpenForeign() cons
     int depth;
     FindVisualAndDepth(display, mFormat, &visual, &depth);
     if (!visual)
       return nullptr;
 
     surf = new gfxXlibSurface(display, mId, visual, mSize);
   }
 
-#ifdef GL_PROVIDER_GLX
   if (mGLXPixmap)
     surf->BindGLXPixmap(mGLXPixmap);
-#endif
 
   return surf->CairoStatus() ? nullptr : surf.forget();
 }
 
 /*static*/ void
 ShadowLayerForwarder::PlatformSyncBeforeUpdate()
 {
   if (UsingXCompositing()) {
--- a/gfx/layers/opengl/X11TextureSourceOGL.cpp
+++ b/gfx/layers/opengl/X11TextureSourceOGL.cpp
@@ -1,16 +1,14 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/. */
 
-#ifdef GL_PROVIDER_GLX
-
 #include "X11TextureSourceOGL.h"
 #include "gfxXlibSurface.h"
 #include "gfx2DGlue.h"
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gfx;
@@ -98,9 +96,8 @@ X11TextureSourceOGL::ContentTypeToSurfac
     default:
       return SurfaceFormat::UNKNOWN;
   }
 }
 
 }
 }
 
-#endif
--- a/gfx/layers/opengl/X11TextureSourceOGL.h
+++ b/gfx/layers/opengl/X11TextureSourceOGL.h
@@ -2,17 +2,17 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/. */
 
 #ifndef MOZILLA_GFX_X11TEXTURESOURCEOGL__H
 #define MOZILLA_GFX_X11TEXTURESOURCEOGL__H
 
-#ifdef GL_PROVIDER_GLX
+#ifdef MOZ_X11
 
 #include "mozilla/layers/CompositorOGL.h"
 #include "mozilla/layers/TextureHostOGL.h"
 #include "mozilla/layers/X11TextureHost.h"
 #include "mozilla/gfx/2D.h"
 
 namespace mozilla {
 namespace layers {
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -37,21 +37,19 @@
 #include "gfxImageSurface.h"
 #ifdef MOZ_X11
 #include <gdk/gdkx.h>
 #include "gfxXlibSurface.h"
 #include "cairo-xlib.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/X11Util.h"
 
-#ifdef GL_PROVIDER_GLX
 #include "GLContextProvider.h"
 #include "GLContextGLX.h"
 #include "GLXLibrary.h"
-#endif
 
 /* Undefine the Status from Xlib since it will conflict with system headers on OSX */
 #if defined(__APPLE__) && defined(Status)
 #undef Status
 #endif
 
 #endif /* MOZ_X11 */
 
@@ -503,17 +501,17 @@ gfxPlatformGtk::CheckVariationFontSuppor
   // Although there was some variation/multiple-master support in FreeType
   // in older versions, it seems too incomplete/unstable for us to use
   // until at least 2.7.1.
   FT_Int major, minor, patch;
   FT_Library_Version(GetFTLibrary(), &major, &minor, &patch);
   return major * 1000000 + minor * 1000 + patch >= 2007001;
 }
 
-#ifdef GL_PROVIDER_GLX
+#ifdef MOZ_X11
 
 class GLXVsyncSource final : public VsyncSource
 {
 public:
   GLXVsyncSource()
   {
     MOZ_ASSERT(NS_IsMainThread());
     mGlobalDisplay = new GLXDisplay();
--- a/gfx/thebes/gfxPlatformGtk.h
+++ b/gfx/thebes/gfxPlatformGtk.h
@@ -92,17 +92,17 @@ public:
     uint32_t MaxGenericSubstitions();
 
     bool SupportsPluginDirectBitmapDrawing() override {
       return true;
     }
 
     bool AccelerateLayersByDefault() override;
 
-#ifdef GL_PROVIDER_GLX
+#ifdef MOZ_X11
     already_AddRefed<mozilla::gfx::VsyncSource> CreateHardwareVsyncSource() override;
 #endif
 
 #ifdef MOZ_X11
     Display* GetCompositorDisplay() {
       return mCompositorDisplay;
     }
 #endif // MOZ_X11
--- a/gfx/thebes/gfxXlibSurface.cpp
+++ b/gfx/thebes/gfxXlibSurface.cpp
@@ -20,80 +20,71 @@
 #include <algorithm>
 #include "mozilla/CheckedInt.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual)
     : mPixmapTaken(false), mDisplay(dpy), mDrawable(drawable)
-#if defined(GL_PROVIDER_GLX)
     , mGLXPixmap(X11None)
-#endif
 {
     const gfx::IntSize size = DoSizeQuery();
     cairo_surface_t *surf = cairo_xlib_surface_create(dpy, drawable, visual, size.width, size.height);
     Init(surf);
 }
 
 gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const gfx::IntSize& size)
     : mPixmapTaken(false), mDisplay(dpy), mDrawable(drawable)
-#if defined(GL_PROVIDER_GLX)
     , mGLXPixmap(X11None)
-#endif
 {
     NS_ASSERTION(Factory::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT),
                  "Bad size");
 
     cairo_surface_t *surf = cairo_xlib_surface_create(dpy, drawable, visual, size.width, size.height);
     Init(surf);
 }
 
 gfxXlibSurface::gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFormat *format,
                                const gfx::IntSize& size)
-    : mPixmapTaken(false), mDisplay(DisplayOfScreen(screen)),
-      mDrawable(drawable)
-#if defined(GL_PROVIDER_GLX)
-      , mGLXPixmap(X11None)
-#endif
+    : mPixmapTaken(false)
+    , mDisplay(DisplayOfScreen(screen))
+    , mDrawable(drawable)
+    , mGLXPixmap(X11None)
 {
     NS_ASSERTION(Factory::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT),
                  "Bad Size");
 
     cairo_surface_t *surf =
         cairo_xlib_surface_create_with_xrender_format(mDisplay, drawable,
                                                       screen, format,
                                                       size.width, size.height);
     Init(surf);
 }
 
 gfxXlibSurface::gfxXlibSurface(cairo_surface_t *csurf)
     : mPixmapTaken(false)
-#if defined(GL_PROVIDER_GLX)
-      , mGLXPixmap(X11None)
-#endif
+    , mGLXPixmap(X11None)
 {
     MOZ_ASSERT(cairo_surface_status(csurf) == 0,
                "Not expecting an error surface");
 
     mDrawable = cairo_xlib_surface_get_drawable(csurf);
     mDisplay = cairo_xlib_surface_get_display(csurf);
 
     Init(csurf, true);
 }
 
 gfxXlibSurface::~gfxXlibSurface()
 {
     // gfxASurface's destructor calls RecordMemoryFreed().
     if (mPixmapTaken) {
-#if defined(GL_PROVIDER_GLX)
         if (mGLXPixmap) {
             gl::sGLXLibrary.DestroyPixmap(mDisplay, mGLXPixmap);
         }
-#endif
         XFreePixmap (mDisplay, mDrawable);
     }
 }
 
 static Drawable
 CreatePixmap(Screen *screen, const gfx::IntSize& size, unsigned int depth,
              Drawable relatedDrawable)
 {
@@ -267,22 +258,20 @@ gfxXlibSurface::CreateSimilarSurface(gfx
     }
 
     return gfxASurface::CreateSimilarSurface(aContent, aSize);
 }
 
 void
 gfxXlibSurface::Finish()
 {
-#if defined(GL_PROVIDER_GLX)
     if (mPixmapTaken && mGLXPixmap) {
         gl::sGLXLibrary.DestroyPixmap(mDisplay, mGLXPixmap);
         mGLXPixmap = X11None;
     }
-#endif
     gfxASurface::Finish();
 }
 
 const gfx::IntSize
 gfxXlibSurface::GetSize() const
 {
     if (!mSurfaceValid)
         return gfx::IntSize(0,0);
@@ -582,17 +571,16 @@ gfxXlibSurface::XScreen()
 }
 
 XRenderPictFormat*
 gfxXlibSurface::XRenderFormat()
 {
     return cairo_xlib_surface_get_xrender_format(CairoSurface());
 }
 
-#if defined(GL_PROVIDER_GLX)
 GLXPixmap
 gfxXlibSurface::GetGLXPixmap()
 {
     if (!mGLXPixmap) {
 #ifdef DEBUG
         // cairo_surface_has_show_text_glyphs is used solely for the
         // side-effect of setting the error on surface if
         // cairo_surface_finish() has been called.
@@ -607,9 +595,8 @@ gfxXlibSurface::GetGLXPixmap()
 
 void
 gfxXlibSurface::BindGLXPixmap(GLXPixmap aPixmap)
 {
     MOZ_ASSERT(!mGLXPixmap, "A GLXPixmap is already bound!");
     mGLXPixmap = aPixmap;
 }
 
-#endif
--- a/gfx/thebes/gfxXlibSurface.h
+++ b/gfx/thebes/gfxXlibSurface.h
@@ -7,19 +7,17 @@
 #define GFX_XLIBSURFACE_H
 
 #include "gfxASurface.h"
 
 #include <X11/extensions/Xrender.h>
 #include <X11/Xlib.h>
 #include "X11UndefineNone.h"
 
-#if defined(GL_PROVIDER_GLX)
 #include "GLXLibrary.h"
-#endif
 
 #include "nsSize.h"
 
 // Although the dimension parameters in the xCreatePixmapReq wire protocol are
 // 16-bit unsigned integers, the server's CreatePixmap returns BadAlloc if
 // either dimension cannot be represented by a 16-bit *signed* integer.
 #define XLIB_IMAGE_SIDE_SIZE_LIMIT 0x7fff
 
@@ -81,22 +79,20 @@ public:
     // Release ownership of this surface's Pixmap.  This is only valid
     // on gfxXlibSurfaces for which the user called TakePixmap(), or
     // on those created by a Create() factory method.
     Drawable ReleasePixmap();
 
     // Find a visual and colormap pair suitable for rendering to this surface.
     bool GetColormapAndVisual(Colormap* colormap, Visual **visual);
 
-#if defined(GL_PROVIDER_GLX)
     GLXPixmap GetGLXPixmap();
     // Binds a GLXPixmap backed by this context's surface.
     // Primarily for use in sharing surfaces.
     void BindGLXPixmap(GLXPixmap aPixmap);
-#endif
 
     // Return true if cairo will take its slow path when this surface is used
     // in a pattern with EXTEND_PAD.  As a workaround for XRender's RepeatPad
     // not being implemented correctly on old X servers, cairo avoids XRender
     // and instead reads back to perform EXTEND_PAD with pixman.  Cairo does
     // this for servers older than xorg-server 1.7.
     bool IsPadSlow() {
         // The test here matches that for buggy_pad_reflect in
@@ -109,14 +105,12 @@ protected:
     // if TakePixmap() has been called on this
     bool mPixmapTaken;
     
     Display *mDisplay;
     Drawable mDrawable;
 
     const mozilla::gfx::IntSize DoSizeQuery();
 
-#if defined(GL_PROVIDER_GLX)
     GLXPixmap mGLXPixmap;
-#endif
 };
 
 #endif /* GFX_XLIBSURFACE_H */