[dali_2.2.3] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-async-loading-helper.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "texture-async-loading-helper.h"
20
21 // EXTERNAL HEADERS
22 #include <dali/integration-api/debug.h>
23
24 // INTERNAL HEADERS
25 #include <dali-toolkit/internal/image-loader/async-image-loader-impl.h>
26 #include <dali-toolkit/public-api/image-loader/sync-image-loader.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace Internal
33 {
34 #ifdef DEBUG_ENABLED
35 extern Debug::Filter* gTextureManagerLogFilter; ///< Define at texture-manager-impl.cpp
36 #endif
37
38 TextureAsyncLoadingHelper::TextureAsyncLoadingHelper(TextureManager& textureManager)
39 : mTextureManager(textureManager),
40   mLoadTaskId(0u)
41 {
42 }
43
44 void TextureAsyncLoadingHelper::LoadAnimatedImage(const TextureManager::TextureId&                textureId,
45                                                   Dali::AnimatedImageLoading                      animatedImageLoading,
46                                                   const std::uint32_t&                            frameIndex,
47                                                   const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad)
48 {
49   LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, animatedImageLoading, frameIndex, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
50   loadingTask->SetTextureId(textureId);
51   Dali::AsyncTaskManager::Get().AddTask(loadingTask);
52 }
53
54 void TextureAsyncLoadingHelper::Load(const TextureManager::TextureId&                textureId,
55                                      const VisualUrl&                                url,
56                                      const Dali::ImageDimensions&                    desiredSize,
57                                      const Dali::FittingMode::Type&                  fittingMode,
58                                      const Dali::SamplingMode::Type&                 samplingMode,
59                                      const bool&                                     orientationCorrection,
60                                      const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad,
61                                      const bool&                                     loadYuvPlanes)
62 {
63   LoadingTaskPtr loadingTask;
64   if(DALI_UNLIKELY(url.IsBufferResource()))
65   {
66     loadingTask = new LoadingTask(++mLoadTaskId, mTextureManager.GetEncodedImageBuffer(url.GetUrl()), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
67   }
68   else
69   {
70     loadingTask = new LoadingTask(++mLoadTaskId, url, desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, loadYuvPlanes, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
71   }
72
73   loadingTask->SetTextureId(textureId);
74   Dali::AsyncTaskManager::Get().AddTask(loadingTask);
75 }
76
77 void TextureAsyncLoadingHelper::ApplyMask(const TextureManager::TextureId&                textureId,
78                                           Devel::PixelBuffer                              pixelBuffer,
79                                           Devel::PixelBuffer                              maskPixelBuffer,
80                                           const float&                                    contentScale,
81                                           const bool&                                     cropToMask,
82                                           const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad)
83 {
84
85   LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
86   loadingTask->SetTextureId(textureId);
87   Dali::AsyncTaskManager::Get().AddTask(loadingTask);
88 }
89
90 void TextureAsyncLoadingHelper::AsyncLoadComplete(LoadingTaskPtr task)
91 {
92   // Call TextureManager::AsyncLoadComplete
93   if(task->textureId != TextureManager::INVALID_TEXTURE_ID)
94   {
95     mTextureManager.AsyncLoadComplete(task->textureId, task->pixelBuffers);
96   }
97 }
98
99 } // namespace Internal
100
101 } // namespace Toolkit
102
103 } // namespace Dali