2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/texture-manager/texture-async-loading-helper.h>
22 #include <dali/integration-api/debug.h>
25 #include <dali-toolkit/internal/image-loader/async-image-loader-impl.h>
26 #include <dali-toolkit/public-api/image-loader/sync-image-loader.h>
35 extern Debug::Filter* gTextureManagerLogFilter; ///< Define at texture-manager-impl.cpp
38 TextureAsyncLoadingHelper::TextureAsyncLoadingHelper(TextureManager& textureManager)
39 : mTextureManager(textureManager),
44 void TextureAsyncLoadingHelper::LoadAnimatedImage(const TextureManager::TextureId textureId,
45 Dali::AnimatedImageLoading animatedImageLoading,
46 const uint32_t frameIndex,
47 const Dali::ImageDimensions& desiredSize,
48 const Dali::FittingMode::Type fittingMode,
49 const Dali::SamplingMode::Type samplingMode,
50 const DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
52 LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, animatedImageLoading, frameIndex, desiredSize, fittingMode, samplingMode, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
53 loadingTask->SetTextureId(textureId);
54 Dali::AsyncTaskManager::Get().AddTask(loadingTask);
57 void TextureAsyncLoadingHelper::Load(const TextureManager::TextureId textureId,
59 const Dali::ImageDimensions& desiredSize,
60 const Dali::FittingMode::Type fittingMode,
61 const Dali::SamplingMode::Type samplingMode,
62 const bool orientationCorrection,
63 const DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
64 const bool loadYuvPlanes)
66 LoadingTaskPtr loadingTask;
67 if(DALI_UNLIKELY(url.IsBufferResource()))
69 loadingTask = new LoadingTask(++mLoadTaskId, mTextureManager.GetEncodedImageBuffer(url.GetUrl()), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
73 loadingTask = new LoadingTask(++mLoadTaskId, url, desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, loadYuvPlanes, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
76 loadingTask->SetTextureId(textureId);
77 Dali::AsyncTaskManager::Get().AddTask(loadingTask);
80 void TextureAsyncLoadingHelper::ApplyMask(const TextureManager::TextureId textureId,
81 Devel::PixelBuffer pixelBuffer,
82 Devel::PixelBuffer maskPixelBuffer,
83 const float contentScale,
84 const bool cropToMask,
85 const DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
87 LoadingTaskPtr loadingTask = new LoadingTask(++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad, MakeCallback(this, &TextureAsyncLoadingHelper::AsyncLoadComplete));
88 loadingTask->SetTextureId(textureId);
89 Dali::AsyncTaskManager::Get().AddTask(loadingTask);
92 void TextureAsyncLoadingHelper::AsyncLoadComplete(LoadingTaskPtr task)
94 // Call TextureManager::AsyncLoadComplete
95 if(task->textureId != TextureManager::INVALID_TEXTURE_ID)
97 mTextureManager.AsyncLoadComplete(task->textureId, task->pixelBuffers);
101 } // namespace Internal
103 } // namespace Toolkit