Add lock for image loading 05/247805/6
authorSunghyun Kim <scholb.kim@samsung.com>
Tue, 17 Nov 2020 02:49:24 +0000 (11:49 +0900)
committerSunghyun Kim <scholb.kim@samsung.com>
Wed, 24 Mar 2021 10:44:22 +0000 (19:44 +0900)
loading image have to thread-safe.
for this, i added lock to gif and webp

Change-Id: I2f0921535fc944919916d2ac5e2768e9256c8692

dali/internal/imaging/common/gif-loading.cpp
dali/internal/imaging/common/webp-loading.cpp

index 6b0d709435cb8e915b2d059b55c5d4bd719bd52d..a1424473aa0a98b7dbd57eaeb44690010b9fd310 100644 (file)
@@ -29,6 +29,7 @@
 #include <cstring>
 #include <memory>
 
+#include <dali/devel-api/threading/mutex.h>
 #include <dali/integration-api/debug.h>
 #include <dali/internal/imaging/common/file-download.h>
 #include <dali/internal/system/common/file-reader.h>
@@ -1238,7 +1239,8 @@ struct GifLoading::Impl
 public:
   Impl(const std::string& url, bool isLocalResource)
   : mUrl(url),
-    mLoadSucceeded(true)
+    mLoadSucceeded(true),
+    mMutex()
   {
     loaderInfo.gifAccessor = nullptr;
     int error;
@@ -1258,6 +1260,7 @@ public:
   LoaderInfo      loaderInfo;
   ImageProperties imageProperties;
   bool            mLoadSucceeded;
+  Mutex           mMutex;
 };
 
 AnimatedImageLoadingPtr GifLoading::New(const std::string& url, bool isLocalResource)
@@ -1279,6 +1282,8 @@ bool GifLoading::LoadNextNFrames(uint32_t frameStartIndex, int count, std::vecto
 {
   int  error;
   bool ret = false;
+
+  Mutex::ScopedLock lock(mImpl->mMutex);
   if(!mImpl->mLoadSucceeded)
   {
     return false;
@@ -1316,6 +1321,7 @@ Dali::Devel::PixelBuffer GifLoading::LoadFrame(uint32_t frameIndex)
     return pixelBuffer;
   }
 
+  Mutex::ScopedLock lock(mImpl->mMutex);
   DALI_LOG_INFO(gGifLoadingLogFilter, Debug::Concise, "LoadFrame( frameIndex:%d )\n", frameIndex);
 
   pixelBuffer = Dali::Devel::PixelBuffer::New(mImpl->imageProperties.w, mImpl->imageProperties.h, Dali::Pixel::RGBA8888);
index 2068240844231f21fa815146077f8898df8f9ae8..7e4511cb4e54ed7df94b42b2ec59205f31d7acfc 100644 (file)
@@ -31,6 +31,7 @@
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/images/pixel-data.h>
 
+#include <dali/devel-api/threading/mutex.h>
 #include <dali/internal/imaging/common/file-download.h>
 #include <dali/internal/system/common/file-reader.h>
 #include <fcntl.h>
@@ -62,7 +63,8 @@ struct WebPLoading::Impl
 public:
   Impl(const std::string& url, bool isLocalResource)
   : mUrl(url),
-    mLoadSucceeded(true)
+    mLoadSucceeded(true),
+    mMutex()
   {
 #ifdef DALI_WEBP_ENABLED
     if(ReadWebPInformation(isLocalResource))
@@ -182,6 +184,7 @@ public:
   std::vector<uint32_t> mTimeStamp;
   uint32_t              mLoadingFrame{0};
   bool                  mLoadSucceeded;
+  Mutex                 mMutex;
 
 #ifdef DALI_WEBP_ENABLED
   WebPData         mWebPData{0};
@@ -211,6 +214,7 @@ WebPLoading::~WebPLoading()
 bool WebPLoading::LoadNextNFrames(uint32_t frameStartIndex, int count, std::vector<Dali::PixelData>& pixelData)
 {
 #ifdef DALI_WEBP_ENABLED
+  Mutex::ScopedLock lock(mImpl->mMutex);
   if(frameStartIndex >= mImpl->mWebPAnimInfo.frame_count || !mImpl->mLoadSucceeded)
   {
     return false;
@@ -267,6 +271,7 @@ Dali::Devel::PixelBuffer WebPLoading::LoadFrame(uint32_t frameIndex)
   Dali::Devel::PixelBuffer pixelBuffer;
 
 #ifdef DALI_WEBP_ENABLED
+  Mutex::ScopedLock lock(mImpl->mMutex);
   if(frameIndex >= mImpl->mWebPAnimInfo.frame_count || !mImpl->mLoadSucceeded)
   {
     return pixelBuffer;