[dali_2.3.27] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / svg / svg-visual.cpp
index 3f280d1..773e69b 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.
@@ -16,7 +16,7 @@
  */
 
 // CLASS HEADER
-#include "svg-visual.h"
+#include <dali-toolkit/internal/visuals/svg/svg-visual.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/visuals/image-atlas-manager.h>
@@ -63,7 +63,7 @@ SvgVisualPtr SvgVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderF
 }
 
 SvgVisual::SvgVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size)
-: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::SVG),
+: Visual::Base(factoryCache, Visual::FittingMode::DONT_CARE, Toolkit::Visual::SVG),
   mImageVisualShaderFactory(shaderFactory),
   mAtlasRect(FULL_TEXTURE_RECT),
   mImageUrl(imageUrl),
@@ -71,7 +71,7 @@ SvgVisual::SvgVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory&
   mDefaultWidth(0),
   mDefaultHeight(0),
   mPlacementActor(),
-  mRasterizedSize(Vector2::ZERO),
+  mRasterizedSize(-Vector2::ONE), ///< Let we don't use zero since visual size could be zero after trasnform
   mDesiredSize(size),
   mLoadFailed(false),
   mAttemptAtlasing(false)
@@ -92,6 +92,12 @@ SvgVisual::~SvgVisual()
     {
       Dali::AsyncTaskManager::Get().RemoveTask(mRasterizingTask);
     }
+
+    if(mImageUrl.IsBufferResource())
+    {
+      TextureManager& textureManager = mFactoryCache.GetTextureManager();
+      textureManager.RemoveEncodedImageBuffer(mImageUrl.GetUrl());
+    }
   }
 }
 
@@ -105,9 +111,22 @@ void SvgVisual::OnInitialize()
   Vector2 dpi     = Stage::GetCurrent().GetDpi();
   float   meanDpi = (dpi.height + dpi.width) * 0.5f;
 
-  mLoadingTask = new SvgLoadingTask(mVectorRenderer, mImageUrl, meanDpi, MakeCallback(this, &SvgVisual::ApplyRasterizedImage));
+  EncodedImageBuffer encodedImageBuffer;
+
+  if(mImageUrl.IsBufferResource())
+  {
+    // Increase reference count of External Resources :
+    // EncodedImageBuffer.
+    // Reference count will be decreased at destructor of the visual.
+    TextureManager& textureManager = mFactoryCache.GetTextureManager();
+    textureManager.UseExternalResource(mImageUrl.GetUrl());
+
+    encodedImageBuffer = textureManager.GetEncodedImageBuffer(mImageUrl.GetUrl());
+  }
+
+  mLoadingTask = new SvgLoadingTask(mVectorRenderer, mImageUrl, encodedImageBuffer, meanDpi, MakeCallback(this, &SvgVisual::ApplyRasterizedImage));
 
-  if(IsSynchronousLoadingRequired() && mImageUrl.IsLocalResource())
+  if(IsSynchronousLoadingRequired() && (mImageUrl.IsLocalResource() || mImageUrl.IsBufferResource()))
   {
     mLoadingTask->Process();
     if(!mLoadingTask->HasSucceeded())
@@ -317,11 +336,15 @@ void SvgVisual::AddRasterizationTask(const Vector2& size)
       mRasterizingTask.Reset();
     }
 
-    unsigned int width  = static_cast<unsigned int>(size.width);
-    unsigned int height = static_cast<unsigned int>(size.height);
+    uint32_t width  = static_cast<uint32_t>(roundf(size.width));
+    uint32_t height = static_cast<uint32_t>(roundf(size.height));
 
     mRasterizingTask = new SvgRasterizingTask(mVectorRenderer, width, height, MakeCallback(this, &SvgVisual::ApplyRasterizedImage));
 
+#ifdef TRACE_ENABLED
+    reinterpret_cast<SvgRasterizingTask*>(mRasterizingTask.Get())->SetUrl(mImageUrl);
+#endif
+
     if(IsSynchronousLoadingRequired() && mImageUrl.IsLocalResource())
     {
       mRasterizingTask->Process();
@@ -471,6 +494,10 @@ void SvgVisual::OnSetTransform()
       size = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
     }
 
+    // roundf and change as integer scale.
+    size.width  = static_cast<uint32_t>(roundf(size.width));
+    size.height = static_cast<uint32_t>(roundf(size.height));
+
     if(size != mRasterizedSize || mDefaultWidth == 0 || mDefaultHeight == 0)
     {
       mRasterizedSize = size;