Bug 1235002 - Skip requesting a restyle when mProperties is empty. r?birtles draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Mon, 09 May 2016 12:33:52 +0900
changeset 364700 eefe0082110d39f6df7cef340ce89d7456720627
parent 364682 bae525a694e2dc0aa433885be8751330d4995a49
child 520373 11da4fda2a3eb60bbd2dd2ccd4be5d08051ca1cb
push id17549
push userbmo:hiikezoe@mozilla-japan.org
push dateMon, 09 May 2016 03:34:04 +0000
reviewersbirtles
bugs1235002
milestone49.0a1
Bug 1235002 - Skip requesting a restyle when mProperties is empty. r?birtles The test case here does not check whether requesting restyles for empty properties are skipped or not. It just checks that whether restyles happen or not because there is no way to check each request for restyles yet. MozReview-Commit-ID: I5XMYfCTYU8
dom/animation/KeyframeEffect.cpp
dom/animation/test/chrome/test_restyles.html
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -163,28 +163,21 @@ KeyframeEffectReadOnly::NotifyAnimationT
         effectSet->MarkCascadeNeedsUpdate();
       }
     }
     mInEffectOnLastAnimationTimingUpdate = inEffect;
   }
 
   // Request restyle if necessary.
   //
-  // Bug 1235002: We should skip requesting a restyle when mProperties is empty.
-  // However, currently we don't properly encapsulate mProperties so we can't
-  // detect when it changes. As a result, if we skip requesting restyles when
-  // mProperties is empty and we play an animation and *then* add properties to
-  // it (as we currently do when building CSS animations), we will fail to
-  // request a restyle at all. Since animations without properties are rare, we
-  // currently just request the restyle regardless of whether mProperties is
-  // empty or not.
-  //
   // Bug 1216843: When we implement iteration composite modes, we need to
   // also detect if the current iteration has changed.
-  if (mAnimation && GetComputedTiming().mProgress != mProgressOnLastCompose) {
+  if (mAnimation &&
+      !mProperties.IsEmpty() &&
+      GetComputedTiming().mProgress != mProgressOnLastCompose) {
     EffectCompositor::RestyleType restyleType =
       CanThrottle() ?
       EffectCompositor::RestyleType::Throttled :
       EffectCompositor::RestyleType::Standard;
     RequestRestyle(restyleType);
   }
 
   // If we're no longer "in effect", our ComposeStyle method will never be
--- a/dom/animation/test/chrome/test_restyles.html
+++ b/dom/animation/test/chrome/test_restyles.html
@@ -437,12 +437,42 @@ waitForAllPaints(function() {
 
     ok(animation.isRunningOnCompositor,
        'Opacity script animations restored from "display: none" should be ' +
        'run on the compositor');
 
     yield ensureElementRemoval(div);
   });
 
+  add_task(function* restyling_for_empty_keyframes() {
+    var div = addDiv(null);
+    var animation = div.animate({ }, 100 * MS_PER_SEC);
+
+    yield animation.ready;
+    var markers = yield observeStyling(5);
+
+    is(markers.length, 0,
+       'Animations with no keyframes should not cause restyles');
+
+    animation.effect.setFrames({ backgroundColor: ['red', 'blue'] });
+    markers = yield observeStyling(5);
+
+    // There are 5 eRestyle_CSSAnimations and 1 eRestyle_CSSTransitions.
+    // 1 eRestyle_CSSTransitions comes from
+    // EffectCompositor::UpdateCascadeResults.
+    ok(markers.length == 6,
+       'Setting valid keyframes should cause regular animation restyles to ' +
+       'occur');
+
+    animation.effect.setFrames({ });
+    markers = yield observeStyling(5);
+
+    is(markers.length, 1,
+       'Setting an empty set of keyframes should trigger a single restyle ' +
+       'to remove the previous animated style');
+
+    yield ensureElementRemoval(div);
+  });
+
 });
 
 </script>
 </body>