Bug 1112480 part 5 - Add AnimationTimeline::IsUnderTestControl; r=jwatt
authorBrian Birtles <birtles@gmail.com>
Fri, 09 Jan 2015 07:57:58 +0900
changeset 248642 003c367a510f7396f172c6f48d2bd99ed7d42248
parent 248641 69a084bd65e4fe5a47f6d4f36f3dccfb126c975b
child 248643 d99b6fd9ca56842a48fd7147cecc7d0947b9cc72
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1112480
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1112480 part 5 - Add AnimationTimeline::IsUnderTestControl; r=jwatt Earlier in this patch series we added AnimationPlayer::StartOnNextTick which takes a ready time parameter expressed in timeline time. In order to call this method when painting finishes we need to convert the TimeStamp recorded when painting finished to a timeline time. However, when the timeline is driven by a refresh driver under test control we can no longer meaningfully do this conversion since there is no correspondence between the notion of time used to record the time when painting finished (wallclock time) and the notion of time used by the timeline (which has been arbitrarily adjusted by test code). We need a way to detect this situation so that we know not to call ToTimelineTime in that case. Alternatively, we could make ToTimelineTime automatically return a null value when its refresh driver is under test control. However, in this situation ToTimelineTime can still actually be used to convert a TimeStamp to a timeline time as long as the TimeStamp is from the same refresh driver. Indeed, GetCurrentTime does exactly that. So if we were to go down that route we would have to provide a way for GetCurrentTime to work around that restriction. For now, this patch puts the onus on the caller of ToTimelineTime to check if the timeline is under test control first (unless they are passing a TimeStamp from the same refresh driver, in which case there is no need to check).
dom/animation/AnimationTimeline.h
--- a/dom/animation/AnimationTimeline.h
+++ b/dom/animation/AnimationTimeline.h
@@ -7,19 +7,19 @@
 #define mozilla_dom_AnimationTimeline_h
 
 #include "nsWrapperCache.h"
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/TimeStamp.h"
 #include "js/TypeDecls.h"
 #include "nsIDocument.h"
+#include "nsRefreshDriver.h"
 
 struct JSContext;
-class nsRefreshDriver;
 
 namespace mozilla {
 namespace dom {
 
 class AnimationTimeline MOZ_FINAL : public nsWrapperCache
 {
 public:
   explicit AnimationTimeline(nsIDocument* aDocument)
@@ -42,16 +42,21 @@ public:
 
   // AnimationTimeline methods
   Nullable<TimeDuration> GetCurrentTime() const;
 
   // Wrapper functions for AnimationTimeline DOM methods when called from
   // script.
   Nullable<double> GetCurrentTimeAsDouble() const;
 
+  // Converts a TimeStamp to the equivalent value in timeline time.
+  // Note that when IsUnderTestControl() is true, there is no correspondence
+  // between timeline time and wallclock time. In such a case, passing a
+  // timestamp from TimeStamp::Now() to this method will not return a
+  // meaningful result.
   Nullable<TimeDuration> ToTimelineTime(const TimeStamp& aTimeStamp) const;
   TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const;
 
   // Force the timeline to advance to |aTimeStamp|.
   //
   // Normally the timeline uses the refresh driver time but when we have
   // animations that are timed from when their first frame is rendered we need
   // to bring the timeline forward to that moment. If we don't, calling
@@ -61,16 +66,26 @@ public:
   //
   // |aTimeStamp| must be greater or equal to the current refresh driver
   // time for the document with which this timeline is associated unless the
   // refresh driver is under test control, in which case this method will
   // be a no-op.
   void FastForward(const TimeStamp& aTimeStamp);
 
   nsRefreshDriver* GetRefreshDriver() const;
+  // Returns true if this timeline is driven by a refresh driver that is
+  // under test control. In such a case, there is no correspondence between
+  // TimeStamp values returned by the refresh driver and wallclock time.
+  // As a result, passing a value from TimeStamp::Now() to ToTimelineTime()
+  // would not return a meaningful result.
+  bool IsUnderTestControl() const
+  {
+    nsRefreshDriver* refreshDriver = GetRefreshDriver();
+    return refreshDriver && refreshDriver->IsTestControllingRefreshesEnabled();
+  }
 
 protected:
   TimeStamp GetCurrentTimeStamp() const;
 
   nsCOMPtr<nsIDocument> mDocument;
 
   // The most recently used refresh driver time. This is used in cases where
   // we don't have a refresh driver (e.g. because we are in a display:none