Remove VisualFactory::Get() code at AsyncImageLoader 49/262049/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 2 Aug 2021 05:29:12 +0000 (14:29 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 3 Aug 2021 03:23:22 +0000 (12:23 +0900)
Make to send EncodedImageBuffer from TextureManager to AsyncImageLoader directly.
Now we don't need to get standalone factory at AsyncImageLoader.
So we don't need fearful exception check

Change-Id: I9b903c6a446fc167d11bdf7e22e6c7e19d085cc5
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-toolkit/internal/image-loader/async-image-loader-impl.cpp
dali-toolkit/internal/image-loader/async-image-loader-impl.h
dali-toolkit/internal/visuals/texture-manager-impl.cpp

index ea10924..64639b5 100644 (file)
@@ -21,9 +21,6 @@
 // EXTERNAL INCLUDES
 #include <dali/integration-api/adaptor-framework/adaptor.h>
 
-// INTERNAL INCLUDES
-#include <dali-toolkit/internal/visuals/visual-factory-impl.h>
-
 namespace Dali
 {
 namespace Toolkit
@@ -74,24 +71,24 @@ uint32_t AsyncImageLoader::Load(const VisualUrl&                         url,
     mLoadThread.Start();
     mIsLoadThreadStarted = true;
   }
-  if(url.IsBufferResource())
-  {
-    auto visualFactory = Toolkit::VisualFactory::Get();
-    if(visualFactory)
-    {
-      // Get EncodedImageBuffer from texturemanager
-      // and make new LoadingTask with buffer
-      auto& textureManager = GetImplementation(visualFactory).GetTextureManager();
+  mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad));
 
-      const EncodedImageBuffer& encodedBuffer = textureManager.GetEncodedImageBuffer(url.GetUrl());
+  return mLoadTaskId;
+}
 
-      mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, encodedBuffer, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad));
-    }
-  }
-  else
+uint32_t AsyncImageLoader::LoadEncodedImageBuffer(const EncodedImageBuffer&                encodedImageBuffer,
+                                                  ImageDimensions                          dimensions,
+                                                  FittingMode::Type                        fittingMode,
+                                                  SamplingMode::Type                       samplingMode,
+                                                  bool                                     orientationCorrection,
+                                                  DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
+{
+  if(!mIsLoadThreadStarted)
   {
-    mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad));
+    mLoadThread.Start();
+    mIsLoadThreadStarted = true;
   }
+  mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, encodedImageBuffer, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad));
 
   return mLoadTaskId;
 }
index 2227711..39e4690 100644 (file)
@@ -62,6 +62,23 @@ public:
                 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
 
   /**
+   * @brief Starts an image loading task by encoded image buffer.
+   * @param[in] encodedImageBuffer The encoded buffer of the image to load
+   * @param[in] dimensions The width and height to fit the loaded image to
+   * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
+   * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
+   * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header
+   * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
+   * @return The loading task id
+   */
+  uint32_t LoadEncodedImageBuffer(const EncodedImageBuffer&                encodedImageBuffer,
+                                  ImageDimensions                          dimensions,
+                                  FittingMode::Type                        fittingMode,
+                                  SamplingMode::Type                       samplingMode,
+                                  bool                                     orientationCorrection,
+                                  DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
+
+  /**
    * @brief Starts an mask applying task.
    * @param[in] pixelBuffer of the to be masked image
    * @param[in] maskPixelBuffer of the mask image
index dbb1230..c6fc0c2 100644 (file)
@@ -1419,8 +1419,16 @@ void TextureManager::AsyncLoadingHelper::Load(TextureId
                                               DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
 {
   mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
-  auto id                             = GetImplementation(mLoader).Load(url, desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad);
-  mLoadingInfoContainer.back().loadId = id;
+  if(DALI_UNLIKELY(url.IsBufferResource()))
+  {
+    auto id                             = GetImplementation(mLoader).LoadEncodedImageBuffer(mTextureManager.GetEncodedImageBuffer(url.GetUrl()), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad);
+    mLoadingInfoContainer.back().loadId = id;
+  }
+  else
+  {
+    auto id                             = GetImplementation(mLoader).Load(url, desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad);
+    mLoadingInfoContainer.back().loadId = id;
+  }
 }
 
 void TextureManager::AsyncLoadingHelper::ApplyMask(TextureId                                textureId,