[Tizen] Fixed Cache for AnimatedVectorImageVisual 45/302145/1
authorseungho baek <sbsh.baek@samsung.com>
Thu, 26 Oct 2023 09:17:02 +0000 (18:17 +0900)
committersunghyun kim <scholb.kim@samsung.com>
Fri, 1 Dec 2023 02:12:15 +0000 (11:12 +0900)
Change-Id: I22bab282652f5377b95ce1d34db4564398be0ae8
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
dali-toolkit/devel-api/visuals/image-visual-properties-devel.h
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h
dali-toolkit/internal/visuals/visual-string-constants.cpp
dali-toolkit/internal/visuals/visual-string-constants.h

index 9e6d199..1f92daa 100644 (file)
@@ -155,7 +155,17 @@ enum Type
    * So we change its value to MASKING_ON_RENDERING even if the visual sets the MASKING_TYPE as MASKING_ON_LOADING when it uses external texture.
    * @note It is used in the ImageVisual and AnimatedImageVisual. The default is MASKING_ON_LOADING.
    */
-  MASKING_TYPE = ORIENTATION_CORRECTION + 12
+  MASKING_TYPE = ORIENTATION_CORRECTION + 12,
+
+  /**
+   * @brief Whether to animated image visual uses fixed cache or not.
+   * @details Name "useFixedCache", type Property::BOOLEAN.
+   * If this property is true, animated image visual uses fixed cache for loading and keeps loaded frame
+   * until the visual is removed. It reduces CPU cost when the animated image will be looping.
+   * But it can spend a lot of memory if the resource has high resolution image or many frame count.
+   * @note It is used in the AnimatedImageVisual. The default is false
+   */
+  USE_FIXED_CACHE = ORIENTATION_CORRECTION + 13
 };
 
 } //namespace Property
index 4f8f04d..1f5be69 100644 (file)
@@ -98,7 +98,8 @@ AnimatedVectorImageVisual::AnimatedVectorImageVisual(VisualFactoryCache& factory
   mLoadFailed(false),
   mRendererAdded(false),
   mCoreShutdown(false),
-  mRedrawInScalingDown(true)
+  mRedrawInScalingDown(true),
+  mUseFixedCache(false)
 {
   // the rasterized image is with pre-multiplied alpha format
   mImpl->mFlags |= Visual::Base::Impl::IS_PREMULTIPLIED_ALPHA;
@@ -204,6 +205,7 @@ void AnimatedVectorImageVisual::DoCreatePropertyMap(Property::Map& map) const
   map.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, IsSynchronousLoadingRequired());
   map.Insert(Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth());
   map.Insert(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight());
+  map.Insert(Toolkit::DevelImageVisual::Property::USE_FIXED_CACHE, mUseFixedCache);
 }
 
 void AnimatedVectorImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
@@ -264,6 +266,10 @@ void AnimatedVectorImageVisual::DoSetProperties(const Property::Map& propertyMap
       {
         DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, keyValue.second);
       }
+      else if(keyValue.first == USE_FIXED_CACHE)
+      {
+        DoSetProperty(Toolkit::DevelImageVisual::Property::USE_FIXED_CACHE, keyValue.second);
+      }
     }
   }
 
@@ -369,6 +375,20 @@ void AnimatedVectorImageVisual::DoSetProperty(Property::Index index, const Prope
       }
       break;
     }
+
+    case Toolkit::DevelImageVisual::Property::USE_FIXED_CACHE:
+    {
+      bool useFixedCache = false;
+      if(value.Get(useFixedCache))
+      {
+        mUseFixedCache = useFixedCache;
+        if(mVectorAnimationTask)
+        {
+          mVectorAnimationTask->KeepRasterizedBuffer(mUseFixedCache);
+        }
+      }
+      break;
+    }
   }
 }
 
@@ -377,6 +397,7 @@ void AnimatedVectorImageVisual::OnInitialize(void)
   mVectorAnimationTask->ResourceReadySignal().Connect(this, &AnimatedVectorImageVisual::OnResourceReady);
   mVectorAnimationTask->SetAnimationFinishedCallback(new EventThreadCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished)));
 
+  mVectorAnimationTask->KeepRasterizedBuffer(mUseFixedCache);
   mVectorAnimationTask->RequestLoad(mUrl.GetUrl(), IsSynchronousLoadingRequired());
 
   auto& vectorAnimationManager = mFactoryCache.GetVectorAnimationManager();
index b0a7569..f579c73 100644 (file)
@@ -253,6 +253,7 @@ private:
   bool                               mRendererAdded;
   bool                               mCoreShutdown;
   bool                               mRedrawInScalingDown;
+  bool                               mUseFixedCache;
 };
 
 } // namespace Internal
index 45d3484..843d48b 100644 (file)
@@ -76,7 +76,9 @@ VectorAnimationTask::VectorAnimationTask(VisualFactoryCache& factoryCache)
   mAnimationDataUpdated(false),
   mDestroyTask(false),
   mLoadRequest(false),
-  mLoadFailed(false)
+  mLoadFailed(false),
+  mUseFixedCache(false),
+  mSizeUpdated(false)
 {
   mVectorRenderer.UploadCompletedSignal().Connect(this, &VectorAnimationTask::OnUploadCompleted);
 }
@@ -197,6 +199,18 @@ void VectorAnimationTask::SetSize(uint32_t width, uint32_t height)
 
     mWidth  = width;
     mHeight = height;
+    if(mUseFixedCache)
+    {
+      if(mTotalFrame > 0 && !mLoadFailed)
+      {
+        DALI_LOG_ERROR("fixed texture cache is assigned in SetSize\n");
+        mVectorRenderer.KeepRasterizedBuffer();
+      }
+      else
+      {
+        mSizeUpdated = true;
+      }
+    }
 
     DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetSize: width = %d, height = %d [%p]\n", width, height, this);
   }
@@ -691,6 +705,11 @@ void VectorAnimationTask::OnLoadCompleted()
 {
   if(!mLoadFailed)
   {
+    if(mUseFixedCache && mSizeUpdated)
+    {
+      mVectorRenderer.KeepRasterizedBuffer();
+      mSizeUpdated = false;
+    }
     mResourceReadySignal.Emit(ResourceStatus::LOADED);
   }
   else
index 4a0c497..14085eb 100644 (file)
@@ -227,6 +227,16 @@ public:
    */
   TimePoint GetNextFrameTime();
 
+  void KeepRasterizedBuffer(bool useFixedCache)
+  {
+    mUseFixedCache = useFixedCache;
+  }
+
+  bool IsKeptRasterizedBuffer()
+  {
+    return mUseFixedCache;
+  }
+
 private:
   /**
    * @brief Loads the animation file.
@@ -357,6 +367,8 @@ private:
   bool                                 mDestroyTask;
   bool                                 mLoadRequest;
   bool                                 mLoadFailed;
+  bool                                 mUseFixedCache;
+  bool                                 mSizeUpdated;
 };
 
 } // namespace Internal
index c79c9a6..0ef6515 100644 (file)
@@ -124,6 +124,7 @@ const char* const ALPHA_MASK_URL("alphaMaskUrl");
 const char* const REDRAW_IN_SCALING_DOWN_NAME("redrawInScalingDown");
 const char* const MASKING_TYPE_NAME("maskingType");
 const char* const MASK_TEXTURE_RATIO_NAME("maskTextureRatio");
+const char* const USE_FIXED_CACHE("useFixedCache");
 
 // Text visual
 const char* const TEXT_PROPERTY("text");
index b65292f..438c340 100644 (file)
@@ -108,6 +108,7 @@ extern const char* const ALPHA_MASK_URL;
 extern const char* const REDRAW_IN_SCALING_DOWN_NAME;
 extern const char* const MASKING_TYPE_NAME;
 extern const char* const MASK_TEXTURE_RATIO_NAME;
+extern const char* const USE_FIXED_CACHE;
 
 // Text visual
 extern const char* const TEXT_PROPERTY;