Merge "(ThreadSync) Ensure elapsed time is passed into Core when required" into devel...
[platform/core/uifw/dali-adaptor.git] / adaptors / base / separate-update-render / vsync-notifier.cpp
index 7ade234..dc407f8 100644 (file)
@@ -27,6 +27,7 @@
 #include <base/interfaces/adaptor-internal-services.h>
 #include <base/separate-update-render/thread-synchronization.h>
 #include <base/environment-options.h>
+#include <base/time-service.h>
 
 namespace Dali
 {
@@ -40,6 +41,8 @@ namespace Adaptor
 namespace
 {
 
+const unsigned int NANOSECONDS_PER_SECOND( 1e+9 );
+const unsigned int NANOSECONDS_PER_MICROSECOND( 1000u );
 const unsigned int MICROSECONDS_PER_SECOND( 1000000u );
 const unsigned int TIME_PER_FRAME_IN_MICROSECONDS( 16667u );
 
@@ -54,7 +57,6 @@ VSyncNotifier::VSyncNotifier( ThreadSynchronization& sync,
                               const EnvironmentOptions& environmentOptions )
 : mThreadSynchronization( sync ),
   mCore( adaptorInterfaces.GetCore() ),
-  mPlatformAbstraction( adaptorInterfaces.GetPlatformAbstractionInterface() ),
   mVSyncMonitor( adaptorInterfaces.GetVSyncMonitorInterface() ),
   mThread( NULL ),
   mEnvironmentOptions( environmentOptions ),
@@ -112,10 +114,10 @@ void VSyncNotifier::Run()
 
   unsigned int frameNumber( 0u );             // frameCount, updated when the thread is paused
   unsigned int currentSequenceNumber( 0u );   // platform specific vsync sequence number (increments with each vsync)
-  unsigned int currentSeconds( 0u );          // timestamp at latest sync
-  unsigned int currentMicroseconds( 0u );     // timestamp at latest sync
-  unsigned int seconds( 0u );
-  unsigned int microseconds( 0u );
+  unsigned int currentSeconds( 0u );              // timestamp at latest sync
+  unsigned int currentMicroseconds( 0u );         // timestamp at latest sync
+  uint64_t seconds( 0u );
+  uint64_t microseconds( 0u );
 
   bool validSync( true );
   while( mThreadSynchronization.VSyncReady( validSync, frameNumber++, currentSeconds, currentMicroseconds, mNumberOfVSyncsPerRender ) )
@@ -136,7 +138,12 @@ void VSyncNotifier::Run()
     else
     {
       // No..use software timer
-      mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
+      uint64_t nanoseconds = 0;
+      TimeService::GetNanoseconds( nanoseconds );
+
+      seconds = nanoseconds / NANOSECONDS_PER_SECOND; // Convert to seconds
+      nanoseconds -= seconds * NANOSECONDS_PER_SECOND; // Only want remainder nanoseconds
+      microseconds = nanoseconds / NANOSECONDS_PER_MICROSECOND; // Convert to microseconds
 
       unsigned int timeDelta( MICROSECONDS_PER_SECOND * (seconds - currentSeconds) );
       if( microseconds < currentMicroseconds)