Bug 1196114 - Part 1: Add SetPerformanceWarning. r?birtles draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Fri, 04 Mar 2016 06:36:36 +0900
changeset 336793 64fec231dbcb268bc5a65ed53cad0eddcf842483
parent 336498 2b5237c178ea02133a777396c24dd2b713f2b8ee
child 336794 29f2ddc6cc2d15871d4071b07f4e632ccedf2942
push id12183
push userhiikezoe@mozilla-japan.org
push dateFri, 04 Mar 2016 06:04:41 +0000
reviewersbirtles
bugs1196114
milestone47.0a1
Bug 1196114 - Part 1: Add SetPerformanceWarning. r?birtles MozReview-Commit-ID: 8NqvuOjKfZM
dom/animation/EffectCompositor.cpp
dom/animation/EffectCompositor.h
dom/animation/KeyframeEffect.cpp
dom/animation/KeyframeEffect.h
--- 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();