Bug 1359842 - Use the StackingContextHelper for WebRenderContainerLayer as well. r?nical draft
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 26 Apr 2017 16:37:17 -0400
changeset 568975 d2ee3c4f7d03db2c63d3440ccfe627270c0ed916
parent 568974 2a87c0e57690892498f96bd0543ae99870dcfa1d
child 568976 6614a1e8f1419d653c9b3e0c635702fd85b2e6f6
push id56034
push userkgupta@mozilla.com
push dateWed, 26 Apr 2017 20:37:45 +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
@@ -19,31 +19,16 @@ WebRenderContainerLayer::RenderLayer(wr:
 {
   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 +37,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();