(Vector) Do not change shader at dali-extension side. 43/307643/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 12 Mar 2024 04:37:30 +0000 (13:37 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Fri, 15 Mar 2024 10:17:08 +0000 (19:17 +0900)
Let we make to change shader at animated-vector-visual side, instead of
dali-extension side.

It will make we can use cached shader, so we don't need to re-create shader.

Change-Id: Iaf92115e17ed6ade455de404fa02213bdbd9ee4c
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-extension/vector-animation-renderer/vector-animation-renderer-tizen.cpp
dali-extension/vector-animation-renderer/vector-animation-renderer-tizen.h
dali-extension/vector-animation-renderer/vector-animation-renderer-x.cpp
dali-extension/vector-animation-renderer/vector-animation-renderer-x.h
dali-extension/vector-animation-renderer/vector-animation-renderer.cpp
dali-extension/vector-animation-renderer/vector-animation-renderer.h

index f15e0a7e980cd0cc4269c9ebe32389608bda4269..2e003dc0a15f4cdbe13321b074a9d9c0004c3de0 100644 (file)
@@ -276,56 +276,8 @@ void VectorAnimationRendererTizen::OnNotify()
 void VectorAnimationRendererTizen::PrepareTarget(std::shared_ptr<RenderingData> renderingData)
 {
   std::shared_ptr<RenderingDataImpl> renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(renderingData);
-  renderingDataImpl->mTargetSurface = NativeImageSourceQueue::New(renderingDataImpl->mWidth, renderingDataImpl->mHeight, NativeImageSourceQueue::ColorFormat::BGRA8888);
-  renderingDataImpl->mTexture       = Texture::New(*renderingDataImpl->mTargetSurface);
-}
-
-// This Method is called inside mRenderingDataMutex
-void VectorAnimationRendererTizen::SetShader(std::shared_ptr<RenderingData> renderingData)
-{
-  if(mShaderChanged)
-  {
-    return;
-  }
-
-  Shader shader = mRenderer.GetShader();
-
-  std::string fragmentShader;
-  std::string vertexShader;
-
-  // Get the current fragment shader source
-  Property::Value program = shader.GetProperty(Shader::Property::PROGRAM);
-  Property::Map*  map     = program.GetMap();
-  if(map)
-  {
-    Property::Value* fragment = map->Find("fragment");
-    if(fragment)
-    {
-      fragmentShader = fragment->Get<std::string>();
-    }
-
-    Property::Value* vertex = map->Find("vertex");
-    if(vertex)
-    {
-      vertexShader = vertex->Get<std::string>();
-    }
-  }
-
-  // Get custom fragment shader prefix
-  if(!renderingData)
-  {
-    DALI_LOG_ERROR("Target Surface is not yet prepared.\n");
-  }
-  std::shared_ptr<RenderingDataImpl> renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(renderingData);
-  renderingDataImpl->mTargetSurface->ApplyNativeFragmentShader(fragmentShader);
-
-  // Set the modified shader again
-  Shader newShader = Shader::New(vertexShader, fragmentShader);
-  newShader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
-
-  mRenderer.SetShader(newShader);
-
-  mShaderChanged = true;
+  renderingDataImpl->mTargetSurface                    = NativeImageSourceQueue::New(renderingDataImpl->mWidth, renderingDataImpl->mHeight, NativeImageSourceQueue::ColorFormat::BGRA8888);
+  renderingDataImpl->mTexture                          = Texture::New(*renderingDataImpl->mTargetSurface);
 }
 
 // This Method is called inside mRenderingDataMutex
index 5b22d19b7bac5551890294a505adb6ada248ad76..9f55314db16f28f825d536c66a9491da00a012c6 100644 (file)
@@ -79,11 +79,6 @@ private:
    */
   void PrepareTarget(std::shared_ptr<RenderingData> renderingData) override;
 
-  /**
-   * @brief Set shader for NativeImageSourceQueue with custom sampler type and prefix.
-   */
-  void SetShader(std::shared_ptr<RenderingData> renderingData) override;
-
   /**
    * @copydoc VectorAnimationRenderer::OnSetSize()
    */
index 972055ade69e2a327299e3296f6a4999ac38a3a8..7e3c49d46b972d04db2d12e03ada7f34c4d56826 100644 (file)
@@ -154,26 +154,6 @@ void VectorAnimationRendererX::PrepareTarget(std::shared_ptr<RenderingData> rend
   renderingDataImpl->mLottieSurface                    = rlottie::Surface(reinterpret_cast<uint32_t*>(renderingDataImpl->mPixelBuffer.GetBuffer()), renderingDataImpl->mWidth, renderingDataImpl->mHeight, static_cast<size_t>(renderingDataImpl->mPixelBuffer.GetStride() * 4));
 }
 
-// This Method is called inside mRenderingDataMutex
-void VectorAnimationRendererX::SetShader(std::shared_ptr<RenderingData> renderingData)
-{
-  if(!renderingData)
-  {
-    DALI_LOG_ERROR("Target Surface is not yet prepared.\n");
-    return;
-  }
-  std::shared_ptr<RenderingDataImpl> renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(renderingData);
-
-  if(mShaderChanged || !renderingDataImpl->mTexture)
-  {
-    return;
-  }
-
-  // Not implemented
-
-  mShaderChanged = true;
-}
-
 bool VectorAnimationRendererX::IsTargetPrepared()
 {
   std::shared_ptr<RenderingDataImpl> renderingDataImpl;
index 29fc3dce0f07d72dffdce1d9db2eef1e2c537dae..e87e2b2ead1d8913bf1d90a1b15103bfc9bfc076 100644 (file)
@@ -78,11 +78,6 @@ private:
    */
   void PrepareTarget(std::shared_ptr<RenderingData> renderingData) override;
 
-  /**
-   * @brief Set shader for NativeImageSourceQueue with custom sampler type and prefix.
-   */
-  void SetShader(std::shared_ptr<RenderingData> renderingData) override;
-
   /**
    * @copydoc VectorAnimationRenderer::OnSetSize()
    * @note This Method is called inside mRenderingDataMutex
index 48fd7a73f0b50b19b2e5b4bf0fc1f6fb197533af..60729eff83ddfb5602be4be22ac30a855bdb7547 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 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.
@@ -57,7 +57,6 @@ VectorAnimationRenderer::VectorAnimationRenderer()
   mFrameRate(60.0f),
   mLoadFailed(false),
   mResourceReady(false),
-  mShaderChanged(false),
   mResourceReadyTriggered(false),
   mEnableFixedCache(false)
 {
@@ -153,8 +152,9 @@ bool VectorAnimationRenderer::Load(const Dali::Vector<uint8_t>& data)
 
 void VectorAnimationRenderer::SetRenderer(Renderer renderer)
 {
-  mRenderer      = renderer;
-  mShaderChanged = false;
+  mRenderer = renderer;
+
+  bool emitSignal = false;
 
   if(IsTargetPrepared())
   {
@@ -167,13 +167,13 @@ void VectorAnimationRenderer::SetRenderer(Renderer renderer)
 
         textureSet.SetTexture(0, GetTargetTexture());
 
-        mUploadCompletedSignal.Emit();
+        emitSignal = true;
       }
     }
 
+    if(emitSignal)
     {
-      Dali::Mutex::ScopedLock lock(mRenderingDataMutex);
-      SetShader(mPreparedRenderingData ? mPreparedRenderingData : mCurrentRenderingData);
+      mUploadCompletedSignal.Emit();
     }
   }
 }
@@ -215,11 +215,6 @@ void VectorAnimationRenderer::SetSize(uint32_t width, uint32_t height)
 
   PrepareTarget(preparedRenderingData);
 
-  if(mRenderer)
-  {
-    SetShader(preparedRenderingData);
-  }
-
   OnSetSize(preparedRenderingData);
 
   {
@@ -320,8 +315,7 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
       case VectorProperty::FILL_COLOR:
       {
         mVectorRenderer->setValue<rlottie::Property::FillColor>(keyPath,
-                                                                [property, callback, id](const rlottie::FrameInfo& info)
-                                                                {
+                                                                [property, callback, id](const rlottie::FrameInfo& info) {
                                                                   Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
                                                                   Vector3         color;
                                                                   if(value.Get(color))
@@ -335,8 +329,7 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
       case VectorProperty::FILL_OPACITY:
       {
         mVectorRenderer->setValue<rlottie::Property::FillOpacity>(keyPath,
-                                                                  [property, callback, id](const rlottie::FrameInfo& info)
-                                                                  {
+                                                                  [property, callback, id](const rlottie::FrameInfo& info) {
                                                                     Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
                                                                     float           opacity;
                                                                     if(value.Get(opacity))
@@ -350,8 +343,7 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
       case VectorProperty::STROKE_COLOR:
       {
         mVectorRenderer->setValue<rlottie::Property::StrokeColor>(keyPath,
-                                                                  [property, callback, id](const rlottie::FrameInfo& info)
-                                                                  {
+                                                                  [property, callback, id](const rlottie::FrameInfo& info) {
                                                                     Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
                                                                     Vector3         color;
                                                                     if(value.Get(color))
@@ -365,8 +357,7 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
       case VectorProperty::STROKE_OPACITY:
       {
         mVectorRenderer->setValue<rlottie::Property::StrokeOpacity>(keyPath,
-                                                                    [property, callback, id](const rlottie::FrameInfo& info)
-                                                                    {
+                                                                    [property, callback, id](const rlottie::FrameInfo& info) {
                                                                       Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
                                                                       float           opacity;
                                                                       if(value.Get(opacity))
@@ -380,8 +371,7 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
       case VectorProperty::STROKE_WIDTH:
       {
         mVectorRenderer->setValue<rlottie::Property::StrokeWidth>(keyPath,
-                                                                  [property, callback, id](const rlottie::FrameInfo& info)
-                                                                  {
+                                                                  [property, callback, id](const rlottie::FrameInfo& info) {
                                                                     Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
                                                                     float           width;
                                                                     if(value.Get(width))
@@ -395,8 +385,7 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
       case VectorProperty::TRANSFORM_ANCHOR:
       {
         mVectorRenderer->setValue<rlottie::Property::TrAnchor>(keyPath,
-                                                               [property, callback, id](const rlottie::FrameInfo& info)
-                                                               {
+                                                               [property, callback, id](const rlottie::FrameInfo& info) {
                                                                  Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
                                                                  Vector2         point;
                                                                  if(value.Get(point))
@@ -410,8 +399,7 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
       case VectorProperty::TRANSFORM_POSITION:
       {
         mVectorRenderer->setValue<rlottie::Property::TrPosition>(keyPath,
-                                                                 [property, callback, id](const rlottie::FrameInfo& info)
-                                                                 {
+                                                                 [property, callback, id](const rlottie::FrameInfo& info) {
                                                                    Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
                                                                    Vector2         position;
                                                                    if(value.Get(position))
@@ -425,8 +413,7 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
       case VectorProperty::TRANSFORM_SCALE:
       {
         mVectorRenderer->setValue<rlottie::Property::TrScale>(keyPath,
-                                                              [property, callback, id](const rlottie::FrameInfo& info)
-                                                              {
+                                                              [property, callback, id](const rlottie::FrameInfo& info) {
                                                                 Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
                                                                 Vector2         scale;
                                                                 if(value.Get(scale))
@@ -440,8 +427,7 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
       case VectorProperty::TRANSFORM_ROTATION:
       {
         mVectorRenderer->setValue<rlottie::Property::TrRotation>(keyPath,
-                                                                 [property, callback, id](const rlottie::FrameInfo& info)
-                                                                 {
+                                                                 [property, callback, id](const rlottie::FrameInfo& info) {
                                                                    Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
                                                                    float           rotation;
                                                                    if(value.Get(rotation))
@@ -455,8 +441,7 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
       case VectorProperty::TRANSFORM_OPACITY:
       {
         mVectorRenderer->setValue<rlottie::Property::TrOpacity>(keyPath,
-                                                                [property, callback, id](const rlottie::FrameInfo& info)
-                                                                {
+                                                                [property, callback, id](const rlottie::FrameInfo& info) {
                                                                   Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
                                                                   float           opacity;
                                                                   if(value.Get(opacity))
index 169a03dc7d96f32d168897de4c5ca229833d5815..6d2985a1abb3fbd9aa62012f151fe1dfa3b29d38 100644 (file)
@@ -156,11 +156,6 @@ protected:
    */
   virtual void PrepareTarget(std::shared_ptr<RenderingData> renderingData) = 0;
 
-  /**
-   * @brief Set shader for NativeImageSourceQueue with custom sampler type and prefix.
-   */
-  virtual void SetShader(std::shared_ptr<RenderingData> renderingData) = 0;
-
   /**
    * @brief Apply the changes of Size
    */
@@ -211,7 +206,6 @@ protected:
   float                               mFrameRate;              ///< The frame rate of the content
   bool                                mLoadFailed;             ///< Whether the file is loaded
   bool                                mResourceReady;          ///< Whether the resource is ready
-  bool                                mShaderChanged;          ///< Whether the shader is changed to support native image
   bool                                mResourceReadyTriggered; ///< Whether the resource ready is triggered
   bool                                mEnableFixedCache;
 };