[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / npatch-data.h
index 60e6e6b..99c4d08 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_NPATCH_DATA_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.
  */
 
 // EXTERNAL INCLUDES
-#include <string>
-#include <dali/public-api/rendering/texture-set.h>
 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+#include <dali/public-api/object/ref-object.h>
+#include <dali/public-api/rendering/texture-set.h>
+#include <string>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/internal/visuals/texture-manager-impl.h>
 #include <dali-toolkit/devel-api/utility/npatch-utilities.h>
+#include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
+#include <dali-toolkit/internal/visuals/visual-url.h>
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 namespace Internal
 {
+class NPatchData;
+typedef IntrusivePtr<NPatchData> NPatchDataPtr;
 
-class NPatchData : public Dali::Toolkit::TextureUploadObserver
+class NPatchData : public ConnectionTracker, public Dali::Toolkit::TextureUploadObserver, public Dali::RefObject
 {
 public:
-  typedef int32_t NPatchDataId;                 ///< The NPatchDataId type. This is used as a handle to refer to a particular Npatch Data.
-  static const int INVALID_NPATCH_DATA_ID = -1; ///< Used to represent a null TextureId or error
+  typedef int32_t           NPatchDataId;                ///< The NPatchDataId type. This is used as a handle to refer to a particular Npatch Data.
+  static const NPatchDataId INVALID_NPATCH_DATA_ID = -1; ///< Used to represent a null TextureId or error
 
   /**
    * @brief Loading State of the NPatch image.
    */
   enum class LoadingState
   {
-    LOADING = 0,   ///< NPatch is on loading.
-    LOAD_COMPLETE, ///< NPatch loading is completed successfully.
-    LOAD_FAILED    ///< NPatch loading is failed.
+    NOT_STARTED = 0, ///< NPatch loading is not started yet.
+    LOADING,         ///< NPatch is on loading.
+    LOAD_COMPLETE,   ///< NPatch loading is completed successfully.
+    LOAD_FAILED      ///< NPatch loading is failed.
   };
 
 public:
-
   /**
    * Constructor
    */
@@ -64,7 +66,6 @@ public:
   ~NPatchData();
 
 public:
-
   /**
    * @brief Set cache data id.
    *
@@ -105,14 +106,14 @@ public:
    *
    * @param [in] url NPatch image url
    */
-  void SetUrl(const std::string url);
+  void SetUrl(const VisualUrl& url);
 
   /**
    * @brief Retrieve the image url.
    *
    * @return Return the image url.
    */
-  std::string GetUrl() const;
+  VisualUrl GetUrl() const;
 
   /**
    * @brief Set texture set on the cache data
@@ -240,7 +241,6 @@ public:
    */
   LoadingState GetLoadingState() const;
 
-
   /**
    * @brief Retrieve NPatch rendering data.
    *
@@ -254,44 +254,52 @@ public:
    * @param [in] pixelBuffer loaded pixel buffer.
    * @param [in] preMultiplied whether the loaded image is premultiplied or not
    */
-  void SetLoadedNPatchData( Devel::PixelBuffer& pixelBuffer, bool preMultiplied );
-
-private:
+  void SetLoadedNPatchData(Devel::PixelBuffer& pixelBuffer, bool preMultiplied);
 
   /**
-   * @copydoc TextureUploadObserver::UploadCompleted
+   * @brief Send LoadComplete notify with current setuped NPatchData
    *
-   * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready.
-   * This callback is the place to add the renderer as it would be called once the loading is finished.
+   * @param [in] observer observer who will be got LoadComplete notify
+   * @param [in] loadSuccess whether the image load success or not.
    */
-  void UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) override {}
+  void NotifyObserver(TextureUploadObserver* observer, const bool& loadSuccess);
 
+private:
   /**
    * @copydoc TextureUploadObserver::LoadComplete
    *
    * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready.
    * This callback is the place to add the renderer as it would be called once the loading is finished.
    */
-  void LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) override;
+  void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override;
 
+  /**
+   * This is called by the TextureUploadObserver when an observer is destroyed.
+   * We use the callback to know when to remove an observer from our notify list.
+   * @param[in] observer The observer that generated the callback
+   */
+  void ObserverDestroyed(TextureUploadObserver* observer);
 
 private:
-
   using ObserverListType = Dali::Vector<TextureUploadObserver*>;
 
-  NPatchDataId                 mId;
-  ObserverListType             mObserverList;      ///< Container used to store all observer clients of this Texture
-  std::string                  mUrl;               ///< Url of the N-Patch
-  TextureSet                   mTextureSet;        ///< Texture containing the cropped image
-  NPatchUtility::StretchRanges mStretchPixelsX;    ///< X stretch pixels
-  NPatchUtility::StretchRanges mStretchPixelsY;    ///< Y stretch pixels
-  std::size_t                  mHash;              ///< Hash code for the Url
-  uint32_t                     mCroppedWidth;      ///< Width of the cropped middle part of N-patch
-  uint32_t                     mCroppedHeight;     ///< Height of the cropped middle part of N-patch
-  Rect<int>                    mBorder;            ///< The size of the border
-  LoadingState                 mLoadingState;      ///< True if the data loading is completed
-  bool                         mPreMultiplyOnLoad; ///< Whether to multiply alpha into color channels on load
-  void*                        mRenderingMap;      ///< NPatch rendering data
+  NPatchDataId     mId;
+  ObserverListType mObserverList;    ///< Container used to store all observer clients of this Texture
+  ObserverListType mQueuedObservers; ///< Container observers when user try to add during notify observers
+
+  VisualUrl                    mUrl;            ///< Url of the N-Patch
+  TextureSet                   mTextureSet;     ///< Texture containing the cropped image
+  NPatchUtility::StretchRanges mStretchPixelsX; ///< X stretch pixels
+  NPatchUtility::StretchRanges mStretchPixelsY; ///< Y stretch pixels
+  std::size_t                  mHash;           ///< Hash code for the Url
+  uint32_t                     mCroppedWidth;   ///< Width of the cropped middle part of N-patch
+  uint32_t                     mCroppedHeight;  ///< Height of the cropped middle part of N-patch
+  Rect<int>                    mBorder;         ///< The size of the border
+  LoadingState                 mLoadingState;   ///< True if the data loading is completed
+  void*                        mRenderingMap;   ///< NPatch rendering data
+
+  bool mPreMultiplyOnLoad : 1; ///< Whether to multiply alpha into color channels on load
+  bool mObserverNotifying : 1; ///< Whether this NPatchData notifying observers or not.
 };
 
 } // namespace Internal