[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-image / fixed-image-cache.h
index d884e28..4fc4ecc 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_FIXED_IMAGE_CACHE_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -18,8 +18,8 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
 #include <dali-toolkit/internal/visuals/animated-image/image-cache.h>
-#include <dali-toolkit/internal/visuals/texture-manager-impl.h>
 
 namespace Dali
 {
@@ -27,93 +27,110 @@ namespace Toolkit
 {
 namespace Internal
 {
-
 class FixedImageCache : public ImageCache, public TextureUploadObserver
 {
 public:
   /**
    * Constructor.
-   * @param[in] textureManager The texture manager
-   * @param[in] urlList List of urls to cache
-   * @param[in] observer FrameReady observer
-   * @param[in] batchSize The size of a batch to load
+   * @param[in] textureManager    The texture manager
+   * @param[in] size              The width and height to fit the loaded image to.
+   * @param[in] fittingMode       The FittingMode of the resource to load
+   * @param[in] samplingMode      The SamplingMode of the resource to load
+   * @param[in] urlList           List of urls to cache
+   * @param[in] maskingData       Masking data to be applied.
+   * @param[in] observer          FrameReady observer
+   * @param[in] batchSize         The size of a batch to load
+   * @param[in] interval          Time interval between each frame
+   * @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. The cache is as large as the number of urls.
    */
-  FixedImageCache( TextureManager&                 textureManager,
-                   UrlList&                        urlList,
-                   ImageCache::FrameReadyObserver& observer,
-                   unsigned int                    batchSize );
-
-  virtual ~FixedImageCache();
+  FixedImageCache(TextureManager&                     textureManager,
+                  ImageDimensions                     size,
+                  Dali::FittingMode::Type             fittingMode,
+                  Dali::SamplingMode::Type            samplingMode,
+                  UrlList&                            urlList,
+                  TextureManager::MaskingDataPointer& maskingData,
+                  ImageCache::FrameReadyObserver&     observer,
+                  uint32_t                            batchSize,
+                  uint32_t                            interval,
+                  bool                                preMultiplyOnLoad);
+
+  ~FixedImageCache() 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 next frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
-   * This will trigger the loading of the next batch.
+   * @copydoc Internal::ImageCache::GetFrameInterval()
    */
-  TextureSet NextFrame() override;
+  uint32_t GetFrameInterval(uint32_t frameIndex) const override;
 
-private:
   /**
-   * @return true if the front frame is ready
+   * @copydoc Internal::ImageCache::GetCurrentFrameIndex()
    */
-  bool IsFrontReady() const;
+  int32_t GetCurrentFrameIndex() const override;
 
   /**
-   * Load the next batch of images
+   * @copydoc Internal::ImageCache::GetTotalFrameCount()
    */
-  void LoadBatch();
+  int32_t GetTotalFrameCount() const override;
 
   /**
-   * Find the matching image frame, and set it to ready
+   * @copydoc Internal::ImageCache::ClearCache()
    */
-  void SetImageFrameReady( TextureManager::TextureId textureId );
+  void ClearCache() override;
 
+private:
   /**
-   * Get the texture set of the front frame.
-   * @return the texture set
+   * @brief Check whether the frame is ready or not.
+   * @param[in] frameIndex The frame index to check the frame is ready or not.
+   *
+   * @return true if the frame is ready
    */
-  TextureSet GetFrontTextureSet() const;
+  bool IsFrameReady(uint32_t frameIndex) const;
 
   /**
-   * Check if the front frame has become ready - if so, inform observer
+   * @brief Load the next batch of images
+   */
+  void LoadBatch();
+
+  /**
+   * @brief Get the texture set at the input frame index
+   * @param[in] frameIndex The frame index to retrieve texture set.
+   *
+   * @return the texture set of the front of Cache.
+   */
+  TextureSet GetTextureSet(uint32_t frameIndex) const;
+
+  /**
+   * @brief Check if the front frame has become ready - if so, inform observer
+   *
    * @param[in] wasReady Readiness before call.
+   * @param[in] frameIndex The frame index for this frame
+   * @param[in] preMultiplied whether the texture is premultied alpha or not.
    */
-  void CheckFrontFrame( bool wasReady );
+  void MakeReady(bool wasReady, uint32_t frameIndex, bool preMultiplied);
 
 protected:
-  void UploadComplete(
-    bool           loadSuccess,
-    int32_t        textureId,
-    TextureSet     textureSet,
-    bool           useAtlasing,
-    const Vector4& atlasRect,
-    bool           premultiplied ) override;
-
-  void LoadComplete(
-    bool loadSuccess,
-    Devel::PixelBuffer pixelBuffer,
-    const VisualUrl& url,
-    bool preMultiplied ) override;
+  /**
+   * @copydoc Toolkit::TextureUploadObserver::LoadComplete()
+   */
+  void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override;
 
 private:
-  std::vector<UrlStore>& mImageUrls;
-  std::vector<bool> mReadyFlags;
-  unsigned int      mFront;
+  std::vector<UrlStore>&                 mImageUrls;
+  std::vector<bool>                      mReadyFlags;
+  std::vector<TextureManager::LoadState> mLoadStates;
+  uint32_t                               mCurrentFrameIndex;
 };
 
 } //namespace Internal