[Tizen] Add lock for image loading 78/248578/3 accepted/tizen/6.0/unified/20201202.212218 submit/tizen_6.0/20201201.081346
authorSunghyun Kim <scholb.kim@samsung.com>
Tue, 17 Nov 2020 02:49:24 +0000 (11:49 +0900)
committerSunghyun Kim <scholb.kim@samsung.com>
Tue, 1 Dec 2020 05:35:02 +0000 (14:35 +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 16057f7..111d1cf 100644 (file)
@@ -31,6 +31,7 @@
 #include <dali/public-api/images/pixel-data.h>
 #include <dali/internal/imaging/common/file-download.h>
 #include <dali/internal/system/common/file-reader.h>
+#include <dali/devel-api/threading/mutex.h>
 
 #define IMG_TOO_BIG( w, h )                                                        \
   ( ( static_cast<unsigned long long>(w) * static_cast<unsigned long long>(h) ) >= \
@@ -1192,7 +1193,8 @@ struct GifLoading::Impl
 {
 public:
   Impl( const std::string& url, bool isLocalResource )
-  : mUrl( url )
+  : mUrl( url ),
+    mMutex()
   {
     loaderInfo.gif = nullptr;
     int error;
@@ -1232,6 +1234,7 @@ public:
   std::string mUrl;
   LoaderInfo loaderInfo;
   ImageProperties imageProperties;
+  Mutex mMutex;
 };
 
 AnimatedImageLoadingPtr GifLoading::New( const std::string &url, bool isLocalResource )
@@ -1255,6 +1258,7 @@ bool GifLoading::LoadNextNFrames( uint32_t frameStartIndex, int count, std::vect
   int error;
   bool ret = false;
 
+  Mutex::ScopedLock lock( mImpl->mMutex );
   const int bufferSize = mImpl->imageProperties.w * mImpl->imageProperties.h * sizeof( uint32_t );
 
   DALI_LOG_INFO( gGifLoadingLogFilter, Debug::Concise, "LoadNextNFrames( frameStartIndex:%d, count:%d )\n", frameStartIndex, count );
@@ -1285,6 +1289,7 @@ Dali::Devel::PixelBuffer GifLoading::LoadFrame( uint32_t frameIndex )
   int error;
   Dali::Devel::PixelBuffer 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 cc4246a..f6e65b0 100644 (file)
@@ -38,6 +38,7 @@
 #include <cstring>
 #include <dali/internal/imaging/common/file-download.h>
 #include <dali/internal/system/common/file-reader.h>
+#include <dali/devel-api/threading/mutex.h>
 
 typedef unsigned char WebPByteType;
 
@@ -65,7 +66,8 @@ struct WebPLoading::Impl
 {
 public:
   Impl( const std::string& url, bool isLocalResource )
-  : mUrl( url )
+  : mUrl( url ),
+    mMutex()
   {
 #ifdef DALI_WEBP_ENABLED
     if( ReadWebPInformation( isLocalResource ) )
@@ -180,6 +182,7 @@ public:
   std::string mUrl;
   std::vector<uint32_t> mTimeStamp;
   uint32_t mLoadingFrame{0};
+  Mutex mMutex;
 
 #ifdef DALI_WEBP_ENABLED
   WebPData mWebPData{0};
@@ -209,6 +212,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 )
   {
     return false;
@@ -266,6 +270,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 )
   {
     return pixelBuffer;