Merge "Support asynchronous svg loading" into devel/master
authorHeeyong Song <heeyong.song@samsung.com>
Tue, 17 May 2022 10:11:45 +0000 (10:11 +0000)
committerGerrit Code Review <gerrit@review>
Tue, 17 May 2022 10:11:45 +0000 (10:11 +0000)
automated-tests/src/dali-toolkit-internal/utc-Dali-DebugRendering.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-image-renderer.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-image-renderer.h [new file with mode: 0644]
automated-tests/src/dali-toolkit/utc-Dali-Control.cpp
automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp
dali-toolkit/internal/visuals/svg/svg-rasterize-thread.cpp
dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h
dali-toolkit/internal/visuals/svg/svg-visual.cpp
dali-toolkit/internal/visuals/svg/svg-visual.h

index d39b00c..e2ff409 100755 (executable)
@@ -160,7 +160,7 @@ int UtcDaliDebugRenderingGetVisual1(void)
   propertyMap5.Insert(ImageVisual::Property::URL, TEST_SVG_FILE_NAME);
   Visual::Base svgVisual = factory.CreateVisual(propertyMap5);
   DALI_TEST_CHECK(svgVisual);
-  TestDebugVisual(application.GetScene(), svgVisual, Visual::SVG, Vector2(100.f, 100.f));
+  TestDebugVisual(application.GetScene(), svgVisual, Visual::SVG, Vector2::ZERO);
 
   // Test that AnimatedImageVisual is replaced with debug visual
   // TEST_GIF_FILE: anim.gif
index cf276f4..d809e66 100644 (file)
@@ -21,6 +21,7 @@
 #include <sys/stat.h>
 #include <toolkit-application.h>
 #include <toolkit-event-thread-callback.h>
+#include <toolkit-vector-image-renderer.h>
 #include <cstring>
 #include <memory>
 
@@ -30,13 +31,15 @@ namespace Internal
 {
 namespace Adaptor
 {
+namespace
+{
+Dali::Internal::Adaptor::VectorImageRenderer* gVectorImageRenderer = nullptr;
+}
+
 class VectorImageRenderer : public Dali::BaseObject
 {
 public:
   VectorImageRenderer()
-  : mWidth(0),
-    mHeight(0),
-    mRasterizeSuccess(true)
   {
   }
 
@@ -46,6 +49,7 @@ public:
 
   bool Load(const Vector<uint8_t>& data, float dpi)
   {
+    mLoadCount++;
     if(strncmp(reinterpret_cast<char*>(data.Begin()), "invalid", 7) == 0)
     {
       return false;
@@ -57,6 +61,11 @@ public:
     return true;
   }
 
+  bool IsLoaded() const
+  {
+    return mLoadCount > 0 ? true : false;
+  }
+
   Dali::Devel::PixelBuffer Rasterize(uint32_t width, uint32_t height)
   {
     if(mRasterizeSuccess)
@@ -74,9 +83,10 @@ public:
   }
 
 public:
-  uint32_t mWidth;
-  uint32_t mHeight;
-  bool     mRasterizeSuccess;
+  uint32_t mWidth{0};
+  uint32_t mHeight{0};
+  uint32_t mLoadCount{0};
+  bool     mRasterizeSuccess{true};
 };
 
 inline VectorImageRenderer& GetImplementation(Dali::VectorImageRenderer& renderer)
@@ -105,6 +115,8 @@ VectorImageRenderer VectorImageRenderer::New()
 {
   Internal::Adaptor::VectorImageRenderer* imageRenderer = new Internal::Adaptor::VectorImageRenderer();
 
+  Internal::Adaptor::gVectorImageRenderer = imageRenderer;
+
   return VectorImageRenderer(imageRenderer);
 }
 
@@ -126,6 +138,11 @@ bool VectorImageRenderer::Load(const Vector<uint8_t>& data, float dpi)
   return Internal::Adaptor::GetImplementation(*this).Load(data, dpi);
 }
 
+bool VectorImageRenderer::IsLoaded() const
+{
+  return Internal::Adaptor::GetImplementation(*this).IsLoaded();
+}
+
 Dali::Devel::PixelBuffer VectorImageRenderer::Rasterize(uint32_t width, uint32_t height)
 {
   return Internal::Adaptor::GetImplementation(*this).Rasterize(width, height);
@@ -137,3 +154,15 @@ void VectorImageRenderer::GetDefaultSize(uint32_t& width, uint32_t& height) cons
 }
 
 } // namespace Dali
+
+namespace Test
+{
+namespace VectorImageRenderer
+{
+uint32_t GetLoadCount()
+{
+  return Dali::Internal::Adaptor::gVectorImageRenderer->mLoadCount;
+}
+
+} // namespace VectorImageRenderer
+} // namespace Test
diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-image-renderer.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-image-renderer.h
new file mode 100644 (file)
index 0000000..37cc362
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef DALI_TOOLKIT_TEST_VECTOR_IMAGE_RENDERER_H
+#define DALI_TOOLKIT_TEST_VECTOR_IMAGE_RENDERER_H
+
+/*
+ * Copyright (c) 2022 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Test
+{
+namespace VectorImageRenderer
+{
+uint32_t GetLoadCount();
+
+} // namespace VectorImageRenderer
+} // namespace Test
+
+#endif // DALI_TOOLKIT_TEST_VECTOR_IMAGE_RENDERER_H
index 6745fea..3ae49cc 100644 (file)
@@ -73,7 +73,7 @@ static void TestKeyInputFocusCallback(Control control)
 
 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
 const char* TEST_IMAGE_FILE_NAME       = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
-const char* TEST_SVG_FILE_NAME         = TEST_RESOURCE_DIR "/Kid1.svg";
+const char* TEST_SVG_FILE_NAME         = TEST_RESOURCE_DIR "/svg1.svg";
 
 Vector4 GetControlBackgroundColor(Control& control)
 {
@@ -269,8 +269,8 @@ int UtcDaliControlNavigationProperties(void)
   DALI_TEST_EQUALS(-1, control.GetProperty(DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID).Get<int>(), TEST_LOCATION);
   DALI_TEST_EQUALS(-1, control.GetProperty(DevelControl::Property::UP_FOCUSABLE_ACTOR_ID).Get<int>(), TEST_LOCATION);
   DALI_TEST_EQUALS(-1, control.GetProperty(DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID).Get<int>(), TEST_LOCATION);
-  DALI_TEST_EQUALS(-1, control.GetProperty( DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION);
-  DALI_TEST_EQUALS(-1, control.GetProperty( DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION);
+  DALI_TEST_EQUALS(-1, control.GetProperty(DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID).Get<int>(), TEST_LOCATION);
+  DALI_TEST_EQUALS(-1, control.GetProperty(DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID).Get<int>(), TEST_LOCATION);
 
   control.SetProperty(DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 1);
   DALI_TEST_EQUALS(1, control.GetProperty(DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID).Get<int>(), TEST_LOCATION);
@@ -290,9 +290,9 @@ int UtcDaliControlNavigationProperties(void)
   control.SetProperty(DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 18);
   DALI_TEST_EQUALS(18, control.GetProperty(DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID).Get<int>(), TEST_LOCATION);
   control.SetProperty(DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID, 19);
-  DALI_TEST_EQUALS(19, control.GetProperty( DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION);
+  DALI_TEST_EQUALS(19, control.GetProperty(DevelControl::Property::CLOCKWISE_FOCUSABLE_ACTOR_ID).Get<int>(), TEST_LOCATION);
   control.SetProperty(DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID, 20);
-  DALI_TEST_EQUALS(20, control.GetProperty( DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION);
+  DALI_TEST_EQUALS(20, control.GetProperty(DevelControl::Property::COUNTER_CLOCKWISE_FOCUSABLE_ACTOR_ID).Get<int>(), TEST_LOCATION);
 
   END_TEST;
 }
@@ -1074,6 +1074,9 @@ int UtcDaliControlResourcesReady02(void)
   application.SendNotification();
   application.Render();
 
+  // Wait for rasterization
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
   DALI_TEST_EQUALS(control.IsResourceReady(), true, TEST_LOCATION);
   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
   gResourceReadySignalFired = false;
index 10d6445..edaeec1 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <dali-toolkit-test-suite-utils.h>
 #include <toolkit-event-thread-callback.h>
+#include <toolkit-vector-image-renderer.h>
 #include "dummy-control.h"
 
 #include <test-encoded-image-buffer.h>
@@ -2727,12 +2728,7 @@ int UtcDaliImageViewSyncSVGLoading(void)
 
   tet_infoline("ImageView Testing SVG image sync loading");
 
-  // Sync loading, automatic atlasing for small size image
   {
-    TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
-    callStack.Reset();
-    callStack.Enable(true);
-
     ImageView imageView = ImageView::New();
 
     // Sync loading is used
@@ -2746,7 +2742,6 @@ int UtcDaliImageViewSyncSVGLoading(void)
     DALI_TEST_CHECK(imageView);
 
     application.SendNotification();
-    application.Render(16);
     Vector3 naturalSize = imageView.GetNaturalSize();
 
     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
@@ -2761,28 +2756,27 @@ int UtcDaliImageViewAsyncSVGLoading(void)
 
   tet_infoline("ImageView Testing SVG image async loading");
 
-  // Sync loading, automatic atlasing for small size image
   {
-    TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
-    callStack.Reset();
-    callStack.Enable(true);
-
     ImageView imageView = ImageView::New();
 
-    // Sync loading is used
-    Property::Map syncLoadingMap;
-    syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
-    syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
-    syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, false);
-    imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
+    // Async loading is used - default value of SYNCHRONOUS_LOADING is false.
+    Property::Map propertyMap;
+    propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
+    propertyMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
+    imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
 
     application.GetScene().Add(imageView);
     DALI_TEST_CHECK(imageView);
 
     application.SendNotification();
+
+    // Wait for rasterization
+    DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+    application.SendNotification();
     application.Render(16);
-    Vector3 naturalSize = imageView.GetNaturalSize();
 
+    Vector3 naturalSize = imageView.GetNaturalSize();
     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
   }
@@ -2795,12 +2789,8 @@ int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
 
   tet_infoline("ImageView Testing SVG image async loading");
 
-  // Sync loading, automatic atlasing for small size image
+  // Sync loading
   {
-    TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
-    callStack.Reset();
-    callStack.Enable(true);
-
     ImageView imageView = ImageView::New();
 
     // Sync loading is used
@@ -2819,7 +2809,13 @@ int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
     DALI_TEST_CHECK(imageView);
 
     application.SendNotification();
+
+    // Wait for rasterization
+    DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+    application.SendNotification();
     application.Render(16);
+
     Vector3 naturalSize = imageView.GetNaturalSize();
     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
@@ -2856,6 +2852,11 @@ int UtcDaliImageViewSvgLoadingFailure(void)
     application.GetScene().Add(imageView);
 
     application.SendNotification();
+
+    // loading started, this waits for the loader thread
+    DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+    application.SendNotification();
     application.Render(16);
 
     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
@@ -2880,6 +2881,11 @@ int UtcDaliImageViewSvgLoadingFailure(void)
     application.GetScene().Add(imageView);
 
     application.SendNotification();
+
+    // loading started, this waits for the loader thread
+    DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+    application.SendNotification();
     application.Render(16);
 
     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
@@ -2905,6 +2911,11 @@ int UtcDaliImageViewSvgLoadingFailure(void)
     application.GetScene().Add(imageView);
 
     application.SendNotification();
+
+    // loading started, this waits for the loader thread
+    DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+    application.SendNotification();
     application.Render(16);
 
     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
@@ -3015,6 +3026,44 @@ int UtcDaliImageViewSvgRasterizationFailure(void)
   END_TEST;
 }
 
+int UtcDaliImageViewSvgChageSize(void)
+{
+  ToolkitTestApplication application;
+
+  TestGlAbstraction& gl           = application.GetGlAbstraction();
+  TraceCallStack&    textureTrace = gl.GetTextureTrace();
+  textureTrace.Enable(true);
+
+  ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME);
+  application.GetScene().Add(imageView);
+
+  application.SendNotification();
+
+  // loading started, this waits for the loader thread
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render(16);
+
+  DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
+
+  // Change actor size, then rasterization should be done again
+  imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
+
+  application.SendNotification();
+
+  // loading started, this waits for the loader thread
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render(16);
+
+  // We should not load the file again.
+  DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliImageViewTVGLoading(void)
 {
   ToolkitTestApplication application;
@@ -3022,12 +3071,17 @@ int UtcDaliImageViewTVGLoading(void)
   tet_infoline("ImageView Testing TVG image loading");
 
   {
-    ImageView imageView = ImageView::New();
-
-    imageView.SetImage(TEST_RESOURCE_DIR "/test.tvg");
-
+    ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/test.tvg");
     application.GetScene().Add(imageView);
     DALI_TEST_CHECK(imageView);
+
+    application.SendNotification();
+
+    DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+    application.SendNotification();
+    application.Render(16);
+
     Vector3 naturalSize = imageView.GetNaturalSize();
 
     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
@@ -3603,7 +3657,7 @@ int UtcDaliImageViewCheckVariousCaseSendOnResourceReadySignal(void)
 
   // Test broken case
   TestResourceReadyUrl(1, 0, 0, "invalid.jpg", "", TEST_LOCATION);
-  TestResourceReadyUrl(0, 0, 0, "invalid.svg", "", TEST_LOCATION); // 0 rasterize
+  TestResourceReadyUrl(1, 0, 0, "invalid.svg", "", TEST_LOCATION);
   TestResourceReadyUrl(1, 0, 0, "invalid.9.png", "", TEST_LOCATION);
   TestResourceReadyUrl(1, 0, 0, "invalid.gif", "", TEST_LOCATION);  // 1 image loading
   TestResourceReadyUrl(0, 0, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
@@ -3633,7 +3687,7 @@ int UtcDaliImageViewCheckVariousCaseSendOnResourceReadySignal(void)
 
   // Test broken case
   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "", TEST_LOCATION);
-  TestResourceReadyUrl(0, 1, 0, "invalid.svg", "", TEST_LOCATION); // 0 rasterize
+  TestResourceReadyUrl(0, 1, 0, "invalid.svg", "", TEST_LOCATION);
   TestResourceReadyUrl(0, 1, 0, "invalid.9.png", "", TEST_LOCATION);
   TestResourceReadyUrl(0, 1, 0, "invalid.gif", "", TEST_LOCATION);
   TestResourceReadyUrl(0, 1, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
index c17567a..bd3469a 100644 (file)
@@ -325,7 +325,6 @@ int UtcDaliVisualSize(void)
   DALI_TEST_EQUALS(naturalSize, Vector2::ZERO, TEST_LOCATION);
 
   // animated gradient visual
-  Vector2 animated_gradient_visual_size(10.f, 10.f);
   propertyMap.Clear();
   propertyMap.Insert(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT);
   Visual::Base animatedGradientVisual = factory.CreateVisual(propertyMap);
@@ -333,20 +332,6 @@ int UtcDaliVisualSize(void)
   animatedGradientVisual.SetTransformAndSize(DefaultTransform(), controlSize);
   DALI_TEST_EQUALS(naturalSize, Vector2::ZERO, TEST_LOCATION);
 
-  // svg visual
-  Visual::Base svgVisual = factory.CreateVisual(TEST_SVG_FILE_NAME, ImageDimensions());
-  svgVisual.GetNaturalSize(naturalSize);
-  // TEST_SVG_FILE:
-  //  <svg width="100" height="100">
-  //  <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
-  //  </svg>
-  DALI_TEST_EQUALS(naturalSize, Vector2(100.f, 100.f), TEST_LOCATION);
-
-  // svg visual with a size
-  Visual::Base svgVisual2 = factory.CreateVisual(TEST_SVG_FILE_NAME, ImageDimensions(200, 200));
-  svgVisual2.GetNaturalSize(naturalSize);
-  DALI_TEST_EQUALS(naturalSize, Vector2(100.f, 100.f), TEST_LOCATION); // Natural size should still be 100, 100
-
   // Text visual.
 
   // Load some fonts to get the same metrics on different platforms.
index 08e416e..24f9981 100644 (file)
@@ -33,8 +33,8 @@ namespace Toolkit
 {
 namespace Internal
 {
-RasterizingTask::RasterizingTask(SvgVisual* svgRenderer, VectorImageRenderer vectorRenderer, const VisualUrl& url, float dpi, unsigned int width, unsigned int height)
-: mSvgVisual(svgRenderer),
+RasterizingTask::RasterizingTask(SvgVisual* svgVisual, VectorImageRenderer vectorRenderer, const VisualUrl& url, float dpi, unsigned int width, unsigned int height)
+: mSvgVisual(svgVisual),
   mVectorRenderer(vectorRenderer),
   mUrl(url),
   mDpi(dpi),
@@ -50,29 +50,41 @@ RasterizingTask::~RasterizingTask()
 
 void RasterizingTask::Load()
 {
+  if(mVectorRenderer.IsLoaded())
+  {
+    // Already loaded
+    mLoadSuccess = true;
+    return;
+  }
+
+  Dali::Vector<uint8_t> buffer;
+
   if(!mUrl.IsLocalResource())
   {
-    Dali::Vector<uint8_t> remoteBuffer;
-    if(!Dali::FileLoader::DownloadFileSynchronously(mUrl.GetUrl(), remoteBuffer))
+    if(!Dali::FileLoader::DownloadFileSynchronously(mUrl.GetUrl(), buffer))
     {
-      DALI_LOG_ERROR("RasterizingTask::Load: Failed to download file! [%s]\n", mUrl.GetUrl().c_str());
+      DALI_LOG_ERROR("Failed to download file! [%s]\n", mUrl.GetUrl().c_str());
       return;
     }
-
-    remoteBuffer.PushBack('\0');
-
-    if(!mVectorRenderer.Load(remoteBuffer, mDpi))
+  }
+  else
+  {
+    if(!Dali::FileLoader::ReadFile(mUrl.GetUrl(), buffer))
     {
-      DALI_LOG_ERROR("RasterizingTask::Load:Failed to load data! [%s]\n", mUrl.GetUrl().c_str());
+      DALI_LOG_ERROR("Failed to read file! [%s]\n", mUrl.GetUrl().c_str());
       return;
     }
-
-    mLoadSuccess = true;
   }
-  else
+
+  buffer.PushBack('\0');
+
+  if(!mVectorRenderer.Load(buffer, mDpi))
   {
-    mLoadSuccess = true;
+    DALI_LOG_ERROR("Failed to load data! [%s]\n", mUrl.GetUrl().c_str());
+    return;
   }
+
+  mLoadSuccess = true;
 }
 
 void RasterizingTask::Rasterize()
@@ -87,11 +99,6 @@ void RasterizingTask::Rasterize()
   mPixelData = Devel::PixelBuffer::Convert(pixelBuffer);
 }
 
-VectorImageRenderer RasterizingTask::GetVectorRenderer() const
-{
-  return mVectorRenderer;
-}
-
 bool RasterizingTask::IsLoaded() const
 {
   return mLoadSuccess;
@@ -258,7 +265,7 @@ void SvgRasterizeThread::ApplyRasterizedSVGToSampler()
 {
   while(RasterizingTaskPtr task = NextCompletedTask())
   {
-    task->GetSvgVisual()->ApplyRasterizedImage(task->GetVectorRenderer(), task->GetPixelData(), task->IsLoaded());
+    task->GetSvgVisual()->ApplyRasterizedImage(task->GetPixelData(), task->IsLoaded());
   }
 
   UnregisterProcessor();
index 0204bef..c0cf726 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_SVG_RASTERIZE_THREAD_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -29,7 +29,6 @@
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/images/pixel-data.h>
 #include <dali/public-api/object/ref-object.h>
-#include <dali/public-api/rendering/texture-set.h>
 #include <memory>
 
 // INTERNAL INCLUDES
@@ -60,12 +59,14 @@ class RasterizingTask : public RefObject
 public:
   /**
    * Constructor
-   * @param[in] svgRenderer The renderer which the rasterized image to be applied.
+   * @param[in] svgVisual The visual which the rasterized image to be applied.
+   * @param[in] vectorRenderer The vector rasterizer.
    * @param[in] url The URL to svg resource to use.
+   * @param[in] dpi The DPI of the screen.
    * @param[in] width The rasterization width.
    * @param[in] height The rasterization height.
    */
-  RasterizingTask(SvgVisual* svgRenderer, VectorImageRenderer vectorRenderer, const VisualUrl& url, float dpi, unsigned int width, unsigned int height);
+  RasterizingTask(SvgVisual* svgVisual, VectorImageRenderer vectorRenderer, const VisualUrl& url, float dpi, unsigned int width, unsigned int height);
 
   /**
    * Destructor.
@@ -73,6 +74,11 @@ public:
   ~RasterizingTask() override;
 
   /**
+   * Load svg file
+   */
+  void Load();
+
+  /**
    * Do the rasterization with the mRasterizer.
    */
   void Rasterize();
@@ -89,21 +95,11 @@ public:
   PixelData GetPixelData() const;
 
   /**
-   * Get the VectorRenderer.
-   * @return VectorRenderer.
-   */
-  VectorImageRenderer GetVectorRenderer() const;
-  /**
    * Whether the resource is loaded.
    * @return True if the resource is loaded.
    */
   bool IsLoaded() const;
 
-  /**
-   * Load svg file
-   */
-  void Load();
-
 private:
   // Undefined
   RasterizingTask(const RasterizingTask& task);
@@ -117,8 +113,8 @@ private:
   VisualUrl           mUrl;
   PixelData           mPixelData;
   float               mDpi;
-  unsigned int        mWidth;
-  unsigned int        mHeight;
+  uint32_t            mWidth;
+  uint32_t            mHeight;
   bool                mLoadSuccess;
 };
 
index 6851c75..bddb7f0 100644 (file)
@@ -27,7 +27,6 @@
 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
 
 // EXTERNAL INCLUDES
-#include <dali/devel-api/adaptor-framework/file-loader.h>
 #include <dali/devel-api/common/stage.h>
 #include <dali/integration-api/debug.h>
 
@@ -49,7 +48,6 @@ const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
 SvgVisualPtr SvgVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties)
 {
   SvgVisualPtr svgVisual(new SvgVisual(factoryCache, shaderFactory, imageUrl));
-  svgVisual->Load();
   svgVisual->SetProperties(properties);
   svgVisual->Initialize();
   return svgVisual;
@@ -58,7 +56,6 @@ SvgVisualPtr SvgVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderF
 SvgVisualPtr SvgVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl)
 {
   SvgVisualPtr svgVisual(new SvgVisual(factoryCache, shaderFactory, imageUrl));
-  svgVisual->Load();
   svgVisual->Initialize();
   return svgVisual;
 }
@@ -238,34 +235,6 @@ void SvgVisual::EnablePreMultipliedAlpha(bool preMultiplied)
   }
 }
 
-void SvgVisual::Load()
-{
-  // load remote resource on svg rasterize thread.
-  if(mImageUrl.IsLocalResource())
-  {
-    Dali::Vector<uint8_t> buffer;
-    if(Dali::FileLoader::ReadFile(mImageUrl.GetUrl(), buffer))
-    {
-      buffer.PushBack('\0');
-
-      Vector2 dpi     = Stage::GetCurrent().GetDpi();
-      float   meanDpi = (dpi.height + dpi.width) * 0.5f;
-      if(!mVectorRenderer.Load(buffer, meanDpi))
-      {
-        mLoadFailed = true;
-        DALI_LOG_ERROR("SvgVisual::Load: Failed to load file! [%s]\n", mImageUrl.GetUrl().c_str());
-        return;
-      }
-      mVectorRenderer.GetDefaultSize(mDefaultWidth, mDefaultHeight);
-    }
-    else
-    {
-      mLoadFailed = true;
-      DALI_LOG_ERROR("SvgVisual::Load: Failed to read file! [%s]\n", mImageUrl.GetUrl().c_str());
-    }
-  }
-}
-
 void SvgVisual::AddRasterizationTask(const Vector2& size)
 {
   if(mImpl->mRenderer)
@@ -277,11 +246,12 @@ void SvgVisual::AddRasterizationTask(const Vector2& size)
     float   meanDpi = (dpi.height + dpi.width) * 0.5f;
 
     RasterizingTaskPtr newTask = new RasterizingTask(this, mVectorRenderer, mImageUrl, meanDpi, width, height);
+
     if(IsSynchronousLoadingRequired() && mImageUrl.IsLocalResource())
     {
       newTask->Load();
       newTask->Rasterize();
-      ApplyRasterizedImage(newTask->GetVectorRenderer(), newTask->GetPixelData(), newTask->IsLoaded());
+      ApplyRasterizedImage(newTask->GetPixelData(), newTask->IsLoaded());
     }
     else
     {
@@ -290,7 +260,7 @@ void SvgVisual::AddRasterizationTask(const Vector2& size)
   }
 }
 
-void SvgVisual::ApplyRasterizedImage(VectorImageRenderer vectorRenderer, PixelData rasterizedPixelData, bool isLoaded)
+void SvgVisual::ApplyRasterizedImage(PixelData rasterizedPixelData, bool isLoaded)
 {
   if(isLoaded && rasterizedPixelData && IsOnScene())
   {
@@ -388,8 +358,8 @@ void SvgVisual::OnSetTransform()
   {
     if(visualSize != mRasterizedSize || mDefaultWidth == 0 || mDefaultHeight == 0)
     {
-      AddRasterizationTask(visualSize);
       mRasterizedSize = visualSize;
+      AddRasterizationTask(visualSize);
     }
   }
 
index 2b1dbe1..9dd6807 100644 (file)
@@ -151,19 +151,13 @@ public:
   /**
    * @bried Apply the rasterized image to the visual.
    *
-   * @param[in] vectorImage The data of vector image.
    * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
    * @param[in] bool Whether the resource is loaded
    */
-  void ApplyRasterizedImage(VectorImageRenderer vectorImage, PixelData rasterizedPixelData, bool isLoaded);
+  void ApplyRasterizedImage(PixelData rasterizedPixelData, bool isLoaded);
 
 private:
   /**
-   * @brief Load the SVG Image from the set URL.
-   */
-  void Load();
-
-  /**
    * @bried Rasterize the svg with the given size, and add it to the visual.
    *
    * @param[in] size The target size of the SVG rasterization.