[Tizen] SecondPhase initialize for ProcessorController 42/302642/1
authorEunki Hong <eunkiki.hong@samsung.com>
Wed, 6 Dec 2023 15:52:46 +0000 (00:52 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Mon, 11 Dec 2023 10:13:56 +0000 (19:13 +0900)
Let we allow to create ProcessController not-main thread.
Rather then, let we create & register at App Initialized timing.

Change-Id: I59b1d0f04ce08a759e238419ac2996dbdddbf91d
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
dali-csharp-binder/common/processor-controller.cpp
dali-csharp-binder/common/processor-controller.h

index fa2222e..e1869d5 100644 (file)
 // EXTERNAL INCLUDES
 #include <dali/devel-api/common/stage-devel.h>
 #include <dali/integration-api/adaptor-framework/adaptor.h>
+#include <dali/integration-api/debug.h>
+#include <dali/integration-api/trace.h>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+namespace
+{
+DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false);
+}
 
 ProcessorController::ProcessorController()
 : mHandler(nullptr),
   mPostHandler(nullptr),
+  mProcessRegistered(false),
   mKeepRenderingApplied(false),
   mProcessingEvents(false),
   mProcessEventsIdleRequested(false)
 {
-  {
-    try
-    {
-      Dali::Adaptor::Get().RegisterProcessor(*this);
-      Dali::Adaptor::Get().RegisterProcessor(*this, true);
-    }
-    CALL_CATCH_EXCEPTION();
-  }
 }
 
 ProcessorController::~ProcessorController()
@@ -48,8 +44,13 @@ ProcessorController::~ProcessorController()
   {
     try
     {
-      Dali::Adaptor::Get().UnregisterProcessor(*this);
-      Dali::Adaptor::Get().UnregisterProcessor(*this, true);
+      if(mProcessRegistered)
+      {
+        Dali::Adaptor::Get().UnregisterProcessor(*this);
+        Dali::Adaptor::Get().UnregisterProcessor(*this, true);
+
+        mProcessRegistered = false;
+      }
     }
     CALL_CATCH_EXCEPTION();
   }
@@ -67,13 +68,15 @@ void ProcessorController::Process(bool postProcessor)
 
     if(DALI_LIKELY(mHandler != nullptr))
     {
+      DALI_TRACE_SCOPE(gTraceFilter, "NUI_PROCESS");
       mHandler();
     }
   }
   else
   {
-    if(DALI_LIKELY(mPostHandler != nullptr))
+    if(mPostHandler != nullptr)
     {
+      DALI_TRACE_SCOPE(gTraceFilter, "NUI_POST_PROCESS");
       mPostHandler();
     }
     // Make awake events can be applied after PostProcess done.
@@ -106,6 +109,8 @@ void ProcessorController::RemovePostCallback(  ProcessorControllerProcessCallbac
 
 void ProcessorController::Awake()
 {
+  DALI_ASSERT_ALWAYS(mProcessRegistered && "ProcessorController should be initialized before call Awake");
+
   if(!mProcessingEvents && !mKeepRenderingApplied)
   {
     if(DALI_LIKELY(Dali::Stage::IsInstalled())) ///< Avoid worker thread calling.
@@ -126,6 +131,25 @@ void ProcessorController::Awake()
   }
 }
 
+void ProcessorController::RegisterProcess()
+{
+  if(!mProcessRegistered)
+  {
+    try
+    {
+      Dali::Adaptor::Get().RegisterProcessor(*this);
+      Dali::Adaptor::Get().RegisterProcessor(*this, true);
+
+      mProcessRegistered = true;
+    }
+    CALL_CATCH_EXCEPTION(); 
+  }
+}
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 // ProcessorController Bindings
 SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_new_ProcessorController() {
 
@@ -150,6 +174,16 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_delete_ProcessorController(void * jarg1)
   }
 }
 
+SWIGEXPORT void SWIGSTDCALL CSharp_Dali_ProcessorController_Initialize(void* jarg1)
+{
+  ProcessorController* processorController = (ProcessorController *) jarg1;
+
+  if( processorController )
+  {
+    processorController->RegisterProcess();
+  }
+}
+
 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_ProcessorController_SetCallback( void* jarg1, ProcessorController::ProcessorControllerProcessCallback callback )
 {
   ProcessorController* processorController = (ProcessorController *) jarg1;
index e6569fc..9939e67 100644 (file)
@@ -38,7 +38,7 @@ public:
 
 public:
   /**
-   * @brief Constructor - creates a ProcessorController and registers it with dali-core.
+   * @brief Constructor - creates a ProcessorController.
    *
    */
   ProcessorController();
@@ -49,6 +49,11 @@ public:
   ~ProcessorController();
 
   /**
+   * @brief Register this processor into dali-core.
+   */
+  void RegisterProcess();
+
+  /**
    * @copydoc Dali::Integration::Processor::Process()
    */
   void Process(bool postProcessor) override;
@@ -89,6 +94,7 @@ private:
   ProcessorControllerProcessCallback mHandler;              ///< PreProcessHandler before Relayout
   ProcessorControllerProcessCallback mPostHandler;          ///< PostProcessHandler after Relayout
 
+  bool mProcessRegistered : 1;          ///< True if we call RegisterProcess. False otherwise.
   bool mKeepRenderingApplied : 1;       ///< True if we call Stage::KeepRendering(0.0f). It need to avoid duplicated keep rendering call
   bool mProcessingEvents : 1;           ///< True if we are running Process now.
   bool mProcessEventsIdleRequested : 1; ///< True if we call Adaptor::RequestProcessEventsOnIdle(). It need to avoid duplicated request call.