Bug 1256565 - Part 1. Implement GetEventTimeStamp(). r=jchen r?karlt draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 20 Feb 2017 12:34:44 +0900
changeset 486842 1b0742e4dc15ca3530311a264a1417400c4f7d9e
parent 486741 16effd5b21ab03629feca04b5b83911bb757394c
child 486843 489d47c32247f7cd75e28595fa9092d64bf39f58
push id46075
push userm_kato@ga2.so-net.ne.jp
push dateMon, 20 Feb 2017 03:38:04 +0000
reviewersjchen, karlt
bugs1256565
milestone54.0a1
Bug 1256565 - Part 1. Implement GetEventTimeStamp(). r=jchen r?karlt Android uses android.os.SystemClock.uptimeMilles for event time and SystemClock.uptimeMilles uses SYSTEM_TIME_MONOTONIC. So since TimeStamp posix impelemetation uses SYSTEM_TIME_MONOTONIC too, so we can use event time on FromSystemTime. MozReview-Commit-ID: 5Qb5kmnHHCI
mozglue/misc/TimeStamp.h
widget/android/nsWindow.cpp
--- a/mozglue/misc/TimeStamp.h
+++ b/mozglue/misc/TimeStamp.h
@@ -418,19 +418,22 @@ public:
 
   /**
    * The system timestamps are the same as the TimeStamp
    * retrieved by mozilla::TimeStamp. Since we need this for
    * vsync timestamps, we enable the creation of mozilla::TimeStamps
    * on platforms that support vsync aligned refresh drivers / compositors
    * Verified true as of Jan 31, 2015: B2G and OS X
    * False on Windows 7
+   * Android's event time uses CLOCK_MONOTONIC via SystemClock.uptimeMilles.
+   * So it is same value of TimeStamp posix implementation.
    * UNTESTED ON OTHER PLATFORMS
    */
-#if defined(MOZ_WIDGET_GONK) || defined(XP_DARWIN)
+#if defined(MOZ_WIDGET_GONK) || defined(XP_DARWIN) || \
+    defined(MOZ_WIDGET_ANDROID)
   static TimeStamp FromSystemTime(int64_t aSystemTime)
   {
     static_assert(sizeof(aSystemTime) == sizeof(TimeStampValue),
                   "System timestamp should be same units as TimeStampValue");
     return TimeStamp(aSystemTime);
   }
 #endif
 
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -97,16 +97,30 @@ NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, n
 
 #include "mozilla/layers/CompositorBridgeChild.h"
 #include "mozilla/layers/CompositorSession.h"
 #include "mozilla/layers/LayerTransactionParent.h"
 #include "mozilla/layers/UiCompositorControllerChild.h"
 #include "mozilla/Services.h"
 #include "nsThreadUtils.h"
 
+static TimeStamp
+GetEventTimeStamp(int64_t aEventTime)
+{
+    // Android's event time is SystemClock.uptimeMillis that is counted in ms
+    // since OS was booted.
+    // (https://developer.android.com/reference/android/os/SystemClock.html)
+    // and this SystemClock.uptimeMillis uses SYSTEM_TIME_MONOTONIC.
+    // Our posix implemententaion of TimeStamp::Now uses SYSTEM_TIME_MONOTONIC
+    //  too. Due to same implementation, we can use this via FromSystemTime.
+    int64_t tick =
+        BaseTimeDurationPlatformUtils::TicksFromMilliseconds(aEventTime);
+    return TimeStamp::FromSystemTime(tick);
+}
+
 // All the toplevel windows that have been created; these are in
 // stacking order, so the window at gTopLevelWindows[0] is the topmost
 // one.
 static nsTArray<nsWindow*> gTopLevelWindows;
 
 static bool sFailedToCreateGLContext = false;
 
 // Multitouch swipe thresholds in inches