Bug 1196114 - Part 1: Add SetPerformanceWarning. r?birtles
MozReview-Commit-ID: 8NqvuOjKfZM
--- a/dom/animation/EffectCompositor.cpp
+++ b/dom/animation/EffectCompositor.cpp
@@ -711,16 +711,31 @@ EffectCompositor::GetPresContext(Element
MOZ_ASSERT(aElement);
nsIPresShell* shell = nsComputedDOMStyle::GetPresShellForContent(aElement);
if (!shell) {
return nullptr;
}
return shell->GetPresContext();
}
+/* static */ void
+EffectCompositor::SetPerformanceWarning(const nsIFrame *aFrame,
+ nsCSSProperty aProperty,
+ const nsAString& aMessage)
+{
+ EffectSet* effects = EffectSet::GetEffectSet(aFrame);
+ if (!effects) {
+ return;
+ }
+
+ for (KeyframeEffectReadOnly* effect : *effects) {
+ effect->SetPerformanceWarning(aProperty, aMessage);
+ }
+}
+
// ---------------------------------------------------------
//
// Nested class: AnimationStyleRuleProcessor
//
// ---------------------------------------------------------
NS_IMPL_ISUPPORTS(EffectCompositor::AnimationStyleRuleProcessor,
nsIStyleRuleProcessor)
--- a/dom/animation/EffectCompositor.h
+++ b/dom/animation/EffectCompositor.h
@@ -182,16 +182,22 @@ public:
// AnimationCollection), *not* the generated content.
//
// Returns an empty result when a suitable element cannot be found including
// when the frame represents a pseudo-element on which we do not support
// animations.
static Maybe<Pair<dom::Element*, CSSPseudoElementType>>
GetAnimationElementAndPseudoForFrame(const nsIFrame* aFrame);
+ // Associates a warning message with effects on |aFrame| if the effect
+ // has |aProperty|.
+ static void SetPerformanceWarning(const nsIFrame* aFrame,
+ nsCSSProperty aProperty,
+ const nsAString& aMessage);
+
private:
~EffectCompositor() = default;
// Rebuilds the animation rule corresponding to |aCascadeLevel| on the
// EffectSet associated with the specified (pseudo-)element.
static void ComposeAnimationRule(dom::Element* aElement,
CSSPseudoElementType aPseudoType,
CascadeLevel aCascadeLevel,
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -628,16 +628,22 @@ KeyframeEffectReadOnly::SetIsRunningOnCo
{
MOZ_ASSERT(nsCSSProps::PropHasFlags(aProperty,
CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR),
"Property being animated on compositor is a recognized "
"compositor-animatable property");
for (AnimationProperty& property : mProperties) {
if (property.mProperty == aProperty) {
property.mIsRunningOnCompositor = aIsRunning;
+ // We currently only set a performance warning message when animations
+ // cannot be run on the compositor, so if this animation is running
+ // on the compositor we don't need a message.
+ if (aIsRunning) {
+ property.mPerformanceWarning.reset();
+ }
return;
}
}
}
KeyframeEffectReadOnly::~KeyframeEffectReadOnly()
{
}
@@ -2149,16 +2155,28 @@ KeyframeEffectReadOnly::ShouldBlockCompo
return true;
}
}
}
return false;
}
+void
+KeyframeEffectReadOnly::SetPerformanceWarning(nsCSSProperty aProperty,
+ const nsAString &aMessage)
+{
+ for (AnimationProperty& property : mProperties) {
+ if (property.mProperty == aProperty) {
+ property.mPerformanceWarning.emplace(aMessage);
+ return;
+ }
+ }
+}
+
//---------------------------------------------------------------------
//
// KeyframeEffect
//
//---------------------------------------------------------------------
KeyframeEffect::KeyframeEffect(nsIDocument* aDocument,
Element* aTarget,
--- a/dom/animation/KeyframeEffect.h
+++ b/dom/animation/KeyframeEffect.h
@@ -140,16 +140,20 @@ struct AnimationProperty
// between calling RequestRestyle on its EffectCompositor and when the
// restyle is performed, this member may temporarily become false even if
// the animation remains on the layer after the restyle.
//
// **NOTE**: This member is not included when comparing AnimationProperty
// objects for equality.
bool mIsRunningOnCompositor = false;
+ // A warning string indicating why this property could not be animated
+ // on the compositor.
+ Maybe<nsString> mPerformanceWarning;
+
InfallibleTArray<AnimationPropertySegment> mSegments;
// NOTE: This operator does *not* compare the mWinsInCascade member *or* the
// mIsRunningOnCompositor member.
// This is because AnimationProperty objects are compared when recreating
// CSS animations to determine if mutation observer change records need to
// be created or not. However, at the point when these objects are compared
// neither the mWinsInCascade nor the mIsRunningOnCompositor will have been
@@ -317,16 +321,22 @@ public:
//
// Bug 1218620 - It seems like we don't need to be this restrictive. Wouldn't
// it be ok to do 'opacity' animations on the compositor in either case?
bool ShouldBlockCompositorAnimations(const nsIFrame* aFrame) const;
nsIDocument* GetRenderedDocument() const;
nsPresContext* GetPresContext() const;
+ // Associates a warning string with the animated property on the specified
+ // frame indicating why, for example, the property could not be animated
+ // on the compositor.
+ void SetPerformanceWarning(nsCSSProperty aProperty,
+ const nsAString& aMessage);
+
protected:
KeyframeEffectReadOnly(nsIDocument* aDocument,
Element* aTarget,
CSSPseudoElementType aPseudoType,
AnimationEffectTimingReadOnly* aTiming);
virtual ~KeyframeEffectReadOnly();