Title: [132755] trunk/Source/WebCore
Revision
132755
Author
p...@google.com
Date
2012-10-28 16:32:24 -0700 (Sun, 28 Oct 2012)

Log Message

Cache calcMode() value for SVG animations.
https://bugs.webkit.org/show_bug.cgi?id=99694

Reviewed by Eric Seidel.

This patch refactors SVGAnimationElement::calcMode() to return a cached value instead
of recalculating its value on every call. On a simple test of 100 rectangles with 100
animations each, calls to calcMode() account for 3% of the total animation. After this
patch, calcMode() no longer appears in animation profiles at all.

No new tests as this functionality is covered by existing tests.

* svg/SVGAnimateMotionElement.cpp:
(WebCore::SVGAnimateMotionElement::SVGAnimateMotionElement):

    The default calcMode for all animation types is linear except AnimateMotion,
    which defaults to CalcModePaced.
    See: http://www.w3.org/TR/SVG/single-page.html#animate-CalcModeAttribute

* svg/SVGAnimationElement.cpp:
(WebCore::SVGAnimationElement::SVGAnimationElement):
(WebCore::SVGAnimationElement::isSupportedAttribute):
(WebCore::SVGAnimationElement::parseAttribute):
(WebCore::SVGAnimationElement::setCalcMode):
* svg/SVGAnimationElement.h:
(WebCore::SVGAnimationElement::calcMode):
(WebCore::SVGAnimationElement::setCalcMode):
(SVGAnimationElement):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (132754 => 132755)


--- trunk/Source/WebCore/ChangeLog	2012-10-28 22:35:33 UTC (rev 132754)
+++ trunk/Source/WebCore/ChangeLog	2012-10-28 23:32:24 UTC (rev 132755)
@@ -1,3 +1,34 @@
+2012-10-28  Philip Rogers  <p...@google.com>
+
+        Cache calcMode() value for SVG animations.
+        https://bugs.webkit.org/show_bug.cgi?id=99694
+
+        Reviewed by Eric Seidel.
+
+        This patch refactors SVGAnimationElement::calcMode() to return a cached value instead
+        of recalculating its value on every call. On a simple test of 100 rectangles with 100
+        animations each, calls to calcMode() account for 3% of the total animation. After this
+        patch, calcMode() no longer appears in animation profiles at all.
+
+        No new tests as this functionality is covered by existing tests.
+
+        * svg/SVGAnimateMotionElement.cpp:
+        (WebCore::SVGAnimateMotionElement::SVGAnimateMotionElement):
+
+            The default calcMode for all animation types is linear except AnimateMotion,
+            which defaults to CalcModePaced.
+            See: http://www.w3.org/TR/SVG/single-page.html#animate-CalcModeAttribute
+
+        * svg/SVGAnimationElement.cpp:
+        (WebCore::SVGAnimationElement::SVGAnimationElement):
+        (WebCore::SVGAnimationElement::isSupportedAttribute):
+        (WebCore::SVGAnimationElement::parseAttribute):
+        (WebCore::SVGAnimationElement::setCalcMode):
+        * svg/SVGAnimationElement.h:
+        (WebCore::SVGAnimationElement::calcMode):
+        (WebCore::SVGAnimationElement::setCalcMode):
+        (SVGAnimationElement):
+
 2012-10-28  Dimitri Glazkov  <dglaz...@chromium.org>
 
         Get rid of StyleResolver state related to unknown pseudo-elements.

Modified: trunk/Source/WebCore/svg/SVGAnimateMotionElement.cpp (132754 => 132755)


--- trunk/Source/WebCore/svg/SVGAnimateMotionElement.cpp	2012-10-28 22:35:33 UTC (rev 132754)
+++ trunk/Source/WebCore/svg/SVGAnimateMotionElement.cpp	2012-10-28 23:32:24 UTC (rev 132755)
@@ -46,6 +46,7 @@
     : SVGAnimationElement(tagName, document)
     , m_hasToPointAtEndOfDuration(false)
 {
+    setCalcMode(CalcModePaced);
     ASSERT(hasTagName(animateMotionTag));
 }
 

Modified: trunk/Source/WebCore/svg/SVGAnimationElement.cpp (132754 => 132755)


--- trunk/Source/WebCore/svg/SVGAnimationElement.cpp	2012-10-28 22:35:33 UTC (rev 132754)
+++ trunk/Source/WebCore/svg/SVGAnimationElement.cpp	2012-10-28 23:32:24 UTC (rev 132755)
@@ -58,6 +58,7 @@
     , m_animationValid(false)
     , m_attributeType(AttributeTypeAuto)
     , m_hasInvalidCSSAttributeType(false)
+    , m_calcMode(CalcModeLinear)
 {
     registerAnimatedPropertiesForSVGAnimationElement();
 }
@@ -149,6 +150,7 @@
         supportedAttributes.add(SVGNames::keyPointsAttr);
         supportedAttributes.add(SVGNames::keySplinesAttr);
         supportedAttributes.add(SVGNames::attributeTypeAttr);
+        supportedAttributes.add(SVGNames::calcModeAttr);
     }
     return supportedAttributes.contains<QualifiedName, SVGAttributeHashTranslator>(attrName);
 }
@@ -194,6 +196,11 @@
         return;
     }
 
+    if (attribute.name() == SVGNames::calcModeAttr) {
+        setCalcMode(attribute.value());
+        return;
+    }
+
     if (SVGTests::parseAttribute(attribute))
         return;
     if (SVGExternalResourcesRequired::parseAttribute(attribute))
@@ -276,22 +283,22 @@
     return NoAnimation;
 }
 
-CalcMode SVGAnimationElement::calcMode() const
-{    
+void SVGAnimationElement::setCalcMode(const AtomicString& calcMode)
+{
     DEFINE_STATIC_LOCAL(const AtomicString, discrete, ("discrete"));
     DEFINE_STATIC_LOCAL(const AtomicString, linear, ("linear"));
     DEFINE_STATIC_LOCAL(const AtomicString, paced, ("paced"));
     DEFINE_STATIC_LOCAL(const AtomicString, spline, ("spline"));
-    const AtomicString& value = fastGetAttribute(SVGNames::calcModeAttr);
-    if (value == discrete)
-        return CalcModeDiscrete;
-    if (value == linear)
-        return CalcModeLinear;
-    if (value == paced)
-        return CalcModePaced;
-    if (value == spline)
-        return CalcModeSpline;
-    return hasTagName(SVGNames::animateMotionTag) ? CalcModePaced : CalcModeLinear;
+    if (calcMode == discrete)
+        setCalcMode(CalcModeDiscrete);
+    else if (calcMode == linear)
+        setCalcMode(CalcModeLinear);
+    else if (calcMode == paced)
+        setCalcMode(CalcModePaced);
+    else if (calcMode == spline)
+        setCalcMode(CalcModeSpline);
+    else
+        setCalcMode(hasTagName(SVGNames::animateMotionTag) ? CalcModePaced : CalcModeLinear);
 }
 
 void SVGAnimationElement::setAttributeType(const AtomicString& attributeType)

Modified: trunk/Source/WebCore/svg/SVGAnimationElement.h (132754 => 132755)


--- trunk/Source/WebCore/svg/SVGAnimationElement.h	2012-10-28 22:35:33 UTC (rev 132754)
+++ trunk/Source/WebCore/svg/SVGAnimationElement.h	2012-10-28 23:32:24 UTC (rev 132755)
@@ -88,7 +88,7 @@
     virtual bool isAdditive() const;
     bool isAccumulated() const;
     AnimationMode animationMode() const;
-    CalcMode calcMode() const;
+    CalcMode calcMode() const { return m_calcMode; }
 
     enum ShouldApplyAnimation {
         DontApplyAnimation,
@@ -201,6 +201,8 @@
     virtual void targetElementWillChange(SVGElement* currentTarget, SVGElement* oldTarget) OVERRIDE;
     bool hasInvalidCSSAttributeType() const { return m_hasInvalidCSSAttributeType; }
 
+    void setCalcMode(CalcMode calcMode) { m_calcMode = calcMode; }
+
 private:
     virtual void animationAttributeChanged() OVERRIDE;
     virtual void setAttributeName(const QualifiedName&) OVERRIDE;
@@ -235,6 +237,8 @@
     virtual void synchronizeRequiredExtensions() { SVGTests::synchronizeRequiredExtensions(this); }
     virtual void synchronizeSystemLanguage() { SVGTests::synchronizeSystemLanguage(this); }
 
+    void setCalcMode(const AtomicString&);
+
     bool m_animationValid;
 
     AttributeType m_attributeType;
@@ -245,6 +249,7 @@
     String m_lastValuesAnimationFrom;
     String m_lastValuesAnimationTo;
     bool m_hasInvalidCSSAttributeType;
+    CalcMode m_calcMode;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to