mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 23:13:18 +00:00
886c0a2723
- Bug 1215411 - Define MOZ_FALLTHROUGH annotation to suppress clang's -Wimplicit-fallthrough warnings. r=botond (5549d55e8b)
- Bug 1202794 - Explicitly clear array in SortChildrenBy3DZOrder to satisfy the move analysis, r=mattwoodrow (0c53a3db36)
- Bug 1217168 - Respect layer clip rects during plugin visibility computation. r=jimm (6289d35ff1)
- Bug 1220693 - Make mozilla::Atomic<enum class> work even on compilers that don't have <atomic>. r=froydnj (ef1b490ffd)
- Bug 947062 - Make background-position inline-style changes and CSS animations trigger layer activity. r=roc (44bc576960)
- Bug 1201330 - Refactor LayerActivity property management. r=roc (92528b8765)
- Bug 1201330 - Keep scroll handler induced layer activity active until the scroll frame becomes inactive. r=roc (08670902ec)
- Bug 1147707 - Intersect correctly in DisplayItemClip::ApplyNonRoundedIntersection. r=roc (66991b6be6)
- better attempt at 10.5 compaitbility, avoiding out-of-bounds array access (18f481ff6b)
- Bug 1217662 - part 1 - make LayerManagerUserDataDestroy a static function of LayerManager; r=mattwoodrow (f2d34451e0)
- Bug 1217662 - part 2 - move mozilla::layers::LayerUserData to a separate header; r=mattwoodrow (036d7327fa)
- Bug 1217662 - part 3 - move nsDisplayBlendContainer::GetLayerState out-of-line; r=mattwoodrow (fb2bd6bd20)
- Bug 1217662 - part 4 - move {LayerManager,Layer}::RemoveUserData out-of-line; r=mattwoodrow (86836f2a9b)
- Bug 1217662 - part 5 - move FrameLayerBuilder and helper classes's ctors/dtors out-of-line; r=mattwoodrow (e838bde0ec)
- Bug 1217662 - part 6 - remove Layers.h #include from FrameListBuilder.h; r=mattwoodrow (8aea4cb842)
- Bug 1216288 - Disable warning when we don't build an active layer for RenderFrameParent within an opacity:0 subtree. r=roc (2c5e70760a)
- Bug 1169996 - Don't lose eEditorMailMask; r=ehsan (b4647557bb)
- Bug 1211654 - Force opacity layers that were only created for APZ hit-testing information to always be inactive. r=mstange (4c56d440cf)
- Bug 1154336 - Convert nsTextEditorState::mRestoringSelection into a strong reference; r=baku (3e24a6ad18)
- Bug 549674 part.1 Commit composition string at setting value of <input> or <textarea> r=smaug (e6a6471370)
- Bug 1109410 Resolve CSS transform in ContentEventHandler::ConvertToRootViewRelativeOffset() r=roc (5ff3388f28)
- Bug 1180589 part 3 - Rename shadowed variable name; r=bholley (7194cda020)
- Bug 1222145 - Bump maximum video size to 8k. r=jya (056778dda9)
- Bug 1180589 part 1 - Add simulator code for TV Manager API; r=seanlin (dd78a38a27)
- Bug 1180589 part 2 - Add code to create a simulated mediastream; r=se# (c255e0dd07)
- spacing (856ee42504)
- missing bit of Bug 1136827 - Stop synchronously (befed33dbe)
- bit of Bug 1204401 (c1f98ed982)
- bits of 1142527 (dc39662797)
- Bug 1212220 - cache pref values so they are safe to access off the main thread. r=roc. (adb186836b)
- Bug 1194918 - Add VideoSink which contains either AudioSinkWrapper or DecodedStreamSink as a default operating MediaSink in MDSM. r=jwwang. (7ccda9b055)
- Bug 1194918 - Move av-sync and video frame rendering logic from MDSM to VideoSink. r=jwwang. (ba56ae120b)
- Bug 1202533 - Fix naming convention of MediaSink::PlaybackParams. (eed5ed3839)
- Bug 1194918 - Override function SetVolume/SetPreservesPitch in VideoSink for the contained AudioSink. r=jwwang. (0d96e6a395)
- Bug 1198663. Skip null Images in VideoSink::RenderVideoFrames instead of treating them as valid. r=jwwang (aaac235c1f)
- Bug 1207198: P2. Defer dormant request while ReadMetadata is pending in MDSM. r=sotaro (0a8e1f4bb0)
- Bug 1209850: Only attempt to initialize decoders as they are required. r=alfredo (615e41b66b)
- Bug 1192733: fix the MediaFormatReader can not back from dormant state. r=jya (c266107d33)
- Bug 1207198: P1. Do not initialize decoders during ReadMetadata. r=cpearce (4174dbc409)
- missing bit of 1196696 (7b1c0fbe95)
- Bug 1208922. Part 6 - IsWaitingOnCDMResource() is not used by MDSM anymore. Remove it from MediaDecoderReader and make it private in MediaFormatReader. r=cpearce. (db67939710)
- adapted of Bug 1208922. Part 3 - forward the CDMProxy from MediaDecoder (a5dca2f89d)
552 lines
18 KiB
C++
552 lines
18 KiB
C++
/* 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"
|
|
|
|
#include "mozilla/ArrayUtils.h"
|
|
#include "mozilla/gfx/Matrix.h"
|
|
#include "mozilla/PodOperations.h"
|
|
#include "nsExpirationTracker.h"
|
|
#include "nsContainerFrame.h"
|
|
#include "nsIContent.h"
|
|
#include "nsRefreshDriver.h"
|
|
#include "nsPIDOMWindow.h"
|
|
#include "nsIDocument.h"
|
|
#include "nsAnimationManager.h"
|
|
#include "nsStyleTransformMatrix.h"
|
|
#include "nsTransitionManager.h"
|
|
#include "nsDisplayList.h"
|
|
|
|
namespace mozilla {
|
|
|
|
using namespace gfx;
|
|
|
|
/**
|
|
* 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:
|
|
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
|
|
};
|
|
|
|
explicit LayerActivity(nsIFrame* aFrame)
|
|
: mFrame(aFrame)
|
|
, mContent(nullptr)
|
|
, mContentActive(false)
|
|
{
|
|
PodArrayZero(mRestyleCounts);
|
|
}
|
|
~LayerActivity();
|
|
nsExpirationState* GetExpirationState() { return &mState; }
|
|
uint8_t& RestyleCountForProperty(nsCSSProperty aProperty)
|
|
{
|
|
return mRestyleCounts[GetActivityIndexForProperty(aProperty)];
|
|
}
|
|
|
|
static ActivityIndex GetActivityIndexForProperty(nsCSSProperty aProperty)
|
|
{
|
|
switch (aProperty) {
|
|
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;
|
|
default: MOZ_ASSERT(false); return ACTIVITY_OPACITY;
|
|
}
|
|
}
|
|
|
|
// 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.
|
|
nsIFrame* mFrame;
|
|
nsIContent* mContent;
|
|
|
|
nsExpirationState mState;
|
|
|
|
// Previous scale due to the CSS transform property.
|
|
Maybe<gfxSize> mPreviousTransformScale;
|
|
|
|
// 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;
|
|
|
|
// Number of restyle operations detected
|
|
uint8_t mRestyleCounts[ACTIVITY_COUNT];
|
|
bool mContentActive;
|
|
};
|
|
|
|
class LayerActivityTracker final : public nsExpirationTracker<LayerActivity,4> {
|
|
public:
|
|
// 75-100ms is a good timeout period. We use 4 generations of 25ms each.
|
|
enum { GENERATION_MS = 100 };
|
|
LayerActivityTracker()
|
|
: nsExpirationTracker<LayerActivity,4>(GENERATION_MS,
|
|
"LayerActivityTracker")
|
|
, mDestroying(false)
|
|
{}
|
|
~LayerActivityTracker() {
|
|
mDestroying = true;
|
|
AgeAllGenerations();
|
|
}
|
|
|
|
virtual void NotifyExpired(LayerActivity* aObject);
|
|
|
|
public:
|
|
nsWeakFrame mCurrentScrollHandlerFrame;
|
|
|
|
private:
|
|
bool mDestroying;
|
|
};
|
|
|
|
static LayerActivityTracker* gLayerActivityTracker = nullptr;
|
|
|
|
LayerActivity::~LayerActivity()
|
|
{
|
|
if (mFrame || mContent) {
|
|
NS_ASSERTION(gLayerActivityTracker, "Should still have a tracker");
|
|
gLayerActivityTracker->RemoveObject(this);
|
|
}
|
|
}
|
|
|
|
// Frames with this property have NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY set
|
|
NS_DECLARE_FRAME_PROPERTY(LayerActivityProperty, DeleteValue<LayerActivity>)
|
|
|
|
void
|
|
LayerActivityTracker::NotifyExpired(LayerActivity* aObject)
|
|
{
|
|
if (!mDestroying && aObject->mAnimatingScrollHandlerFrame.IsAlive()) {
|
|
// Reset the restyle counts, but let the layer activity survive.
|
|
PodArrayZero(aObject->mRestyleCounts);
|
|
MarkUsed(aObject);
|
|
return;
|
|
}
|
|
|
|
RemoveObject(aObject);
|
|
|
|
nsIFrame* f = aObject->mFrame;
|
|
nsIContent* c = aObject->mContent;
|
|
aObject->mFrame = nullptr;
|
|
aObject->mContent = nullptr;
|
|
|
|
MOZ_ASSERT((f == nullptr) != (c == nullptr),
|
|
"A LayerActivity object should always have a reference to either its frame or its content");
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
static LayerActivity*
|
|
GetLayerActivity(nsIFrame* aFrame)
|
|
{
|
|
if (!aFrame->HasAnyStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY)) {
|
|
return nullptr;
|
|
}
|
|
FrameProperties properties = aFrame->Properties();
|
|
return static_cast<LayerActivity*>(properties.Get(LayerActivityProperty()));
|
|
}
|
|
|
|
static LayerActivity*
|
|
GetLayerActivityForUpdate(nsIFrame* aFrame)
|
|
{
|
|
FrameProperties properties = aFrame->Properties();
|
|
LayerActivity* layerActivity =
|
|
static_cast<LayerActivity*>(properties.Get(LayerActivityProperty()));
|
|
if (layerActivity) {
|
|
gLayerActivityTracker->MarkUsed(layerActivity);
|
|
} else {
|
|
if (!gLayerActivityTracker) {
|
|
gLayerActivityTracker = new LayerActivityTracker();
|
|
}
|
|
layerActivity = new LayerActivity(aFrame);
|
|
gLayerActivityTracker->AddObject(layerActivity);
|
|
aFrame->AddStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY);
|
|
properties.Set(LayerActivityProperty(), layerActivity);
|
|
}
|
|
return layerActivity;
|
|
}
|
|
|
|
static void
|
|
IncrementMutationCount(uint8_t* aCount)
|
|
{
|
|
*aCount = uint8_t(std::min(0xFF, *aCount + 1));
|
|
}
|
|
|
|
/* static */ void
|
|
ActiveLayerTracker::TransferActivityToContent(nsIFrame* aFrame, nsIContent* aContent)
|
|
{
|
|
if (!aFrame->HasAnyStateBits(NS_FRAME_HAS_LAYER_ACTIVITY_PROPERTY)) {
|
|
return;
|
|
}
|
|
FrameProperties properties = aFrame->Properties();
|
|
LayerActivity* layerActivity =
|
|
static_cast<LayerActivity*>(properties.Remove(LayerActivityProperty()));
|
|
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);
|
|
}
|
|
|
|
static void
|
|
IncrementScaleRestyleCountIfNeeded(nsIFrame* aFrame, LayerActivity* aActivity)
|
|
{
|
|
const nsStyleDisplay* display = aFrame->StyleDisplay();
|
|
if (!display->mSpecifiedTransform) {
|
|
// The transform was removed.
|
|
aActivity->mPreviousTransformScale = Nothing();
|
|
IncrementMutationCount(&aActivity->mRestyleCounts[LayerActivity::ACTIVITY_SCALE]);
|
|
return;
|
|
}
|
|
|
|
// Compute the new scale due to the CSS transform property.
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
RuleNodeCacheConditions dummy;
|
|
nsStyleTransformMatrix::TransformReferenceBox refBox(aFrame);
|
|
Matrix4x4 transform =
|
|
nsStyleTransformMatrix::ReadTransforms(display->mSpecifiedTransform->mHead,
|
|
aFrame->StyleContext(),
|
|
presContext,
|
|
dummy, refBox,
|
|
presContext->AppUnitsPerCSSPixel());
|
|
Matrix transform2D;
|
|
if (!transform.Is2D(&transform2D)) {
|
|
// We don't attempt to handle 3D transforms; just assume the scale changed.
|
|
aActivity->mPreviousTransformScale = Nothing();
|
|
IncrementMutationCount(&aActivity->mRestyleCounts[LayerActivity::ACTIVITY_SCALE]);
|
|
return;
|
|
}
|
|
|
|
gfxSize scale = ThebesMatrix(transform2D).ScaleFactors(true);
|
|
if (aActivity->mPreviousTransformScale == Some(scale)) {
|
|
return; // Nothing changed.
|
|
}
|
|
|
|
aActivity->mPreviousTransformScale = Some(scale);
|
|
IncrementMutationCount(&aActivity->mRestyleCounts[LayerActivity::ACTIVITY_SCALE]);
|
|
}
|
|
|
|
/* static */ void
|
|
ActiveLayerTracker::NotifyRestyle(nsIFrame* aFrame, nsCSSProperty aProperty)
|
|
{
|
|
LayerActivity* layerActivity = GetLayerActivityForUpdate(aFrame);
|
|
uint8_t& mutationCount = layerActivity->RestyleCountForProperty(aProperty);
|
|
IncrementMutationCount(&mutationCount);
|
|
|
|
if (aProperty == eCSSProperty_transform) {
|
|
IncrementScaleRestyleCountIfNeeded(aFrame, layerActivity);
|
|
}
|
|
}
|
|
|
|
/* static */ void
|
|
ActiveLayerTracker::NotifyOffsetRestyle(nsIFrame* aFrame)
|
|
{
|
|
LayerActivity* layerActivity = GetLayerActivityForUpdate(aFrame);
|
|
IncrementMutationCount(&layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_LEFT]);
|
|
IncrementMutationCount(&layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_TOP]);
|
|
IncrementMutationCount(&layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_RIGHT]);
|
|
IncrementMutationCount(&layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_BOTTOM]);
|
|
}
|
|
|
|
/* static */ void
|
|
ActiveLayerTracker::NotifyAnimated(nsIFrame* aFrame, nsCSSProperty aProperty)
|
|
{
|
|
LayerActivity* layerActivity = GetLayerActivityForUpdate(aFrame);
|
|
uint8_t& mutationCount = layerActivity->RestyleCountForProperty(aProperty);
|
|
// We know this is animated, so just hack the mutation count.
|
|
mutationCount = 0xFF;
|
|
}
|
|
|
|
/* static */ void
|
|
ActiveLayerTracker::NotifyAnimatedFromScrollHandler(nsIFrame* aFrame, nsCSSProperty aProperty,
|
|
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;
|
|
}
|
|
|
|
static bool
|
|
IsPresContextInScriptAnimationCallback(nsPresContext* aPresContext)
|
|
{
|
|
if (aPresContext->RefreshDriver()->IsInRefresh()) {
|
|
return true;
|
|
}
|
|
// Treat timeouts/setintervals as scripted animation callbacks for our
|
|
// purposes.
|
|
nsPIDOMWindow* win = aPresContext->Document()->GetInnerWindow();
|
|
return win && win->IsRunningTimeout();
|
|
}
|
|
|
|
/* static */ void
|
|
ActiveLayerTracker::NotifyInlineStyleRuleModified(nsIFrame* aFrame,
|
|
nsCSSProperty aProperty)
|
|
{
|
|
if (IsPresContextInScriptAnimationCallback(aFrame->PresContext())) {
|
|
NotifyAnimated(aFrame, aProperty);
|
|
}
|
|
if (gLayerActivityTracker &&
|
|
gLayerActivityTracker->mCurrentScrollHandlerFrame.IsAlive()) {
|
|
NotifyAnimatedFromScrollHandler(aFrame, aProperty,
|
|
gLayerActivityTracker->mCurrentScrollHandlerFrame.GetFrame());
|
|
}
|
|
}
|
|
|
|
/* static */ bool
|
|
ActiveLayerTracker::IsStyleMaybeAnimated(nsIFrame* aFrame, nsCSSProperty aProperty)
|
|
{
|
|
return IsStyleAnimated(nullptr, aFrame, aProperty);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/* static */ bool
|
|
ActiveLayerTracker::IsStyleAnimated(nsDisplayListBuilder* aBuilder,
|
|
nsIFrame* aFrame, nsCSSProperty aProperty)
|
|
{
|
|
// TODO: Add some abuse restrictions
|
|
if ((aFrame->StyleDisplay()->mWillChangeBitField & NS_STYLE_WILL_CHANGE_TRANSFORM) &&
|
|
aProperty == eCSSProperty_transform &&
|
|
(!aBuilder || aBuilder->IsInWillChangeBudget(aFrame, aFrame->GetSize()))) {
|
|
return true;
|
|
}
|
|
if ((aFrame->StyleDisplay()->mWillChangeBitField & NS_STYLE_WILL_CHANGE_OPACITY) &&
|
|
aProperty == eCSSProperty_opacity &&
|
|
(!aBuilder || aBuilder->IsInWillChangeBudget(aFrame, aFrame->GetSize()))) {
|
|
return true;
|
|
}
|
|
|
|
LayerActivity* layerActivity = GetLayerActivity(aFrame);
|
|
if (layerActivity) {
|
|
LayerActivity::ActivityIndex activityIndex = LayerActivity::GetActivityIndexForProperty(aProperty);
|
|
if (layerActivity->mRestyleCounts[activityIndex] >= 2) {
|
|
return true;
|
|
}
|
|
if (CheckScrollInducedActivity(layerActivity, activityIndex, aBuilder)) {
|
|
return true;
|
|
}
|
|
}
|
|
if (aProperty == eCSSProperty_transform && aFrame->Combines3DTransformWithAncestors()) {
|
|
return IsStyleAnimated(aBuilder, aFrame->GetParent(), aProperty);
|
|
}
|
|
return nsLayoutUtils::HasCurrentAnimationsForProperties(aFrame, &aProperty, 1);
|
|
}
|
|
|
|
/* static */ bool
|
|
ActiveLayerTracker::IsOffsetOrMarginStyleAnimated(nsIFrame* aFrame)
|
|
{
|
|
LayerActivity* layerActivity = GetLayerActivity(aFrame);
|
|
if (layerActivity) {
|
|
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) {
|
|
return true;
|
|
}
|
|
}
|
|
// 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.
|
|
return false;
|
|
}
|
|
|
|
// A helper function for IsScaleSubjectToAnimation which returns true if the
|
|
// given AnimationCollection contains a current effect that animates scale.
|
|
static bool
|
|
ContainsAnimatedScale(AnimationCollection* aCollection, nsIFrame* aFrame)
|
|
{
|
|
if (!aCollection) {
|
|
return false;
|
|
}
|
|
|
|
for (dom::Animation* anim : aCollection->mAnimations) {
|
|
if (!anim->HasCurrentEffect()) {
|
|
continue;
|
|
}
|
|
KeyframeEffectReadOnly* effect = anim->GetEffect();
|
|
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);
|
|
if (layerActivity && layerActivity->mRestyleCounts[LayerActivity::ACTIVITY_SCALE] >= 2) {
|
|
return true;
|
|
}
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
if (!content || !content->IsElement()) {
|
|
return false;
|
|
}
|
|
|
|
nsCSSPseudoElements::Type pseudoType =
|
|
aFrame->StyleContext()->GetPseudoType();
|
|
|
|
// Check if any transitions associated with this frame may animate its scale.
|
|
AnimationCollection* transitions =
|
|
aFrame->PresContext()->TransitionManager()->GetAnimations(
|
|
content->AsElement(), pseudoType, false /* don't create */);
|
|
if (ContainsAnimatedScale(transitions, aFrame)) {
|
|
return true;
|
|
}
|
|
|
|
// Check if any animations associated with this frame may animate its scale.
|
|
AnimationCollection* animations =
|
|
aFrame->PresContext()->AnimationManager()->GetAnimations(
|
|
content->AsElement(), pseudoType, false /* don't create */);
|
|
if (ContainsAnimatedScale(animations, aFrame)) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/* 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;
|
|
}
|
|
|
|
/* static */ void
|
|
ActiveLayerTracker::SetCurrentScrollHandlerFrame(nsIFrame* aFrame)
|
|
{
|
|
if (!gLayerActivityTracker) {
|
|
gLayerActivityTracker = new LayerActivityTracker();
|
|
}
|
|
gLayerActivityTracker->mCurrentScrollHandlerFrame = aFrame;
|
|
}
|
|
|
|
/* static */ void
|
|
ActiveLayerTracker::Shutdown()
|
|
{
|
|
delete gLayerActivityTracker;
|
|
gLayerActivityTracker = nullptr;
|
|
}
|
|
|
|
} // namespace mozilla
|