Merge "Fix shader compile crash issue" into devel/master
[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    * @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.
68    */
69   void LoadAnimatedImage(const TextureManager::TextureId&                textureId,
70                          Dali::AnimatedImageLoading                      animatedImageLoading,
71                          const std::uint32_t&                            frameIndex,
72                          const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad);
73
74   /**
75    * @brief Load a new texture.
76    * @param[in] textureId             TextureId to reference the texture that will be loaded
77    * @param[in] url                   The URL of the image to load
78    * @param[in] desiredSize           The size the image is likely to appear at.
79    *                                  This can be set to 0,0 for automatic
80    * @param[in] fittingMode           The FittingMode to use
81    * @param[in] samplingMode          The SamplingMode to use
82    * @param[in] orientationCorrection Whether to use image metadata to rotate or flip the image,
83    *                                  e.g., from portrait to landscape
84    * @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.
85    * @param[in] loadYuvPlanes         True if the image should be loaded as yuv planes
86    */
87   void Load(const TextureManager::TextureId&                textureId,
88             const VisualUrl&                                url,
89             const Dali::ImageDimensions&                    desiredSize,
90             const Dali::FittingMode::Type&                  fittingMode,
91             const Dali::SamplingMode::Type&                 samplingMode,
92             const bool&                                     orientationCorrection,
93             const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad,
94             const bool&                                     loadYuvPlanes);
95
96   /**
97    * @brief Apply mask
98    * @param [in] textureId of the texture
99    * @param [in] pixelBuffer of the to be masked image
100    * @param [in] maskPixelBuffer of the mask image
101    * @param [in] contentScale The factor to scale the content
102    * @param [in] cropToMask Whether to crop the content to the mask size
103    * @param [in] preMultiplyOnLoad if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
104    */
105   void ApplyMask(const TextureManager::TextureId&                textureId,
106                  Devel::PixelBuffer                              pixelBuffer,
107                  Devel::PixelBuffer                              maskPixelBuffer,
108                  const float&                                    contentScale,
109                  const bool&                                     cropToMask,
110                  const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad);
111
112 public:
113   TextureAsyncLoadingHelper(const TextureAsyncLoadingHelper&) = delete;
114   TextureAsyncLoadingHelper& operator=(const TextureAsyncLoadingHelper&) = delete;
115
116   TextureAsyncLoadingHelper(TextureAsyncLoadingHelper&& rhs);
117   TextureAsyncLoadingHelper& operator=(TextureAsyncLoadingHelper&& rhs) = delete;
118
119 private:                                                              // Private typedefs:
120   typedef std::deque<AsyncLoadingInfo> AsyncLoadingInfoContainerType; ///< The container type used to manage Asynchronous loads in progress
121
122 private:
123   /**
124    * @brief Main constructor that used by all other constructors
125    */
126   TextureAsyncLoadingHelper(Toolkit::AsyncImageLoader       loader,
127                             TextureManager&                 textureManager,
128                             AsyncLoadingInfoContainerType&& loadingInfoContainer);
129
130   /**
131    * @brief Callback to be called when texture loading is complete, it passes the pixel buffer list on to texture manager.
132    * @param[in] id           Loader id
133    * @param[in] pixelBuffers Image data
134    */
135   void AsyncLoadComplete(std::uint32_t id, std::vector<Devel::PixelBuffer>& pixelBuffers);
136
137 private: // Member Variables:
138   Toolkit::AsyncImageLoader     mLoader;
139   TextureManager&               mTextureManager;
140   AsyncLoadingInfoContainerType mLoadingInfoContainer;
141 };
142
143 } // namespace Internal
144
145 } // namespace Toolkit
146
147 } // namespace Dali
148
149 #endif // DALI_TOOLKIT_TEXTURE_ASYNC_LOADING_HELPER_H