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
--- 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 */