Bug 1359842 - Use the StackingContextHelper for WebRenderContainerLayer as well. r=nical
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 27 Apr 2017 12:04:25 -0400
changeset 569624 f0d513a6709f8eca32780e60136dc655f548164c
parent 569623 007c9fb80cfa99da87b670f88e6f1a60e8c66326
child 569625 258e92719dfe752cce90b050ff4c479a68ee0f97
push id56240
push usermozilla@buttercookie.de
push dateThu, 27 Apr 2017 18:44:39 +0000
reviewersnical
bugs1359842
milestone55.0a1
Bug 1359842 - Use the StackingContextHelper for WebRenderContainerLayer as well. r=nical MozReview-Commit-ID: DXhhBB3qdzX
gfx/layers/wr/StackingContextHelper.cpp
gfx/layers/wr/StackingContextHelper.h
gfx/layers/wr/WebRenderContainerLayer.cpp
--- a/gfx/layers/wr/StackingContextHelper.cpp
+++ b/gfx/layers/wr/StackingContextHelper.cpp
@@ -20,16 +20,32 @@ StackingContextHelper::StackingContextHe
   gfx::Matrix4x4 transform = aTransform.valueOr(layer->GetTransform());
   mBuilder->PushStackingContext(wr::ToWrRect(scBounds),
                                 1.0f,
                                 transform,
                                 wr::ToWrMixBlendMode(layer->GetMixBlendMode()));
   mOrigin = aLayer->Bounds().TopLeft();
 }
 
+StackingContextHelper::StackingContextHelper(wr::DisplayListBuilder& aBuilder,
+                                             WebRenderLayer* aLayer,
+                                             uint64_t aAnimationsId,
+                                             float* aOpacityPtr,
+                                             gfx::Matrix4x4* aTransformPtr)
+  : mBuilder(&aBuilder)
+{
+  LayerRect scBounds = aLayer->RelativeToParent(aLayer->BoundsForStackingContext());
+  mBuilder->PushStackingContext(wr::ToWrRect(scBounds),
+                                aAnimationsId,
+                                aOpacityPtr,
+                                aTransformPtr,
+                                wr::ToWrMixBlendMode(aLayer->GetLayer()->GetMixBlendMode()));
+  mOrigin = aLayer->Bounds().TopLeft();
+}
+
 StackingContextHelper::~StackingContextHelper()
 {
   mBuilder->PopStackingContext();
 }
 
 WrRect
 StackingContextHelper::ToRelativeWrRect(const LayerRect& aRect)
 {
--- a/gfx/layers/wr/StackingContextHelper.h
+++ b/gfx/layers/wr/StackingContextHelper.h
@@ -26,16 +26,23 @@ class MOZ_RAII StackingContextHelper
 public:
   // Pushes a stacking context onto the provided DisplayListBuilder. It uses
   // the transform if provided, otherwise takes the transform from the layer.
   // It also takes the mix-blend-mode and bounds from the layer, and uses 1.0
   // for the opacity.
   StackingContextHelper(wr::DisplayListBuilder& aBuilder,
                         WebRenderLayer* aLayer,
                         const Maybe<gfx::Matrix4x4>& aTransform = Nothing());
+  // Alternate constructor which invokes the version of PushStackingContext
+  // for animations.
+  StackingContextHelper(wr::DisplayListBuilder& aBuilder,
+                        WebRenderLayer* aLayer,
+                        uint64_t aAnimationsId,
+                        float* aOpacityPtr,
+                        gfx::Matrix4x4* aTransformPtr);
   // Pops the stacking context
   ~StackingContextHelper();
 
   // When this StackingContextHelper is in scope, this function can be used
   // to convert a rect from the layer system's coordinate space to a WrRect
   // that is relative to the stacking context. This is useful because most
   // things that are pushed inside the stacking context need to be relative
   // to the stacking context.
--- a/gfx/layers/wr/WebRenderContainerLayer.cpp
+++ b/gfx/layers/wr/WebRenderContainerLayer.cpp
@@ -3,47 +3,33 @@
  * 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 "WebRenderContainerLayer.h"
 
 #include <inttypes.h>
 #include "gfxPrefs.h"
 #include "LayersLogging.h"
+#include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 #include "mozilla/webrender/WebRenderTypes.h"
 
 namespace mozilla {
 namespace layers {
 
 void
 WebRenderContainerLayer::RenderLayer(wr::DisplayListBuilder& aBuilder)
 {
   nsTArray<LayerPolygon> children = SortChildrenBy3DZOrder(SortMode::WITHOUT_GEOMETRY);
 
   gfx::Matrix4x4 transform = GetTransform();
   gfx::Matrix4x4* maybeTransform = &transform;
   float opacity = GetLocalOpacity();
   float* maybeOpacity = &opacity;
   uint64_t animationsId = 0;
-  LayerRect relBounds = GetWrRelBounds();
-  gfx::Rect clip(0, 0, relBounds.width, relBounds.height);
-
-  Maybe<WrImageMask> mask = BuildWrMaskLayer(true);
-
-  wr::MixBlendMode mixBlendMode = wr::ToWrMixBlendMode(GetMixBlendMode());
-
-  if (gfxPrefs::LayersDump()) {
-    printf_stderr("ContainerLayer %p using bounds=%s, clip=%s, transform=%s, mix-blend-mode=%s\n",
-                  this->GetLayer(),
-                  Stringify(relBounds).c_str(),
-                  Stringify(clip).c_str(),
-                  Stringify(transform).c_str(),
-                  Stringify(mixBlendMode).c_str());
-  }
 
   if (gfxPrefs::WebRenderOMTAEnabled() &&
       GetAnimations().Length()) {
     MOZ_ASSERT(GetCompositorAnimationsId());
 
     animationsId = GetCompositorAnimationsId();
     CompositorAnimations anim;
     anim.animations() = GetAnimations();
@@ -52,33 +38,32 @@ WebRenderContainerLayer::RenderLayer(wr:
 
     if (!HasOpacityAnimation()) {
       maybeOpacity = nullptr;
     }
     if (!HasTransformAnimation()) {
       maybeTransform = nullptr;
     }
   }
-  aBuilder.PushStackingContext(wr::ToWrRect(relBounds),
-                               animationsId,
-                               maybeOpacity,
-                               maybeTransform,
-                               mixBlendMode);
+
+  StackingContextHelper sc(aBuilder, this, animationsId, maybeOpacity, maybeTransform);
 
-  aBuilder.PushClip(wr::ToWrRect(clip),
-                    mask.ptrOr(nullptr));
+  LayerRect rect = Bounds();
+  DumpLayerInfo("ContainerLayer", rect);
+
+  Maybe<WrImageMask> mask = BuildWrMaskLayer(true);
+  aBuilder.PushClip(sc.ToRelativeWrRect(rect), mask.ptrOr(nullptr));
 
   for (LayerPolygon& child : children) {
     if (child.layer->IsBackfaceHidden()) {
       continue;
     }
     ToWebRenderLayer(child.layer)->RenderLayer(aBuilder);
   }
   aBuilder.PopClip();
-  aBuilder.PopStackingContext();
 }
 
 void
 WebRenderRefLayer::RenderLayer(wr::DisplayListBuilder& aBuilder)
 {
   gfx::Matrix4x4 transform;// = GetTransform();
   gfx::Rect relBounds = TransformedVisibleBoundsRelativeToParent();