Bug 1389138 - Introduce a variant type to allow unifying the clip and scroll ids. r=mstange draft
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 17 Aug 2017 11:06:31 -0400
changeset 648483 f2f80e89a400d5b9982d138b29e534701b247072
parent 648482 99f77b7629ab39e78316fc890ea3253ce51f8732
child 648484 677a92f918481a73877f551b9ac32975e0110be9
push id74768
push userkgupta@mozilla.com
push dateThu, 17 Aug 2017 20:14:33 +0000
reviewersmstange
bugs1389138
milestone57.0a1
Bug 1389138 - Introduce a variant type to allow unifying the clip and scroll ids. r=mstange This allows us to keep a single stack where we track both clip ids and scroll ids with the correct interleaving order that they were pushed in. MozReview-Commit-ID: DHHfR8JnnBw
gfx/layers/wr/ScrollingLayersHelper.cpp
gfx/layers/wr/ScrollingLayersHelper.h
gfx/webrender_bindings/WebRenderTypes.h
--- a/gfx/layers/wr/ScrollingLayersHelper.cpp
+++ b/gfx/layers/wr/ScrollingLayersHelper.cpp
@@ -16,17 +16,16 @@ namespace mozilla {
 namespace layers {
 
 ScrollingLayersHelper::ScrollingLayersHelper(WebRenderLayer* aLayer,
                                              wr::DisplayListBuilder& aBuilder,
                                              const StackingContextHelper& aStackingContext)
   : mLayer(aLayer)
   , mBuilder(&aBuilder)
   , mPushedLayerLocalClip(false)
-  , mClipsPushed(0)
 {
   if (!mLayer->WrManager()->AsyncPanZoomEnabled()) {
     // If APZ is disabled then we don't need to push the scrolling clips. We
     // still want to push the layer's local clip though.
     PushLayerLocalClip(aStackingContext);
     return;
   }
 
@@ -88,17 +87,16 @@ ScrollingLayersHelper::ScrollingLayersHe
 
 ScrollingLayersHelper::ScrollingLayersHelper(nsDisplayItem* aItem,
                                              wr::DisplayListBuilder& aBuilder,
                                              const StackingContextHelper& aStackingContext,
                                              WebRenderLayerManager::ClipIdMap& aCache)
   : mLayer(nullptr)
   , mBuilder(&aBuilder)
   , mPushedLayerLocalClip(false)
-  , mClipsPushed(0)
 {
   DefineAndPushChain(aItem->GetClipChain(), aBuilder, aStackingContext,
       aItem->Frame()->PresContext()->AppUnitsPerDevPixel(), aCache);
 }
 
 void
 ScrollingLayersHelper::DefineAndPushChain(const DisplayItemClipChain* aChain,
                                           wr::DisplayListBuilder& aBuilder,
@@ -133,17 +131,17 @@ ScrollingLayersHelper::DefineAndPushChai
     nsTArray<wr::WrComplexClipRegion> wrRoundedRects;
     aChain->mClip.ToWrComplexClipRegions(aAppUnitsPerDevPixel, aStackingContext, wrRoundedRects);
     clipId = Some(aBuilder.DefineClip(aStackingContext.ToRelativeLayoutRect(clip), &wrRoundedRects));
     aCache[aChain] = clipId.value();
   }
   // Finally, push the clip onto the WR stack
   MOZ_ASSERT(clipId);
   aBuilder.PushClip(clipId.value());
-  mClipsPushed++;
+  mPushedClips.push_back(wr::ScrollOrClipId(clipId.value()));
 }
 
 bool
 ScrollingLayersHelper::PushScrollLayer(const FrameMetrics& aMetrics,
                                        const StackingContextHelper& aStackingContext)
 {
   if (!aMetrics.IsScrollable()) {
     return false;
@@ -208,20 +206,22 @@ ScrollingLayersHelper::PushLayerClip(con
   }
   mBuilder->PushClip(mBuilder->DefineClip(
       aSc.ToRelativeLayoutRect(clipRect), nullptr, mask.ptrOr(nullptr)));
 }
 
 ScrollingLayersHelper::~ScrollingLayersHelper()
 {
   if (!mLayer) {
-    // For layers-free mode
-    while (mClipsPushed > 0) {
+    // For layers-free mode.
+    while (!mPushedClips.empty()) {
+      wr::ScrollOrClipId id = mPushedClips.back();
+      MOZ_ASSERT(id.is<wr::WrClipId>());
       mBuilder->PopClip();
-      mClipsPushed--;
+      mPushedClips.pop_back();
     }
     return;
   }
 
   Layer* layer = mLayer->GetLayer();
   if (!mLayer->WrManager()->AsyncPanZoomEnabled()) {
     if (mPushedLayerLocalClip) {
       mBuilder->PopClip();
--- a/gfx/layers/wr/ScrollingLayersHelper.h
+++ b/gfx/layers/wr/ScrollingLayersHelper.h
@@ -46,15 +46,15 @@ private:
                        const StackingContextHelper& aStackingContext);
   void PushLayerLocalClip(const StackingContextHelper& aStackingContext);
   void PushLayerClip(const LayerClip& aClip,
                      const StackingContextHelper& aSc);
 
   WebRenderLayer* mLayer;
   wr::DisplayListBuilder* mBuilder;
   bool mPushedLayerLocalClip;
-  int mClipsPushed;
+  std::vector<wr::ScrollOrClipId> mPushedClips;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif
--- a/gfx/webrender_bindings/WebRenderTypes.h
+++ b/gfx/webrender_bindings/WebRenderTypes.h
@@ -1,24 +1,26 @@
 /* -*- Mode: C++; tab-width: 2; 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 GFX_WEBRENDERTYPES_H
 #define GFX_WEBRENDERTYPES_H
 
+#include "FrameMetrics.h"
 #include "mozilla/webrender/webrender_ffi.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/gfx/Matrix.h"
 #include "mozilla/gfx/Types.h"
 #include "mozilla/gfx/Tools.h"
 #include "mozilla/layers/LayersTypes.h"
 #include "mozilla/PodOperations.h"
 #include "mozilla/Range.h"
+#include "mozilla/Variant.h"
 #include "Units.h"
 #include "RoundedRect.h"
 #include "nsStyleConsts.h"
 
 namespace mozilla {
 namespace wr {
 
 typedef wr::WrWindowId WindowId;
@@ -657,12 +659,14 @@ static inline wr::WrFilterOp ToWrFilterO
 struct WrClipId {
   uint64_t id;
 
   bool operator==(const WrClipId& other) const {
     return id == other.id;
   }
 };
 
+typedef Variant<layers::FrameMetrics::ViewID, WrClipId> ScrollOrClipId;
+
 } // namespace wr
 } // namespace mozilla
 
 #endif /* GFX_WEBRENDERTYPES_H */