Bug 973227 - Split up TextureHostX11 into TextureSource and TextureHost file, make it backend independent. r=nical
authorTom Schuster <evilpies@gmail.com>
Tue, 18 Feb 2014 01:30:05 +0100
changeset 180196 cd950a00e2cbf4728043adfb0099ff4361dc70cf
parent 180195 57f2c6e6895e2152a6d6b03870251ef28b26daf0
child 180197 5eeffd689732242c358c621b950aec456b0d1bb2
push id5439
push userffxbld
push dateMon, 17 Mar 2014 23:08:15 +0000
treeherdermozilla-aurora@c0befb3c8038 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs973227
milestone30.0a1
Bug 973227 - Split up TextureHostX11 into TextureSource and TextureHost file, make it backend independent. r=nical
gfx/layers/basic/TextureHostBasic.cpp
gfx/layers/basic/TextureHostX11.cpp
gfx/layers/basic/TextureHostX11.h
gfx/layers/basic/X11TextureSourceBasic.cpp
gfx/layers/basic/X11TextureSourceBasic.h
gfx/layers/composite/TextureHost.cpp
gfx/layers/composite/X11TextureHost.cpp
gfx/layers/composite/X11TextureHost.h
gfx/layers/moz.build
--- a/gfx/layers/basic/TextureHostBasic.cpp
+++ b/gfx/layers/basic/TextureHostBasic.cpp
@@ -1,17 +1,14 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * 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 "TextureHostBasic.h"
-#ifdef MOZ_X11
-#include "TextureHostX11.h"
-#endif
 #include "MacIOSurfaceTextureHostBasic.h"
 
 using namespace mozilla::gl;
 using namespace mozilla::gfx;
 
 namespace mozilla {
 namespace layers {
 
@@ -23,21 +20,13 @@ CreateTextureHostBasic(const SurfaceDesc
 #ifdef XP_MACOSX
   if (aDesc.type() == SurfaceDescriptor::TSurfaceDescriptorMacIOSurface) {
     const SurfaceDescriptorMacIOSurface& desc =
       aDesc.get_SurfaceDescriptorMacIOSurface();
     RefPtr<TextureHost> result = new MacIOSurfaceTextureHostBasic(aFlags, desc);
     return result;
   }
 #endif
-#ifdef MOZ_X11
-  if (aDesc.type() == SurfaceDescriptor::TSurfaceDescriptorX11) {
-    const SurfaceDescriptorX11& desc = aDesc.get_SurfaceDescriptorX11();
-    RefPtr<TextureHost> result = new TextureHostX11(aFlags, desc);
-    return result;
-  }
-#endif
-
   return CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
 }
 
 } // namespace layers
 } // namespace gfx
rename from gfx/layers/basic/TextureHostX11.cpp
rename to gfx/layers/basic/X11TextureSourceBasic.cpp
--- a/gfx/layers/basic/TextureHostX11.cpp
+++ b/gfx/layers/basic/X11TextureSourceBasic.cpp
@@ -1,111 +1,65 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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 "TextureHostX11.h"
+#include "X11TextureSourceBasic.h"
 #include "mozilla/layers/BasicCompositor.h"
 #include "gfxXlibSurface.h"
 #include "gfx2DGlue.h"
 
 using namespace mozilla;
 using namespace mozilla::layers;
 using namespace mozilla::gfx;
 
-static inline SurfaceFormat
-ContentTypeToSurfaceFormat(gfxContentType type)
+X11TextureSourceBasic::X11TextureSourceBasic(BasicCompositor* aCompositor, gfxXlibSurface* aSurface)
+  : mCompositor(aCompositor),
+    mSurface(aSurface)
+{
+}
+
+IntSize
+X11TextureSourceBasic::GetSize() const
+{
+  return ToIntSize(mSurface->GetSize());
+}
+
+SurfaceFormat
+X11TextureSourceBasic::GetFormat() const
 {
-  switch (type) {
+  gfxContentType type = mSurface->GetContentType();
+  return X11TextureSourceBasic::ContentTypeToSurfaceFormat(type);
+}
+
+SourceSurface*
+X11TextureSourceBasic::GetSurface()
+{
+  if (!mSourceSurface) {
+    mSourceSurface =
+      Factory::CreateSourceSurfaceForCairoSurface(mSurface->CairoSurface(), GetFormat());
+  }
+  return mSourceSurface;
+}
+
+void
+X11TextureSourceBasic::SetCompositor(Compositor* aCompositor)
+{
+  MOZ_ASSERT(aCompositor->GetBackendType() == LayersBackend::LAYERS_BASIC);
+  BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor);
+  mCompositor = compositor;
+}
+
+SurfaceFormat
+X11TextureSourceBasic::ContentTypeToSurfaceFormat(gfxContentType aType)
+{
+  switch (aType) {
     case gfxContentType::COLOR:
       return SurfaceFormat::B8G8R8X8;
     case gfxContentType::ALPHA:
       return SurfaceFormat::A8;
     case gfxContentType::COLOR_ALPHA:
       return SurfaceFormat::B8G8R8A8;
     default:
       return SurfaceFormat::UNKNOWN;
   }
-}
-
-TextureSourceX11::TextureSourceX11(BasicCompositor* aCompositor, gfxXlibSurface* aSurface)
-  : mCompositor(aCompositor),
-    mSurface(aSurface)
-{
-}
-
-IntSize
-TextureSourceX11::GetSize() const
-{
-  return ToIntSize(mSurface->GetSize());
-}
-
-SurfaceFormat
-TextureSourceX11::GetFormat() const
-{
-  return ContentTypeToSurfaceFormat(mSurface->GetContentType());
-}
-
-SourceSurface*
-TextureSourceX11::GetSurface()
-{
-  if (!mSourceSurface) {
-    mSourceSurface =
-      Factory::CreateSourceSurfaceForCairoSurface(mSurface->CairoSurface(), GetFormat());
-  }
-  return mSourceSurface;
-}
-
-void
-TextureSourceX11::SetCompositor(Compositor* aCompositor)
-{
-  BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor);
-  mCompositor = compositor;
-}
-
-TextureHostX11::TextureHostX11(TextureFlags aFlags,
-                               const SurfaceDescriptorX11& aDescriptor)
- : TextureHost(aFlags)
-{
-  nsRefPtr<gfxXlibSurface> surface = aDescriptor.OpenForeign();
-  mSurface = surface.get();
-
-  // The host always frees the pixmap.
-  MOZ_ASSERT(!(aFlags & TEXTURE_DEALLOCATE_CLIENT));
-  mSurface->TakePixmap();
-}
-
-bool
-TextureHostX11::Lock()
-{
-  if (!mCompositor) {
-    return false;
-  }
-
-  if (!mTextureSource) {
-    mTextureSource = new TextureSourceX11(mCompositor, mSurface);
-  }
-
-  return true;
-}
-
-void
-TextureHostX11::SetCompositor(Compositor* aCompositor)
-{
-  BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor);
-  mCompositor = compositor;
-  if (mTextureSource) {
-    mTextureSource->SetCompositor(compositor);
-  }
-}
-
-SurfaceFormat
-TextureHostX11::GetFormat() const
-{
-  return ContentTypeToSurfaceFormat(mSurface->GetContentType());
-}
-
-IntSize
-TextureHostX11::GetSize() const
-{
-  return ToIntSize(mSurface->GetSize());
-}
+}
\ No newline at end of file
rename from gfx/layers/basic/TextureHostX11.h
rename to gfx/layers/basic/X11TextureSourceBasic.h
--- a/gfx/layers/basic/TextureHostX11.h
+++ b/gfx/layers/basic/X11TextureSourceBasic.h
@@ -1,76 +1,46 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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_TEXTUREHOSTX11__H
-#define MOZILLA_GFX_TEXTUREHOSTX11__H
+#ifndef MOZILLA_GFX_X11TEXTURESOURCEBASIC__H
+#define MOZILLA_GFX_X11TEXTURESOURCEBASIC__H
 
 #include "mozilla/layers/TextureHostBasic.h"
 #include "mozilla/gfx/2D.h"
 
 namespace mozilla {
 namespace layers {
 
 class BasicCompositor;
 
 // TextureSource for Xlib-backed surfaces.
-class TextureSourceX11
+class X11TextureSourceBasic
   : public TextureSourceBasic,
     public NewTextureSource
 {
 public:
-  TextureSourceX11(BasicCompositor* aCompositor, gfxXlibSurface* aSurface);
+  X11TextureSourceBasic(BasicCompositor* aCompositor, gfxXlibSurface* aSurface);
 
-  virtual TextureSourceX11* AsSourceBasic() MOZ_OVERRIDE { return this; }
+  virtual X11TextureSourceBasic* AsSourceBasic() MOZ_OVERRIDE { return this; }
 
   virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
   virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
   virtual gfx::SourceSurface* GetSurface() MOZ_OVERRIDE;
 
   virtual void DeallocateDeviceData() MOZ_OVERRIDE { }
 
   virtual void SetCompositor(Compositor* aCompositor);
 
+  static gfx::SurfaceFormat ContentTypeToSurfaceFormat(gfxContentType aType);
+
 protected:
   BasicCompositor* mCompositor;
   RefPtr<gfxXlibSurface> mSurface;
   RefPtr<gfx::SourceSurface> mSourceSurface;
 };
 
-// TextureSource for Xlib-backed TextureSources.
-class TextureHostX11 : public TextureHost
-{
-public:
-  TextureHostX11(TextureFlags aFlags,
-                 const SurfaceDescriptorX11& aDescriptor);
-
-  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
-  virtual bool Lock() MOZ_OVERRIDE;
-  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
-  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
-
-  virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
-  {
-    return mTextureSource;
-  }
-
-  virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
-  {
-    return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
-  }
-
-#ifdef MOZ_LAYERS_HAVE_LOG
-  virtual const char* Name() { return "TextureHostX11"; }
-#endif
-
-protected:
-  BasicCompositor* mCompositor;
-  RefPtr<TextureSourceX11> mTextureSource;
-  RefPtr<gfxXlibSurface> mSurface;
-};
-
 } // namespace layers
 } // namespace mozilla
 
-#endif // MOZILLA_GFX_TEXTUREHOSTX11__H
+#endif // MOZILLA_GFX_X11TEXTURESOURCEBASIC__H
--- a/gfx/layers/composite/TextureHost.cpp
+++ b/gfx/layers/composite/TextureHost.cpp
@@ -9,16 +9,19 @@
 #include "gfx2DGlue.h"                  // for ToIntSize
 #include "gfxImageSurface.h"            // for gfxImageSurface
 #include "mozilla/gfx/2D.h"             // for DataSourceSurface, Factory
 #include "mozilla/ipc/Shmem.h"          // for Shmem
 #include "mozilla/layers/Compositor.h"  // for Compositor
 #include "mozilla/layers/ISurfaceAllocator.h"  // for ISurfaceAllocator
 #include "mozilla/layers/ImageDataSerializer.h"
 #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor, etc
+#ifdef MOZ_X11
+#include "mozilla/layers/X11TextureHost.h"
+#endif
 #include "mozilla/layers/YCbCrImageDataSerializer.h"
 #include "nsAString.h"
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsPrintfCString.h"            // for nsPrintfCString
 #include "mozilla/layers/PTextureParent.h"
 
 struct nsIntPoint;
 
@@ -178,18 +181,21 @@ TextureHost::Create(const SurfaceDescrip
       return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
     case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface:
       if (Compositor::GetBackend() == LayersBackend::LAYERS_OPENGL) {
         return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
       } else {
         return CreateTextureHostBasic(aDesc, aDeallocator, aFlags);
       }
 #ifdef MOZ_X11
-    case SurfaceDescriptor::TSurfaceDescriptorX11:
-      return CreateTextureHostBasic(aDesc, aDeallocator, aFlags);
+    case SurfaceDescriptor::TSurfaceDescriptorX11: {
+      const SurfaceDescriptorX11& desc = aDesc.get_SurfaceDescriptorX11();
+      RefPtr<TextureHost> result = new X11TextureHost(aFlags, desc);
+      return result;
+    }
 #endif
 #ifdef XP_WIN
     case SurfaceDescriptor::TSurfaceDescriptorD3D9:
     case SurfaceDescriptor::TSurfaceDescriptorDIB:
       return CreateTextureHostD3D9(aDesc, aDeallocator, aFlags);
     case SurfaceDescriptor::TSurfaceDescriptorD3D10:
       return CreateTextureHostD3D11(aDesc, aDeallocator, aFlags);
 #endif
copy from gfx/layers/basic/TextureHostX11.cpp
copy to gfx/layers/composite/X11TextureHost.cpp
--- a/gfx/layers/basic/TextureHostX11.cpp
+++ b/gfx/layers/composite/X11TextureHost.cpp
@@ -1,111 +1,69 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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 "TextureHostX11.h"
+#include "X11TextureHost.h"
 #include "mozilla/layers/BasicCompositor.h"
+#include "mozilla/layers/X11TextureSourceBasic.h"
 #include "gfxXlibSurface.h"
 #include "gfx2DGlue.h"
 
 using namespace mozilla;
 using namespace mozilla::layers;
 using namespace mozilla::gfx;
 
-static inline SurfaceFormat
-ContentTypeToSurfaceFormat(gfxContentType type)
-{
-  switch (type) {
-    case gfxContentType::COLOR:
-      return SurfaceFormat::B8G8R8X8;
-    case gfxContentType::ALPHA:
-      return SurfaceFormat::A8;
-    case gfxContentType::COLOR_ALPHA:
-      return SurfaceFormat::B8G8R8A8;
-    default:
-      return SurfaceFormat::UNKNOWN;
-  }
-}
-
-TextureSourceX11::TextureSourceX11(BasicCompositor* aCompositor, gfxXlibSurface* aSurface)
-  : mCompositor(aCompositor),
-    mSurface(aSurface)
-{
-}
-
-IntSize
-TextureSourceX11::GetSize() const
-{
-  return ToIntSize(mSurface->GetSize());
-}
-
-SurfaceFormat
-TextureSourceX11::GetFormat() const
-{
-  return ContentTypeToSurfaceFormat(mSurface->GetContentType());
-}
-
-SourceSurface*
-TextureSourceX11::GetSurface()
-{
-  if (!mSourceSurface) {
-    mSourceSurface =
-      Factory::CreateSourceSurfaceForCairoSurface(mSurface->CairoSurface(), GetFormat());
-  }
-  return mSourceSurface;
-}
-
-void
-TextureSourceX11::SetCompositor(Compositor* aCompositor)
-{
-  BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor);
-  mCompositor = compositor;
-}
-
-TextureHostX11::TextureHostX11(TextureFlags aFlags,
+X11TextureHost::X11TextureHost(TextureFlags aFlags,
                                const SurfaceDescriptorX11& aDescriptor)
  : TextureHost(aFlags)
 {
   nsRefPtr<gfxXlibSurface> surface = aDescriptor.OpenForeign();
   mSurface = surface.get();
 
   // The host always frees the pixmap.
   MOZ_ASSERT(!(aFlags & TEXTURE_DEALLOCATE_CLIENT));
   mSurface->TakePixmap();
 }
 
 bool
-TextureHostX11::Lock()
+X11TextureHost::Lock()
 {
   if (!mCompositor) {
     return false;
   }
 
   if (!mTextureSource) {
-    mTextureSource = new TextureSourceX11(mCompositor, mSurface);
+    switch (mCompositor->GetBackendType()) {
+      case LayersBackend::LAYERS_BASIC:
+        mTextureSource =
+          new X11TextureSourceBasic(static_cast<BasicCompositor*>(mCompositor),
+                                    mSurface);
+        break;
+      default:
+        return false;
+    }
   }
 
   return true;
 }
 
 void
-TextureHostX11::SetCompositor(Compositor* aCompositor)
+X11TextureHost::SetCompositor(Compositor* aCompositor)
 {
-  BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor);
-  mCompositor = compositor;
+  mCompositor = aCompositor;
   if (mTextureSource) {
-    mTextureSource->SetCompositor(compositor);
+    mTextureSource->SetCompositor(aCompositor);
   }
 }
 
 SurfaceFormat
-TextureHostX11::GetFormat() const
+X11TextureHost::GetFormat() const
 {
-  return ContentTypeToSurfaceFormat(mSurface->GetContentType());
+  return X11TextureSourceBasic::ContentTypeToSurfaceFormat(mSurface->GetContentType());
 }
 
 IntSize
-TextureHostX11::GetSize() const
+X11TextureHost::GetSize() const
 {
   return ToIntSize(mSurface->GetSize());
 }
copy from gfx/layers/basic/TextureHostX11.h
copy to gfx/layers/composite/X11TextureHost.h
--- a/gfx/layers/basic/TextureHostX11.h
+++ b/gfx/layers/composite/X11TextureHost.h
@@ -1,53 +1,30 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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_TEXTUREHOSTX11__H
-#define MOZILLA_GFX_TEXTUREHOSTX11__H
+#ifndef MOZILLA_GFX_X11TEXTUREHOST__H
+#define MOZILLA_GFX_X11TEXTUREHOST__H
 
-#include "mozilla/layers/TextureHostBasic.h"
+#include "mozilla/layers/TextureHost.h"
+#include "mozilla/layers/LayersSurfaces.h"
 #include "mozilla/gfx/2D.h"
 
+class gfxXlibSurface;
+
 namespace mozilla {
 namespace layers {
 
-class BasicCompositor;
-
-// TextureSource for Xlib-backed surfaces.
-class TextureSourceX11
-  : public TextureSourceBasic,
-    public NewTextureSource
+// TextureSource for Xlib-backed TextureSources.
+class X11TextureHost : public TextureHost
 {
 public:
-  TextureSourceX11(BasicCompositor* aCompositor, gfxXlibSurface* aSurface);
-
-  virtual TextureSourceX11* AsSourceBasic() MOZ_OVERRIDE { return this; }
-
-  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
-  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
-  virtual gfx::SourceSurface* GetSurface() MOZ_OVERRIDE;
-
-  virtual void DeallocateDeviceData() MOZ_OVERRIDE { }
-
-  virtual void SetCompositor(Compositor* aCompositor);
-
-protected:
-  BasicCompositor* mCompositor;
-  RefPtr<gfxXlibSurface> mSurface;
-  RefPtr<gfx::SourceSurface> mSourceSurface;
-};
-
-// TextureSource for Xlib-backed TextureSources.
-class TextureHostX11 : public TextureHost
-{
-public:
-  TextureHostX11(TextureFlags aFlags,
+  X11TextureHost(TextureFlags aFlags,
                  const SurfaceDescriptorX11& aDescriptor);
 
   virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
   virtual bool Lock() MOZ_OVERRIDE;
   virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
   virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
 
   virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
@@ -56,21 +33,21 @@ public:
   }
 
   virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
   {
     return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
   }
 
 #ifdef MOZ_LAYERS_HAVE_LOG
-  virtual const char* Name() { return "TextureHostX11"; }
+  virtual const char* Name() { return "X11TextureHost"; }
 #endif
 
 protected:
-  BasicCompositor* mCompositor;
-  RefPtr<TextureSourceX11> mTextureSource;
+  Compositor* mCompositor;
+  RefPtr<NewTextureSource> mTextureSource;
   RefPtr<gfxXlibSurface> mSurface;
 };
 
 } // namespace layers
 } // namespace mozilla
 
-#endif // MOZILLA_GFX_TEXTUREHOSTX11__H
+#endif // MOZILLA_GFX_X11TEXTUREHOST__H
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -153,23 +153,25 @@ EXPORTS.mozilla.layers += [
     'opengl/TextureHostOGL.h',
     'RenderTrace.h',
     'YCbCrImageDataSerializer.h',
 ]
 
 if CONFIG['MOZ_X11']:
     EXPORTS.mozilla.layers += [
         'basic/TextureClientX11.h',
-        'basic/TextureHostX11.h',
+        'basic/X11TextureSourceBasic.h',
+        'composite/X11TextureHost.h',
         'ipc/ShadowLayerUtilsX11.h',
     ]
     SOURCES += [
         'basic/TextureClientX11.cpp',
-        'basic/TextureHostX11.cpp',
-        'ipc/ShadowLayerUtilsX11.cpp'
+        'basic/X11TextureSourceBasic.cpp',
+        'composite/X11TextureHost.cpp',
+        'ipc/ShadowLayerUtilsX11.cpp',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     EXPORTS.mozilla.layers += [
         'opengl/GLManager.h',
     ]
     EXPORTS += [
         'MacIOSurfaceImage.h',