2013-09-04 11:30:57 +00: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"
|
|
|
|
|
2015-04-06 02:53:51 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2016-09-04 07:34:21 +00:00
|
|
|
#include "mozilla/dom/KeyframeEffectReadOnly.h"
|
2015-07-20 02:30:37 +00:00
|
|
|
#include "mozilla/gfx/Matrix.h"
|
2015-12-03 23:32:53 +00:00
|
|
|
#include "mozilla/EffectSet.h"
|
2015-10-21 14:25:09 +00:00
|
|
|
#include "mozilla/PodOperations.h"
|
2015-09-10 10:24:34 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2013-09-04 11:30:57 +00:00
|
|
|
#include "nsExpirationTracker.h"
|
2014-05-24 22:20:39 +00:00
|
|
|
#include "nsContainerFrame.h"
|
2013-09-04 11:30:57 +00:00
|
|
|
#include "nsIContent.h"
|
2013-09-04 11:47:23 +00:00
|
|
|
#include "nsRefreshDriver.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIDocument.h"
|
2013-12-11 20:48:06 +00:00
|
|
|
#include "nsAnimationManager.h"
|
2015-07-20 02:30:37 +00:00
|
|
|
#include "nsStyleTransformMatrix.h"
|
2013-12-11 20:48:06 +00:00
|
|
|
#include "nsTransitionManager.h"
|
2014-10-22 01:54:32 +00:00
|
|
|
#include "nsDisplayList.h"
|
2016-02-12 14:38:50 +00:00
|
|
|
#include "nsDOMCSSDeclaration.h"
|
2013-09-04 11:30:57 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-07-20 02:30:37 +00:00
|
|
|
using namespace gfx;
|
|
|
|
|
2013-09-04 11:30:57 +00: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.
|
|
|
|
*/
|
|
|
|
class LayerActivity {
|
|
|
|
public:
|
2015-10-21 14:25:09 +00:00
|
|
|
enum ActivityIndex {
|
|
|
|
ACTIVITY_OPACITY,
|
|
|
|
ACTIVITY_TRANSFORM,
|
|
|
|
ACTIVITY_LEFT,
|
|
|
|
ACTIVITY_TOP,
|
|
|
|
ACTIVITY_RIGHT,
|
|
|
|
ACTIVITY_BOTTOM,
|
|
|
|
ACTIVITY_MARGIN_LEFT,
|
|
|
|
ACTIVITY_MARGIN_TOP,
|
|
|
|
ACTIVITY_MARGIN_RIGHT,
|
|
|
|
ACTIVITY_MARGIN_BOTTOM,
|
|
|
|
ACTIVITY_BACKGROUND_POSITION,
|
|
|
|
|
|
|
|
ACTIVITY_SCALE,
|
|
|
|
|
|
|
|
// keep as last item
|
|
|
|
ACTIVITY_COUNT
|
|
|
|
};
|
|
|
|
|
2014-09-01 03:36:37 +00:00
|
|
|
explicit LayerActivity(nsIFrame* aFrame)
|
2013-09-04 11:30:57 +00:00
|
|
|
: mFrame(aFrame)
|
2014-05-13 17:30:11 +00:00
|
|
|
, mContent(nullptr)
|
2013-09-04 11:30:57 +00:00
|
|
|
, mContentActive(false)
|
2015-10-21 14:25:09 +00:00
|
|
|
{
|
|
|
|
PodArrayZero(mRestyleCounts);
|
|
|
|
}
|
2013-09-04 11:30:57 +00:00
|
|
|
~LayerActivity();
|
|
|
|
nsExpirationState* GetExpirationState() { return &mState; }
|
2016-08-17 01:37:48 +00:00
|
|
|
uint8_t& RestyleCountForProperty(nsCSSPropertyID aProperty)
|
2015-10-21 14:25:09 +00:00
|
|
|
{
|
|
|
|
return mRestyleCounts[GetActivityIndexForProperty(aProperty)];
|
|
|
|
}
|
|
|
|
|
2016-08-17 01:37:48 +00:00
|
|
|
static ActivityIndex GetActivityIndexForProperty(nsCSSPropertyID aProperty)
|
2013-09-04 11:30:57 +00:00
|
|
|
{
|
|
|
|
switch (aProperty) {
|
2015-10-21 14:25:09 +00:00
|
|
|
case eCSSProperty_opacity: return ACTIVITY_OPACITY;
|
|
|
|
case eCSSProperty_transform: return ACTIVITY_TRANSFORM;
|
|
|
|
case eCSSProperty_left: return ACTIVITY_LEFT;
|
|
|
|
case eCSSProperty_top: return ACTIVITY_TOP;
|
|
|
|
case eCSSProperty_right: return ACTIVITY_RIGHT;
|
|
|
|
case eCSSProperty_bottom: return ACTIVITY_BOTTOM;
|
|
|
|
case eCSSProperty_margin_left: return ACTIVITY_MARGIN_LEFT;
|
|
|
|
case eCSSProperty_margin_top: return ACTIVITY_MARGIN_TOP;
|
|
|
|
case eCSSProperty_margin_right: return ACTIVITY_MARGIN_RIGHT;
|
|
|
|
case eCSSProperty_margin_bottom: return ACTIVITY_MARGIN_BOTTOM;
|
|
|
|
case eCSSProperty_background_position: return ACTIVITY_BACKGROUND_POSITION;
|
2016-04-21 03:34:46 +00:00
|
|
|
case eCSSProperty_background_position_x: return ACTIVITY_BACKGROUND_POSITION;
|
|
|
|
case eCSSProperty_background_position_y: return ACTIVITY_BACKGROUND_POSITION;
|
2015-10-21 14:25:09 +00:00
|
|
|
default: MOZ_ASSERT(false); return ACTIVITY_OPACITY;
|
2013-09-04 11:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-13 17:30:11 +00: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 11:30:57 +00:00
|
|
|
nsIFrame* mFrame;
|
2014-05-13 17:30:11 +00:00
|
|
|
nsIContent* mContent;
|
|
|
|
|
2013-09-04 11:30:57 +00:00
|
|
|
nsExpirationState mState;
|
2015-07-20 02:30:37 +00:00
|
|
|
|
|
|
|
// Previous scale due to the CSS transform property.
|
|
|
|
Maybe<gfxSize> mPreviousTransformScale;
|
|
|
|
|
2015-10-30 15:28:53 +00:00
|
|
|
// The scroll frame during for which we most recently received a call to
|
|
|
|
// NotifyAnimatedFromScrollHandler.
|
|
|
|
nsWeakFrame mAnimatingScrollHandlerFrame;
|
|
|
|
// The set of activities that were triggered during
|
|
|
|
// mAnimatingScrollHandlerFrame's scroll event handler.
|
|
|
|
EnumSet<ActivityIndex> mScrollHandlerInducedActivity;
|
|
|
|
|
2013-09-04 11:30:57 +00:00
|
|
|
// Number of restyle operations detected
|
2015-10-21 14:25:09 +00:00
|
|
|
uint8_t mRestyleCounts[ACTIVITY_COUNT];
|
2013-09-04 11:30:57 +00:00
|
|
|
bool mContentActive;
|
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class LayerActivityTracker final : public nsExpirationTracker<LayerActivity,4> {
|
2013-09-04 11:30:57 +00:00
|
|
|
public:
|
|
|
|
// 75-100ms is a good timeout period. We use 4 generations of 25ms each.
|
|
|
|
enum { GENERATION_MS = 100 };
|
|
|
|
LayerActivityTracker()
|
2015-09-10 04:07:07 +00:00
|
|
|
: nsExpirationTracker<LayerActivity,4>(GENERATION_MS,
|
|
|
|
"LayerActivityTracker")
|
2015-10-30 15:28:53 +00:00
|
|
|
, mDestroying(false)
|
2015-09-10 04:07:07 +00:00
|
|
|
{}
|
2013-09-04 11:30:57 +00:00
|
|
|
~LayerActivityTracker() {
|
2015-10-30 15:28:53 +00:00
|
|
|
mDestroying = true;
|
2013-09-04 11:30:57 +00:00
|
|
|
AgeAllGenerations();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void NotifyExpired(LayerActivity* aObject);
|
2015-10-30 15:28:53 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
nsWeakFrame mCurrentScrollHandlerFrame;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mDestroying;
|
2013-09-04 11:30:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static LayerActivityTracker* gLayerActivityTracker = nullptr;
|
|
|
|
|
|
|
|
LayerActivity::~LayerActivity()
|
|
|
|
{
|
2014-05-13 17:30:11 +00:00
|
|
|
if (mFrame || mContent) {
|
2013-09-04 11:30:57 +00:00
|
|
|
NS_ASSERTION(gLayerActivityTracker, "Should still have a tracker");
|
|
|
|
gLayerActivityTracker->RemoveObject(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 00:08:41 +00:00
|
|
|
// Frames with this property have NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY set
|
2016-01-28 03:23:59 +00:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(LayerActivityProperty, LayerActivity)
|
2013-09-04 11:30:57 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
LayerActivityTracker::NotifyExpired(LayerActivity* aObject)
|
|
|
|
{
|
2015-10-30 15:28:53 +00:00
|
|
|
if (!mDestroying && aObject->mAnimatingScrollHandlerFrame.IsAlive()) {
|
|
|
|
// Reset the restyle counts, but let the layer activity survive.
|
|
|
|
PodArrayZero(aObject->mRestyleCounts);
|
|
|
|
MarkUsed(aObject);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-04 11:30:57 +00:00
|
|
|
RemoveObject(aObject);
|
|
|
|
|
|
|
|
nsIFrame* f = aObject->mFrame;
|
2014-05-13 17:30:11 +00:00
|
|
|
nsIContent* c = aObject->mContent;
|
2013-09-04 11:30:57 +00:00
|
|
|
aObject->mFrame = nullptr;
|
2014-05-13 17:30:11 +00:00
|
|
|
aObject->mContent = nullptr;
|
|
|
|
|
|
|
|
MOZ_ASSERT((f == nullptr) != (c == nullptr),
|
|
|
|
"A LayerActivity object should always have a reference to either its frame or its content");
|
2013-09-04 11:30:57 +00:00
|
|
|
|
2014-05-13 17:30:11 +00:00
|
|
|
if (f) {
|
|
|
|
// The pres context might have been detached during the delay -
|
|
|
|
// that's fine, just skip the paint.
|
|
|
|
if (f->PresContext()->GetContainerWeak()) {
|
|
|
|
f->SchedulePaint();
|
|
|
|
}
|
|
|
|
f->RemoveStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY);
|
|
|
|
f->Properties().Delete(LayerActivityProperty());
|
|
|
|
} else {
|
|
|
|
c->DeleteProperty(nsGkAtoms::LayerActivity);
|
2014-02-10 02:14:38 +00:00
|
|
|
}
|
2013-09-04 11:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static LayerActivity*
|
|
|
|
GetLayerActivity(nsIFrame* aFrame)
|
|
|
|
{
|
2013-09-10 00:08:41 +00:00
|
|
|
if (!aFrame->HasAnyStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-09-04 11:30:57 +00:00
|
|
|
FrameProperties properties = aFrame->Properties();
|
2016-01-28 03:23:59 +00:00
|
|
|
return properties.Get(LayerActivityProperty());
|
2013-09-04 11:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static LayerActivity*
|
|
|
|
GetLayerActivityForUpdate(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
FrameProperties properties = aFrame->Properties();
|
2016-01-28 03:23:59 +00:00
|
|
|
LayerActivity* layerActivity = properties.Get(LayerActivityProperty());
|
2013-09-04 11:30:57 +00:00
|
|
|
if (layerActivity) {
|
|
|
|
gLayerActivityTracker->MarkUsed(layerActivity);
|
|
|
|
} else {
|
|
|
|
if (!gLayerActivityTracker) {
|
|
|
|
gLayerActivityTracker = new LayerActivityTracker();
|
|
|
|
}
|
|
|
|
layerActivity = new LayerActivity(aFrame);
|
|
|
|
gLayerActivityTracker->AddObject(layerActivity);
|
2013-09-10 00:08:41 +00:00
|
|
|
aFrame->AddStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY);
|
2013-09-04 11:30:57 +00:00
|
|
|
properties.Set(LayerActivityProperty(), layerActivity);
|
|
|
|
}
|
|
|
|
return layerActivity;
|
|
|
|
}
|
|
|
|
|
2013-09-10 00:08:41 +00:00
|
|
|
static void
|
|
|
|
IncrementMutationCount(uint8_t* aCount)
|
|
|
|
{
|
|
|
|
*aCount = uint8_t(std::min(0xFF, *aCount + 1));
|
|
|
|
}
|
|
|
|
|
2014-05-13 17:30:11 +00:00
|
|
|
/* static */ void
|
|
|
|
ActiveLayerTracker::TransferActivityToContent(nsIFrame* aFrame, nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (!aFrame->HasAnyStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FrameProperties properties = aFrame->Properties();
|
2016-01-28 03:23:59 +00:00
|
|
|
LayerActivity* layerActivity = properties.Remove(LayerActivityProperty());
|
2014-05-13 17:30:11 +00:00
|
|
|
aFrame->RemoveStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY);
|
|
|
|
if (!layerActivity) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
layerActivity->mFrame = nullptr;
|
|
|
|
layerActivity->mContent = aContent;
|
|
|
|
aContent->SetProperty(nsGkAtoms::LayerActivity, layerActivity,
|
|
|
|
nsINode::DeleteProperty<LayerActivity>, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
ActiveLayerTracker::TransferActivityToFrame(nsIContent* aContent, nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
LayerActivity* layerActivity = static_cast<LayerActivity*>(
|
|
|
|
aContent->UnsetProperty(nsGkAtoms::LayerActivity));
|
|
|
|
if (!layerActivity) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
layerActivity->mContent = nullptr;
|
|
|
|
layerActivity->mFrame = aFrame;
|
|
|
|
aFrame->AddStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY);
|
|
|
|
aFrame->Properties().Set(LayerActivityProperty(), layerActivity);
|
|
|
|
}
|
|
|
|
|
2015-07-20 02:30:37 +00:00
|
|
|
static void
|
|
|
|
IncrementScaleRestyleCountIfNeeded(nsIFrame* aFrame, LayerActivity* aActivity)
|
|
|
|
{
|
|
|
|
const nsStyleDisplay* display = aFrame->StyleDisplay();
|
|
|
|
if (!display->mSpecifiedTransform) {
|
|
|
|
// The transform was removed.
|
|
|
|
aActivity->mPreviousTransformScale = Nothing();
|
2015-10-21 14:25:09 +00:00
|
|
|
IncrementMutationCount(&aActivity->mRestyleCounts[LayerActivity::ACTIVITY_SCALE]);
|
2015-07-20 02:30:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the new scale due to the CSS transform property.
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
RuleNodeCacheConditions dummy;
|
2016-02-02 00:45:09 +00:00
|
|
|
bool dummyBool;
|
2015-07-20 02:30:37 +00:00
|
|
|
nsStyleTransformMatrix::TransformReferenceBox refBox(aFrame);
|
2015-07-11 00:05:47 +00:00
|
|
|
Matrix4x4 transform =
|
2015-07-20 02:30:37 +00:00
|
|
|
nsStyleTransformMatrix::ReadTransforms(display->mSpecifiedTransform->mHead,
|
|
|
|
aFrame->StyleContext(),
|
|
|
|
presContext,
|
|
|
|
dummy, refBox,
|
2016-02-02 00:45:09 +00:00
|
|
|
presContext->AppUnitsPerCSSPixel(),
|
|
|
|
&dummyBool);
|
2015-07-20 02:30:37 +00:00
|
|
|
Matrix transform2D;
|
|
|
|
if (!transform.Is2D(&transform2D)) {
|
|
|
|
// We don't attempt to handle 3D transforms; just assume the scale changed.
|
|
|
|
aActivity->mPreviousTransformScale = Nothing();
|
2015-10-21 14:25:09 +00:00
|
|
|
IncrementMutationCount(&aActivity->mRestyleCounts[LayerActivity::ACTIVITY_SCALE]);
|
2015-07-20 02:30:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxSize scale = ThebesMatrix(transform2D).ScaleFactors(true);
|
|
|
|
if (aActivity->mPreviousTransformScale == Some(scale)) {
|
|
|
|
return; // Nothing changed.
|
|
|
|
}
|
|
|
|
|
|
|
|
aActivity->mPreviousTransformScale = Some(scale);
|
2015-10-21 14:25:09 +00:00
|
|
|
IncrementMutationCount(&aActivity->mRestyleCounts[LayerActivity::ACTIVITY_SCALE]);
|
2015-07-20 02:30:37 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 11:30:57 +00:00
|
|
|
/* static */ void
|
2016-08-17 01:37:48 +00:00
|
|
|
ActiveLayerTracker::NotifyRestyle(nsIFrame* aFrame, nsCSSPropertyID aProperty)
|
2013-09-04 11:30:57 +00:00
|
|
|
{
|
|
|
|
LayerActivity* layerActivity = GetLayerActivityForUpdate(aFrame);
|
|
|
|
uint8_t& mutationCount = layerActivity->RestyleCountForProperty(aProperty);
|
2013-09-10 00:08:41 +00:00
|
|
|
IncrementMutationCount(&mutationCount);
|
2015-07-20 02:30:37 +00:00
|
|
|
|
|
|
|
if (aProperty == eCSSProperty_transform) {
|
|
|
|
IncrementScaleRestyleCountIfNeeded(aFrame, layerActivity);
|
|
|
|
}
|
2013-09-10 00:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
ActiveLayerTracker::NotifyOffsetRestyle(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
LayerActivity* layerActivity = GetLayerActivityForUpdate(aFrame);
|
2015-10-21 14:25:09 +00:00
|
|
|
IncrementMutationCount(&layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_LEFT]);
|
|
|
|
IncrementMutationCount(&layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_TOP]);
|
|
|
|
IncrementMutationCount(&layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_RIGHT]);
|
|
|
|
IncrementMutationCount(&layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_BOTTOM]);
|
2013-09-04 11:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2016-02-12 14:38:50 +00:00
|
|
|
ActiveLayerTracker::NotifyAnimated(nsIFrame* aFrame,
|
2016-08-17 01:37:48 +00:00
|
|
|
nsCSSPropertyID aProperty,
|
2016-02-12 14:38:50 +00:00
|
|
|
const nsAString& aNewValue,
|
|
|
|
nsDOMCSSDeclaration* aDOMCSSDecl)
|
2013-09-04 11:30:57 +00:00
|
|
|
{
|
|
|
|
LayerActivity* layerActivity = GetLayerActivityForUpdate(aFrame);
|
|
|
|
uint8_t& mutationCount = layerActivity->RestyleCountForProperty(aProperty);
|
2016-02-12 14:38:50 +00:00
|
|
|
if (mutationCount != 0xFF) {
|
|
|
|
nsAutoString oldValue;
|
|
|
|
aDOMCSSDecl->GetPropertyValue(aProperty, oldValue);
|
|
|
|
if (aNewValue != oldValue) {
|
|
|
|
// We know this is animated, so just hack the mutation count.
|
|
|
|
mutationCount = 0xFF;
|
|
|
|
}
|
|
|
|
}
|
2013-09-04 11:30:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-30 15:28:53 +00:00
|
|
|
/* static */ void
|
2016-08-17 01:37:48 +00:00
|
|
|
ActiveLayerTracker::NotifyAnimatedFromScrollHandler(nsIFrame* aFrame, nsCSSPropertyID aProperty,
|
2015-10-30 15:28:53 +00:00
|
|
|
nsIFrame* aScrollFrame)
|
|
|
|
{
|
|
|
|
if (aFrame->PresContext() != aScrollFrame->PresContext()) {
|
|
|
|
// Don't allow cross-document dependencies.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LayerActivity* layerActivity = GetLayerActivityForUpdate(aFrame);
|
|
|
|
LayerActivity::ActivityIndex activityIndex = LayerActivity::GetActivityIndexForProperty(aProperty);
|
|
|
|
|
|
|
|
if (layerActivity->mAnimatingScrollHandlerFrame.GetFrame() != aScrollFrame) {
|
|
|
|
// Discard any activity of a different scroll frame. We only track the
|
|
|
|
// most recent scroll handler induced activity.
|
|
|
|
layerActivity->mScrollHandlerInducedActivity.clear();
|
|
|
|
layerActivity->mAnimatingScrollHandlerFrame = aScrollFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
layerActivity->mScrollHandlerInducedActivity += activityIndex;
|
|
|
|
}
|
|
|
|
|
2013-09-04 11:47:23 +00: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 17:05:36 +00:00
|
|
|
nsPIDOMWindowInner* win = aPresContext->Document()->GetInnerWindow();
|
2013-09-04 11:47:23 +00:00
|
|
|
return win && win->IsRunningTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
ActiveLayerTracker::NotifyInlineStyleRuleModified(nsIFrame* aFrame,
|
2016-08-17 01:37:48 +00:00
|
|
|
nsCSSPropertyID aProperty,
|
2016-02-12 14:38:50 +00:00
|
|
|
const nsAString& aNewValue,
|
|
|
|
nsDOMCSSDeclaration* aDOMCSSDecl)
|
2013-09-04 11:47:23 +00:00
|
|
|
{
|
2015-10-30 15:28:53 +00:00
|
|
|
if (IsPresContextInScriptAnimationCallback(aFrame->PresContext())) {
|
2016-02-12 14:38:50 +00:00
|
|
|
NotifyAnimated(aFrame, aProperty, aNewValue, aDOMCSSDecl);
|
2015-10-30 15:28:53 +00:00
|
|
|
}
|
|
|
|
if (gLayerActivityTracker &&
|
|
|
|
gLayerActivityTracker->mCurrentScrollHandlerFrame.IsAlive()) {
|
|
|
|
NotifyAnimatedFromScrollHandler(aFrame, aProperty,
|
|
|
|
gLayerActivityTracker->mCurrentScrollHandlerFrame.GetFrame());
|
2013-09-04 11:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-22 01:55:55 +00:00
|
|
|
/* static */ bool
|
2016-08-17 01:37:48 +00:00
|
|
|
ActiveLayerTracker::IsStyleMaybeAnimated(nsIFrame* aFrame, nsCSSPropertyID aProperty)
|
2014-10-22 01:55:55 +00:00
|
|
|
{
|
|
|
|
return IsStyleAnimated(nullptr, aFrame, aProperty);
|
|
|
|
}
|
|
|
|
|
2016-04-21 03:34:46 +00:00
|
|
|
/* static */ bool
|
|
|
|
ActiveLayerTracker::IsBackgroundPositionAnimated(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
return IsStyleAnimated(aBuilder, aFrame, eCSSProperty_background_position_x) ||
|
|
|
|
IsStyleAnimated(aBuilder, aFrame, eCSSProperty_background_position_y);
|
|
|
|
}
|
|
|
|
|
2015-10-30 15:28:53 +00:00
|
|
|
static bool
|
|
|
|
CheckScrollInducedActivity(LayerActivity* aLayerActivity,
|
|
|
|
LayerActivity::ActivityIndex aActivityIndex,
|
|
|
|
nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
if (!aLayerActivity->mScrollHandlerInducedActivity.contains(aActivityIndex) ||
|
|
|
|
!aLayerActivity->mAnimatingScrollHandlerFrame.IsAlive()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIScrollableFrame* scrollFrame =
|
|
|
|
do_QueryFrame(aLayerActivity->mAnimatingScrollHandlerFrame.GetFrame());
|
|
|
|
if (scrollFrame && (!aBuilder || scrollFrame->IsScrollingActive(aBuilder))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The scroll frame has been destroyed or has become inactive. Clear it from
|
|
|
|
// the layer activity so that it can expire.
|
|
|
|
aLayerActivity->mAnimatingScrollHandlerFrame = nullptr;
|
|
|
|
aLayerActivity->mScrollHandlerInducedActivity.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-04 11:30:57 +00:00
|
|
|
/* static */ bool
|
2014-10-22 01:54:32 +00:00
|
|
|
ActiveLayerTracker::IsStyleAnimated(nsDisplayListBuilder* aBuilder,
|
2016-08-17 01:37:48 +00:00
|
|
|
nsIFrame* aFrame, nsCSSPropertyID aProperty)
|
2013-09-04 11:30:57 +00:00
|
|
|
{
|
2013-11-22 18:14:34 +00:00
|
|
|
// TODO: Add some abuse restrictions
|
2015-03-20 04:12:17 +00:00
|
|
|
if ((aFrame->StyleDisplay()->mWillChangeBitField & NS_STYLE_WILL_CHANGE_TRANSFORM) &&
|
2014-10-22 01:54:32 +00:00
|
|
|
aProperty == eCSSProperty_transform &&
|
2015-07-06 20:32:53 +00:00
|
|
|
(!aBuilder || aBuilder->IsInWillChangeBudget(aFrame, aFrame->GetSize()))) {
|
2013-11-22 18:14:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-20 04:12:17 +00:00
|
|
|
if ((aFrame->StyleDisplay()->mWillChangeBitField & NS_STYLE_WILL_CHANGE_OPACITY) &&
|
2014-10-22 01:54:32 +00:00
|
|
|
aProperty == eCSSProperty_opacity &&
|
2015-07-06 20:32:53 +00:00
|
|
|
(!aBuilder || aBuilder->IsInWillChangeBudget(aFrame, aFrame->GetSize()))) {
|
2013-11-22 18:14:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-04 11:30:57 +00:00
|
|
|
LayerActivity* layerActivity = GetLayerActivity(aFrame);
|
|
|
|
if (layerActivity) {
|
2015-10-30 15:28:53 +00:00
|
|
|
LayerActivity::ActivityIndex activityIndex = LayerActivity::GetActivityIndexForProperty(aProperty);
|
|
|
|
if (layerActivity->mRestyleCounts[activityIndex] >= 2) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (CheckScrollInducedActivity(layerActivity, activityIndex, aBuilder)) {
|
2013-09-04 11:30:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-09-17 01:31:00 +00:00
|
|
|
if (aProperty == eCSSProperty_transform && aFrame->Combines3DTransformWithAncestors()) {
|
2014-10-22 01:54:32 +00:00
|
|
|
return IsStyleAnimated(aBuilder, aFrame->GetParent(), aProperty);
|
2013-09-04 11:30:57 +00:00
|
|
|
}
|
2016-10-05 05:25:41 +00:00
|
|
|
return nsLayoutUtils::HasActiveAnimationOfProperty(aFrame, aProperty);
|
2013-09-04 11:30:57 +00:00
|
|
|
}
|
|
|
|
|
2013-09-10 00:08:41 +00:00
|
|
|
/* static */ bool
|
2013-09-10 00:08:42 +00:00
|
|
|
ActiveLayerTracker::IsOffsetOrMarginStyleAnimated(nsIFrame* aFrame)
|
2013-09-10 00:08:41 +00:00
|
|
|
{
|
|
|
|
LayerActivity* layerActivity = GetLayerActivity(aFrame);
|
|
|
|
if (layerActivity) {
|
2015-10-21 14:25:09 +00:00
|
|
|
if (layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_LEFT] >= 2 ||
|
|
|
|
layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_TOP] >= 2 ||
|
|
|
|
layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_RIGHT] >= 2 ||
|
|
|
|
layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_BOTTOM] >= 2 ||
|
|
|
|
layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_MARGIN_LEFT] >= 2 ||
|
|
|
|
layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_MARGIN_TOP] >= 2 ||
|
|
|
|
layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_MARGIN_RIGHT] >= 2 ||
|
|
|
|
layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_MARGIN_BOTTOM] >= 2) {
|
2013-09-10 00:08:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-04-21 20:41:58 +00:00
|
|
|
// We should also check for running CSS animations of these properties once
|
|
|
|
// bug 1009693 is fixed. Until that happens, layerization isn't useful for
|
|
|
|
// animations of these properties because we'll invalidate the layer contents
|
|
|
|
// on every change anyway.
|
|
|
|
// See bug 1151346 for a patch that adds a check for CSS animations.
|
2013-09-10 00:08:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-20 02:30:40 +00:00
|
|
|
// A helper function for IsScaleSubjectToAnimation which returns true if the
|
2015-12-03 23:32:53 +00:00
|
|
|
// given EffectSet contains a current effect that animates scale.
|
2015-07-20 02:30:40 +00:00
|
|
|
static bool
|
2015-12-03 23:32:53 +00:00
|
|
|
ContainsAnimatedScale(EffectSet& aEffects, nsIFrame* aFrame)
|
2015-07-20 02:30:40 +00:00
|
|
|
{
|
2015-12-03 23:32:53 +00:00
|
|
|
for (dom::KeyframeEffectReadOnly* effect : aEffects) {
|
|
|
|
if (!effect->IsCurrent()) {
|
2015-07-20 02:30:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
2015-12-03 23:32:53 +00:00
|
|
|
|
2015-07-20 02:30:40 +00:00
|
|
|
for (const AnimationProperty& prop : effect->Properties()) {
|
|
|
|
if (prop.mProperty != eCSSProperty_transform) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (AnimationPropertySegment segment : prop.mSegments) {
|
|
|
|
gfxSize from = segment.mFromValue.GetScaleValue(aFrame);
|
|
|
|
if (from != gfxSize(1.0f, 1.0f)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
gfxSize to = segment.mToValue.GetScaleValue(aFrame);
|
|
|
|
if (to != gfxSize(1.0f, 1.0f)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
ActiveLayerTracker::IsScaleSubjectToAnimation(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
// Check whether JavaScript is animating this frame's scale.
|
|
|
|
LayerActivity* layerActivity = GetLayerActivity(aFrame);
|
2015-10-21 14:25:09 +00:00
|
|
|
if (layerActivity && layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_SCALE] >= 2) {
|
2015-07-20 02:30:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-03 23:32:53 +00:00
|
|
|
// Check if any animations, transitions, etc. associated with this frame may
|
|
|
|
// animate its scale.
|
|
|
|
EffectSet* effects = EffectSet::GetEffectSet(aFrame);
|
|
|
|
if (effects && ContainsAnimatedScale(*effects, aFrame)) {
|
2015-07-20 02:30:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-04 11:30:57 +00:00
|
|
|
/* static */ void
|
|
|
|
ActiveLayerTracker::NotifyContentChange(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
LayerActivity* layerActivity = GetLayerActivityForUpdate(aFrame);
|
|
|
|
layerActivity->mContentActive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
ActiveLayerTracker::IsContentActive(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
LayerActivity* layerActivity = GetLayerActivity(aFrame);
|
|
|
|
return layerActivity && layerActivity->mContentActive;
|
|
|
|
}
|
|
|
|
|
2015-10-30 15:28:53 +00:00
|
|
|
/* static */ void
|
|
|
|
ActiveLayerTracker::SetCurrentScrollHandlerFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!gLayerActivityTracker) {
|
|
|
|
gLayerActivityTracker = new LayerActivityTracker();
|
|
|
|
}
|
|
|
|
gLayerActivityTracker->mCurrentScrollHandlerFrame = aFrame;
|
|
|
|
}
|
|
|
|
|
2013-09-04 11:30:57 +00:00
|
|
|
/* static */ void
|
|
|
|
ActiveLayerTracker::Shutdown()
|
|
|
|
{
|
|
|
|
delete gLayerActivityTracker;
|
|
|
|
gLayerActivityTracker = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace mozilla
|