(Vector) Fix occasional tc failure
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-vector-image / animated-vector-image-visual.h
index 8aaed9c..221cf23 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
 
 /*
- * Copyright (c) 2019 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/public-api/common/intrusive-ptr.h>
-#include <dali/public-api/object/weak-handle.h>
-#include <dali/public-api/object/property-notification.h>
 #include <dali/devel-api/actors/actor-devel.h>
 #include <dali/public-api/adaptor-framework/window.h>
+#include <dali/public-api/common/intrusive-ptr.h>
+#include <dali/public-api/object/property-notification.h>
+#include <dali/public-api/object/weak-handle.h>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/internal/visuals/visual-base-impl.h>
-#include <dali-toolkit/internal/visuals/visual-url.h>
 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
+#include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h>
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/internal/visuals/visual-url.h>
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 namespace Internal
 {
-
 class ImageVisualShaderFactory;
 class AnimatedVectorImageVisual;
-using AnimatedVectorImageVisualPtr = IntrusivePtr< AnimatedVectorImageVisual >;
+using AnimatedVectorImageVisualPtr = IntrusivePtr<AnimatedVectorImageVisual>;
 
 /**
  * The visual which renders an animated vector image using VectorAnimationRenderer.
@@ -55,10 +53,9 @@ using AnimatedVectorImageVisualPtr = IntrusivePtr< AnimatedVectorImageVisual >;
  * | url                      | STRING           |
  *
  */
-class AnimatedVectorImageVisual: public Visual::Base, public ConnectionTracker
+class AnimatedVectorImageVisual : public Visual::Base, public ConnectionTracker, public VectorAnimationManager::LifecycleObserver
 {
 public:
-
   /**
    * @brief Create the AnimatedVectorImageVisual using the image URL.
    *
@@ -68,7 +65,7 @@ public:
    * @param[in] properties A Property::Map containing settings for this visual
    * @return A smart-pointer to the newly allocated visual.
    */
-  static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties );
+  static AnimatedVectorImageVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties);
 
   /**
    * @brief Create the AnimatedVectorImageVisual using the image URL.
@@ -78,27 +75,36 @@ public:
    * @param[in] imageUrl The URL to an animated vector image to use
    * @return A smart-pointer to the newly allocated visual.
    */
-  static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
-
-public:  // from Visual
+  static AnimatedVectorImageVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl);
 
+public: // from Visual
   /**
    * @copydoc Visual::Base::GetNaturalSize
    */
-  void GetNaturalSize( Vector2& naturalSize ) override;
+  void GetNaturalSize(Vector2& naturalSize) override;
 
   /**
    * @copydoc Visual::Base::CreatePropertyMap
    */
-  void DoCreatePropertyMap( Property::Map& map ) const override;
+  void DoCreatePropertyMap(Property::Map& map) const override;
 
   /**
    * @copydoc Visual::Base::CreateInstancePropertyMap
    */
-  void DoCreateInstancePropertyMap( Property::Map& map ) const override;
+  void DoCreateInstancePropertyMap(Property::Map& map) const override;
 
-protected:
+  /**
+   * @copydoc Visual::Base::EnablePreMultipliedAlpha
+   */
+  void EnablePreMultipliedAlpha(bool preMultiplied) override;
+
+protected: // From VectorAnimationManager::LifecycleObserver:
+  /**
+   * @copydoc VectorAnimationManager::LifecycleObserver::VectorAnimationManagerDestroyed()
+   */
+  void VectorAnimationManagerDestroyed() override;
 
+protected:
   /**
    * @brief Constructor.
    *
@@ -106,27 +112,32 @@ protected:
    * @param[in] shaderFactory The ImageVisualShaderFactory object
    * @param[in] imageUrl The URL to an animated vector image to use
    */
-  AnimatedVectorImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
+  AnimatedVectorImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl);
 
   /**
    * @brief A reference counted object may only be deleted by calling Unreference().
    */
-  virtual ~AnimatedVectorImageVisual();
+  ~AnimatedVectorImageVisual() override;
+
+  /**
+   * @copydoc Visual::Base::OnInitialize
+   */
+  void OnInitialize() override;
 
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
-  void DoSetProperties( const Property::Map& propertyMap ) override;
+  void DoSetProperties(const Property::Map& propertyMap) override;
 
   /**
-   * @copydoc Visual::Base::DoSetOnStage
+   * @copydoc Visual::Base::DoSetOnScene
    */
-  void DoSetOnStage( Actor& actor ) override;
+  void DoSetOnScene(Actor& actor) override;
 
   /**
-   * @copydoc Visual::Base::DoSetOffStage
+   * @copydoc Visual::Base::DoSetOffScene
    */
-  void DoSetOffStage( Actor& actor ) override;
+  void DoSetOffScene(Actor& actor) override;
 
   /**
    * @copydoc Visual::Base::OnSetTransform
@@ -134,23 +145,33 @@ protected:
   void OnSetTransform() override;
 
   /**
+   * @copydoc Visual::Base::UpdateShader
+   */
+  void UpdateShader() override;
+
+  /**
+   * @copydoc Visual::Base::GenerateShader
+   */
+  Shader GenerateShader() const override;
+
+  /**
    * @copydoc Visual::Base::OnDoAction
    */
-  void OnDoAction( const Property::Index actionId, const Property::Value& attributes ) override;
+  void OnDoAction(const Property::Index actionId, const Property::Value& attributes) override;
 
 private:
-
   /**
    * Helper method to set individual values by index key.
    * @param[in] index The index key of the value
    * @param[in] value The value
    */
-  void DoSetProperty( Property::Index index, const Property::Value& value );
+  void DoSetProperty(Property::Index index, const Property::Value& value);
 
   /**
-   * @brief Called when the texture upload is completed.
+   * @brief Called when the resource is ready.
+   * @param[in] status The resource status
    */
-  void OnUploadCompleted();
+  void OnResourceReady(VectorAnimationTask::ResourceStatus status);
 
   /**
    * @brief Event callback from rasterize thread. This is called after the animation is finished.
@@ -173,47 +194,57 @@ private:
   void StopAnimation();
 
   /**
+   * @brief Trigger rasterization of the vector content.
+   */
+  void TriggerVectorRasterization();
+
+  /**
    * @brief Callback when the world scale factor changes.
    */
-  void OnScaleNotification( PropertyNotification& source );
+  void OnScaleNotification(PropertyNotification& source);
 
   /**
    * @brief Callback when the size changes.
    */
-  void OnSizeNotification( PropertyNotification& source );
+  void OnSizeNotification(PropertyNotification& source);
 
   /**
    * @brief Callback when the visibility of the actor is changed.
    */
-  void OnControlVisibilityChanged( Actor actor, bool visible, DevelActor::VisibilityChange::Type type );
+  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 );
+  void OnWindowVisibilityChanged(Window window, bool visible);
+
+  /**
+   * @brief Callback when the event is processed.
+   */
+  void OnProcessEvents();
 
   // Undefined
-  AnimatedVectorImageVisual( const AnimatedVectorImageVisual& visual ) = delete;
+  AnimatedVectorImageVisual(const AnimatedVectorImageVisual& visual) = delete;
 
   // Undefined
-  AnimatedVectorImageVisual& operator=( const AnimatedVectorImageVisual& visual ) = delete;
+  AnimatedVectorImageVisual& operator=(const AnimatedVectorImageVisual& visual) = delete;
 
 private:
-  VisualUrl                                    mUrl;
-  VectorAnimationTaskPtr                       mVectorAnimationTask;
-  ImageVisualShaderFactory&                    mImageVisualShaderFactory;
-  PropertyNotification                         mScaleNotification;
-  PropertyNotification                         mSizeNotification;
-  Vector2                                      mVisualSize;
-  Vector2                                      mVisualScale;
-  Property::Array                              mPlayRange;
-  WeakHandle< Actor >                          mPlacementActor;
-  int32_t                                      mLoopCount;
-  uint32_t                                     mResendFlag;
-  DevelAnimatedVectorImageVisual::Action::Type mActionStatus;
-  DevelImageVisual::StopBehavior::Type         mStopBehavior;
-  DevelImageVisual::LoopingMode::Type          mLoopingMode;
-  bool                                         mRendererAdded;
+  VisualUrl                          mUrl;
+  VectorAnimationTask::AnimationData mAnimationData;
+  VectorAnimationTaskPtr             mVectorAnimationTask;
+  ImageVisualShaderFactory&          mImageVisualShaderFactory;
+  PropertyNotification               mScaleNotification;
+  PropertyNotification               mSizeNotification;
+  Vector2                            mVisualSize;
+  Vector2                            mVisualScale;
+  WeakHandle<Actor>                  mPlacementActor;
+  DevelImageVisual::PlayState::Type  mPlayState;
+  CallbackBase*                      mEventCallback; // Not owned
+  bool                               mLoadFailed;
+  bool                               mRendererAdded;
+  bool                               mCoreShutdown;
+  bool                               mRedrawInScalingDown;
 };
 
 } // namespace Internal