CPU Alpha Masking for Animated Image Visual
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-image / fixed-image-cache.cpp
index 192a3c4..8cc69ff 100644 (file)
@@ -35,9 +35,13 @@ constexpr bool ENABLE_ORIENTATION_CORRECTION(true);
 constexpr uint32_t FIRST_FRAME_INDEX = 0u;
 } // namespace
 
-FixedImageCache::FixedImageCache(
-  TextureManager& textureManager, UrlList& urlList, ImageCache::FrameReadyObserver& observer, uint32_t batchSize, uint32_t interval)
-: ImageCache(textureManager, observer, batchSize, interval),
+FixedImageCache::FixedImageCache(TextureManager&                     textureManager,
+                                 UrlList&                            urlList,
+                                 TextureManager::MaskingDataPointer& maskingData,
+                                 ImageCache::FrameReadyObserver&     observer,
+                                 uint32_t                            batchSize,
+                                 uint32_t                            interval)
+: ImageCache(textureManager, maskingData, observer, batchSize, interval),
   mImageUrls(urlList),
   mFront(FIRST_FRAME_INDEX)
 {
@@ -122,7 +126,6 @@ void FixedImageCache::LoadBatch()
     bool                               synchronousLoading = false;
     bool                               atlasingStatus     = false;
     bool                               loadingStatus      = false;
-    TextureManager::MaskingDataPointer maskInfo           = nullptr;
     AtlasUploadObserver*               atlasObserver      = nullptr;
     ImageAtlasManagerPtr               imageAtlasManager  = nullptr;
     Vector4                            textureRect;
@@ -130,7 +133,7 @@ void FixedImageCache::LoadBatch()
     auto                               preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
     mTextureManager.LoadTexture(
-      url, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, maskInfo, synchronousLoading, mImageUrls[frameIndex].mTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiply);
+      url, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, mMaskingData, synchronousLoading, mImageUrls[frameIndex].mTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiply);
 
     mRequestingLoad = false;
   }
@@ -157,10 +160,21 @@ void FixedImageCache::ClearCache()
     {
       mTextureManager.Remove(mImageUrls[i].mTextureId, this);
       mImageUrls[i].mTextureId = TextureManager::INVALID_TEXTURE_ID;
+
+      if(mMaskingData && mMaskingData->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID)
+      {
+        // In the CPU alpha masking, each frame increases reference count of masking texture.
+        // We should call TextureManager::Remove to decrease reference count when each frame is removed.
+        mTextureManager.Remove(mMaskingData->mAlphaMaskId, this);
+      }
     }
   }
   mReadyFlags.clear();
   mLoadState = TextureManager::LoadState::NOT_STARTED;
+  if(mMaskingData)
+  {
+    mMaskingData->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID;
+  }
 }
 
 void FixedImageCache::LoadComplete(bool loadSuccess, TextureInformation textureInformation)