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-manager-impl.h"
22 #include <dali/devel-api/adaptor-framework/environment-variable.h>
23 #include <dali/devel-api/adaptor-framework/image-loading.h>
24 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/rendering/geometry.h>
29 #include <dali-toolkit/internal/texture-manager/texture-async-loading-helper.h>
30 #include <dali-toolkit/internal/texture-manager/texture-cache-manager.h>
31 #include <dali-toolkit/internal/visuals/image-atlas-manager.h>
32 #include <dali-toolkit/internal/visuals/rendering-addon.h>
36 constexpr auto INITIAL_HASH_NUMBER = size_t{0u};
37 constexpr auto DEFAULT_NUMBER_OF_LOCAL_LOADER_THREADS = size_t{4u};
38 constexpr auto DEFAULT_NUMBER_OF_REMOTE_LOADER_THREADS = size_t{8u};
40 constexpr auto NUMBER_OF_LOCAL_LOADER_THREADS_ENV = "DALI_TEXTURE_LOCAL_THREADS";
41 constexpr auto NUMBER_OF_REMOTE_LOADER_THREADS_ENV = "DALI_TEXTURE_REMOTE_THREADS";
43 size_t GetNumberOfThreads(const char* environmentVariable, size_t defaultValue)
45 using Dali::EnvironmentVariable::GetEnvironmentVariable;
46 auto numberString = GetEnvironmentVariable(environmentVariable);
47 auto numberOfThreads = numberString ? std::strtoul(numberString, nullptr, 10) : 0;
48 constexpr auto MAX_NUMBER_OF_THREADS = 100u;
49 DALI_ASSERT_DEBUG(numberOfThreads < MAX_NUMBER_OF_THREADS);
50 return (numberOfThreads > 0 && numberOfThreads < MAX_NUMBER_OF_THREADS) ? numberOfThreads : defaultValue;
53 size_t GetNumberOfLocalLoaderThreads()
55 return GetNumberOfThreads(NUMBER_OF_LOCAL_LOADER_THREADS_ENV, DEFAULT_NUMBER_OF_LOCAL_LOADER_THREADS);
58 size_t GetNumberOfRemoteLoaderThreads()
60 return GetNumberOfThreads(NUMBER_OF_REMOTE_LOADER_THREADS_ENV, DEFAULT_NUMBER_OF_REMOTE_LOADER_THREADS);
72 // Define logfilter Internal namespace level so other files (e.g. texture-cache-manager.cpp) can also use this filter.
73 Debug::Filter* gTextureManagerLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_TEXTURE_MANAGER");
76 #define GET_LOAD_STATE_STRING(loadState) \
77 loadState == TextureManagerType::LoadState::NOT_STARTED ? "NOT_STARTED" : \
78 loadState == TextureManagerType::LoadState::LOADING ? "LOADING" : \
79 loadState == TextureManagerType::LoadState::LOAD_FINISHED ? "LOAD_FINISHED" : \
80 loadState == TextureManagerType::LoadState::WAITING_FOR_MASK ? "WAITING_FOR_MASK" : \
81 loadState == TextureManagerType::LoadState::MASK_APPLYING ? "MASK_APPLYING" : \
82 loadState == TextureManagerType::LoadState::MASK_APPLIED ? "MASK_APPLIED" : \
83 loadState == TextureManagerType::LoadState::UPLOADED ? "UPLOADED" : \
84 loadState == TextureManagerType::LoadState::CANCELLED ? "CANCELLED" : \
85 loadState == TextureManagerType::LoadState::LOAD_FAILED ? "LOAD_FAILED" : \
92 const uint32_t DEFAULT_ATLAS_SIZE(1024u); ///< This size can fit 8 by 8 images of average size 128 * 128
93 const Vector4 FULL_ATLAS_RECT(0.0f, 0.0f, 1.0f, 1.0f); ///< UV Rectangle that covers the full Texture
95 void PreMultiply(Devel::PixelBuffer pixelBuffer, TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
97 if(Pixel::HasAlpha(pixelBuffer.GetPixelFormat()))
99 if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
101 pixelBuffer.MultiplyColorByAlpha();
106 preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
110 } // Anonymous namespace
112 TextureManager::MaskingData::MaskingData()
114 mAlphaMaskId(INVALID_TEXTURE_ID),
115 mContentScaleFactor(1.0f),
117 mPreappliedMasking(true),
118 mMaskImageLoadingFailed(false)
122 TextureManager::TextureManager()
123 : mTextureCacheManager(),
124 mAsyncLocalLoaders(GetNumberOfLocalLoaderThreads(), [&]() { return TextureAsyncLoadingHelper(*this); }),
125 mAsyncRemoteLoaders(GetNumberOfRemoteLoaderThreads(), [&]() { return TextureAsyncLoadingHelper(*this); }),
126 mLifecycleObservers(),
129 mQueueLoadFlag(false)
131 // Initialize the AddOn
132 RenderingAddOn::Get();
135 TextureManager::~TextureManager()
137 for(auto iter = mLifecycleObservers.Begin(), endIter = mLifecycleObservers.End(); iter != endIter; ++iter)
139 (*iter)->TextureManagerDestroyed();
143 TextureSet TextureManager::LoadAnimatedImageTexture(
144 const VisualUrl& url,
145 Dali::AnimatedImageLoading animatedImageLoading,
146 const uint32_t& frameIndex,
147 TextureManager::TextureId& textureId,
148 MaskingDataPointer& maskInfo,
149 const Dali::SamplingMode::Type& samplingMode,
150 const Dali::WrapMode::Type& wrapModeU,
151 const Dali::WrapMode::Type& wrapModeV,
152 const bool& synchronousLoading,
153 TextureUploadObserver* textureObserver,
154 TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
156 TextureSet textureSet;
158 if(synchronousLoading)
160 Devel::PixelBuffer pixelBuffer;
161 if(animatedImageLoading)
163 pixelBuffer = animatedImageLoading.LoadFrame(frameIndex);
167 DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous loading is failed\n");
172 if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
174 Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile(maskInfo->mAlphaMaskUrl.GetUrl(), ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true);
177 if(!maskInfo->mPreappliedMasking)
179 PixelData maskPixelData = Devel::PixelBuffer::Convert(maskPixelBuffer); // takes ownership of buffer
180 maskTexture = Texture::New(Dali::TextureType::TEXTURE_2D, maskPixelData.GetPixelFormat(), maskPixelData.GetWidth(), maskPixelData.GetHeight());
181 maskTexture.Upload(maskPixelData);
185 pixelBuffer.ApplyMask(maskPixelBuffer, maskInfo->mContentScaleFactor, maskInfo->mCropToMask);
190 DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous mask image loading is failed\n");
194 if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
196 PreMultiply(pixelBuffer, preMultiplyOnLoad);
199 PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
202 Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight());
203 texture.Upload(pixelData);
204 textureSet = TextureSet::New();
205 textureSet.SetTexture(0u, texture);
208 textureSet.SetTexture(1u, maskTexture);
215 TextureId alphaMaskId = INVALID_TEXTURE_ID;
216 float contentScaleFactor = 1.0f;
217 bool cropToMask = false;
218 if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
220 maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, maskInfo->mPreappliedMasking ? StorageType::KEEP_PIXEL_BUFFER : StorageType::KEEP_TEXTURE);
221 alphaMaskId = maskInfo->mAlphaMaskId;
222 if(maskInfo->mPreappliedMasking)
224 contentScaleFactor = maskInfo->mContentScaleFactor;
225 cropToMask = maskInfo->mCropToMask;
229 textureId = RequestLoadInternal(url, alphaMaskId, contentScaleFactor, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, UseAtlas::NO_ATLAS, cropToMask, StorageType::UPLOAD_TO_TEXTURE, textureObserver, true, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoad, animatedImageLoading, frameIndex, false);
231 TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
232 if(loadState == TextureManager::LoadState::UPLOADED)
234 // LoadComplete has already been called - keep the same texture set
235 textureSet = GetTextureSet(textureId);
241 Sampler sampler = Sampler::New();
242 sampler.SetWrapMode(wrapModeU, wrapModeV);
243 textureSet.SetSampler(0u, sampler);
249 Devel::PixelBuffer TextureManager::LoadPixelBuffer(
250 const VisualUrl& url,
251 const Dali::ImageDimensions& desiredSize,
252 const Dali::FittingMode::Type& fittingMode,
253 const Dali::SamplingMode::Type& samplingMode,
254 const bool& synchronousLoading,
255 TextureUploadObserver* textureObserver,
256 const bool& orientationCorrection,
257 TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
259 Devel::PixelBuffer pixelBuffer;
260 if(synchronousLoading)
264 if(url.IsBufferResource())
266 const EncodedImageBuffer& encodedImageBuffer = mTextureCacheManager.GetEncodedImageBuffer(url);
267 if(encodedImageBuffer)
269 pixelBuffer = LoadImageFromBuffer(encodedImageBuffer.GetRawBuffer(), desiredSize, fittingMode, samplingMode, orientationCorrection);
274 pixelBuffer = LoadImageFromFile(url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection);
276 if(pixelBuffer && preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
278 PreMultiply(pixelBuffer, preMultiplyOnLoad);
284 RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, UseAtlas::NO_ATLAS, false, StorageType::RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, false);
290 TextureSet TextureManager::LoadTexture(
291 const VisualUrl& url,
292 const Dali::ImageDimensions& desiredSize,
293 const Dali::FittingMode::Type& fittingMode,
294 const Dali::SamplingMode::Type& samplingMode,
295 MaskingDataPointer& maskInfo,
296 const bool& synchronousLoading,
297 TextureManager::TextureId& textureId,
298 Vector4& textureRect,
299 Dali::ImageDimensions& textureRectSize,
300 bool& atlasingStatus,
302 const Dali::WrapMode::Type& wrapModeU,
303 const Dali::WrapMode::Type& wrapModeV,
304 TextureUploadObserver* textureObserver,
305 AtlasUploadObserver* atlasObserver,
306 ImageAtlasManagerPtr imageAtlasManager,
307 const bool& orientationCorrection,
308 const TextureManager::ReloadPolicy& reloadPolicy,
309 TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
311 TextureSet textureSet;
313 loadingStatus = false;
314 textureRect = FULL_ATLAS_RECT;
316 if(VisualUrl::TEXTURE == url.GetProtocolType())
318 std::string location = url.GetLocation();
319 if(location.size() > 0u)
321 TextureId id = std::stoi(location);
322 textureSet = mTextureCacheManager.GetExternalTextureSet(id);
325 preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
334 if(synchronousLoading && atlasingStatus)
336 const bool synchronousAtlasAvaliable = (desiredSize != ImageDimensions() || url.IsLocalResource()) ? imageAtlasManager->CheckAtlasAvailable(url, desiredSize)
338 if(synchronousAtlasAvaliable)
340 Devel::PixelBuffer pixelBuffer = LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection);
342 if(pixelBuffer && maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
344 Devel::PixelBuffer maskPixelBuffer = LoadImageSynchronously(maskInfo->mAlphaMaskUrl, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true);
347 pixelBuffer.ApplyMask(maskPixelBuffer, maskInfo->mContentScaleFactor, maskInfo->mCropToMask);
354 PreMultiply(pixelBuffer, preMultiplyOnLoad);
355 data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
359 textureSet = imageAtlasManager->Add(textureRect, data);
362 textureRectSize.SetWidth(data.GetWidth());
363 textureRectSize.SetHeight(data.GetHeight());
368 DALI_LOG_ERROR("TextureManager::LoadTexture: Synchronous Texture loading with atlasing is failed.\n");
373 atlasingStatus = false;
380 loadingStatus = true;
381 // Atlas manager can chage desired size when it is set by 0,0.
382 // We should store into textureRectSize only if atlasing successed.
383 // So copy inputed desiredSize, and replace value into textureRectSize only if atlasing success.
384 Dali::ImageDimensions atlasDesiredSize = desiredSize;
387 if(url.IsBufferResource())
389 const EncodedImageBuffer& encodedImageBuffer = GetEncodedImageBuffer(url.GetUrl());
390 if(encodedImageBuffer)
392 textureSet = imageAtlasManager->Add(textureRect, encodedImageBuffer, desiredSize, fittingMode, true, atlasObserver);
397 textureSet = imageAtlasManager->Add(textureRect, url, atlasDesiredSize, fittingMode, true, atlasObserver);
400 if(!textureSet) // big image, no atlasing or atlasing failed
402 atlasingStatus = false;
404 TextureId alphaMaskId = INVALID_TEXTURE_ID;
405 float contentScaleFactor = 1.0f;
406 bool cropToMask = false;
407 if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
409 maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, maskInfo->mPreappliedMasking ? StorageType::KEEP_PIXEL_BUFFER : StorageType::KEEP_TEXTURE, synchronousLoading);
410 alphaMaskId = maskInfo->mAlphaMaskId;
411 if(maskInfo && maskInfo->mPreappliedMasking)
413 contentScaleFactor = maskInfo->mContentScaleFactor;
414 cropToMask = maskInfo->mCropToMask;
418 textureId = RequestLoad(
428 orientationCorrection,
433 TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
434 if(loadState == TextureManager::LoadState::UPLOADED)
436 // LoadComplete has already been called - keep the same texture set
437 textureSet = mTextureCacheManager.GetTextureSet(textureId);
440 // If we are loading the texture, or waiting for the ready signal handler to complete, inform
441 // caller that they need to wait.
442 loadingStatus = (loadState == TextureManager::LoadState::LOADING ||
443 loadState == TextureManager::LoadState::WAITING_FOR_MASK ||
444 loadState == TextureManager::LoadState::MASK_APPLYING ||
445 loadState == TextureManager::LoadState::MASK_APPLIED ||
446 loadState == TextureManager::LoadState::NOT_STARTED ||
451 textureRectSize = atlasDesiredSize;
456 if(!atlasingStatus && textureSet)
458 Sampler sampler = Sampler::New();
459 sampler.SetWrapMode(wrapModeU, wrapModeV);
460 textureSet.SetSampler(0u, sampler);
463 if(synchronousLoading)
465 loadingStatus = false;
471 TextureManager::TextureId TextureManager::RequestLoad(
472 const VisualUrl& url,
473 const ImageDimensions& desiredSize,
474 const Dali::FittingMode::Type& fittingMode,
475 const Dali::SamplingMode::Type& samplingMode,
476 const UseAtlas& useAtlas,
477 TextureUploadObserver* observer,
478 const bool& orientationCorrection,
479 const TextureManager::ReloadPolicy& reloadPolicy,
480 TextureManager::MultiplyOnLoad& preMultiplyOnLoad,
481 const bool& synchronousLoading)
483 return RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, useAtlas, false, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
486 TextureManager::TextureId TextureManager::RequestLoad(
487 const VisualUrl& url,
488 const TextureManager::TextureId& maskTextureId,
489 const float& contentScale,
490 const Dali::ImageDimensions& desiredSize,
491 const Dali::FittingMode::Type& fittingMode,
492 const Dali::SamplingMode::Type& samplingMode,
493 const TextureManager::UseAtlas& useAtlas,
494 const bool& cropToMask,
495 TextureUploadObserver* observer,
496 const bool& orientationCorrection,
497 const TextureManager::ReloadPolicy& reloadPolicy,
498 TextureManager::MultiplyOnLoad& preMultiplyOnLoad,
499 const bool& synchronousLoading)
501 return RequestLoadInternal(url, maskTextureId, contentScale, desiredSize, fittingMode, samplingMode, useAtlas, cropToMask, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
504 TextureManager::TextureId TextureManager::RequestMaskLoad(
505 const VisualUrl& maskUrl,
506 StorageType storageType,
507 const bool& synchronousLoading)
509 // Use the normal load procedure to get the alpha mask.
510 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
511 return RequestLoadInternal(maskUrl, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, UseAtlas::NO_ATLAS, false, storageType, NULL, true, TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
514 TextureManager::TextureId TextureManager::RequestLoadInternal(
515 const VisualUrl& url,
516 const TextureManager::TextureId& maskTextureId,
517 const float& contentScale,
518 const Dali::ImageDimensions& desiredSize,
519 const Dali::FittingMode::Type& fittingMode,
520 const Dali::SamplingMode::Type& samplingMode,
521 const TextureManager::UseAtlas& useAtlas,
522 const bool& cropToMask,
523 const TextureManager::StorageType& storageType,
524 TextureUploadObserver* observer,
525 const bool& orientationCorrection,
526 const TextureManager::ReloadPolicy& reloadPolicy,
527 TextureManager::MultiplyOnLoad& preMultiplyOnLoad,
528 Dali::AnimatedImageLoading animatedImageLoading,
529 const std::uint32_t& frameIndex,
530 const bool& synchronousLoading)
532 TextureHash textureHash = INITIAL_HASH_NUMBER;
533 TextureCacheIndex cacheIndex = INVALID_CACHE_INDEX;
534 if(storageType != StorageType::RETURN_PIXEL_BUFFER)
536 textureHash = mTextureCacheManager.GenerateHash(url, desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, cropToMask, frameIndex);
538 // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
539 cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url, desiredSize, fittingMode, samplingMode, useAtlas, storageType, maskTextureId, cropToMask, preMultiplyOnLoad, (animatedImageLoading) ? true : false, frameIndex);
542 TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
543 // Check if the requested Texture exists in the cache.
544 if(cacheIndex != INVALID_CACHE_INDEX)
546 if(TextureManager::ReloadPolicy::CACHED == reloadPolicy)
548 // Mark this texture being used by another client resource. Forced reload would replace the current texture
549 // without the need for incrementing the reference count.
550 ++(mTextureCacheManager[cacheIndex].referenceCount);
552 textureId = mTextureCacheManager[cacheIndex].textureId;
554 // Update preMultiplyOnLoad value. It should be changed according to preMultiplied value of the cached info.
555 preMultiplyOnLoad = mTextureCacheManager[cacheIndex].preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
557 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) Using cached texture id@%d, textureId=%d, frameindex=%d, premultiplied=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, frameIndex, mTextureCacheManager[cacheIndex].preMultiplied ? 1 : 0);
560 if(textureId == INVALID_TEXTURE_ID) // There was no caching, or caching not required
562 textureId = mTextureCacheManager.GenerateTextureId();
564 bool preMultiply = (preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
566 // Cache new texutre, and get cacheIndex.
567 cacheIndex = mTextureCacheManager.AppendCache(TextureInfo(textureId, maskTextureId, url, desiredSize, contentScale, fittingMode, samplingMode, false, cropToMask, useAtlas, textureHash, orientationCorrection, preMultiply, animatedImageLoading, frameIndex));
569 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) New texture, cacheIndex:%d, textureId=%d, frameindex=%d premultiply=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, frameIndex, preMultiply);
572 // The below code path is common whether we are using the cache or not.
573 // The textureInfoIndex now refers to either a pre-existing cached TextureInfo,
574 // or a new TextureInfo just created.
575 TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
576 textureInfo.maskTextureId = maskTextureId;
577 textureInfo.storageType = storageType;
578 textureInfo.orientationCorrection = orientationCorrection;
580 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureInfo loadState:%s\n", GET_LOAD_STATE_STRING(textureInfo.loadState));
582 // Force reloading of texture by setting loadState unless already loading or cancelled.
583 if(TextureManager::ReloadPolicy::FORCED == reloadPolicy &&
584 TextureManager::LoadState::LOADING != textureInfo.loadState &&
585 TextureManager::LoadState::WAITING_FOR_MASK != textureInfo.loadState &&
586 TextureManager::LoadState::MASK_APPLYING != textureInfo.loadState &&
587 TextureManager::LoadState::MASK_APPLIED != textureInfo.loadState &&
588 TextureManager::LoadState::CANCELLED != textureInfo.loadState)
590 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "TextureManager::RequestLoad( url=%s observer=%p ) ForcedReload cacheIndex:%d, textureId=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId);
592 textureInfo.loadState = TextureManager::LoadState::NOT_STARTED;
595 if(!synchronousLoading)
597 // Check if we should add the observer.
598 // Only do this if we have not loaded yet and it will not have loaded by the end of this method.
599 switch(textureInfo.loadState)
601 case TextureManager::LoadState::LOAD_FAILED: // Failed notifies observer which then stops observing.
602 case TextureManager::LoadState::NOT_STARTED:
604 LoadOrQueueTexture(textureInfo, observer); // If called inside NotifyObservers, queues until afterwards
607 case TextureManager::LoadState::LOADING:
608 case TextureManager::LoadState::WAITING_FOR_MASK:
609 case TextureManager::LoadState::MASK_APPLYING:
610 case TextureManager::LoadState::MASK_APPLIED:
612 ObserveTexture(textureInfo, observer);
615 case TextureManager::LoadState::UPLOADED:
619 LoadOrQueueTexture(textureInfo, observer);
623 case TextureManager::LoadState::CANCELLED:
625 // A cancelled texture hasn't finished loading yet. Treat as a loading texture
626 // (it's ref count has already been incremented, above)
627 textureInfo.loadState = TextureManager::LoadState::LOADING;
628 ObserveTexture(textureInfo, observer);
631 case TextureManager::LoadState::LOAD_FINISHED:
633 // Loading has already completed.
634 if(observer && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
636 LoadOrQueueTexture(textureInfo, observer);
644 // If the image is already finished to load, use cached texture.
645 // We don't need to consider Observer because this is synchronous loading.
646 if(!(textureInfo.loadState == TextureManager::LoadState::UPLOADED ||
647 textureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED))
649 Devel::PixelBuffer pixelBuffer = LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection);
653 // If pixelBuffer loading is failed in synchronously, call Remove() method.
654 Remove(textureId, nullptr);
655 return INVALID_TEXTURE_ID;
658 if(storageType == StorageType::KEEP_PIXEL_BUFFER) // For the mask image loading.
660 textureInfo.pixelBuffer = pixelBuffer; // Store the pixel data
661 textureInfo.loadState = LoadState::LOAD_FINISHED;
663 else // For the image loading.
666 if(maskTextureId != INVALID_TEXTURE_ID)
668 TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
669 if(maskCacheIndex != INVALID_CACHE_INDEX)
671 if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_TEXTURE)
673 TextureSet maskTextures = mTextureCacheManager[maskCacheIndex].textureSet;
674 if(maskTextures && maskTextures.GetTextureCount())
676 maskTexture = maskTextures.GetTexture(0u);
679 else if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_PIXEL_BUFFER)
681 Devel::PixelBuffer maskPixelBuffer = mTextureCacheManager[maskCacheIndex].pixelBuffer;
684 pixelBuffer.ApplyMask(maskPixelBuffer, contentScale, cropToMask);
688 DALI_LOG_ERROR("Mask image cached invalid pixel buffer!\n");
694 DALI_LOG_ERROR("Mask image is not stored in cache.\n");
697 PreMultiply(pixelBuffer, preMultiplyOnLoad);
700 UploadTexture(pixelBuffer, textureInfo);
701 if(maskTexture && textureInfo.textureSet)
703 textureInfo.textureSet.SetTexture(1u, maskTexture);
711 void TextureManager::Remove(const TextureManager::TextureId& textureId, TextureUploadObserver* observer)
713 if(textureId != INVALID_TEXTURE_ID)
717 // Remove textureId after NotifyObserver finished
718 mRemoveQueue.PushBack(textureId);
722 // Remove textureId in CacheManager.
723 mTextureCacheManager.RemoveCache(textureId);
728 // Remove element from the LoadQueue
729 for(auto&& element : mLoadQueue)
731 if(element.mObserver == observer)
733 // Do not erase the item. We will clear it later in ProcessLoadQueue().
734 element.mObserver = nullptr;
742 Devel::PixelBuffer TextureManager::LoadImageSynchronously(
743 const VisualUrl& url,
744 const Dali::ImageDimensions& desiredSize,
745 const Dali::FittingMode::Type& fittingMode,
746 const Dali::SamplingMode::Type& samplingMode,
747 const bool& orientationCorrection)
749 Devel::PixelBuffer pixelBuffer;
750 if(url.IsBufferResource())
752 const EncodedImageBuffer& encodedImageBuffer = mTextureCacheManager.GetEncodedImageBuffer(url);
753 if(encodedImageBuffer)
755 pixelBuffer = LoadImageFromBuffer(encodedImageBuffer.GetRawBuffer(), desiredSize, fittingMode, samplingMode, orientationCorrection);
760 pixelBuffer = LoadImageFromFile(url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection);
765 void TextureManager::AddObserver(TextureManager::LifecycleObserver& observer)
767 // make sure an observer doesn't observe the same object twice
768 // otherwise it will get multiple calls to ObjectDestroyed()
769 DALI_ASSERT_DEBUG(mLifecycleObservers.End() == std::find(mLifecycleObservers.Begin(), mLifecycleObservers.End(), &observer));
770 mLifecycleObservers.PushBack(&observer);
773 void TextureManager::RemoveObserver(TextureManager::LifecycleObserver& observer)
775 // Find the observer...
776 auto endIter = mLifecycleObservers.End();
777 for(auto iter = mLifecycleObservers.Begin(); iter != endIter; ++iter)
779 if((*iter) == &observer)
781 mLifecycleObservers.Erase(iter);
785 DALI_ASSERT_DEBUG(endIter != mLifecycleObservers.End());
788 void TextureManager::LoadOrQueueTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
790 switch(textureInfo.loadState)
792 case LoadState::NOT_STARTED:
793 case LoadState::LOAD_FAILED:
797 QueueLoadTexture(textureInfo, observer);
801 LoadTexture(textureInfo, observer);
805 case LoadState::UPLOADED:
809 QueueLoadTexture(textureInfo, observer);
813 // The Texture has already loaded. The other observers have already been notified.
814 // We need to send a "late" loaded notification for this observer.
815 EmitLoadComplete(observer, textureInfo, true);
819 case LoadState::LOADING:
820 case LoadState::CANCELLED:
821 case LoadState::LOAD_FINISHED:
822 case LoadState::WAITING_FOR_MASK:
823 case LoadState::MASK_APPLYING:
824 case LoadState::MASK_APPLIED:
831 void TextureManager::QueueLoadTexture(const TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
833 const auto& textureId = textureInfo.textureId;
834 mLoadQueue.PushBack(LoadQueueElement(textureId, observer));
836 observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
839 void TextureManager::LoadTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
841 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::LoadTexture(): url:%s sync:%s\n", textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously ? "T" : "F");
843 textureInfo.loadState = LoadState::LOADING;
844 if(!textureInfo.loadSynchronously)
846 auto& loadersContainer = (textureInfo.url.IsLocalResource() || textureInfo.url.IsBufferResource()) ? mAsyncLocalLoaders : mAsyncRemoteLoaders;
847 auto loadingHelperIt = loadersContainer.GetNext();
848 auto premultiplyOnLoad = (textureInfo.preMultiplyOnLoad && textureInfo.maskTextureId == INVALID_TEXTURE_ID) ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
849 DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
850 if(textureInfo.animatedImageLoading)
852 loadingHelperIt->LoadAnimatedImage(textureInfo.textureId, textureInfo.animatedImageLoading, textureInfo.frameIndex, premultiplyOnLoad);
856 loadingHelperIt->Load(textureInfo.textureId, textureInfo.url, textureInfo.desiredSize, textureInfo.fittingMode, textureInfo.samplingMode, textureInfo.orientationCorrection, premultiplyOnLoad);
859 ObserveTexture(textureInfo, observer);
862 void TextureManager::ProcessLoadQueue()
864 for(auto&& element : mLoadQueue)
866 if(!element.mObserver)
871 TextureCacheIndex cacheIndex = mTextureCacheManager.GetCacheIndexFromId(element.mTextureId);
872 if(cacheIndex != INVALID_CACHE_INDEX)
874 TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
875 if((textureInfo.loadState == LoadState::UPLOADED) || (textureInfo.loadState == LoadState::LOAD_FINISHED && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER))
877 EmitLoadComplete(element.mObserver, textureInfo, true);
879 else if(textureInfo.loadState == LoadState::LOADING)
881 // Note : LOADING state texture cannot be queue.
882 // This case be occured when same texture id are queue in mLoadQueue.
883 ObserveTexture(textureInfo, element.mObserver);
887 LoadTexture(textureInfo, element.mObserver);
894 void TextureManager::ProcessRemoveQueue()
896 for(const auto& textureId : mRemoveQueue)
898 mTextureCacheManager.RemoveCache(textureId);
900 mRemoveQueue.Clear();
903 void TextureManager::ObserveTexture(TextureManager::TextureInfo& textureInfo,
904 TextureUploadObserver* observer)
906 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::ObserveTexture(): url:%s observer:%p\n", textureInfo.url.GetUrl().c_str(), observer);
910 textureInfo.observerList.PushBack(observer);
911 observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
915 void TextureManager::AsyncLoadComplete(const TextureManager::TextureId& textureId, Devel::PixelBuffer pixelBuffer)
917 TextureCacheIndex cacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
918 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::AsyncLoadComplete( textureId:%d CacheIndex:%d )\n", textureId, cacheIndex.GetIndex());
919 if(cacheIndex != INVALID_CACHE_INDEX)
921 TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
923 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, " textureId:%d Url:%s CacheIndex:%d LoadState: %s\n", textureInfo.textureId, textureInfo.url.GetUrl().c_str(), cacheIndex.GetIndex(), GET_LOAD_STATE_STRING(textureInfo.loadState));
925 if(textureInfo.loadState != LoadState::CANCELLED)
927 // textureInfo can be invalidated after this call (as the mTextureInfoContainer may be modified)
928 PostLoad(textureInfo, pixelBuffer);
932 Remove(textureInfo.textureId, nullptr);
937 void TextureManager::PostLoad(TextureManager::TextureInfo& textureInfo, Devel::PixelBuffer& pixelBuffer)
939 // Was the load successful?
940 if(pixelBuffer && (pixelBuffer.GetWidth() != 0) && (pixelBuffer.GetHeight() != 0))
942 // No atlas support for now
943 textureInfo.useAtlas = UseAtlas::NO_ATLAS;
944 textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
946 if(textureInfo.storageType == StorageType::UPLOAD_TO_TEXTURE)
948 // If there is a mask texture ID associated with this texture, then apply the mask
949 // if it's already loaded. If it hasn't, and the mask is still loading,
950 // wait for the mask to finish loading.
951 // note, If the texture is already uploaded synchronously during loading,
952 // we don't need to apply mask.
953 if(textureInfo.loadState != LoadState::UPLOADED &&
954 textureInfo.maskTextureId != INVALID_TEXTURE_ID)
956 if(textureInfo.loadState == LoadState::MASK_APPLYING)
958 textureInfo.loadState = LoadState::MASK_APPLIED;
959 UploadTexture(pixelBuffer, textureInfo);
960 NotifyObservers(textureInfo, true);
964 LoadState maskLoadState = mTextureCacheManager.GetTextureStateInternal(textureInfo.maskTextureId);
965 textureInfo.pixelBuffer = pixelBuffer; // Store the pixel buffer temporarily
966 if(maskLoadState == LoadState::LOADING)
968 textureInfo.loadState = LoadState::WAITING_FOR_MASK;
970 else if(maskLoadState == LoadState::LOAD_FINISHED || maskLoadState == LoadState::UPLOADED)
972 // Send New Task to Thread
973 TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureInfo.maskTextureId);
974 if(maskCacheIndex != INVALID_CACHE_INDEX)
976 TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
977 if(maskTextureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER)
979 // Send New Task to Thread
980 ApplyMask(textureInfo, textureInfo.maskTextureId);
982 else if(maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
984 // Upload image texture. textureInfo.loadState will be UPLOADED.
985 UploadTexture(textureInfo.pixelBuffer, textureInfo);
986 if(maskTextureInfo.textureSet.GetTextureCount() > 0u)
988 Texture maskTexture = maskTextureInfo.textureSet.GetTexture(0u);
989 textureInfo.textureSet.SetTexture(1u, maskTexture);
991 // notify mask texture set.
992 NotifyObservers(textureInfo, true);
996 else // maskLoadState == LoadState::LOAD_FAILED
998 // Url texture load success, But alpha mask texture load failed. Run as normal image upload.
999 DALI_LOG_ERROR("Alpha mask image loading failed! Image will not be masked\n");
1000 UploadTexture(pixelBuffer, textureInfo);
1001 NotifyObservers(textureInfo, true);
1007 UploadTexture(pixelBuffer, textureInfo);
1008 NotifyObservers(textureInfo, true);
1013 textureInfo.pixelBuffer = pixelBuffer; // Store the pixel data
1014 textureInfo.loadState = LoadState::LOAD_FINISHED;
1016 if(textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
1018 NotifyObservers(textureInfo, true);
1020 else // for the StorageType::KEEP_PIXEL_BUFFER and StorageType::KEEP_TEXTURE
1022 // Check if there was another texture waiting for this load to complete
1023 // (e.g. if this was an image mask, and its load is on a different thread)
1024 CheckForWaitingTexture(textureInfo);
1030 textureInfo.loadState = LoadState::LOAD_FAILED;
1031 if(textureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER || textureInfo.storageType == StorageType::KEEP_TEXTURE)
1033 // Check if there was another texture waiting for this load to complete
1034 // (e.g. if this was an image mask, and its load is on a different thread)
1035 CheckForWaitingTexture(textureInfo);
1039 NotifyObservers(textureInfo, false);
1044 void TextureManager::CheckForWaitingTexture(TextureManager::TextureInfo& maskTextureInfo)
1046 if(maskTextureInfo.loadState == LoadState::LOAD_FINISHED &&
1047 maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
1049 // Upload mask texture. textureInfo.loadState will be UPLOADED.
1050 UploadTexture(maskTextureInfo.pixelBuffer, maskTextureInfo);
1053 // Search the cache, checking if any texture has this texture id as a
1055 const std::size_t size = mTextureCacheManager.size();
1057 // TODO : Refactorize here to not iterate whole cached image.
1058 for(TextureCacheIndex cacheIndex = TextureCacheIndex(TextureManagerType::TEXTURE_CACHE_INDEX_TYPE_LOCAL, 0u); cacheIndex.GetIndex() < size; ++cacheIndex.detailValue.index)
1060 if(mTextureCacheManager[cacheIndex].maskTextureId == maskTextureInfo.textureId &&
1061 mTextureCacheManager[cacheIndex].loadState == LoadState::WAITING_FOR_MASK)
1063 TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
1065 if(maskTextureInfo.loadState == LoadState::LOAD_FINISHED)
1067 if(maskTextureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER)
1069 // Send New Task to Thread
1070 ApplyMask(textureInfo, maskTextureInfo.textureId);
1073 else if(maskTextureInfo.loadState == LoadState::UPLOADED)
1075 if(maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
1077 // Upload image texture. textureInfo.loadState will be UPLOADED.
1078 UploadTexture(textureInfo.pixelBuffer, textureInfo);
1079 if(maskTextureInfo.textureSet.GetTextureCount() > 0u)
1081 Texture maskTexture = maskTextureInfo.textureSet.GetTexture(0u);
1082 textureInfo.textureSet.SetTexture(1u, maskTexture);
1084 // notify mask texture set.
1085 NotifyObservers(textureInfo, true);
1090 // Url texture load success, But alpha mask texture load failed. Run as normal image upload.
1091 DALI_LOG_ERROR("Alpha mask image loading failed! Image will not be masked\n");
1092 UploadTexture(textureInfo.pixelBuffer, textureInfo);
1093 NotifyObservers(textureInfo, true);
1099 void TextureManager::ApplyMask(TextureManager::TextureInfo& textureInfo, const TextureManager::TextureId& maskTextureId)
1101 TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
1102 if(maskCacheIndex != INVALID_CACHE_INDEX)
1104 Devel::PixelBuffer maskPixelBuffer = mTextureCacheManager[maskCacheIndex].pixelBuffer;
1105 Devel::PixelBuffer pixelBuffer = textureInfo.pixelBuffer;
1106 textureInfo.pixelBuffer.Reset();
1108 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::ApplyMask(): url:%s sync:%s\n", textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously ? "T" : "F");
1110 textureInfo.loadState = LoadState::MASK_APPLYING;
1111 auto& loadersContainer = (textureInfo.url.IsLocalResource() || textureInfo.url.IsBufferResource()) ? mAsyncLocalLoaders : mAsyncRemoteLoaders;
1112 auto loadingHelperIt = loadersContainer.GetNext();
1113 auto premultiplyOnLoad = textureInfo.preMultiplyOnLoad ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
1114 DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
1115 loadingHelperIt->ApplyMask(textureInfo.textureId, pixelBuffer, maskPixelBuffer, textureInfo.scaleFactor, textureInfo.cropToMask, premultiplyOnLoad);
1119 void TextureManager::UploadTexture(Devel::PixelBuffer& pixelBuffer, TextureManager::TextureInfo& textureInfo)
1121 if(textureInfo.loadState != LoadState::UPLOADED && textureInfo.useAtlas != UseAtlas::USE_ATLAS)
1123 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, " TextureManager::UploadTexture() New Texture for textureId:%d\n", textureInfo.textureId);
1125 // Check if this pixelBuffer is premultiplied
1126 textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
1128 auto& renderingAddOn = RenderingAddOn::Get();
1129 if(renderingAddOn.IsValid())
1131 renderingAddOn.CreateGeometry(textureInfo.textureId, pixelBuffer);
1134 Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelBuffer.GetPixelFormat(), pixelBuffer.GetWidth(), pixelBuffer.GetHeight());
1136 PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer);
1137 texture.Upload(pixelData);
1138 if(!textureInfo.textureSet)
1140 textureInfo.textureSet = TextureSet::New();
1142 textureInfo.textureSet.SetTexture(0u, texture);
1145 // Update the load state.
1146 // Note: This is regardless of success as we care about whether a
1147 // load attempt is in progress or not. If unsuccessful, a broken
1148 // image is still loaded.
1149 textureInfo.loadState = LoadState::UPLOADED;
1152 void TextureManager::NotifyObservers(TextureManager::TextureInfo& textureInfo, const bool& success)
1154 TextureId textureId = textureInfo.textureId;
1156 // If there is an observer: Notify the load is complete, whether successful or not,
1157 // and erase it from the list
1158 TextureInfo* info = &textureInfo;
1160 if(info->animatedImageLoading)
1162 // If loading failed, we don't need to get frameCount and frameInterval.
1165 info->frameCount = info->animatedImageLoading.GetImageCount();
1166 info->frameInterval = info->animatedImageLoading.GetFrameInterval(info->frameIndex);
1168 info->animatedImageLoading.Reset();
1171 mQueueLoadFlag = true;
1173 // Reverse observer list that we can pop_back the observer.
1174 std::reverse(info->observerList.Begin(), info->observerList.End());
1176 while(info->observerList.Count())
1178 TextureUploadObserver* observer = *(info->observerList.End() - 1u);
1180 // During LoadComplete() a Control ResourceReady() signal is emitted.
1181 // During that signal the app may add remove /add Textures (e.g. via
1183 // It is possible for observers to be removed from the observer list,
1184 // and it is also possible for the mTextureInfoContainer to be modified,
1185 // invalidating the reference to the textureInfo struct.
1186 // Texture load requests for the same URL are deferred until the end of this
1188 DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::NotifyObservers() textureId:%d url:%s loadState:%s\n", textureId, info->url.GetUrl().c_str(), GET_LOAD_STATE_STRING(info->loadState));
1190 // It is possible for the observer to be deleted.
1191 // Disconnect and remove the observer first.
1192 observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
1194 info->observerList.Erase(info->observerList.End() - 1u);
1196 EmitLoadComplete(observer, *info, success);
1198 // Get the textureInfo from the container again as it may have been invalidated.
1199 TextureCacheIndex textureInfoIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
1200 if(textureInfoIndex == INVALID_CACHE_INDEX)
1202 break; // texture has been removed - can stop.
1204 info = &mTextureCacheManager[textureInfoIndex];
1207 mQueueLoadFlag = false;
1209 ProcessRemoveQueue();
1211 if(info->storageType == StorageType::RETURN_PIXEL_BUFFER && info->observerList.Count() == 0)
1213 Remove(info->textureId, nullptr);
1217 void TextureManager::ObserverDestroyed(TextureUploadObserver* observer)
1219 const std::size_t size = mTextureCacheManager.size();
1220 for(TextureCacheIndex cacheIndex = TextureCacheIndex(TextureManagerType::TEXTURE_CACHE_INDEX_TYPE_LOCAL, 0u); cacheIndex.GetIndex() < size; ++cacheIndex.detailValue.index)
1222 TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
1223 for(TextureInfo::ObserverListType::Iterator j = textureInfo.observerList.Begin();
1224 j != textureInfo.observerList.End();)
1228 j = textureInfo.observerList.Erase(j);
1237 // Remove element from the LoadQueue
1238 for(auto&& element : mLoadQueue)
1240 if(element.mObserver == observer)
1242 element.mObserver = nullptr;
1247 Dali::Geometry TextureManager::GetRenderGeometry(const TextureManager::TextureId& textureId, std::uint32_t& frontElements, std::uint32_t& backElements)
1249 return RenderingAddOn::Get().IsValid() ? RenderingAddOn::Get().GetGeometry(textureId, frontElements, backElements) : Geometry();
1252 void TextureManager::EmitLoadComplete(TextureUploadObserver* observer, TextureManager::TextureInfo& textureInfo, const bool& success)
1254 if(textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
1256 observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::PIXEL_BUFFER, textureInfo.pixelBuffer, textureInfo.url.GetUrl(), textureInfo.preMultiplied));
1258 else if(textureInfo.isAnimatedImageFormat)
1260 observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::ANIMATED_IMAGE_TEXTURE, textureInfo.textureId, textureInfo.frameCount, textureInfo.frameInterval));
1264 observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, textureInfo.textureId, textureInfo.textureSet, (textureInfo.useAtlas == UseAtlas::USE_ATLAS) ? true : false, textureInfo.atlasRect, textureInfo.preMultiplied));
1268 } // namespace Internal
1270 } // namespace Toolkit