Apply WrapMode in animated visual
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-image / rolling-animated-image-cache.h
index 503f65e..8fed2d7 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H
 
 /*
- * Copyright (c) 2020 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.
  */
 
 // EXTERNAL INCLUDES
+#include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
+#include <dali-toolkit/internal/visuals/animated-image/image-cache.h>
 #include <dali/devel-api/adaptor-framework/animated-image-loading.h>
 #include <dali/devel-api/common/circular-queue.h>
-#include <dali-toolkit/internal/visuals/animated-image/image-cache.h>
-#include <dali-toolkit/internal/visuals/texture-manager-impl.h>
 
 namespace Dali
 {
@@ -29,7 +29,6 @@ namespace Toolkit
 {
 namespace Internal
 {
-
 /**
  * Class to manage a rolling cache of Animated images, where the cache size
  * is smaller than the total number of images.
@@ -37,71 +36,136 @@ namespace Internal
  * Frames are always ready, so the observer.FrameReady callback is never triggered;
  * the FirstFrame and NextFrame APIs will always return a texture.
  */
-class RollingAnimatedImageCache : public ImageCache
+class RollingAnimatedImageCache : public ImageCache, public TextureUploadObserver
 {
 public:
   /**
-   * Constructor.
-   * @param[in] textureManager The texture manager
-   * @param[in] animatedImageLoader The loaded animated image
-   * @param[in] frameCount The number of frames in the animated image
-   * @param[in] observer FrameReady observer
-   * @param[in] cacheSize The size of the cache
-   * @param[in] batchSize The size of a batch to load
+   * @brief Constructor.
+   * @param[in] textureManager       The texture manager
+   * @param[in] animatedImageLoading  The loaded animated image
+   * @param[in] maskingData          Masking data to be applied.
+   * @param[in] observer             FrameReady observer
+   * @param[in] cacheSize            The size of the cache
+   * @param[in] batchSize            The size of a batch to load
+   * @param[in] wrapModeU            Horizontal Wrap mode
+   * @param[in] wrapModeV            Vertical Wrap mode
+   * @param[in] isSynchronousLoading The flag to define whether to load first frame synchronously
+   * @param[in] preMultiplyOnLoad    The flag if image's color should be multiplied by it's alpha
    *
    * This will start loading textures immediately, according to the
    * batch and cache sizes.
    */
-  RollingAnimatedImageCache( TextureManager&                 textureManager,
-                        AnimatedImageLoading&           animatedImageLoader,
-                        uint32_t                        frameCount,
-                        ImageCache::FrameReadyObserver& observer,
-                        uint16_t                        cacheSize,
-                        uint16_t                        batchSize );
+  RollingAnimatedImageCache(TextureManager&                     textureManager,
+                            AnimatedImageLoading&               animatedImageLoading,
+                            TextureManager::MaskingDataPointer& maskingData,
+                            ImageCache::FrameReadyObserver&     observer,
+                            uint16_t                            cacheSize,
+                            uint16_t                            batchSize,
+                            const Dali::WrapMode::Type&         wrapModeU,
+                            const Dali::WrapMode::Type&         wrapModeV,
+                            bool                                isSynchronousLoading,
+                            bool                                preMultiplyOnLoad);
 
   /**
-   * Destructor
+   * @brief Destructor
    */
-  virtual ~RollingAnimatedImageCache();
+  ~RollingAnimatedImageCache() override;
 
   /**
-   * Get the Nth frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
+   * @copydoc Internal::ImageCache::Frame()
    */
-  TextureSet Frame( uint32_t frameIndex ) override;
+  TextureSet Frame(uint32_t frameIndex) override;
 
   /**
-   * Get the first frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
+   * @copydoc Internal::ImageCache::FirstFrame()
    */
   TextureSet FirstFrame() override;
 
   /**
-   * Get the interval of Nth frame.
+   * @copydoc Internal::ImageCache::GetFrameInterval()
+   */
+  uint32_t GetFrameInterval(uint32_t frameIndex) const override;
+
+  /**
+   * @copydoc Internal::ImageCache::GetCurrentFrameIndex()
+   */
+  int32_t GetCurrentFrameIndex() const override;
+
+  /**
+   * @copydoc Internal::ImageCache::GetTotalFrameCount()
    */
-  uint32_t GetFrameInterval( uint32_t frameIndex ) override;
+  int32_t GetTotalFrameCount() const override;
+
+  /**
+   * @copydoc Internal::ImageCache::ClearCache()
+   */
+  void ClearCache() override;
 
 private:
   /**
+   * @brief Check whether the front frame is ready or not.
+   *
    * @return true if the front frame is ready
    */
   bool IsFrontReady() const;
 
   /**
-   * Load the next batch of images
+   * @brief Request to Load a frame
+   *
+   * @param[in] frameIndex          index of frame to be loaded.
+   * @param[in] synchronousLoading  true if the frame should be loaded synchronously
+   *
+   * @return the texture set currently loaded.
    */
-  void LoadBatch();
+  TextureSet RequestFrameLoading(uint32_t frameIndex, bool synchronousLoading);
 
   /**
-   * Get the texture set of the front frame.
-   * @return the texture set
+   * @brief Load the next batch of images
+   *
+   * @param[in] frameIndex starting frame index of batch to be loaded.
+   */
+  void LoadBatch(uint32_t frameIndex);
+
+  /**
+   * @brief Find the matching image frame, and set it to ready
+   *
+   * @param[in] textureId texture id to be marked as ready.
+   */
+  void SetImageFrameReady(TextureManager::TextureId textureId);
+
+  /**
+   * @brief Get the texture set of the front frame.
+   *
+   * @return the texture set of the front of Cache.
    */
   TextureSet GetFrontTextureSet() const;
 
   /**
-   * Get the texture id of the given index
+   * @brief Get the texture id of the given index
+   *
+   * @param[in] index index of the queue.
+   */
+  TextureManager::TextureId GetCachedTextureId(int index) const;
+
+  /**
+   * @brief Make the loaded frame ready and notify it to the texture upload observer
+   *
+   * @param[in] loadSuccess whether the loading is succeded or not.
+   * @param[in] textureSet textureSet for this frame.
+   * @param[in] interval interval between this frame and next frame.
+   */
+  void MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t interval);
+
+  /**
+   * @brief Pop front entity of Cache.
+   */
+  void PopFrontCache();
+
+protected:
+  /**
+   * @copydoc Toolkit::TextureUploadObserver::LoadComplete()
    */
-  TextureManager::TextureId GetCachedTextureId( int index ) const;
+  void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override;
 
 private:
   /**
@@ -109,15 +173,23 @@ private:
    */
   struct ImageFrame
   {
-    unsigned int mFrameNumber = 0u;
+    uint32_t mFrameNumber = 0u;
+    bool     mReady       = false;
   };
+  std::vector<TextureManager::TextureId> mTextureIds;
 
-  Dali::AnimatedImageLoading& mAnimatedImageLoading;
+  VisualUrl                  mImageUrl;
+  Dali::AnimatedImageLoading mAnimatedImageLoading;
   uint32_t                   mFrameCount;
-  int                        mFrameIndex;
-  std::vector<UrlStore>      mImageUrls;
-  uint16_t                   mCacheSize;
+  uint32_t                   mFrameIndex;
+  uint32_t                   mCacheSize;
+  std::vector<int32_t>       mIntervals;
+  std::vector<uint32_t>      mLoadWaitingQueue;
   CircularQueue<ImageFrame>  mQueue;
+  Dali::WrapMode::Type       mWrapModeU : 3;
+  Dali::WrapMode::Type       mWrapModeV : 3;
+  bool                       mIsSynchronousLoading;
+  bool                       mPreMultiplyOnLoad;
 };
 
 } // namespace Internal