Bug 900133 - Support MaskLayers that are backed by a NewTextureHost. r=nical
authorMatt Woodrow <mwoodrow@mozilla.com>
Thu, 01 Aug 2013 21:12:16 -0400
changeset 153319 12adb590b761a7f1d5e01d6dfd566dc9803b7da8
parent 153318 e08e42b8435b515d3b20dd3b876ea6fc17b14279
child 153320 d623d68577ec83320fb4b63cf93e2a0f8c456550
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs900133
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 900133 - Support MaskLayers that are backed by a NewTextureHost. r=nical
gfx/layers/composite/CanvasLayerComposite.cpp
gfx/layers/composite/ColorLayerComposite.cpp
gfx/layers/composite/CompositableHost.cpp
gfx/layers/composite/CompositableHost.h
gfx/layers/composite/ContainerLayerComposite.cpp
gfx/layers/composite/ImageLayerComposite.cpp
gfx/layers/composite/LayerManagerComposite.cpp
gfx/layers/composite/LayerManagerComposite.h
gfx/layers/composite/ThebesLayerComposite.cpp
--- a/gfx/layers/composite/CanvasLayerComposite.cpp
+++ b/gfx/layers/composite/CanvasLayerComposite.cpp
@@ -88,16 +88,18 @@ CanvasLayerComposite::RenderLayer(const 
   gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height);
 
   mImageHost->Composite(effectChain,
                         GetEffectiveOpacity(),
                         transform,
                         gfx::Point(aOffset.x, aOffset.y),
                         gfx::ToFilter(filter),
                         clipRect);
+
+  LayerManagerComposite::RemoveMaskEffect(mMaskLayer);
 }
 
 CompositableHost*
 CanvasLayerComposite::GetCompositableHost() {
   return mImageHost.get();
 }
 
 void
--- a/gfx/layers/composite/ColorLayerComposite.cpp
+++ b/gfx/layers/composite/ColorLayerComposite.cpp
@@ -35,12 +35,13 @@ ColorLayerComposite::RenderLayer(const n
   ToMatrix4x4(GetEffectiveTransform(), transform);
 
   mCompositor->DrawQuad(rect, clipRect, effects, opacity,
                         transform, gfx::Point(aOffset.x, aOffset.y));
   mCompositor->DrawDiagnostics(gfx::Color(0.0, 1.0, 1.0, 1.0),
                                rect, clipRect,
                                transform, gfx::Point(aOffset.x, aOffset.y));
 
+  LayerManagerComposite::RemoveMaskEffect(GetMaskLayer());
 }
 
 } /* layers */
 } /* mozilla */
--- a/gfx/layers/composite/CompositableHost.cpp
+++ b/gfx/layers/composite/CompositableHost.cpp
@@ -99,31 +99,56 @@ CompositableHost::Update(const SurfaceDe
   return GetDeprecatedTextureHost()->IsValid();
 }
 
 bool
 CompositableHost::AddMaskEffect(EffectChain& aEffects,
                                 const gfx::Matrix4x4& aTransform,
                                 bool aIs3D)
 {
-  RefPtr<TextureSource> source = GetDeprecatedTextureHost();
+  RefPtr<TextureSource> source;
+  RefPtr<DeprecatedTextureHost> oldHost = GetDeprecatedTextureHost();
+  if (oldHost) {
+    oldHost->Lock();
+    source = oldHost;
+  } else {
+    RefPtr<TextureHost> host = GetTextureHost();
+    if (host) {
+      host->Lock();
+      source = host->GetTextureSources();
+    }
+  }
 
   if (!source) {
     NS_WARNING("Using compositable with no texture host as mask layer");
     return false;
   }
 
   RefPtr<EffectMask> effect = new EffectMask(source,
                                              source->GetSize(),
                                              aTransform);
   effect->mIs3D = aIs3D;
   aEffects.mSecondaryEffects[EFFECT_MASK] = effect;
   return true;
 }
 
+void
+CompositableHost::RemoveMaskEffect()
+{
+  RefPtr<DeprecatedTextureHost> oldHost = GetDeprecatedTextureHost();
+  if (oldHost) {
+    oldHost->Unlock();
+  } else {
+    RefPtr<TextureHost> host = GetTextureHost();
+    if (host) {
+      host->Unlock();
+    }
+  }
+}
+
 /* static */ TemporaryRef<CompositableHost>
 CompositableHost::Create(const TextureInfo& aTextureInfo)
 {
   RefPtr<CompositableHost> result;
   switch (aTextureInfo.mCompositableType) {
   case COMPOSITABLE_IMAGE:
     result = new ImageHost(aTextureInfo);
     return result;
--- a/gfx/layers/composite/CompositableHost.h
+++ b/gfx/layers/composite/CompositableHost.h
@@ -167,16 +167,18 @@ public:
   /**
    * Adds a mask effect using this texture as the mask, if possible.
    * @return true if the effect was added, false otherwise.
    */
   bool AddMaskEffect(EffectChain& aEffects,
                      const gfx::Matrix4x4& aTransform,
                      bool aIs3D = false);
 
+  void RemoveMaskEffect();
+
   Compositor* GetCompositor() const
   {
     return mCompositor;
   }
 
   Layer* GetLayer() const { return mLayer; }
   void SetLayer(Layer* aLayer) { mLayer = aLayer; }
 
--- a/gfx/layers/composite/ContainerLayerComposite.cpp
+++ b/gfx/layers/composite/ContainerLayerComposite.cpp
@@ -158,16 +158,18 @@ ContainerRender(ContainerT* aContainer,
     const FrameMetrics& frame = aContainer->GetFrameMetrics();
     LayerRect layerViewport = frame.mViewport * frame.LayersPixelsPerCSSPixel();
     gfx::Rect rect(layerViewport.x, layerViewport.y, layerViewport.width, layerViewport.height);
     gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height);
     aManager->GetCompositor()->DrawDiagnostics(gfx::Color(1.0, 0.0, 0.0, 1.0),
                                                rect, clipRect,
                                                transform, gfx::Point(aOffset.x, aOffset.y));
   }
+
+  LayerManagerComposite::RemoveMaskEffect(aContainer->GetMaskLayer());
 }
 
 ContainerLayerComposite::ContainerLayerComposite(LayerManagerComposite *aManager)
   : ContainerLayer(aManager, nullptr)
   , LayerComposite(aManager)
 {
   MOZ_COUNT_CTOR(ContainerLayerComposite);
   mImplData = static_cast<LayerComposite*>(this);
--- a/gfx/layers/composite/ImageLayerComposite.cpp
+++ b/gfx/layers/composite/ImageLayerComposite.cpp
@@ -91,16 +91,18 @@ ImageLayerComposite::RenderLayer(const n
   gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height);
   mImageHost->SetCompositor(mCompositor);
   mImageHost->Composite(effectChain,
                         GetEffectiveOpacity(),
                         transform,
                         gfx::Point(aOffset.x, aOffset.y),
                         gfx::ToFilter(mFilter),
                         clipRect);
+
+  LayerManagerComposite::RemoveMaskEffect(mMaskLayer);
 }
 
 void 
 ImageLayerComposite::ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
 {
   gfx3DMatrix local = GetLocalTransform();
 
   // Snap image edges to pixel boundaries
--- a/gfx/layers/composite/LayerManagerComposite.cpp
+++ b/gfx/layers/composite/LayerManagerComposite.cpp
@@ -656,16 +656,31 @@ LayerManagerComposite::AddMaskEffect(Lay
     return false;
   }
 
   gfx::Matrix4x4 transform;
   ToMatrix4x4(aMaskLayer->GetEffectiveTransform(), transform);
   return maskLayerComposite->GetCompositableHost()->AddMaskEffect(aEffects, transform, aIs3D);
 }
 
+/* static */ void
+LayerManagerComposite::RemoveMaskEffect(Layer* aMaskLayer)
+{
+  if (!aMaskLayer) {
+    return;
+  }
+  LayerComposite* maskLayerComposite = static_cast<LayerComposite*>(aMaskLayer->ImplData());
+  if (!maskLayerComposite->GetCompositableHost()) {
+    NS_WARNING("Mask layer with no compositable host");
+    return;
+  }
+
+  maskLayerComposite->GetCompositableHost()->RemoveMaskEffect();
+}
+
 TemporaryRef<DrawTarget>
 LayerManagerComposite::CreateDrawTarget(const IntSize &aSize,
                                         SurfaceFormat aFormat)
 {
 #ifdef XP_MACOSX
   // We don't want to accelerate if the surface is too small which indicates
   // that it's likely used for an icon/static image. We also don't want to
   // accelerate anything that is above the maximum texture size of weakest gpu.
--- a/gfx/layers/composite/LayerManagerComposite.h
+++ b/gfx/layers/composite/LayerManagerComposite.h
@@ -160,16 +160,18 @@ public:
    */
   void SetWorldTransform(const gfxMatrix& aMatrix);
   gfxMatrix& GetWorldTransform(void);
 
   static bool AddMaskEffect(Layer* aMaskLayer,
                             EffectChain& aEffect,
                             bool aIs3D = false);
 
+  static void RemoveMaskEffect(Layer* aMaskLayer);
+
   /**
    * Creates a DrawTarget which is optimized for inter-operating with this
    * layermanager.
    */
   virtual TemporaryRef<mozilla::gfx::DrawTarget>
     CreateDrawTarget(const mozilla::gfx::IntSize &aSize,
                      mozilla::gfx::SurfaceFormat aFormat) MOZ_OVERRIDE;
 
--- a/gfx/layers/composite/ThebesLayerComposite.cpp
+++ b/gfx/layers/composite/ThebesLayerComposite.cpp
@@ -135,16 +135,17 @@ ThebesLayerComposite::RenderLayer(const 
                      mRequiresTiledProperties ? &tiledLayerProps
                                               : nullptr);
 
 
   if (mRequiresTiledProperties) {
     mValidRegion = tiledLayerProps.mValidRegion;
   }
 
+  LayerManagerComposite::RemoveMaskEffect(mMaskLayer);
   mCompositeManager->GetCompositor()->MakeCurrent();
 }
 
 CompositableHost*
 ThebesLayerComposite::GetCompositableHost() {
   return mBuffer.get();
 }