Pan Gesture Prediction - Added DALI_PAN_GESTURE_PREDICTION_AMOUNT environment variable
authorJulien Heanley <j.heanley@partner.samsung.com>
Fri, 30 May 2014 09:30:59 +0000 (10:30 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 10 Jun 2014 14:59:18 +0000 (15:59 +0100)
Increase how far pan gestures try to predict position 1.0f is 1 frame further ahead. Can use decimals like 0.6 or 1.3.

Change-Id: Id5ac2e6c7273e25f51d41aa16ad113ec6632256d
Signed-off-by: Julien Heanley <j.heanley@partner.samsung.com>
dali/integration-api/profiling.cpp
dali/integration-api/profiling.h
dali/internal/event/events/gesture-event-processor.cpp
dali/internal/event/events/gesture-event-processor.h
dali/internal/event/events/pan-gesture-processor.cpp
dali/internal/event/events/pan-gesture-processor.h
dali/internal/update/gestures/scene-graph-pan-gesture.cpp
dali/internal/update/gestures/scene-graph-pan-gesture.h

index c8199b3..66b87b8 100644 (file)
@@ -110,6 +110,12 @@ void SetPanGesturePredictionMode( int mode )
   eventProcessor.SetPanGesturePredictionMode(mode);
 }
 
+void SetPanGesturePredictionAmount(float amount)
+{
+  GestureEventProcessor& eventProcessor = ThreadLocalStorage::Get().GetGestureEventProcessor();
+  eventProcessor.SetPanGesturePredictionAmount(amount);
+}
+
 namespace Profiling
 {
 
index 9a35141..d2ca414 100644 (file)
@@ -52,6 +52,13 @@ DALI_IMPORT_API void EnableProfiling( ProfilingType type );
  */
 DALI_IMPORT_API void SetPanGesturePredictionMode( int mode );
 
+/**
+ * @brief Called by adaptor to set the prediction amount of the pan gesture from an environment variable
+ *
+ * @param[in] amount The prediction amount, 0.0f being next vsync and each 1.0f on top is another vsync ahead, can be divisions of (0.5f)
+ */
+DALI_IMPORT_API void SetPanGesturePredictionAmount(float amount);
+
 
 namespace Profiling
 {
index 4b1f4c5..ec19849 100644 (file)
@@ -234,6 +234,11 @@ void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
   mPanGestureProcessor.SetPredictionMode(mode);
 }
 
+void GestureEventProcessor::SetPanGesturePredictionAmount( float amount )
+{
+  mPanGestureProcessor.SetPredictionAmount(amount);
+}
+
 } // namespace Internal
 
 } // namespace Dali
index 4b944cb..27c5837 100644 (file)
@@ -128,6 +128,13 @@ public: // Called by Core
    */
   void SetPanGesturePredictionMode( int mode );
 
+  /**
+   * @brief Sets the prediction amount of the pan gesture
+   *
+   * @param[in] amount The prediction amount, 0.0f being next vsync and each 1.0f on top is another vsync ahead, can be divisions of (0.5f)
+   */
+  void SetPanGesturePredictionAmount( float amount );
+
 private:
 
   // Undefined
index 0d76ea9..dd8e6d5 100644 (file)
@@ -434,6 +434,11 @@ void PanGestureProcessor::SetPredictionMode(int mode)
   mSceneObject->SetPredictionMode(modeEnum);
 }
 
+void PanGestureProcessor::SetPredictionAmount(float amount)
+{
+  mSceneObject->SetPredictionAmount(amount);
+}
+
 void PanGestureProcessor::UpdateDetection()
 {
   DALI_ASSERT_DEBUG(!mGestureDetectors.empty());
index a75362d..efc30ff 100644 (file)
@@ -125,6 +125,13 @@ public: // To be called by GestureEventProcessor
    */
   void SetPredictionMode(int mode);
 
+  /**
+   * @brief Sets the prediction amount of the pan gesture
+   *
+   * @param[in] amount The prediction amount, 0.0f being next vsync and each 1.0f on top is another vsync ahead, can be divisions of (0.5f)
+   */
+  void SetPredictionAmount(float amount);
+
 private:
 
   // Undefined
index 4b0313f..b3340aa 100644 (file)
@@ -33,9 +33,10 @@ namespace SceneGraph
 namespace
 {
 const int MAX_GESTURE_AGE = 50; ///< maximum age of a gesture before disallowing its use in algorithm
+const float DEFAULT_PREDICTION_INTERPOLATION = 0.0f; ///< how much to interpolate pan position and displacement from last vsync time
 } // unnamed namespace
 
-const PanGesture::PredictionMode PanGesture::DEFAULT_PREDICTION_MODE = PanGesture::AVERAGE;
+const PanGesture::PredictionMode PanGesture::DEFAULT_PREDICTION_MODE = PanGesture::PREDICTION_2;
 const int PanGesture::NUM_PREDICTION_MODES = PanGesture::PREDICTION_2 + 1;
 
 PanGesture* PanGesture::New()
@@ -229,13 +230,14 @@ void PanGesture::PredictiveAlgorithm2(int eventsThisFrame, PanInfo& gestureOut,
   }
   // gestureOut's position is currently equal to the last event's position and its displacement is equal to last frame's total displacement
   // add interpolated distance and position to current
-  float interpolationTime = (float)((int)lastVSyncTime - (int)gestureOut.time);
+  unsigned int timeAdvance = ((nextVSyncTime - lastVSyncTime) * mPredictionAmount);
+  unsigned int interpolationTime = (lastVSyncTime + timeAdvance) - gestureOut.time;
   // work out interpolated velocity
   gestureOut.screen.displacement = (gestureOut.screen.velocity * interpolationTime);
   gestureOut.local.displacement = (gestureOut.local.velocity * interpolationTime);
   gestureOut.screen.position += gestureOut.screen.displacement;
   gestureOut.local.position += gestureOut.local.displacement;
-  gestureOut.time += (lastVSyncTime - gestureOut.time);
+  gestureOut.time += interpolationTime;
 }
 
 bool PanGesture::UpdateProperties( unsigned int lastVSyncTime, unsigned int nextVSyncTime )
@@ -405,6 +407,16 @@ const GesturePropertyVector2& PanGesture::GetLocalDisplacementProperty() const
   return mLocalDisplacement;
 }
 
+void PanGesture::SetPredictionMode(PredictionMode mode)
+{
+  mPredictionMode = mode;
+}
+
+void PanGesture::SetPredictionAmount(float amount)
+{
+  mPredictionAmount = amount;
+}
+
 void PanGesture::EnableProfiling()
 {
   if( !mProfiling )
@@ -428,6 +440,7 @@ PanGesture::PanGesture()
   mReadPosition( 0 ),
   mInGesture( false ),
   mPredictionMode(DEFAULT_PREDICTION_MODE),
+  mPredictionAmount(DEFAULT_PREDICTION_INTERPOLATION),
   mProfiling( NULL )
 {
 }
index 5ae28f4..a8e2170 100644 (file)
@@ -256,7 +256,14 @@ public:
    *
    * @param[in] mode The prediction mode
    */
-  void SetPredictionMode(PredictionMode mode) { mPredictionMode = mode; }
+  void SetPredictionMode(PredictionMode mode);
+
+  /**
+   * @brief Sets the prediction amount of the pan gesture
+   *
+   * @param[in] amount The prediction amount, 0.0f being next vsync and each 1.0f on top is another vsync ahead, can be divisions of (0.5f)
+   */
+  void SetPredictionAmount(float amount);
 
   /**
    * Called to provide pan-gesture profiling information.
@@ -299,6 +306,7 @@ private:
   bool mInGesture;              ///< True if the gesture is currently being handled i.e. between Started <-> Finished/Cancelled
 
   PredictionMode mPredictionMode;  ///< The pan gesture prediction mode
+  float          mPredictionAmount; ///< how far into future to predict. 0.0f is next vsync since no point being less than that, adding 1.0f will predict another vsync in advance
   PanGestureProfiling* mProfiling; ///< NULL unless pan-gesture profiling information is required.
 };