Add trace log for touch, wheel and gesture
[platform/core/uifw/dali-core.git] / dali / internal / event / events / long-press-gesture / long-press-gesture-processor.cpp
index d9a2914..9110533 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <algorithm>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/actors/actor.h>
-#include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/events/long-press-gesture.h>
-#include <dali/internal/event/events/long-press-gesture/long-press-gesture-event.h>
 #include <dali/integration-api/debug.h>
+#include <dali/integration-api/trace.h>
 #include <dali/internal/event/actors/actor-impl.h>
 #include <dali/internal/event/common/scene-impl.h>
-#include <dali/internal/event/render-tasks/render-task-impl.h>
-#include <dali/internal/event/events/long-press-gesture/long-press-gesture-recognizer.h>
 #include <dali/internal/event/events/gesture-requests.h>
+#include <dali/internal/event/events/long-press-gesture/long-press-gesture-event.h>
+#include <dali/internal/event/events/long-press-gesture/long-press-gesture-impl.h>
+#include <dali/internal/event/events/long-press-gesture/long-press-gesture-recognizer.h>
+#include <dali/internal/event/render-tasks/render-task-impl.h>
+#include <dali/public-api/actors/actor.h>
+#include <dali/public-api/common/dali-common.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 namespace
 {
-
+DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false);
 const unsigned long DEFAULT_MINIMUM_HOLDING_TIME = 500u;
 
 /**
@@ -52,22 +51,24 @@ const unsigned long DEFAULT_MINIMUM_HOLDING_TIME = 500u;
  * @param[in]  localPoint        Relative to the actor attached to the detector.
  */
 void EmitLongPressSignal(
-    Actor* actor,
-    const GestureDetectorContainer& gestureDetectors,
-    const LongPressGestureEvent& longPressEvent,
-    Vector2 localPoint)
+  Actor*                          actor,
+  const GestureDetectorContainer& gestureDetectors,
+  const LongPressGestureEvent&    longPressEvent,
+  Vector2                         localPoint)
 {
-  LongPressGesture longPress(longPressEvent.state);
-  longPress.time = longPressEvent.time;
-  longPress.numberOfTouches = longPressEvent.numberOfTouches;
-  longPress.screenPoint = longPressEvent.point;
-  longPress.localPoint = localPoint;
-
-  Dali::Actor actorHandle( actor );
+  Internal::LongPressGesturePtr longPress(new Internal::LongPressGesture(longPressEvent.state));
+  longPress->SetTime(longPressEvent.time);
+  longPress->SetNumberOfTouches(longPressEvent.numberOfTouches);
+  longPress->SetScreenPoint(longPressEvent.point);
+  longPress->SetLocalPoint(localPoint);
+  longPress->SetSourceType(longPressEvent.sourceType);
+  longPress->SetSourceData(longPressEvent.sourceData);
+
+  Dali::Actor                                    actorHandle(actor);
   const GestureDetectorContainer::const_iterator endIter = gestureDetectors.end();
-  for ( GestureDetectorContainer::const_iterator iter = gestureDetectors.begin(); iter != endIter; ++iter )
+  for(GestureDetectorContainer::const_iterator iter = gestureDetectors.begin(); iter != endIter; ++iter)
   {
-    static_cast< LongPressGestureDetector* >( *iter )->EmitLongPressGestureSignal( actorHandle, longPress );
+    static_cast<LongPressGestureDetector*>(*iter)->EmitLongPressGestureSignal(actorHandle, Dali::LongPressGesture(longPress.Get()));
   }
 }
 
@@ -81,8 +82,8 @@ struct IsNotAttachedFunctor
    * Constructor
    * @param[in]  actor  The actor to check whether it is attached.
    */
-  IsNotAttachedFunctor( Actor* actor )
-  : actorToCheck( actor )
+  IsNotAttachedFunctor(Actor* actor)
+  : actorToCheck(actor)
   {
   }
 
@@ -91,9 +92,9 @@ struct IsNotAttachedFunctor
    * @param[in]  detector  The detector to check.
    * @return true, if not attached, false otherwise.
    */
-  bool operator()( const GestureDetector* detector ) const
+  bool operator()(const GestureDetector* detector) const
   {
-    return !detector->IsAttached( *actorToCheck );
+    return !detector->IsAttached(*actorToCheck);
   }
 
   Actor* actorToCheck; ///< The actor to check whether it is attached or not.
@@ -102,55 +103,54 @@ struct IsNotAttachedFunctor
 } // unnamed namespace
 
 LongPressGestureProcessor::LongPressGestureProcessor()
-: GestureProcessor( Gesture::LongPress ),
+: GestureProcessor(GestureType::LONG_PRESS),
   mLongPressGestureDetectors(),
   mCurrentEmitters(),
   mCurrentRenderTask(),
-  mMinTouchesRequired( 1 ),
-  mMaxTouchesRequired( 1 ),
-  mCurrentLongPressEvent( NULL ),
-  mMinimumHoldingTime( DEFAULT_MINIMUM_HOLDING_TIME )
+  mMinTouchesRequired(1),
+  mMaxTouchesRequired(1),
+  mCurrentLongPressEvent(nullptr),
+  mMinimumHoldingTime(DEFAULT_MINIMUM_HOLDING_TIME)
 {
 }
 
-LongPressGestureProcessor::~LongPressGestureProcessor()
-{
-}
+LongPressGestureProcessor::~LongPressGestureProcessor() = default;
 
-void LongPressGestureProcessor::Process( Scene& scene, const LongPressGestureEvent& longPressEvent )
+void LongPressGestureProcessor::Process(Scene& scene, const LongPressGestureEvent& longPressEvent)
 {
-  switch ( longPressEvent.state )
+  DALI_TRACE_SCOPE(gTraceFilter, "DALI_PROCESS_LONG_PRESS_GESTURE");
+  switch(longPressEvent.state)
   {
-    case Gesture::Possible:
+    case GestureState::POSSIBLE:
     {
       mCurrentEmitters.clear();
       ResetActor();
 
       HitTestAlgorithm::Results hitTestResults;
-      if( HitTest( scene, longPressEvent.point, hitTestResults ) )
+      if(HitTest(scene, longPressEvent.point, hitTestResults))
       {
-        SetActor( &GetImplementation( hitTestResults.actor ) );
+        SetActor(&GetImplementation(hitTestResults.actor));
       }
       break;
     }
 
-    case Gesture::Started:
+    case GestureState::STARTED:
     {
       Actor* currentGesturedActor = GetCurrentGesturedActor();
-      if ( currentGesturedActor )
+      if(currentGesturedActor)
       {
         HitTestAlgorithm::Results hitTestResults;
-        HitTest( scene, longPressEvent.point, hitTestResults );
+        HitTest(scene, longPressEvent.point, hitTestResults);
 
-        if ( hitTestResults.actor && ( currentGesturedActor == &GetImplementation( hitTestResults.actor ) ) )
+        if(hitTestResults.actor && (currentGesturedActor == &GetImplementation(hitTestResults.actor)))
         {
           // Record the current render-task for Screen->Actor coordinate conversions
           mCurrentRenderTask = hitTestResults.renderTask;
 
           // Set mCurrentLongPressEvent to use inside overridden methods called from ProcessAndEmit()
           mCurrentLongPressEvent = &longPressEvent;
-          ProcessAndEmit( hitTestResults );
-          mCurrentLongPressEvent = NULL;
+          ProcessAndEmit(hitTestResults);
+          mCurrentLongPressEvent = nullptr;
         }
         else
         {
@@ -161,7 +161,7 @@ void LongPressGestureProcessor::Process( Scene& scene, const LongPressGestureEve
       break;
     }
 
-    case Gesture::Finished:
+    case GestureState::FINISHED:
     {
       // The gesture should only be sent to the gesture detector which first received it so that it
       // can be told when the gesture ends as well.
@@ -170,21 +170,21 @@ void LongPressGestureProcessor::Process( Scene& scene, const LongPressGestureEve
       // Check if actor is still touchable.
 
       Actor* currentGesturedActor = GetCurrentGesturedActor();
-      if ( currentGesturedActor )
+      if(currentGesturedActor)
       {
-        if ( currentGesturedActor->IsHittable() && !mCurrentEmitters.empty() && mCurrentRenderTask )
+        if(currentGesturedActor->IsHittable() && !mCurrentEmitters.empty() && mCurrentRenderTask)
         {
           // Ensure actor is still attached to the emitters, if it is not then remove the emitter.
-          GestureDetectorContainer::iterator endIter = std::remove_if( mCurrentEmitters.begin(), mCurrentEmitters.end(), IsNotAttachedFunctor(currentGesturedActor) );
-          mCurrentEmitters.erase( endIter, mCurrentEmitters.end() );
+          GestureDetectorContainer::iterator endIter = std::remove_if(mCurrentEmitters.begin(), mCurrentEmitters.end(), IsNotAttachedFunctor(currentGesturedActor));
+          mCurrentEmitters.erase(endIter, mCurrentEmitters.end());
 
-          if ( !mCurrentEmitters.empty() )
+          if(!mCurrentEmitters.empty())
           {
-            Vector2 actorCoords;
+            Vector2     actorCoords;
             RenderTask& renderTaskImpl = *mCurrentRenderTask.Get();
-            currentGesturedActor->ScreenToLocal( renderTaskImpl, actorCoords.x, actorCoords.y, longPressEvent.point.x, longPressEvent.point.y );
+            currentGesturedActor->ScreenToLocal(renderTaskImpl, actorCoords.x, actorCoords.y, longPressEvent.point.x, longPressEvent.point.y);
 
-            EmitLongPressSignal( currentGesturedActor, mCurrentEmitters, longPressEvent, actorCoords );
+            EmitLongPressSignal(currentGesturedActor, mCurrentEmitters, longPressEvent, actorCoords);
           }
         }
 
@@ -195,34 +195,34 @@ void LongPressGestureProcessor::Process( Scene& scene, const LongPressGestureEve
       break;
     }
 
-    case Gesture::Cancelled:
+    case GestureState::CANCELLED:
     {
       mCurrentEmitters.clear();
       ResetActor();
       break;
     }
 
-    case Gesture::Continuing:
+    case GestureState::CONTINUING:
     {
-      DALI_ABORT( "Incorrect state received from Integration layer: Continuing\n" );
+      DALI_ABORT("Incorrect state received from Integration layer: CONTINUING\n");
       break;
     }
 
-    case Gesture::Clear:
+    case GestureState::CLEAR:
     {
-      DALI_ABORT( "Incorrect state received from Integration layer: Clear\n" );
+      DALI_ABORT("Incorrect state received from Integration layer: CLEAR\n");
       break;
     }
   }
 }
 
-void LongPressGestureProcessor::AddGestureDetector( LongPressGestureDetector* gestureDetector, Scene& scene )
+void LongPressGestureProcessor::AddGestureDetector(LongPressGestureDetector* gestureDetector, Scene& scene)
 {
   bool firstRegistration(mLongPressGestureDetectors.empty());
 
   mLongPressGestureDetectors.push_back(gestureDetector);
 
-  if (firstRegistration)
+  if(firstRegistration)
   {
     mMinTouchesRequired = gestureDetector->GetMinimumTouchesRequired();
     mMaxTouchesRequired = gestureDetector->GetMaximumTouchesRequired();
@@ -233,7 +233,7 @@ void LongPressGestureProcessor::AddGestureDetector( LongPressGestureDetector* ge
 
     Size size = scene.GetSize();
 
-    mGestureRecognizer = new LongPressGestureRecognizer(*this, Vector2(size.width, size.height), static_cast<const LongPressGestureRequest&>(request), mMinimumHoldingTime );
+    mGestureRecognizer = new LongPressGestureRecognizer(*this, Vector2(size.width, size.height), static_cast<const LongPressGestureRequest&>(request), mMinimumHoldingTime);
   }
   else
   {
@@ -241,18 +241,18 @@ void LongPressGestureProcessor::AddGestureDetector( LongPressGestureDetector* ge
   }
 }
 
-void LongPressGestureProcessor::RemoveGestureDetector( LongPressGestureDetector* gestureDetector )
+void LongPressGestureProcessor::RemoveGestureDetector(LongPressGestureDetector* gestureDetector)
 {
   // Find detector ...
-  LongPressGestureDetectorContainer::iterator endIter = std::remove( mLongPressGestureDetectors.begin(), mLongPressGestureDetectors.end(), gestureDetector );
-  DALI_ASSERT_DEBUG( endIter != mLongPressGestureDetectors.end() );
+  LongPressGestureDetectorContainer::iterator endIter = std::remove(mLongPressGestureDetectors.begin(), mLongPressGestureDetectors.end(), gestureDetector);
+  DALI_ASSERT_DEBUG(endIter != mLongPressGestureDetectors.end());
 
   // ... and remove it
-  mLongPressGestureDetectors.erase( endIter, mLongPressGestureDetectors.end() );
+  mLongPressGestureDetectors.erase(endIter, mLongPressGestureDetectors.end());
 
-  if ( mLongPressGestureDetectors.empty() )
+  if(mLongPressGestureDetectors.empty())
   {
-    mGestureRecognizer.Detach();
+    mGestureRecognizer = nullptr;
   }
   else
   {
@@ -260,25 +260,25 @@ void LongPressGestureProcessor::RemoveGestureDetector( LongPressGestureDetector*
   }
 }
 
-void LongPressGestureProcessor::GestureDetectorUpdated( LongPressGestureDetector* gestureDetector )
+void LongPressGestureProcessor::GestureDetectorUpdated(LongPressGestureDetector* gestureDetector)
 {
-  DALI_ASSERT_DEBUG( find( mLongPressGestureDetectors.begin(), mLongPressGestureDetectors.end(), gestureDetector ) != mLongPressGestureDetectors.end() );
+  DALI_ASSERT_DEBUG(find(mLongPressGestureDetectors.begin(), mLongPressGestureDetectors.end(), gestureDetector) != mLongPressGestureDetectors.end());
 
   UpdateDetection();
 }
 
-void LongPressGestureProcessor::SetMinimumHoldingTime( uint32_t time )
+void LongPressGestureProcessor::SetMinimumHoldingTime(uint32_t time)
 {
-  if( time > 0u && mMinimumHoldingTime != time )
+  if(time > 0u && mMinimumHoldingTime != time)
   {
     mMinimumHoldingTime = time;
 
-    if( mGestureRecognizer )
+    if(mGestureRecognizer)
     {
-      LongPressGestureRecognizer* longPressRecognizer = dynamic_cast<LongPressGestureRecognizer*>( mGestureRecognizer.Get() );
-      if( longPressRecognizer )
+      LongPressGestureRecognizer* longPressRecognizer = dynamic_cast<LongPressGestureRecognizer*>(mGestureRecognizer.Get());
+      if(longPressRecognizer)
       {
-        longPressRecognizer->SetMinimumHoldingTime( time );
+        longPressRecognizer->SetMinimumHoldingTime(time);
       }
     }
   }
@@ -296,27 +296,27 @@ void LongPressGestureProcessor::UpdateDetection()
   unsigned int minimumRequired = UINT_MAX;
   unsigned int maximumRequired = 0;
 
-  for ( LongPressGestureDetectorContainer::iterator iter = mLongPressGestureDetectors.begin(), endIter = mLongPressGestureDetectors.end(); iter != endIter; ++iter )
+  for(LongPressGestureDetectorContainer::iterator iter = mLongPressGestureDetectors.begin(), endIter = mLongPressGestureDetectors.end(); iter != endIter; ++iter)
   {
     LongPressGestureDetector* current(*iter);
 
-    if( current )
+    if(current)
     {
       unsigned int minimum = current->GetMinimumTouchesRequired();
-      if (minimum < minimumRequired)
+      if(minimum < minimumRequired)
       {
         minimumRequired = minimum;
       }
 
       unsigned int maximum = current->GetMaximumTouchesRequired();
-      if ( maximum > maximumRequired )
+      if(maximum > maximumRequired)
       {
         maximumRequired = maximum;
       }
     }
   }
 
-  if ( (minimumRequired != mMinTouchesRequired) || (maximumRequired != mMaxTouchesRequired) )
+  if((minimumRequired != mMinTouchesRequired) || (maximumRequired != mMaxTouchesRequired))
   {
     mMinTouchesRequired = minimumRequired;
     mMaxTouchesRequired = maximumRequired;
@@ -333,29 +333,29 @@ void LongPressGestureProcessor::OnGesturedActorStageDisconnection()
   mCurrentEmitters.clear();
 }
 
-bool LongPressGestureProcessor::CheckGestureDetector( GestureDetector* detector, Actor* actor )
+bool LongPressGestureProcessor::CheckGestureDetector(GestureDetector* detector, Actor* actor)
 {
-  DALI_ASSERT_DEBUG( mCurrentLongPressEvent );
+  DALI_ASSERT_DEBUG(mCurrentLongPressEvent);
 
-  LongPressGestureDetector* longPressDetector ( static_cast< LongPressGestureDetector* >( detector ) );
+  LongPressGestureDetector* longPressDetector(static_cast<LongPressGestureDetector*>(detector));
 
-  return ( longPressDetector->GetMinimumTouchesRequired() <= mCurrentLongPressEvent->numberOfTouches ) &&
-         ( longPressDetector->GetMaximumTouchesRequired() >= mCurrentLongPressEvent->numberOfTouches );
+  return (longPressDetector->GetMinimumTouchesRequired() <= mCurrentLongPressEvent->numberOfTouches) &&
+         (longPressDetector->GetMaximumTouchesRequired() >= mCurrentLongPressEvent->numberOfTouches);
 }
 
-void LongPressGestureProcessor::EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
+void LongPressGestureProcessor::EmitGestureSignal(Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates)
 {
-  DALI_ASSERT_DEBUG( mCurrentLongPressEvent );
+  DALI_ASSERT_DEBUG(mCurrentLongPressEvent);
 
   mCurrentEmitters.clear();
   ResetActor();
 
-  EmitLongPressSignal( actor, gestureDetectors, *mCurrentLongPressEvent, actorCoordinates );
+  EmitLongPressSignal(actor, gestureDetectors, *mCurrentLongPressEvent, actorCoordinates);
 
-  if ( actor->OnStage() )
+  if(actor->OnScene())
   {
     mCurrentEmitters = gestureDetectors;
-    SetActor( actor );
+    SetActor(actor);
   }
 }