2 * Copyright (c) 2022 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 "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 : TextureAsyncLoadingHelper(Toolkit::AsyncImageLoader::New(), textureManager, AsyncLoadingInfoContainerType())
43 void TextureAsyncLoadingHelper::LoadAnimatedImage(const TextureManager::TextureId& textureId,
44 Dali::AnimatedImageLoading animatedImageLoading,
45 const std::uint32_t& frameIndex)
47 mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
48 auto id = GetImplementation(mLoader).LoadAnimatedImage(animatedImageLoading, frameIndex);
49 mLoadingInfoContainer.back().loadId = id;
52 void TextureAsyncLoadingHelper::Load(const TextureManager::TextureId& textureId,
54 const Dali::ImageDimensions& desiredSize,
55 const Dali::FittingMode::Type& fittingMode,
56 const Dali::SamplingMode::Type& samplingMode,
57 const bool& orientationCorrection,
58 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad)
60 mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
61 if(DALI_UNLIKELY(url.IsBufferResource()))
63 auto id = GetImplementation(mLoader).LoadEncodedImageBuffer(mTextureManager.GetEncodedImageBuffer(url.GetUrl()), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad);
64 mLoadingInfoContainer.back().loadId = id;
68 auto id = GetImplementation(mLoader).Load(url, desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad);
69 mLoadingInfoContainer.back().loadId = id;
73 void TextureAsyncLoadingHelper::ApplyMask(const TextureManager::TextureId& textureId,
74 Devel::PixelBuffer pixelBuffer,
75 Devel::PixelBuffer maskPixelBuffer,
76 const float& contentScale,
77 const bool& cropToMask,
78 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad)
80 mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
81 auto id = GetImplementation(mLoader).ApplyMask(pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad);
82 mLoadingInfoContainer.back().loadId = id;
85 TextureAsyncLoadingHelper::TextureAsyncLoadingHelper(TextureAsyncLoadingHelper&& rhs)
86 : TextureAsyncLoadingHelper(rhs.mLoader, rhs.mTextureManager, std::move(rhs.mLoadingInfoContainer))
90 TextureAsyncLoadingHelper::TextureAsyncLoadingHelper(
91 Toolkit::AsyncImageLoader loader,
92 TextureManager& textureManager,
93 AsyncLoadingInfoContainerType&& loadingInfoContainer)
95 mTextureManager(textureManager),
96 mLoadingInfoContainer(std::move(loadingInfoContainer))
98 DevelAsyncImageLoader::PixelBufferLoadedSignal(mLoader).Connect(
99 this, &TextureAsyncLoadingHelper::AsyncLoadComplete);
102 void TextureAsyncLoadingHelper::AsyncLoadComplete(uint32_t id,
103 Devel::PixelBuffer pixelBuffer)
105 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureAsyncLoadingHelper::AsyncLoadComplete( loadId :%d )\n", id);
106 if(mLoadingInfoContainer.size() >= 1u)
108 AsyncLoadingInfo loadingInfo = mLoadingInfoContainer.front();
110 // We can assume that First Loading task comes First.
111 if(loadingInfo.loadId == id)
113 // Call TextureManager::AsyncLoadComplete
114 mTextureManager.AsyncLoadComplete(loadingInfo.textureId, pixelBuffer);
117 mLoadingInfoContainer.pop_front();
121 } // namespace Internal
123 } // namespace Toolkit