Let we use OrderedSet for VectorAnimationManager / SceneView 43/309943/3
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 18 Apr 2024 08:20:54 +0000 (17:20 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 29 Apr 2024 05:38:28 +0000 (14:38 +0900)
Some containers that triggered only one times could be optimized by OrderedSet feature.

Let we make Add/Remove time faster.

Change-Id: I3a4864a6e76671fa89f851b3b4382e74893ba130
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp
dali-scene3d/internal/controls/scene-view/scene-view-impl.h
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h

index 8c9b9b3c07ed5695c292b0bf1b5943134063f0b5..7fc62c127601b25d34583316d84a8f83a9ea29ea 100644 (file)
@@ -306,6 +306,7 @@ SceneView::SceneView()
   mSkybox(),
   mSkyboxOrientation(Quaternion()),
   mSkyboxIntensity(1.0f),
+  mLightObservers(),
   mShaderManager(new Scene3D::Loader::ShaderManager())
 {
 }
@@ -437,7 +438,7 @@ void SceneView::RegisterSceneItem(Scene3D::Internal::LightObserver* item)
   {
     item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor, mSpecularMipmapLevels);
     item->NotifyShadowMapTexture(mShadowTexture);
-    mItems.push_back(item);
+    mLightObservers.PushBack(item);
   }
 }
 
@@ -445,13 +446,10 @@ void SceneView::UnregisterSceneItem(Scene3D::Internal::LightObserver* item)
 {
   if(item)
   {
-    for(uint32_t i = 0; i < mItems.size(); ++i)
+    auto iter = mLightObservers.Find(item);
+    if(iter != mLightObservers.End())
     {
-      if(mItems[i] == item)
-      {
-        mItems.erase(mItems.begin() + i);
-        break;
-      }
+      mLightObservers.Erase(iter);
     }
   }
 }
@@ -566,7 +564,7 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const st
 void SceneView::SetImageBasedLightScaleFactor(float scaleFactor)
 {
   mIblScaleFactor = scaleFactor;
-  for(auto&& item : mItems)
+  for(auto&& item : mLightObservers)
   {
     if(item)
     {
@@ -693,7 +691,7 @@ void SceneView::RemoveShadow(Scene3D::Light light)
   mShadowLight.Reset();
 
   mShadowTexture.Reset();
-  for(auto&& item : mItems)
+  for(auto&& item : mLightObservers)
   {
     if(item)
     {
@@ -1020,7 +1018,7 @@ void SceneView::OnSceneConnection(int depth)
 
 void SceneView::OnSceneDisconnection()
 {
-  mItems.clear();
+  mLightObservers.Clear();
 
   Window window = mWindow.GetHandle();
   if(window)
@@ -1369,7 +1367,7 @@ void SceneView::OnIblLoadComplete()
 
 void SceneView::NotifyImageBasedLightTextureChange()
 {
-  for(auto&& item : mItems)
+  for(auto&& item : mLightObservers)
   {
     if(item)
     {
@@ -1411,7 +1409,7 @@ void SceneView::UpdateShadowMapBuffer(uint32_t shadowMapSize)
     DevelFrameBuffer::AttachDepthTexture(mShadowFrameBuffer, mShadowTexture);
     mShadowMapRenderTask.SetFrameBuffer(mShadowFrameBuffer);
 
-    for(auto&& item : mItems)
+    for(auto&& item : mLightObservers)
     {
       if(item)
       {
index 3d8c63961b53baab0504ad2ef2f6ec7d8c7483a6..29661ef53bb60a0f5ede4cf3384464645300414c 100644 (file)
@@ -22,6 +22,7 @@
 #include <dali-toolkit/internal/visuals/image/image-visual.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali/integration-api/adaptor-framework/scene-holder.h>
+#include <dali/integration-api/ordered-set.h>
 #include <dali/public-api/actors/camera-actor.h>
 #include <dali/public-api/actors/layer.h>
 #include <dali/public-api/adaptor-framework/window.h>
@@ -434,21 +435,22 @@ private:
 
   /////////////////////////////////////////////////////////////
   // FrameBuffer and Rendertask to render child objects as a 3D Scene
-  Dali::WeakHandle<Dali::Window>                 mWindow;
-  Integration::SceneHolder                       mSceneHolder;
-  CameraActor                                    mDefaultCamera;
-  CameraActor                                    mSelectedCamera;
-  std::vector<CameraActor>                       mCameras;
-  std::vector<Scene3D::Internal::LightObserver*> mItems;
-  Dali::FrameBuffer                              mFrameBuffer;
-  Dali::Texture                                  mTexture;
-  Dali::RenderTask                               mRenderTask;
-  Layer                                          mRootLayer;
-  int32_t                                        mWindowOrientation;
-  Dali::Actor                                    mSkybox;
-  Quaternion                                     mSkyboxOrientation;
-  float                                          mSkyboxIntensity{1.0f};
-  uint8_t                                        mFrameBufferMultiSamplingLevel{0u};
+  Dali::WeakHandle<Dali::Window> mWindow;
+  Integration::SceneHolder       mSceneHolder;
+  CameraActor                    mDefaultCamera;
+  CameraActor                    mSelectedCamera;
+  std::vector<CameraActor>       mCameras;
+  Dali::FrameBuffer              mFrameBuffer;
+  Dali::Texture                  mTexture;
+  Dali::RenderTask               mRenderTask;
+  Layer                          mRootLayer;
+  int32_t                        mWindowOrientation;
+  Dali::Actor                    mSkybox;
+  Quaternion                     mSkyboxOrientation;
+  float                          mSkyboxIntensity{1.0f};
+  uint8_t                        mFrameBufferMultiSamplingLevel{0u};
+
+  Dali::Integration::OrderedSet<Scene3D::Internal::LightObserver, false> mLightObservers; ///< The set of items to be notified when light properties change. (not owned)
 
   bool     mWindowSizeChanged{false};
   uint32_t mWindowWidth{0};
index 430a0c56040798c9bb9318495ab265aba19eaab9..2d1fce9486440949c7e317442014994bac2344c7 100644 (file)
@@ -51,7 +51,7 @@ VectorAnimationManager::VectorAnimationManager()
 
 VectorAnimationManager::~VectorAnimationManager()
 {
-  mEventCallbacks.clear();
+  mEventCallbacks.Clear();
 
   if(mProcessorRegistered && Adaptor::IsAvailable())
   {
@@ -71,7 +71,7 @@ VectorAnimationThread& VectorAnimationManager::GetVectorAnimationThread()
 
 void VectorAnimationManager::RegisterEventCallback(CallbackBase* callback)
 {
-  mEventCallbacks.emplace_back(std::unique_ptr<Dali::CallbackBase>(callback));
+  mEventCallbacks.PushBack(callback); ///< Take ownership of callback.
 
   if(!mProcessorRegistered)
   {
@@ -82,16 +82,12 @@ void VectorAnimationManager::RegisterEventCallback(CallbackBase* callback)
 
 void VectorAnimationManager::UnregisterEventCallback(CallbackBase* callback)
 {
-  auto iter = std::find_if(mEventCallbacks.begin(),
-                           mEventCallbacks.end(),
-                           [callback](const std::unique_ptr<CallbackBase>& element) {
-                             return element.get() == callback;
-                           });
-  if(iter != mEventCallbacks.end())
+  auto iter = mEventCallbacks.Find(callback);
+  if(iter != mEventCallbacks.End())
   {
-    mEventCallbacks.erase(iter);
+    mEventCallbacks.Erase(iter);
 
-    if(mEventCallbacks.empty())
+    if(mEventCallbacks.Count() == 0u)
     {
       if(Adaptor::IsAvailable())
       {
@@ -107,10 +103,10 @@ void VectorAnimationManager::Process(bool postProcessor)
 #ifdef TRACE_ENABLED
   if(gTraceFilter && gTraceFilter->IsTraceEnabled())
   {
-    if(mEventCallbacks.size() > 0u)
+    if(mEventCallbacks.Count() > 0u)
     {
       std::ostringstream oss;
-      oss << "[" << mEventCallbacks.size() << "]";
+      oss << "[" << mEventCallbacks.Count() << "]";
       DALI_TRACE_BEGIN_WITH_MESSAGE(gTraceFilter, "DALI_VECTOR_ANIMATION_MANAGER_PROCESS", oss.str().c_str());
     }
   }
@@ -124,15 +120,15 @@ void VectorAnimationManager::Process(bool postProcessor)
 #ifdef TRACE_ENABLED
   if(gTraceFilter && gTraceFilter->IsTraceEnabled())
   {
-    if(mEventCallbacks.size() > 0u)
+    if(mEventCallbacks.Count() > 0u)
     {
       std::ostringstream oss;
-      oss << "[" << mEventCallbacks.size() << "]";
+      oss << "[" << mEventCallbacks.Count() << "]";
       DALI_TRACE_END_WITH_MESSAGE(gTraceFilter, "DALI_VECTOR_ANIMATION_MANAGER_PROCESS", oss.str().c_str());
     }
   }
 #endif
-  mEventCallbacks.clear();
+  mEventCallbacks.Clear();
 
   Adaptor::Get().UnregisterProcessor(*this, true);
   mProcessorRegistered = false;
index 98794715da5cb8839c2031ddb015e125fce5cef0..53dbb06dbc8e35f6275e0e4a70ad2d6417426ba9 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali/integration-api/ordered-set.h>
 #include <dali/integration-api/processor-interface.h>
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/signals/callback.h>
@@ -93,9 +94,10 @@ private:
   VectorAnimationManager& operator=(const VectorAnimationManager& manager) = delete;
 
 private:
-  std::vector<std::unique_ptr<CallbackBase>> mEventCallbacks;
-  std::unique_ptr<VectorAnimationThread>     mVectorAnimationThread;
-  bool                                       mProcessorRegistered;
+  Dali::Integration::OrderedSet<CallbackBase> mEventCallbacks; ///< Event triggered callback lists (owned)
+
+  std::unique_ptr<VectorAnimationThread> mVectorAnimationThread;
+  bool                                   mProcessorRegistered : 1;
 };
 
 } // namespace Internal