Add post processor 65/257265/1
authorseungho <sbsh.baek@samsung.com>
Thu, 22 Apr 2021 01:42:03 +0000 (10:42 +0900)
committerseungho <sbsh.baek@samsung.com>
Thu, 22 Apr 2021 01:52:07 +0000 (10:52 +0900)
 - This patch adds post processor that works after relayout.

Change-Id: I194763b5f512517c6a385c27f0b0728f6fcddfc4
Signed-off-by: seungho <sbsh.baek@samsung.com>
automated-tests/src/dali/utc-Dali-Processors.cpp
dali/integration-api/core.cpp
dali/integration-api/core.h
dali/integration-api/processor-interface.h
dali/internal/common/core-impl.cpp
dali/internal/common/core-impl.h

index 9f797fb..0d1b864 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -31,7 +31,7 @@ public:
   {
   }
 
-  virtual void Process()
+  virtual void Process(bool postProcessor)
   {
     processRun = true;
   }
@@ -114,4 +114,39 @@ int UtcDaliCoreProcessorMultipleP(void)
   DALI_TEST_CHECK(testProcessor3.processRun);
 
   END_TEST;
+}
+
+int UtcDaliCorePostProcessorP(void)
+{
+  TestApplication application;
+
+  TestProcessor      testProcessor;
+  Integration::Core& core = application.GetCore();
+  core.RegisterProcessor(testProcessor, true);
+
+  tet_infoline("Test that the processor has not been executed yet:");
+  DALI_TEST_CHECK(testProcessor.processRun == false);
+
+  application.SendNotification();
+
+  tet_infoline("Test that the processor has been executed:");
+  DALI_TEST_CHECK(testProcessor.processRun);
+
+  // Clear down for next part of test
+  testProcessor.processRun = false;
+
+  core.UnregisterProcessor(testProcessor);
+  application.SendNotification();
+  tet_infoline("Test that the processor is still executed:");
+  DALI_TEST_CHECK(testProcessor.processRun);
+
+  // Clear down for next part of test
+  testProcessor.processRun = false;
+
+  core.UnregisterProcessor(testProcessor, true);
+  application.SendNotification();
+  tet_infoline("Test that the processor has not been executed again:");
+  DALI_TEST_CHECK(testProcessor.processRun == false);
+
+  END_TEST;
 }
\ No newline at end of file
index 3942bea..99001f3 100644 (file)
@@ -130,14 +130,14 @@ void Core::PostRender(bool uploadOnly)
   mImpl->PostRender(uploadOnly);
 }
 
-void Core::RegisterProcessor(Processor& processor)
+void Core::RegisterProcessor(Processor& processor, bool postProcessor)
 {
-  mImpl->RegisterProcessor(processor);
+  mImpl->RegisterProcessor(processor, postProcessor);
 }
 
-void Core::UnregisterProcessor(Processor& processor)
+void Core::UnregisterProcessor(Processor& processor, bool postProcessor)
 {
-  mImpl->UnregisterProcessor(processor);
+  mImpl->UnregisterProcessor(processor, postProcessor);
 }
 
 ObjectRegistry Core::GetObjectRegistry() const
index 4952c57..1dd070d 100644 (file)
@@ -392,14 +392,16 @@ public:
    *
    * Note, Core does not take ownership of this processor.
    * @param[in] processor The process to register
+   * @param[in] postProcessor set this processor required to be called after size negotiation. Default is false.
    */
-  void RegisterProcessor(Processor& processor);
+  void RegisterProcessor(Processor& processor, bool postProcessor = false);
 
   /**
    * @brief Unregister a processor
    * @param[in] processor The process to unregister
+   * @param[in] postProcessor True if the processor to be unregister is for post processor.
    */
-  void UnregisterProcessor(Processor& processor);
+  void UnregisterProcessor(Processor& processor, bool postProcessor = false);
 
   /**
    * @brief Gets the Object registry.
index 70c01bd..45408ff 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTEGRATION_PROCESSOR_INTERFACE_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -35,7 +35,7 @@ public:
   /**
    * @brief Run the processor
    */
-  virtual void Process() = 0;
+  virtual void Process(bool postProcessor = false) = 0;
 
 protected:
   /**
index 41adba0..6d129e6 100644 (file)
@@ -297,6 +297,9 @@ void Core::ProcessEvents()
   // Run the size negotiation after event processing finished signal
   mRelayoutController->Relayout();
 
+  // Run any registered post processors
+  RunPostProcessors();
+
   // Rebuild depth tree after event processing has finished
   for(auto scene : scenes)
   {
@@ -328,17 +331,35 @@ uint32_t Core::GetMaximumUpdateCount() const
   return MAXIMUM_UPDATE_COUNT;
 }
 
-void Core::RegisterProcessor(Integration::Processor& processor)
+void Core::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
 {
-  mProcessors.PushBack(&processor);
+  if(postProcessor)
+  {
+    mPostProcessors.PushBack(&processor);
+  }
+  else
+  {
+    mProcessors.PushBack(&processor);
+  }
 }
 
-void Core::UnregisterProcessor(Integration::Processor& processor)
+void Core::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
 {
-  auto iter = std::find(mProcessors.Begin(), mProcessors.End(), &processor);
-  if(iter != mProcessors.End())
+  if(postProcessor)
   {
-    mProcessors.Erase(iter);
+    auto iter = std::find(mPostProcessors.Begin(), mPostProcessors.End(), &processor);
+    if(iter != mPostProcessors.End())
+    {
+      mPostProcessors.Erase(iter);
+    }
+  }
+  else
+  {
+    auto iter = std::find(mProcessors.Begin(), mProcessors.End(), &processor);
+    if(iter != mProcessors.End())
+    {
+      mProcessors.Erase(iter);
+    }
   }
 }
 
@@ -351,7 +372,21 @@ void Core::RunProcessors()
   {
     if(processor)
     {
-      processor->Process();
+      processor->Process(false);
+    }
+  }
+}
+
+void Core::RunPostProcessors()
+{
+  // Copy processor pointers to prevent changes to vector affecting loop iterator.
+  Dali::Vector<Integration::Processor*> processors(mPostProcessors);
+
+  for(auto processor : processors)
+  {
+    if(processor)
+    {
+      processor->Process(true);
     }
   }
 }
index 3f0307d..9744d0d 100644 (file)
@@ -175,12 +175,12 @@ public:
   /**
    * @copydoc Dali::Integration::Core::RegisterProcessor
    */
-  void RegisterProcessor(Dali::Integration::Processor& processor);
+  void RegisterProcessor(Integration::Processor& processor, bool postProcessor = false);
 
   /**
    * @copydoc Dali::Integration::Core::UnregisterProcessor
    */
-  void UnregisterProcessor(Dali::Integration::Processor& processor);
+  void UnregisterProcessor(Dali::Integration::Processor& processor, bool postProcessor = false);
 
   /**
    * @copydoc Dali::Internal::ThreadLocalStorage::AddScene()
@@ -245,6 +245,11 @@ private:
    */
   void RunProcessors();
 
+  /**
+   * Run each registered postprocessor
+   */
+  void RunPostProcessors();
+
   // for use by ThreadLocalStorage
 
   /**
@@ -343,6 +348,7 @@ private:
   OwnerPointer<NotificationManager>             mNotificationManager;   ///< Notification manager
   OwnerPointer<GestureEventProcessor>           mGestureEventProcessor; ///< The gesture event processor
   Dali::Vector<Integration::Processor*>         mProcessors;            ///< Registered processors (not owned)
+  Dali::Vector<Integration::Processor*>         mPostProcessors;        ///< Registered post processors those will called after relayout(not owned)
 
   using SceneContainer = std::vector<ScenePtr>;
   SceneContainer mScenes; ///< A container of scenes that bound to a surface for rendering, owned by Core