Add DesiredWidth/Height and samplingMode in animated image visual
[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/loading-task.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 public:
40   /**
41    * @brief Create an TextureAsyncLoadingHelper.
42    * @param[in] textureManager Reference to the texture manager
43    */
44   TextureAsyncLoadingHelper(TextureManager& textureManager);
45
46   /**
47    * @brief Load a new frame of animated image
48    * @param[in] textureId             TextureId to reference the texture that will be loaded
49    * @param[in] animatedImageLoading  The AnimatedImageLoading to load animated image
50    * @param[in] frameIndex            The frame index of a frame to be loaded frame
51    * @param[in] desiredSize           The size the image is likely to appear at.
52    *                                  This can be set to 0,0 for automatic
53    * @param[in] fittingMode           The FittingMode to use
54    * @param[in] samplingMode          The SamplingMode to use
55    * @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.
56    */
57   void LoadAnimatedImage(const TextureManager::TextureId&                textureId,
58                          Dali::AnimatedImageLoading                      animatedImageLoading,
59                          const std::uint32_t&                            frameIndex,
60                          const Dali::ImageDimensions&                    desiredSize,
61                          const Dali::FittingMode::Type&                  fittingMode,
62                          const Dali::SamplingMode::Type&                 samplingMode,
63                          const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad);
64
65   /**
66    * @brief Load a new texture.
67    * @param[in] textureId             TextureId to reference the texture that will be loaded
68    * @param[in] url                   The URL of the image to load
69    * @param[in] desiredSize           The size the image is likely to appear at.
70    *                                  This can be set to 0,0 for automatic
71    * @param[in] fittingMode           The FittingMode to use
72    * @param[in] samplingMode          The SamplingMode to use
73    * @param[in] orientationCorrection Whether to use image metadata to rotate or flip the image,
74    *                                  e.g., from portrait to landscape
75    * @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.
76    * @param[in] loadYuvPlanes         True if the image should be loaded as yuv planes
77    */
78   void Load(const TextureManager::TextureId&                textureId,
79             const VisualUrl&                                url,
80             const Dali::ImageDimensions&                    desiredSize,
81             const Dali::FittingMode::Type&                  fittingMode,
82             const Dali::SamplingMode::Type&                 samplingMode,
83             const bool&                                     orientationCorrection,
84             const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad,
85             const bool&                                     loadYuvPlanes);
86
87   /**
88    * @brief Apply mask
89    * @param [in] textureId of the texture
90    * @param [in] pixelBuffer of the to be masked image
91    * @param [in] maskPixelBuffer of the mask image
92    * @param [in] contentScale The factor to scale the content
93    * @param [in] cropToMask Whether to crop the content to the mask size
94    * @param [in] preMultiplyOnLoad if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
95    */
96   void ApplyMask(const TextureManager::TextureId&                textureId,
97                  Devel::PixelBuffer                              pixelBuffer,
98                  Devel::PixelBuffer                              maskPixelBuffer,
99                  const float&                                    contentScale,
100                  const bool&                                     cropToMask,
101                  const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad);
102
103 public:
104   TextureAsyncLoadingHelper(const TextureAsyncLoadingHelper&) = delete;
105   TextureAsyncLoadingHelper& operator=(const TextureAsyncLoadingHelper&) = delete;
106
107 private:
108   /**
109    * @brief Callback to be called when texture loading is complete, it passes the pixel buffer list on to texture manager.
110    * @param[in] task LoadingTaskPtr
111    */
112   void AsyncLoadComplete(LoadingTaskPtr task);
113
114 private: // Member Variables:
115   TextureManager& mTextureManager;
116   uint32_t        mLoadTaskId;
117 };
118
119 } // namespace Internal
120
121 } // namespace Toolkit
122
123 } // namespace Dali
124
125 #endif // DALI_TOOLKIT_TEXTURE_ASYNC_LOADING_HELPER_H