[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-image / animated-image-visual.h
index 1d21356..0615123 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H
 
 /*
- * Copyright (c) 2021 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.
@@ -19,6 +19,8 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali/devel-api/actors/actor-devel.h>
+#include <dali/public-api/adaptor-framework/window.h>
 #include <dali/devel-api/adaptor-framework/animated-image-loading.h>
 #include <dali/public-api/adaptor-framework/timer.h>
 #include <dali/public-api/common/dali-vector.h>
@@ -111,8 +113,9 @@ public:
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
    * @param[in] shaderFactory The ImageVisualShaderFactory object
    * @param[in] imageUrl The URL to animated image resource to use
+   * @param[in] size The width and height of the image. The visual size will be used if these are 0.
    */
-  static AnimatedImageVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl);
+  static AnimatedImageVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size = ImageDimensions());
 
 public: // from Visual
   /**
@@ -133,7 +136,7 @@ public: // from Visual
   /**
    * @copydoc Visual::Base::OnDoAction
    */
-  void OnDoAction(const Dali::Property::Index actionName, const Dali::Property::Value& attributes) override;
+  void OnDoAction(const Dali::Property::Index actionId, const Dali::Property::Value& attributes) override;
 
 protected:
   /**
@@ -141,8 +144,9 @@ protected:
    *
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
    * @param[in] shaderFactory The ImageVisualShaderFactory object
+   * @param[in] desiredSize The width and height of the image. The visual size will be used if these are 0.
    */
-  AnimatedImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory);
+  AnimatedImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, ImageDimensions desiredSize);
 
   /**
    * @brief A reference counted object may only be deleted by calling Unreference().
@@ -193,56 +197,76 @@ protected:
 
 private:
   /**
-   * Creates the renderer for the animated image
+   * @brief Initialize the animated image variables.
+   * @param[in] imageUrl The url of the animated image
    */
-  void CreateRenderer();
+  void InitializeAnimatedImage(const VisualUrl& imageUrl);
 
   /**
-   * Starts the Load of the first batch of URLs
+   * @brief Create image cache for animated image or image array.
    */
-  void LoadFirstBatch();
+  void CreateImageCache();
 
   /**
-   * Adds the texture set to the renderer, and the renderer to the
+   * @brief Adds the texture set to the renderer, and the renderer to the
    * placement actor, and starts the frame timer
-   * @param[in] textureSet The texture set to apply
+   * @param[in] textureSet    The texture set to apply
+   * @param[in] firstInterval frame interval(ms) for the first frame.
    */
-  void StartFirstFrame(TextureSet& textureSet);
+  void StartFirstFrame(TextureSet& textureSet, uint32_t firstInterval);
 
   /**
-   * Prepares the texture set for displaying
+   * @brief Prepares the texture set for displaying
    */
-  TextureSet PrepareTextureSet();
+  void PrepareTextureSet();
 
   /**
-   * Set the image size from the texture set
+   * @brief Set the image size from the texture set
    * @param[in] textureSet The texture set to get the size from
    */
   void SetImageSize(TextureSet& textureSet);
 
   /**
-   * Called when the next frame is ready.
+   * @brief Called when the next frame is ready.
    * @param[in] textureSet the texture set to apply
+   * @param[in] interval interval(ms) for the frame
+   * @param[in] preMultiplied whether the texture is premultied alpha or not.
    */
-  void FrameReady(TextureSet textureSet) override;
+  void FrameReady(TextureSet textureSet, uint32_t interval, bool preMultiplied) override;
 
   /**
-   * Display the next frame. It is called when the mFrameDelayTimer ticks.
-   * Returns true to ensure the timer continues running.
+   * @brief Display the next frame. It is called when the mFrameDelayTimer ticks.
+   * @return true to ensure the timer continues running.
    */
   bool DisplayNextFrame();
 
   /**
-   * Initialize the animated image variables.
-   * @param[in] imageUrl The url of the animated image
+   * @brief Set the state of loading fail of an image or a frame.
+   * @return TextureSet of broken image.
    */
-  void InitializeAnimatedImage(const VisualUrl& imageUrl);
+  TextureSet SetLoadingFailed();
 
   /**
-   * Set the state of loading fail of an image or a frame.
-   * Returns TextureSet of broken image.
+   * @brief Allocate mask data.
+   * This is allocated only once.
    */
-  TextureSet SetLoadingFailed();
+  void AllocateMaskData();
+
+  /**
+   * @brief Check whether the mask texture is loaded or not.
+   * If MaskingType is MASKING_ON_LOADING and mask texture is failed to load, update shader.
+   */
+  void CheckMaskTexture();
+
+  /**
+   * @brief Callback when the visibility of the actor is changed.
+   */
+  void OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type);
+
+  /**
+   * @brief Callback when the visibility of the window is changed.
+   */
+  void OnWindowVisibilityChanged(Window window, bool visible);
 
   // Undefined
   AnimatedImageVisual(const AnimatedImageVisual& animatedImageVisual);
@@ -252,6 +276,7 @@ private:
 
 private:
   Timer                     mFrameDelayTimer;
+  WeakHandle<Window>        mPlacementWindow;
   WeakHandle<Actor>         mPlacementActor;
   ImageVisualShaderFactory& mImageVisualShaderFactory;
 
@@ -260,6 +285,7 @@ private:
   VisualUrl                  mImageUrl;
   Dali::AnimatedImageLoading mAnimatedImageLoading; // Only needed for animated image
   uint32_t                   mFrameIndexForJumpTo;  // Frame index into textureRects
+  uint32_t                   mCurrentFrameIndex;
 
   // Variables for Multi-Image player
   ImageCache::UrlList* mImageUrls;
@@ -269,7 +295,12 @@ private:
   uint16_t             mFrameDelay;
   int16_t              mLoopCount;
   int16_t              mCurrentLoopIndex;
-  uint16_t             mUrlIndex;
+
+  // Variables for image visual properties.
+  Dali::Toolkit::ImageVisual::LoadPolicy::Type    mLoadPolicy;
+  Dali::Toolkit::ImageVisual::ReleasePolicy::Type mReleasePolicy;
+  TextureManager::MaskingDataPointer              mMaskingData;
+  Dali::ImageDimensions                           mDesiredSize;
 
   // Shared variables
   uint32_t        mFrameCount; // Number of frames
@@ -277,11 +308,13 @@ private:
 
   DevelAnimatedImageVisual::Action::Type mActionStatus;
 
-  Dali::WrapMode::Type                   mWrapModeU : 3;
-  Dali::WrapMode::Type                   mWrapModeV : 3;
-  DevelImageVisual::StopBehavior::Type   mStopBehavior : 2;
-  bool                                   mStartFirstFrame : 1;
-  bool                                   mIsJumpTo : 1;
+  Dali::WrapMode::Type                 mWrapModeU : 3;
+  Dali::WrapMode::Type                 mWrapModeV : 3;
+  Dali::FittingMode::Type              mFittingMode : 3;
+  Dali::SamplingMode::Type             mSamplingMode : 4;
+  DevelImageVisual::StopBehavior::Type mStopBehavior : 2;
+  bool                                 mStartFirstFrame : 1;
+  bool                                 mIsJumpTo : 1;
 };
 
 } // namespace Internal