Bug 1364525 - Ensure all scroll thumbs have an animations id. r?pchang
In order to have the scrollbar thumbs reflect the async scroll position, we're
going to re-use the API for OMTA. That is, we set an animation id on the
stacking context for the scroll thumb, and we'll update the transform on the
stacking context at composite time based on the async scroll position. For this
to work we need to ensure that the scroll thumb does in fact have an
animation id set on it.
MozReview-Commit-ID: 7kLJ0AYFEq7
--- a/gfx/layers/Layers.cpp
+++ b/gfx/layers/Layers.cpp
@@ -200,24 +200,30 @@ Layer::Layer(LayerManager* aManager, voi
mAnimationGeneration(0)
{
}
Layer::~Layer()
{
}
+void
+Layer::EnsureAnimationsId()
+{
+ if (!mCompositorAnimationsId) {
+ mCompositorAnimationsId = AnimationHelper::GetNextCompositorAnimationsId();
+ }
+}
+
Animation*
Layer::AddAnimation()
{
// Here generates a new id when the first animation is added and
// this id is used to represent the animations in this layer.
- if (!mCompositorAnimationsId) {
- mCompositorAnimationsId = AnimationHelper::GetNextCompositorAnimationsId();
- }
+ EnsureAnimationsId();
MOZ_LAYERS_LOG_IF_SHADOWABLE(
this, ("Layer::Mutated(%p) AddAnimation with id=%" PRIu64, this, mCompositorAnimationsId));
MOZ_ASSERT(!mPendingAnimations, "should have called ClearAnimations first");
Animation* anim = mAnimations.AppendElement();
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -1218,16 +1218,19 @@ public:
void SetTransformIsPerspective(bool aTransformIsPerspective)
{
if (mSimpleAttrs.SetTransformIsPerspective(aTransformIsPerspective)) {
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) TransformIsPerspective", this));
MutatedSimple();
}
}
+ // Ensure that this layer has a valid (non-zero) animations id. This value is
+ // unique across layers.
+ void EnsureAnimationsId();
// Call AddAnimation to add a new animation to this layer from layout code.
// Caller must fill in all the properties of the returned animation.
// A later animation overrides an earlier one.
Animation* AddAnimation();
// ClearAnimations clears animations on this layer.
virtual void ClearAnimations();
// This is only called when the layer tree is updated. Do not call this from
// layout code. To add an animation to this layer, use AddAnimation.
--- a/gfx/layers/wr/WebRenderContainerLayer.cpp
+++ b/gfx/layers/wr/WebRenderContainerLayer.cpp
@@ -85,16 +85,33 @@ WebRenderContainerLayer::RenderLayer(wr:
animationsId = GetCompositorAnimationsId();
OpAddCompositorAnimations
anim(CompositorAnimations(GetAnimations(), animationsId),
transformForCompositor, opacityForCompositor);
WrBridge()->AddWebRenderParentCommand(anim);
}
+ // If APZ is enabled and this layer is a scroll thumb, then it might need
+ // to move in the compositor to represent the async scroll position. So we
+ // ensure that there is an animations id set on it, we will use this to give
+ // WebRender updated transforms for composition.
+ if (WrManager()->AsyncPanZoomEnabled() &&
+ GetScrollThumbData().mDirection != ScrollDirection::NONE) {
+ // A scroll thumb better not have a transform animation already or we're
+ // going to end up clobbering it with APZ animating it too.
+ MOZ_ASSERT(transformForSC);
+
+ EnsureAnimationsId();
+ animationsId = GetCompositorAnimationsId();
+ // We need to set the transform in the stacking context to null for it to
+ // pick up and install the animation id.
+ transformForSC = nullptr;
+ }
+
ScrollingLayersHelper scroller(this, aBuilder, aSc);
StackingContextHelper sc(aSc, aBuilder, this, animationsId, opacityForSC, transformForSC);
LayerRect rect = Bounds();
DumpLayerInfo("ContainerLayer", rect);
Maybe<WrImageMask> mask = BuildWrMaskLayer(&sc);
aBuilder.PushClip(sc.ToRelativeWrRect(rect), mask.ptrOr(nullptr));