2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-09-04 15:30:57 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "ActiveLayerTracker.h"
|
|
|
|
|
2017-02-09 05:28:47 +03:00
|
|
|
#include "mozilla/AnimationUtils.h"
|
2015-04-06 05:53:51 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2020-02-26 20:52:02 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2015-07-20 05:30:37 +03:00
|
|
|
#include "mozilla/gfx/Matrix.h"
|
2015-12-04 02:32:53 +03:00
|
|
|
#include "mozilla/EffectSet.h"
|
2019-10-31 23:07:28 +03:00
|
|
|
#include "mozilla/MotionPathUtils.h"
|
2015-10-21 17:25:09 +03:00
|
|
|
#include "mozilla/PodOperations.h"
|
2021-10-02 21:59:11 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2015-09-10 13:24:34 +03:00
|
|
|
#include "gfx2DGlue.h"
|
2013-09-04 15:30:57 +04:00
|
|
|
#include "nsExpirationTracker.h"
|
2014-05-25 02:20:39 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2013-09-04 15:30:57 +04:00
|
|
|
#include "nsIContent.h"
|
2013-09-04 15:47:23 +04:00
|
|
|
#include "nsRefreshDriver.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2013-12-12 00:48:06 +04:00
|
|
|
#include "nsAnimationManager.h"
|
2015-07-20 05:30:37 +03:00
|
|
|
#include "nsStyleTransformMatrix.h"
|
2013-12-12 00:48:06 +04:00
|
|
|
#include "nsTransitionManager.h"
|
2014-10-22 05:54:32 +04:00
|
|
|
#include "nsDisplayList.h"
|
2016-02-12 17:38:50 +03:00
|
|
|
#include "nsDOMCSSDeclaration.h"
|
2020-10-01 00:05:34 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2013-09-04 15:30:57 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-07-20 05:30:37 +03:00
|
|
|
using namespace gfx;
|
|
|
|
|
2013-09-04 15:30:57 +04:00
|
|
|
/**
|
|
|
|
* This tracks the state of a frame that may need active layers due to
|
|
|
|
* ongoing content changes or style changes that indicate animation.
|
|
|
|
*
|
|
|
|
* When no changes of *any* kind are detected after 75-100ms we remove this
|
|
|
|
* object. Because we only track all kinds of activity with a single
|
|
|
|
* nsExpirationTracker, it's possible a frame might remain active somewhat
|
|
|
|
* spuriously if different kinds of changes kept happening, but that almost
|
|
|
|
* certainly doesn't matter.
|
|
|
|
*/
|
2018-09-04 23:46:21 +03:00
|
|
|
class LayerActivity {
|
2013-09-04 15:30:57 +04:00
|
|
|
public:
|
2018-09-04 23:46:21 +03:00
|
|
|
enum ActivityIndex {
|
2015-10-21 17:25:09 +03:00
|
|
|
ACTIVITY_OPACITY,
|
|
|
|
ACTIVITY_TRANSFORM,
|
|
|
|
|
|
|
|
ACTIVITY_SCALE,
|
2018-06-07 21:44:03 +03:00
|
|
|
ACTIVITY_TRIGGERED_REPAINT,
|
2015-10-21 17:25:09 +03:00
|
|
|
|
|
|
|
// keep as last item
|
|
|
|
ACTIVITY_COUNT
|
|
|
|
};
|
|
|
|
|
2022-01-26 14:39:13 +03:00
|
|
|
explicit LayerActivity(nsIFrame* aFrame) : mFrame(aFrame), mContent(nullptr) {
|
2015-10-21 17:25:09 +03:00
|
|
|
PodArrayZero(mRestyleCounts);
|
|
|
|
}
|
2013-09-04 15:30:57 +04:00
|
|
|
~LayerActivity();
|
|
|
|
nsExpirationState* GetExpirationState() { return &mState; }
|
2016-08-17 04:37:48 +03:00
|
|
|
uint8_t& RestyleCountForProperty(nsCSSPropertyID aProperty) {
|
2015-10-21 17:25:09 +03:00
|
|
|
return mRestyleCounts[GetActivityIndexForProperty(aProperty)];
|
|
|
|
}
|
|
|
|
|
2016-08-17 04:37:48 +03:00
|
|
|
static ActivityIndex GetActivityIndexForProperty(nsCSSPropertyID aProperty) {
|
2013-09-04 15:30:57 +04:00
|
|
|
switch (aProperty) {
|
2018-09-04 23:46:21 +03:00
|
|
|
case eCSSProperty_opacity:
|
|
|
|
return ACTIVITY_OPACITY;
|
|
|
|
case eCSSProperty_transform:
|
2019-02-23 03:21:45 +03:00
|
|
|
case eCSSProperty_translate:
|
|
|
|
case eCSSProperty_rotate:
|
|
|
|
case eCSSProperty_scale:
|
2019-10-31 23:07:45 +03:00
|
|
|
case eCSSProperty_offset_path:
|
|
|
|
case eCSSProperty_offset_distance:
|
|
|
|
case eCSSProperty_offset_rotate:
|
|
|
|
case eCSSProperty_offset_anchor:
|
|
|
|
// TODO: Bug 1559232: Add offset-position.
|
2018-09-04 23:46:21 +03:00
|
|
|
return ACTIVITY_TRANSFORM;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return ACTIVITY_OPACITY;
|
2013-09-04 15:30:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-23 03:21:45 +03:00
|
|
|
static ActivityIndex GetActivityIndexForPropertySet(
|
|
|
|
const nsCSSPropertyIDSet& aPropertySet) {
|
2019-03-02 00:13:07 +03:00
|
|
|
if (aPropertySet.IsSubsetOf(
|
|
|
|
nsCSSPropertyIDSet::TransformLikeProperties())) {
|
2019-02-23 03:21:45 +03:00
|
|
|
return ACTIVITY_TRANSFORM;
|
|
|
|
}
|
2019-03-02 00:13:07 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
aPropertySet.IsSubsetOf(nsCSSPropertyIDSet::OpacityProperties()));
|
2019-02-23 03:21:45 +03:00
|
|
|
return ACTIVITY_OPACITY;
|
|
|
|
}
|
|
|
|
|
2014-05-13 21:30:11 +04:00
|
|
|
// While tracked, exactly one of mFrame or mContent is non-null, depending
|
|
|
|
// on whether this property is stored on a frame or on a content node.
|
|
|
|
// When this property is expired by the layer activity tracker, both mFrame
|
|
|
|
// and mContent are nulled-out and the property is deleted.
|
2013-09-04 15:30:57 +04:00
|
|
|
nsIFrame* mFrame;
|
2014-05-13 21:30:11 +04:00
|
|
|
nsIContent* mContent;
|
|
|
|
|
2013-09-04 15:30:57 +04:00
|
|
|
nsExpirationState mState;
|
2015-07-20 05:30:37 +03:00
|
|
|
|
|
|
|
// Previous scale due to the CSS transform property.
|
2017-11-13 02:37:33 +03:00
|
|
|
Maybe<Size> mPreviousTransformScale;
|
2015-07-20 05:30:37 +03:00
|
|
|
|
2013-09-04 15:30:57 +04:00
|
|
|
// Number of restyle operations detected
|
2015-10-21 17:25:09 +03:00
|
|
|
uint8_t mRestyleCounts[ACTIVITY_COUNT];
|
2013-09-04 15:30:57 +04:00
|
|
|
};
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
class LayerActivityTracker final
|
|
|
|
: public nsExpirationTracker<LayerActivity, 4> {
|
2013-09-04 15:30:57 +04:00
|
|
|
public:
|
|
|
|
// 75-100ms is a good timeout period. We use 4 generations of 25ms each.
|
2018-09-04 23:46:21 +03:00
|
|
|
enum { GENERATION_MS = 100 };
|
|
|
|
|
2017-04-09 11:53:56 +03:00
|
|
|
explicit LayerActivityTracker(nsIEventTarget* aEventTarget)
|
2018-09-04 23:46:21 +03:00
|
|
|
: nsExpirationTracker<LayerActivity, 4>(
|
2022-01-25 02:39:07 +03:00
|
|
|
GENERATION_MS, "LayerActivityTracker", aEventTarget) {}
|
2022-01-31 20:00:21 +03:00
|
|
|
~LayerActivityTracker() override { AgeAllGenerations(); }
|
2013-09-04 15:30:57 +04:00
|
|
|
|
2018-09-04 23:45:55 +03:00
|
|
|
void NotifyExpired(LayerActivity* aObject) override;
|
2013-09-04 15:30:57 +04:00
|
|
|
};
|
|
|
|
|
2021-10-02 21:59:11 +03:00
|
|
|
static StaticAutoPtr<LayerActivityTracker> gLayerActivityTracker;
|
2013-09-04 15:30:57 +04:00
|
|
|
|
|
|
|
LayerActivity::~LayerActivity() {
|
2014-05-13 21:30:11 +04:00
|
|
|
if (mFrame || mContent) {
|
2013-09-04 15:30:57 +04:00
|
|
|
NS_ASSERTION(gLayerActivityTracker, "Should still have a tracker");
|
|
|
|
gLayerActivityTracker->RemoveObject(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 04:08:41 +04:00
|
|
|
// Frames with this property have NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY set
|
2016-01-28 06:23:59 +03:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(LayerActivityProperty, LayerActivity)
|
2013-09-04 15:30:57 +04:00
|
|
|
|
|
|
|
void LayerActivityTracker::NotifyExpired(LayerActivity* aObject) {
|
|
|
|
RemoveObject(aObject);
|
|
|
|
|
|
|
|
nsIFrame* f = aObject->mFrame;
|
2014-05-13 21:30:11 +04:00
|
|
|
nsIContent* c = aObject->mContent;
|
2013-09-04 15:30:57 +04:00
|
|
|
aObject->mFrame = nullptr;
|
2014-05-13 21:30:11 +04:00
|
|
|
aObject->mContent = nullptr;
|
|
|
|
|
|
|
|
MOZ_ASSERT((f == nullptr) != (c == nullptr),
|
2018-09-04 23:46:21 +03:00
|
|
|
"A LayerActivity object should always have a reference to either "
|
|
|
|
"its frame or its content");
|
2013-09-04 15:30:57 +04:00
|
|
|
|
2014-05-13 21:30:11 +04:00
|
|
|
if (f) {
|
|
|
|
f->RemoveStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY);
|
2020-02-06 19:06:49 +03:00
|
|
|
f->RemoveProperty(LayerActivityProperty());
|
2014-05-13 21:30:11 +04:00
|
|
|
} else {
|
2020-02-06 19:06:49 +03:00
|
|
|
c->RemoveProperty(nsGkAtoms::LayerActivity);
|
2014-02-10 06:14:38 +04:00
|
|
|
}
|
2013-09-04 15:30:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static LayerActivity* GetLayerActivity(nsIFrame* aFrame) {
|
2013-09-10 04:08:41 +04:00
|
|
|
if (!aFrame->HasAnyStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-05-27 14:36:00 +03:00
|
|
|
return aFrame->GetProperty(LayerActivityProperty());
|
2013-09-04 15:30:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static LayerActivity* GetLayerActivityForUpdate(nsIFrame* aFrame) {
|
2017-05-28 13:22:39 +03:00
|
|
|
LayerActivity* layerActivity = GetLayerActivity(aFrame);
|
2013-09-04 15:30:57 +04:00
|
|
|
if (layerActivity) {
|
|
|
|
gLayerActivityTracker->MarkUsed(layerActivity);
|
|
|
|
} else {
|
|
|
|
if (!gLayerActivityTracker) {
|
2020-04-07 18:17:07 +03:00
|
|
|
gLayerActivityTracker =
|
|
|
|
new LayerActivityTracker(GetMainThreadSerialEventTarget());
|
2013-09-04 15:30:57 +04:00
|
|
|
}
|
|
|
|
layerActivity = new LayerActivity(aFrame);
|
|
|
|
gLayerActivityTracker->AddObject(layerActivity);
|
2013-09-10 04:08:41 +04:00
|
|
|
aFrame->AddStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY);
|
2017-05-27 14:36:00 +03:00
|
|
|
aFrame->SetProperty(LayerActivityProperty(), layerActivity);
|
2013-09-04 15:30:57 +04:00
|
|
|
}
|
|
|
|
return layerActivity;
|
|
|
|
}
|
|
|
|
|
2013-09-10 04:08:41 +04:00
|
|
|
static void IncrementMutationCount(uint8_t* aCount) {
|
|
|
|
*aCount = uint8_t(std::min(0xFF, *aCount + 1));
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void ActiveLayerTracker::TransferActivityToContent(nsIFrame* aFrame,
|
|
|
|
nsIContent* aContent) {
|
2014-05-13 21:30:11 +04:00
|
|
|
if (!aFrame->HasAnyStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY)) {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-06 03:13:38 +03:00
|
|
|
LayerActivity* layerActivity = aFrame->TakeProperty(LayerActivityProperty());
|
2014-05-13 21:30:11 +04:00
|
|
|
aFrame->RemoveStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY);
|
|
|
|
if (!layerActivity) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
layerActivity->mFrame = nullptr;
|
|
|
|
layerActivity->mContent = aContent;
|
2018-09-04 23:46:21 +03:00
|
|
|
aContent->SetProperty(nsGkAtoms::LayerActivity, layerActivity,
|
|
|
|
nsINode::DeleteProperty<LayerActivity>, true);
|
2014-05-13 21:30:11 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void ActiveLayerTracker::TransferActivityToFrame(nsIContent* aContent,
|
|
|
|
nsIFrame* aFrame) {
|
2020-02-06 01:26:20 +03:00
|
|
|
auto* layerActivity = static_cast<LayerActivity*>(
|
|
|
|
aContent->TakeProperty(nsGkAtoms::LayerActivity));
|
2014-05-13 21:30:11 +04:00
|
|
|
if (!layerActivity) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
layerActivity->mContent = nullptr;
|
|
|
|
layerActivity->mFrame = aFrame;
|
|
|
|
aFrame->AddStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY);
|
2017-05-27 14:36:00 +03:00
|
|
|
aFrame->SetProperty(LayerActivityProperty(), layerActivity);
|
2014-05-13 21:30:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-20 05:30:37 +03:00
|
|
|
static void IncrementScaleRestyleCountIfNeeded(nsIFrame* aFrame,
|
|
|
|
LayerActivity* aActivity) {
|
|
|
|
const nsStyleDisplay* display = aFrame->StyleDisplay();
|
2019-05-17 02:25:10 +03:00
|
|
|
if (!display->HasTransformProperty() && !display->HasIndividualTransform() &&
|
2019-05-21 02:42:50 +03:00
|
|
|
display->mOffsetPath.IsNone()) {
|
2015-07-20 05:30:37 +03:00
|
|
|
// The transform was removed.
|
|
|
|
aActivity->mPreviousTransformScale = Nothing();
|
2018-08-08 04:07:01 +03:00
|
|
|
IncrementMutationCount(
|
|
|
|
&aActivity->mRestyleCounts[LayerActivity::ACTIVITY_SCALE]);
|
2015-07-20 05:30:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the new scale due to the CSS transform property.
|
2019-11-12 02:31:23 +03:00
|
|
|
// Note: Motion path doesn't contribute to scale factor. (It only has 2d
|
|
|
|
// translate and 2d rotate, so we use Nothing() for it.)
|
2015-07-20 05:30:37 +03:00
|
|
|
nsStyleTransformMatrix::TransformReferenceBox refBox(aFrame);
|
2018-08-08 04:07:01 +03:00
|
|
|
Matrix4x4 transform = nsStyleTransformMatrix::ReadTransforms(
|
2019-11-12 02:31:23 +03:00
|
|
|
display->mTranslate, display->mRotate, display->mScale, Nothing(),
|
|
|
|
display->mTransform, refBox, AppUnitsPerCSSPixel());
|
2015-07-20 05:30:37 +03:00
|
|
|
Matrix transform2D;
|
|
|
|
if (!transform.Is2D(&transform2D)) {
|
|
|
|
// We don't attempt to handle 3D transforms; just assume the scale changed.
|
|
|
|
aActivity->mPreviousTransformScale = Nothing();
|
2018-09-04 23:46:21 +03:00
|
|
|
IncrementMutationCount(
|
|
|
|
&aActivity->mRestyleCounts[LayerActivity::ACTIVITY_SCALE]);
|
2015-07-20 05:30:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-18 21:53:01 +03:00
|
|
|
Size scale = transform2D.ScaleFactors();
|
2015-07-20 05:30:37 +03:00
|
|
|
if (aActivity->mPreviousTransformScale == Some(scale)) {
|
2018-09-04 23:46:21 +03:00
|
|
|
return; // Nothing changed.
|
2015-07-20 05:30:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
aActivity->mPreviousTransformScale = Some(scale);
|
2018-09-04 23:46:21 +03:00
|
|
|
IncrementMutationCount(
|
|
|
|
&aActivity->mRestyleCounts[LayerActivity::ACTIVITY_SCALE]);
|
2015-07-20 05:30:37 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void ActiveLayerTracker::NotifyRestyle(nsIFrame* aFrame,
|
|
|
|
nsCSSPropertyID aProperty) {
|
2013-09-04 15:30:57 +04:00
|
|
|
LayerActivity* layerActivity = GetLayerActivityForUpdate(aFrame);
|
|
|
|
uint8_t& mutationCount = layerActivity->RestyleCountForProperty(aProperty);
|
2013-09-10 04:08:41 +04:00
|
|
|
IncrementMutationCount(&mutationCount);
|
2015-07-20 05:30:37 +03:00
|
|
|
|
2019-02-23 03:21:45 +03:00
|
|
|
if (nsCSSPropertyIDSet::TransformLikeProperties().HasProperty(aProperty)) {
|
2015-07-20 05:30:37 +03:00
|
|
|
IncrementScaleRestyleCountIfNeeded(aFrame, layerActivity);
|
|
|
|
}
|
2013-09-10 04:08:41 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void ActiveLayerTracker::NotifyAnimated(nsIFrame* aFrame,
|
|
|
|
nsCSSPropertyID aProperty,
|
2020-01-04 13:36:49 +03:00
|
|
|
const nsACString& aNewValue,
|
2019-02-26 01:09:24 +03:00
|
|
|
nsDOMCSSDeclaration* aDOMCSSDecl) {
|
2013-09-04 15:30:57 +04:00
|
|
|
LayerActivity* layerActivity = GetLayerActivityForUpdate(aFrame);
|
|
|
|
uint8_t& mutationCount = layerActivity->RestyleCountForProperty(aProperty);
|
2016-02-12 17:38:50 +03:00
|
|
|
if (mutationCount != 0xFF) {
|
2020-12-17 17:04:35 +03:00
|
|
|
nsAutoCString oldValue;
|
2016-02-12 17:38:50 +03:00
|
|
|
aDOMCSSDecl->GetPropertyValue(aProperty, oldValue);
|
2020-12-17 17:04:35 +03:00
|
|
|
if (oldValue != aNewValue) {
|
2016-02-12 17:38:50 +03:00
|
|
|
// We know this is animated, so just hack the mutation count.
|
|
|
|
mutationCount = 0xFF;
|
|
|
|
}
|
|
|
|
}
|
2013-09-04 15:30:57 +04:00
|
|
|
}
|
|
|
|
|
2013-09-04 15:47:23 +04:00
|
|
|
static bool IsPresContextInScriptAnimationCallback(
|
|
|
|
nsPresContext* aPresContext) {
|
|
|
|
if (aPresContext->RefreshDriver()->IsInRefresh()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Treat timeouts/setintervals as scripted animation callbacks for our
|
|
|
|
// purposes.
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* win = aPresContext->Document()->GetInnerWindow();
|
2013-09-04 15:47:23 +04:00
|
|
|
return win && win->IsRunningTimeout();
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void ActiveLayerTracker::NotifyInlineStyleRuleModified(
|
2020-01-04 13:36:49 +03:00
|
|
|
nsIFrame* aFrame, nsCSSPropertyID aProperty, const nsACString& aNewValue,
|
2018-09-04 23:46:21 +03:00
|
|
|
nsDOMCSSDeclaration* aDOMCSSDecl) {
|
2015-10-30 18:28:53 +03:00
|
|
|
if (IsPresContextInScriptAnimationCallback(aFrame->PresContext())) {
|
2016-02-12 17:38:50 +03:00
|
|
|
NotifyAnimated(aFrame, aProperty, aNewValue, aDOMCSSDecl);
|
2015-10-30 18:28:53 +03:00
|
|
|
}
|
2013-09-04 15:47:23 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void ActiveLayerTracker::NotifyNeedsRepaint(nsIFrame* aFrame) {
|
2018-06-07 21:44:03 +03:00
|
|
|
LayerActivity* layerActivity = GetLayerActivityForUpdate(aFrame);
|
|
|
|
if (IsPresContextInScriptAnimationCallback(aFrame->PresContext())) {
|
2018-09-04 23:46:21 +03:00
|
|
|
// This is mirroring NotifyInlineStyleRuleModified's NotifyAnimated logic.
|
|
|
|
// Just max out the restyle count if we're in an animation callback.
|
|
|
|
layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_TRIGGERED_REPAINT] =
|
|
|
|
0xFF;
|
2018-06-07 21:44:03 +03:00
|
|
|
} else {
|
2018-09-04 23:46:21 +03:00
|
|
|
IncrementMutationCount(
|
|
|
|
&layerActivity
|
|
|
|
->mRestyleCounts[LayerActivity::ACTIVITY_TRIGGERED_REPAINT]);
|
2018-06-07 21:44:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 23:17:07 +03:00
|
|
|
static bool IsMotionPathAnimated(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame) {
|
|
|
|
return ActiveLayerTracker::IsStyleAnimated(
|
|
|
|
aBuilder, aFrame, nsCSSPropertyIDSet{eCSSProperty_offset_path}) ||
|
|
|
|
(!aFrame->StyleDisplay()->mOffsetPath.IsNone() &&
|
|
|
|
ActiveLayerTracker::IsStyleAnimated(
|
|
|
|
aBuilder, aFrame,
|
|
|
|
nsCSSPropertyIDSet{eCSSProperty_offset_distance,
|
|
|
|
eCSSProperty_offset_rotate,
|
|
|
|
eCSSProperty_offset_anchor}));
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
bool ActiveLayerTracker::IsTransformAnimated(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame) {
|
2019-02-23 03:21:45 +03:00
|
|
|
return IsStyleAnimated(aBuilder, aFrame,
|
2019-11-06 23:17:07 +03:00
|
|
|
nsCSSPropertyIDSet::CSSTransformProperties()) ||
|
|
|
|
IsMotionPathAnimated(aBuilder, aFrame);
|
2019-02-23 03:21:45 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
bool ActiveLayerTracker::IsTransformMaybeAnimated(nsIFrame* aFrame) {
|
2019-02-23 03:21:45 +03:00
|
|
|
return IsStyleAnimated(nullptr, aFrame,
|
2019-11-06 23:17:07 +03:00
|
|
|
nsCSSPropertyIDSet::CSSTransformProperties()) ||
|
|
|
|
IsMotionPathAnimated(nullptr, aFrame);
|
2019-02-23 03:21:45 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
bool ActiveLayerTracker::IsStyleAnimated(
|
2014-10-22 05:54:32 +04:00
|
|
|
nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
2019-02-23 03:21:45 +03:00
|
|
|
const nsCSSPropertyIDSet& aPropertySet) {
|
|
|
|
MOZ_ASSERT(
|
2019-03-02 00:13:07 +03:00
|
|
|
aPropertySet.IsSubsetOf(nsCSSPropertyIDSet::TransformLikeProperties()) ||
|
|
|
|
aPropertySet.IsSubsetOf(nsCSSPropertyIDSet::OpacityProperties()),
|
2019-02-23 03:21:45 +03:00
|
|
|
"Only subset of opacity or transform-like properties set calls this");
|
|
|
|
|
2019-03-18 07:09:35 +03:00
|
|
|
// For display:table content, transforms are applied to the table wrapper
|
|
|
|
// (primary frame) but their will-change style will be specified on the style
|
|
|
|
// frame and, unlike other transform properties, not inherited.
|
|
|
|
// As a result, for transform properties only we need to be careful to look up
|
|
|
|
// the will-change style on the _style_ frame.
|
|
|
|
const nsIFrame* styleFrame = nsLayoutUtils::GetStyleFrame(aFrame);
|
2019-02-23 03:21:45 +03:00
|
|
|
const nsCSSPropertyIDSet transformSet =
|
|
|
|
nsCSSPropertyIDSet::TransformLikeProperties();
|
2019-05-17 02:23:28 +03:00
|
|
|
if ((styleFrame && (styleFrame->StyleDisplay()->mWillChange.bits &
|
2019-12-09 06:32:28 +03:00
|
|
|
StyleWillChangeBits::TRANSFORM)) &&
|
2019-02-23 03:21:45 +03:00
|
|
|
aPropertySet.Intersects(transformSet) &&
|
2018-09-04 23:46:21 +03:00
|
|
|
(!aBuilder ||
|
|
|
|
aBuilder->IsInWillChangeBudget(aFrame, aFrame->GetSize()))) {
|
2013-11-22 22:14:34 +04:00
|
|
|
return true;
|
|
|
|
}
|
2019-05-17 02:23:28 +03:00
|
|
|
if ((aFrame->StyleDisplay()->mWillChange.bits &
|
2019-12-09 06:32:28 +03:00
|
|
|
StyleWillChangeBits::OPACITY) &&
|
2019-02-23 03:21:45 +03:00
|
|
|
aPropertySet.Intersects(nsCSSPropertyIDSet::OpacityProperties()) &&
|
2018-09-04 23:46:21 +03:00
|
|
|
(!aBuilder ||
|
|
|
|
aBuilder->IsInWillChangeBudget(aFrame, aFrame->GetSize()))) {
|
2022-02-03 18:48:33 +03:00
|
|
|
return !StaticPrefs::gfx_will_change_ignore_opacity();
|
2013-11-22 22:14:34 +04:00
|
|
|
}
|
|
|
|
|
2013-09-04 15:30:57 +04:00
|
|
|
LayerActivity* layerActivity = GetLayerActivity(aFrame);
|
|
|
|
if (layerActivity) {
|
2018-09-04 23:46:21 +03:00
|
|
|
LayerActivity::ActivityIndex activityIndex =
|
2019-02-23 03:21:45 +03:00
|
|
|
LayerActivity::GetActivityIndexForPropertySet(aPropertySet);
|
2018-06-14 19:24:34 +03:00
|
|
|
if (layerActivity->mRestyleCounts[activityIndex] >= 2) {
|
|
|
|
// If the frame needs to be repainted frequently, we probably don't get
|
|
|
|
// much from treating the property as animated, *unless* this frame's
|
|
|
|
// 'scale' (which includes the bounds changes of a rotation) is changing.
|
|
|
|
// Marking a scaling transform as animating allows us to avoid resizing
|
|
|
|
// the texture, even if we have to repaint the contents of that texture.
|
2018-09-04 23:46:21 +03:00
|
|
|
if (layerActivity
|
|
|
|
->mRestyleCounts[LayerActivity::ACTIVITY_TRIGGERED_REPAINT] <
|
|
|
|
2 ||
|
2019-02-23 03:21:45 +03:00
|
|
|
(aPropertySet.Intersects(transformSet) &&
|
2018-09-04 23:46:21 +03:00
|
|
|
IsScaleSubjectToAnimation(aFrame))) {
|
2018-06-14 19:24:34 +03:00
|
|
|
return true;
|
|
|
|
}
|
2015-10-30 18:28:53 +03:00
|
|
|
}
|
2013-09-04 15:30:57 +04:00
|
|
|
}
|
2019-12-23 12:52:43 +03:00
|
|
|
|
|
|
|
if (nsLayoutUtils::HasEffectiveAnimation(aFrame, aPropertySet)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aPropertySet.Intersects(transformSet) ||
|
|
|
|
!aFrame->Combines3DTransformWithAncestors()) {
|
|
|
|
return false;
|
2013-09-04 15:30:57 +04:00
|
|
|
}
|
2019-12-23 12:52:43 +03:00
|
|
|
|
|
|
|
// For preserve-3d, we check if there is any transform animation on its parent
|
|
|
|
// frames in the 3d rendering context. If there is one, this function will
|
|
|
|
// return true.
|
|
|
|
return IsStyleAnimated(aBuilder, aFrame->GetParent(), aPropertySet);
|
2013-09-04 15:30:57 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
bool ActiveLayerTracker::IsScaleSubjectToAnimation(nsIFrame* aFrame) {
|
2015-07-20 05:30:40 +03:00
|
|
|
// Check whether JavaScript is animating this frame's scale.
|
|
|
|
LayerActivity* layerActivity = GetLayerActivity(aFrame);
|
2018-09-04 23:46:21 +03:00
|
|
|
if (layerActivity &&
|
|
|
|
layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_SCALE] >= 2) {
|
2015-07-20 05:30:40 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-03-18 07:12:10 +03:00
|
|
|
return AnimationUtils::FrameHasAnimatedScale(aFrame);
|
2015-07-20 05:30:40 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
2021-10-02 21:59:11 +03:00
|
|
|
void ActiveLayerTracker::Shutdown() { gLayerActivityTracker = nullptr; }
|
2013-09-04 15:30:57 +04:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|