Merge "Split texture-manager-impl files" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-upload-observer.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXTURE_UPLOAD_OBSERVER_H
2 #define DALI_TOOLKIT_INTERNAL_TEXTURE_UPLOAD_OBSERVER_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
23 #include <dali/public-api/rendering/texture-set.h>
24 #include <dali/public-api/signals/dali-signal.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/visuals/visual-url.h>
28 #include <dali-toolkit/public-api/dali-toolkit-common.h>
29
30 namespace Dali
31 {
32 namespace Toolkit
33 {
34 /**
35  * @brief Base class used to observe the upload status of a texture.
36  *
37  * Derived class must implement the LoadComplete method which is
38  * executed once the texture is ready to draw.
39  */
40 class TextureUploadObserver
41 {
42 public:
43   typedef Signal<void(TextureUploadObserver*)> DestructionSignalType; ///< Signal prototype for the Destruction Signal.
44
45   enum class ReturnType
46   {
47     TEXTURE = 0,
48     PIXEL_BUFFER
49   };
50
51   struct TextureInformation
52   {
53     TextureInformation(ReturnType returnType, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied);
54     TextureInformation(ReturnType returnType, Devel::PixelBuffer pixelBuffer, const std::string& url, bool preMultiplied);
55
56     TextureInformation();
57
58     ReturnType         returnType;    ///< Returned Texture type.
59     int32_t            textureId;     ///< The textureId of the loaded texture in the TextureManager
60     TextureSet         textureSet;    ///< The TextureSet containing the Texture
61     bool               useAtlasing;   ///< True if atlasing was used (note: this may be different to what was requested)
62     const Vector4&     atlasRect;     ///< If using atlasing, this is the rectangle within the atlas to use.
63     bool               preMultiplied; ///< True if the image had pre-multiplied alpha applied
64     Devel::PixelBuffer pixelBuffer;   ///< The PixelBuffer of the loaded image.
65     std::string_view   url;           ///< The url address of the loaded image.
66   };
67
68 public:
69   /**
70    * @brief Constructor.
71    */
72   TextureUploadObserver();
73
74   /**
75    * @brief Virtual destructor.
76    */
77   virtual ~TextureUploadObserver();
78
79   /**
80    * The action to be taken once the async load has finished.
81    * And in case of texture loading, this method is called after uploading.
82    * This should be overridden by the deriving class.
83    *
84    * @param[in] loadSuccess True if the texture load was successful (i.e. the resource is available). If false, then the resource failed to load. In future, this will automatically upload a "broken" image.
85    * @param[in] textureInformation Structure that contains loaded texture information.
86    */
87   virtual void LoadComplete(bool loadSuccess, TextureInformation textureInformation) = 0;
88
89   /**
90    * @brief Returns the destruction signal.
91    * This is emitted when the observer is destroyed.
92    * This is used by the observer notifier to mark this observer as destroyed (IE. It no longer needs notifying).
93    */
94   DestructionSignalType& DestructionSignal();
95
96 private:
97   DestructionSignalType mDestructionSignal; ///< The destruction signal emitted when the observer is destroyed.
98 };
99
100 } // namespace Toolkit
101
102 } // namespace Dali
103
104 #endif // DALI_TOOLKIT_INTERNAL_TEXTURE_UPLOAD_OBSERVER_H