[Tizen] Change PixelBufferLoadedSignalType
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-async-loading-helper.h
1 #ifndef DALI_TOOLKIT_TEXTURE_ASYNC_LOADING_HELPER_H
2 #define DALI_TOOLKIT_TEXTURE_ASYNC_LOADING_HELPER_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 // EXTERNAL INCLUDES
21 #include <dali/public-api/signals/connection-tracker.h>
22 #include <deque>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/image-loader/async-image-loader-impl.h>
26 #include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace Internal
33 {
34 /**
35  * @brief Helper class to keep the relation between AsyncImageLoader and corresponding LoadingInfo container
36  */
37 class TextureAsyncLoadingHelper : public ConnectionTracker
38 {
39   /**
40    * Struct to hold information about a requested Async load.
41    * This is used to look up a TextureManager::TextureId from the returned AsyncLoad Id.
42    */
43   struct AsyncLoadingInfo
44   {
45     AsyncLoadingInfo(TextureManager::TextureId textureId)
46     : textureId(textureId),
47       loadId(0)
48     {
49     }
50
51     TextureManager::TextureId textureId; ///< The external Texture Id assigned to this load
52     std::uint32_t             loadId;    ///< The load Id used by the async loader to reference this load
53   };
54
55 public:
56   /**
57    * @brief Create an TextureAsyncLoadingHelper.
58    * @param[in] textureManager Reference to the texture manager
59    */
60   TextureAsyncLoadingHelper(TextureManager& textureManager);
61
62   /**
63    * @brief Load a new frame of animated image
64    * @param[in] textureId             TextureId to reference the texture that will be loaded
65    * @param[in] animatedImageLoading  The AnimatedImageLoading to load animated image
66    * @param[in] frameIndex            The frame index of a frame to be loaded frame
67    */
68   void LoadAnimatedImage(const TextureManager::TextureId& textureId,
69                          Dali::AnimatedImageLoading       animatedImageLoading,
70                          const std::uint32_t&             frameIndex);
71
72   /**
73    * @brief Load a new texture.
74    * @param[in] textureId             TextureId to reference the texture that will be loaded
75    * @param[in] url                   The URL of the image to load
76    * @param[in] desiredSize           The size the image is likely to appear at.
77    *                                  This can be set to 0,0 for automatic
78    * @param[in] fittingMode           The FittingMode to use
79    * @param[in] samplingMode          The SamplingMode to use
80    * @param[in] orientationCorrection Whether to use image metadata to rotate or flip the image,
81    *                                  e.g., from portrait to landscape
82    * @param[in] preMultiplyOnLoad     if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha or if the image need to be applied alpha mask.
83    */
84   void Load(const TextureManager::TextureId&                textureId,
85             const VisualUrl&                                url,
86             const Dali::ImageDimensions&                    desiredSize,
87             const Dali::FittingMode::Type&                  fittingMode,
88             const Dali::SamplingMode::Type&                 samplingMode,
89             const bool&                                     orientationCorrection,
90             const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad);
91
92   /**
93    * @brief Apply mask
94    * @param [in] textureId of the texture
95    * @param [in] pixelBuffer of the to be masked image
96    * @param [in] maskPixelBuffer of the mask image
97    * @param [in] contentScale The factor to scale the content
98    * @param [in] cropToMask Whether to crop the content to the mask size
99    * @param [in] preMultiplyOnLoad if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
100    */
101   void ApplyMask(const TextureManager::TextureId&                textureId,
102                  Devel::PixelBuffer                              pixelBuffer,
103                  Devel::PixelBuffer                              maskPixelBuffer,
104                  const float&                                    contentScale,
105                  const bool&                                     cropToMask,
106                  const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad);
107
108 public:
109   TextureAsyncLoadingHelper(const TextureAsyncLoadingHelper&) = delete;
110   TextureAsyncLoadingHelper& operator=(const TextureAsyncLoadingHelper&) = delete;
111
112   TextureAsyncLoadingHelper(TextureAsyncLoadingHelper&& rhs);
113   TextureAsyncLoadingHelper& operator=(TextureAsyncLoadingHelper&& rhs) = delete;
114
115 private:                                                              // Private typedefs:
116   typedef std::deque<AsyncLoadingInfo> AsyncLoadingInfoContainerType; ///< The container type used to manage Asynchronous loads in progress
117
118 private:
119   /**
120    * @brief Main constructor that used by all other constructors
121    */
122   TextureAsyncLoadingHelper(Toolkit::AsyncImageLoader       loader,
123                             TextureManager&                 textureManager,
124                             AsyncLoadingInfoContainerType&& loadingInfoContainer);
125
126   /**
127    * @brief Callback to be called when texture loading is complete, it passes the pixel buffer list on to texture manager.
128    * @param[in] id           Loader id
129    * @param[in] pixelBuffers Image data
130    */
131   void AsyncLoadComplete(std::uint32_t id, std::vector<Devel::PixelBuffer>& pixelBuffers);
132
133 private: // Member Variables:
134   Toolkit::AsyncImageLoader     mLoader;
135   TextureManager&               mTextureManager;
136   AsyncLoadingInfoContainerType mLoadingInfoContainer;
137 };
138
139 } // namespace Internal
140
141 } // namespace Toolkit
142
143 } // namespace Dali
144
145 #endif // DALI_TOOLKIT_TEXTURE_ASYNC_LOADING_HELPER_H