[dali_2.3.42] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-vector-animation-renderer.cpp
index 4b6c5c8..aec90ad 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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 <dali/devel-api/adaptor-framework/pixel-buffer.h>
 #include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
+#include <dali/devel-api/threading/mutex.h>
+#include <dali/public-api/adaptor-framework/native-image-source.h>
 #include <dali/public-api/object/base-object.h>
+#include <dali/public-api/object/property-array.h>
 #include <toolkit-application.h>
 #include <toolkit-event-thread-callback.h>
 #include <toolkit-vector-animation-renderer.h>
@@ -53,6 +56,7 @@ public:
     mFrameRate(60.0f),
     mTestFrameDrop(false),
     mNeedDroppedFrames(false),
+    mUseNativeImage(false),
     mEventThreadCallback(new EventThreadCallback(MakeCallback(this, &VectorAnimationRenderer::OnTriggered)))
   {
     mCount++;
@@ -70,6 +74,7 @@ public:
 
   bool Load(const std::string& url)
   {
+    Dali::Mutex::ScopedLock lock(mMutex);
     mUrl = url;
     if(mUrl == "invalid.json")
     {
@@ -80,7 +85,6 @@ public:
     {
       // Change total frame number for test
       mTotalFrameNumber = 200;
-      mTestFrameDrop    = true;
     }
 
     mDefaultWidth  = 100;
@@ -89,6 +93,16 @@ public:
     return true;
   }
 
+  bool Load(const Dali::Vector<uint8_t>& data)
+  {
+    Dali::Mutex::ScopedLock lock(mMutex);
+
+    mDefaultWidth  = 100;
+    mDefaultHeight = 100;
+
+    return true;
+  }
+
   void SetRenderer(Dali::Renderer renderer)
   {
     mRenderer = renderer;
@@ -96,6 +110,7 @@ public:
 
   void SetSize(uint32_t width, uint32_t height)
   {
+    Dali::Mutex::ScopedLock lock(mMutex);
     mWidth  = width;
     mHeight = height;
 
@@ -108,6 +123,7 @@ public:
 
   bool Render(uint32_t frameNumber)
   {
+    Dali::Mutex::ScopedLock lock(mMutex);
     if(mWidth == 0 || mHeight == 0)
     {
       return false;
@@ -126,6 +142,11 @@ public:
       mNeedDroppedFrames = false;
     }
 
+    if(mDynamicPropertyCallback)
+    {
+      CallbackBase::ExecuteReturn<Property::Value>(*mDynamicPropertyCallback, 0, 0, frameNumber);
+    }
+
     if(mNeedTrigger)
     {
       mEventThreadCallback->Trigger();
@@ -179,8 +200,23 @@ public:
 
   void InvalidateBuffer()
   {
-    mNeedTrigger   = true;
-    mResourceReady = false;
+    Dali::Mutex::ScopedLock lock(mMutex);
+    if(mResourceReady)
+    {
+      mNeedTrigger   = true;
+      mResourceReady = false;
+    }
+  }
+
+  void AddPropertyValueCallback(const std::string& keyPath, Dali::VectorAnimationRenderer::VectorProperty property, CallbackBase* callback, int32_t id)
+  {
+    mDynamicPropertyCallback = std::unique_ptr<CallbackBase>(callback);
+  }
+
+  void KeepRasterizedBuffer()
+  {
+    Dali::Mutex::ScopedLock lock(mMutex);
+    mEnableFixedCache = true;
   }
 
   Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
@@ -195,12 +231,22 @@ public:
       mResourceReady = true;
 
       Dali::TextureSet textureSet = mRenderer.GetTextures();
-      Dali::Texture    texture    = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight);
-      textureSet.SetTexture(0, texture);
 
-      Devel::PixelBuffer pixelBuffer = Devel::PixelBuffer::New(mWidth, mHeight, Pixel::RGBA8888);
-      Dali::PixelData    pixelData   = Devel::PixelBuffer::Convert(pixelBuffer);
-      texture.Upload(pixelData);
+      if(mUseNativeImage)
+      {
+        Dali::NativeImageSourcePtr nativeImageSource = Dali::NativeImageSource::New(mWidth, mHeight, Dali::NativeImageSource::COLOR_DEPTH_32);
+        Dali::Texture              texture           = Dali::Texture::New(*nativeImageSource);
+        textureSet.SetTexture(0, texture);
+      }
+      else
+      {
+        Dali::Texture texture = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight);
+        textureSet.SetTexture(0, texture);
+
+        Devel::PixelBuffer pixelBuffer = Devel::PixelBuffer::New(mWidth, mHeight, Pixel::RGBA8888);
+        Dali::PixelData    pixelData   = Devel::PixelBuffer::Convert(pixelBuffer);
+        texture.Upload(pixelData);
+      }
 
       mUploadCompletedSignal.Emit();
     }
@@ -209,22 +255,27 @@ public:
 public:
   static uint32_t mCount;
 
-  std::string    mUrl;
-  Dali::Renderer mRenderer;
-  uint32_t       mWidth;
-  uint32_t       mHeight;
-  uint32_t       mDefaultWidth;
-  uint32_t       mDefaultHeight;
-  uint32_t       mTotalFrameNumber;
-  uint32_t       mPreviousFrame;
-  uint32_t       mDelayTime;
-  uint32_t       mDroppedFrames;
-  float          mFrameRate;
-  bool           mTestFrameDrop;
-  bool           mNeedDroppedFrames;
-  bool           mLoadFailed{false};
-  bool           mResourceReady{false};
-  bool           mNeedTrigger{true};
+  std::string                   mUrl;
+  Dali::Renderer                mRenderer;
+  Dali::Mutex                   mMutex;
+  std::unique_ptr<CallbackBase> mDynamicPropertyCallback{nullptr};
+
+  uint32_t mWidth;
+  uint32_t mHeight;
+  uint32_t mDefaultWidth;
+  uint32_t mDefaultHeight;
+  uint32_t mTotalFrameNumber;
+  uint32_t mPreviousFrame;
+  uint32_t mDelayTime;
+  uint32_t mDroppedFrames;
+  float    mFrameRate;
+  bool     mTestFrameDrop;
+  bool     mNeedDroppedFrames;
+  bool     mLoadFailed{false};
+  bool     mResourceReady{false};
+  bool     mNeedTrigger{true};
+  bool     mEnableFixedCache{false};
+  bool     mUseNativeImage{false};
 
   Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal;
   std::unique_ptr<EventThreadCallback>                     mEventThreadCallback;
@@ -296,6 +347,11 @@ bool VectorAnimationRenderer::Load(const std::string& url)
   return Internal::Adaptor::GetImplementation(*this).Load(url);
 }
 
+bool VectorAnimationRenderer::Load(const Dali::Vector<uint8_t>& data)
+{
+  return Internal::Adaptor::GetImplementation(*this).Load(data);
+}
+
 void VectorAnimationRenderer::SetRenderer(Renderer renderer)
 {
   Internal::Adaptor::GetImplementation(*this).SetRenderer(renderer);
@@ -311,6 +367,10 @@ bool VectorAnimationRenderer::Render(uint32_t frameNumber)
   return Internal::Adaptor::GetImplementation(*this).Render(frameNumber);
 }
 
+void VectorAnimationRenderer::RenderStopped()
+{
+}
+
 uint32_t VectorAnimationRenderer::GetTotalFrameNumber() const
 {
   return Internal::Adaptor::GetImplementation(*this).GetTotalFrameNumber();
@@ -335,11 +395,27 @@ bool VectorAnimationRenderer::GetMarkerInfo(const std::string& marker, uint32_t&
   return Internal::Adaptor::GetImplementation(*this).GetMarkerInfo(marker, startFrame, endFrame);
 }
 
+void VectorAnimationRenderer::GetMarkerInfo(Property::Map& map) const
+{
+  map.Add(VECTOR_ANIMATION_MARKER_NAME_1, Property::Array({VECTOR_ANIMATION_MARKER_START_FRAME_1, VECTOR_ANIMATION_MARKER_END_FRAME_1}));
+  map.Add(VECTOR_ANIMATION_MARKER_NAME_2, Property::Array({VECTOR_ANIMATION_MARKER_START_FRAME_2, VECTOR_ANIMATION_MARKER_END_FRAME_2}));
+}
+
 void VectorAnimationRenderer::InvalidateBuffer()
 {
   return Internal::Adaptor::GetImplementation(*this).InvalidateBuffer();
 }
 
+void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPath, VectorProperty property, CallbackBase* callback, int32_t id)
+{
+  Internal::Adaptor::GetImplementation(*this).AddPropertyValueCallback(keyPath, property, callback, id);
+}
+
+void VectorAnimationRenderer::KeepRasterizedBuffer()
+{
+  Internal::Adaptor::GetImplementation(*this).KeepRasterizedBuffer();
+}
+
 VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
 {
   return Internal::Adaptor::GetImplementation(*this).UploadCompletedSignal();
@@ -353,7 +429,8 @@ namespace VectorAnimationRenderer
 {
 void DelayRendering(uint32_t delay)
 {
-  Dali::Internal::Adaptor::gVectorAnimationRenderer->mDelayTime = delay;
+  Dali::Internal::Adaptor::gVectorAnimationRenderer->mDelayTime     = delay;
+  Dali::Internal::Adaptor::gVectorAnimationRenderer->mTestFrameDrop = true;
 }
 
 uint32_t GetDroppedFrames()
@@ -361,5 +438,10 @@ uint32_t GetDroppedFrames()
   return Dali::Internal::Adaptor::gVectorAnimationRenderer->mDroppedFrames;
 }
 
+void UseNativeImageTexture(bool useNativeImage)
+{
+  Dali::Internal::Adaptor::gVectorAnimationRenderer->mUseNativeImage = useNativeImage;
+}
+
 } // namespace VectorAnimationRenderer
 } // namespace Test