2 * Copyright (c) 2020 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/visuals/texture-manager-impl.h>
24 #include <dali/public-api/math/vector4.h>
25 #include <dali/devel-api/adaptor-framework/environment-variable.h>
26 #include <dali/devel-api/adaptor-framework/image-loading.h>
27 #include <dali/devel-api/common/hash.h>
28 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/public-api/rendering/geometry.h>
33 #include <dali-toolkit/internal/image-loader/image-atlas-impl.h>
34 #include <dali-toolkit/public-api/image-loader/sync-image-loader.h>
35 #include <dali-toolkit/internal/visuals/image-atlas-manager.h>
36 #include <dali-toolkit/internal/visuals/rendering-addon.h>
41 constexpr auto INITIAL_CACHE_NUMBER = size_t{0u};
42 constexpr auto DEFAULT_NUMBER_OF_LOCAL_LOADER_THREADS = size_t{4u};
43 constexpr auto DEFAULT_NUMBER_OF_REMOTE_LOADER_THREADS = size_t{8u};
45 constexpr auto NUMBER_OF_LOCAL_LOADER_THREADS_ENV = "DALI_TEXTURE_LOCAL_THREADS";
46 constexpr auto NUMBER_OF_REMOTE_LOADER_THREADS_ENV = "DALI_TEXTURE_REMOTE_THREADS";
48 size_t GetNumberOfThreads(const char* environmentVariable, size_t defaultValue)
50 using Dali::EnvironmentVariable::GetEnvironmentVariable;
51 auto numberString = GetEnvironmentVariable(environmentVariable);
52 auto numberOfThreads = numberString ? std::strtoul(numberString, nullptr, 10) : 0;
53 constexpr auto MAX_NUMBER_OF_THREADS = 100u;
54 DALI_ASSERT_DEBUG( numberOfThreads < MAX_NUMBER_OF_THREADS );
55 return ( numberOfThreads > 0 && numberOfThreads < MAX_NUMBER_OF_THREADS ) ? numberOfThreads : defaultValue;
58 size_t GetNumberOfLocalLoaderThreads()
60 return GetNumberOfThreads(NUMBER_OF_LOCAL_LOADER_THREADS_ENV, DEFAULT_NUMBER_OF_LOCAL_LOADER_THREADS);
63 size_t GetNumberOfRemoteLoaderThreads()
65 return GetNumberOfThreads(NUMBER_OF_REMOTE_LOADER_THREADS_ENV, DEFAULT_NUMBER_OF_REMOTE_LOADER_THREADS);
83 Debug::Filter* gTextureManagerLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_TEXTURE_MANAGER" );
85 #define GET_LOAD_STATE_STRING( loadState ) \
86 loadState == TextureManager::LoadState::NOT_STARTED ? "NOT_STARTED" : \
87 loadState == TextureManager::LoadState::LOADING ? "LOADING" : \
88 loadState == TextureManager::LoadState::LOAD_FINISHED ? "LOAD_FINISHED" : \
89 loadState == TextureManager::LoadState::WAITING_FOR_MASK ? "WAITING_FOR_MASK" : \
90 loadState == TextureManager::LoadState::MASK_APPLYING ? "MASK_APPLYING" : \
91 loadState == TextureManager::LoadState::MASK_APPLIED ? "MASK_APPLIED" : \
92 loadState == TextureManager::LoadState::UPLOADED ? "UPLOADED" : \
93 loadState == TextureManager::LoadState::CANCELLED ? "CANCELLED" : \
94 loadState == TextureManager::LoadState::LOAD_FAILED ? "LOAD_FAILED" : "Unknown"
98 const uint32_t DEFAULT_ATLAS_SIZE( 1024u ); ///< This size can fit 8 by 8 images of average size 128 * 128
99 const Vector4 FULL_ATLAS_RECT( 0.0f, 0.0f, 1.0f, 1.0f ); ///< UV Rectangle that covers the full Texture
100 const int INVALID_INDEX( -1 ); ///< Invalid index used to represent a non-existant TextureInfo struct
101 const int INVALID_CACHE_INDEX( -1 ); ///< Invalid Cache index
104 void PreMultiply( Devel::PixelBuffer pixelBuffer, TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
106 if( Pixel::HasAlpha( pixelBuffer.GetPixelFormat() ) )
108 if( preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD )
110 pixelBuffer.MultiplyColorByAlpha();
115 preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
119 } // Anonymous namespace
121 TextureManager::MaskingData::MaskingData()
123 mAlphaMaskId( INVALID_TEXTURE_ID ),
124 mContentScaleFactor( 1.0f ),
129 TextureManager::TextureManager()
130 : mAsyncLocalLoaders( GetNumberOfLocalLoaderThreads(), [&]() { return AsyncLoadingHelper(*this); } ),
131 mAsyncRemoteLoaders( GetNumberOfRemoteLoaderThreads(), [&]() { return AsyncLoadingHelper(*this); } ),
133 mLifecycleObservers(),
135 mCurrentTextureId( 0 ),
136 mQueueLoadFlag(false)
138 // Initialize the AddOn
139 RenderingAddOn::Get();
142 TextureManager::~TextureManager()
144 for( auto iter = mLifecycleObservers.Begin(), endIter = mLifecycleObservers.End(); iter != endIter; ++iter)
146 (*iter)->TextureManagerDestroyed();
150 TextureSet TextureManager::LoadAnimatedImageTexture(
151 Dali::AnimatedImageLoading animatedImageLoading, uint32_t frameIndex, Dali::SamplingMode::Type samplingMode,
152 bool synchronousLoading, TextureManager::TextureId& textureId, Dali::WrapMode::Type wrapModeU, Dali::WrapMode::Type wrapModeV, TextureUploadObserver* textureObserver )
154 TextureSet textureSet;
156 if( synchronousLoading )
158 Devel::PixelBuffer pixelBuffer;
159 if( animatedImageLoading )
161 pixelBuffer = animatedImageLoading.LoadFrame( frameIndex );
165 DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous loading is failed\n");
169 PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
172 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(),
173 pixelData.GetWidth(), pixelData.GetHeight() );
174 texture.Upload( pixelData );
175 textureSet = TextureSet::New();
176 textureSet.SetTexture( 0u, texture );
182 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
183 textureId = RequestLoadInternal( animatedImageLoading.GetUrl(), INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL,
184 SamplingMode::BOX_THEN_LINEAR, TextureManager::NO_ATLAS, false, StorageType::UPLOAD_TO_TEXTURE, textureObserver,
185 true, TextureManager::ReloadPolicy::CACHED, preMultiply, animatedImageLoading, frameIndex );
186 TextureManager::LoadState loadState = GetTextureStateInternal( textureId );
187 if( loadState == TextureManager::LoadState::UPLOADED )
189 // UploadComplete has already been called - keep the same texture set
190 textureSet = GetTextureSet( textureId );
196 Sampler sampler = Sampler::New();
197 sampler.SetWrapMode( wrapModeU, wrapModeV );
198 textureSet.SetSampler( 0u, sampler );
204 Devel::PixelBuffer TextureManager::LoadPixelBuffer(
205 const VisualUrl& url, Dali::ImageDimensions desiredSize, Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode, bool synchronousLoading, TextureUploadObserver* textureObserver, bool orientationCorrection, TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
207 Devel::PixelBuffer pixelBuffer;
208 if( synchronousLoading )
212 pixelBuffer = LoadImageFromFile( url.GetUrl(), desiredSize, fittingMode, samplingMode,
213 orientationCorrection );
214 if( pixelBuffer && preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD )
216 PreMultiply( pixelBuffer, preMultiplyOnLoad );
222 RequestLoadInternal( url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, TextureManager::NO_ATLAS,
223 false, StorageType::RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED,
224 preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u );
230 TextureSet TextureManager::LoadTexture(
231 const VisualUrl& url, Dali::ImageDimensions desiredSize, Dali::FittingMode::Type fittingMode,
232 Dali::SamplingMode::Type samplingMode, MaskingDataPointer& maskInfo,
233 bool synchronousLoading, TextureManager::TextureId& textureId, Vector4& textureRect,
234 Dali::ImageDimensions& textureRectSize, bool& atlasingStatus, bool& loadingStatus,
235 Dali::WrapMode::Type wrapModeU, Dali::WrapMode::Type wrapModeV, TextureUploadObserver* textureObserver,
236 AtlasUploadObserver* atlasObserver, ImageAtlasManagerPtr imageAtlasManager, bool orientationCorrection,
237 TextureManager::ReloadPolicy reloadPolicy, TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
239 TextureSet textureSet;
241 loadingStatus = false;
242 textureRect = FULL_ATLAS_RECT;
244 if( VisualUrl::TEXTURE == url.GetProtocolType())
246 std::string location = url.GetLocation();
247 if( location.size() > 0u )
249 TextureId id = std::stoi( location );
250 for( auto&& elem : mExternalTextures )
252 if( elem.textureId == id )
254 preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
255 textureId = elem.textureId;
256 return elem.textureSet;
261 else if( synchronousLoading )
266 Devel::PixelBuffer pixelBuffer = LoadImageFromFile( url.GetUrl(), desiredSize, fittingMode, samplingMode,
267 orientationCorrection );
268 if( maskInfo && maskInfo->mAlphaMaskUrl.IsValid() )
270 Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile( maskInfo->mAlphaMaskUrl.GetUrl(), ImageDimensions(),
271 FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true );
272 if( maskPixelBuffer )
274 pixelBuffer.ApplyMask( maskPixelBuffer, maskInfo->mContentScaleFactor, maskInfo->mCropToMask );
279 PreMultiply( pixelBuffer, preMultiplyOnLoad );
280 data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
285 DALI_LOG_ERROR("TextureManager::LoadTexture: Synchronous loading is failed\n");
289 if( atlasingStatus ) // attempt atlasing
291 textureSet = imageAtlasManager->Add( textureRect, data );
293 if( !textureSet ) // big image, no atlasing or atlasing failed
295 atlasingStatus = false;
296 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, data.GetPixelFormat(),
297 data.GetWidth(), data.GetHeight() );
298 texture.Upload( data );
299 textureSet = TextureSet::New();
300 textureSet.SetTexture( 0u, texture );
304 textureRectSize.SetWidth(data.GetWidth());
305 textureRectSize.SetHeight(data.GetHeight());
311 loadingStatus = true;
314 textureSet = imageAtlasManager->Add( textureRect, url.GetUrl(), desiredSize, fittingMode, true, atlasObserver);
316 if( !textureSet ) // big image, no atlasing or atlasing failed
318 atlasingStatus = false;
319 if( !maskInfo || !maskInfo->mAlphaMaskUrl.IsValid() )
321 textureId = RequestLoad( url, desiredSize, fittingMode, samplingMode, TextureManager::NO_ATLAS,
322 textureObserver, orientationCorrection, reloadPolicy, preMultiplyOnLoad );
326 maskInfo->mAlphaMaskId = RequestMaskLoad( maskInfo->mAlphaMaskUrl );
327 textureId = RequestLoad( url,
328 maskInfo->mAlphaMaskId,
329 maskInfo->mContentScaleFactor,
331 fittingMode, samplingMode,
332 TextureManager::NO_ATLAS,
333 maskInfo->mCropToMask,
335 orientationCorrection,
336 reloadPolicy, preMultiplyOnLoad );
339 TextureManager::LoadState loadState = GetTextureStateInternal( textureId );
340 if( loadState == TextureManager::LoadState::UPLOADED )
342 // UploadComplete has already been called - keep the same texture set
343 textureSet = GetTextureSet( textureId );
346 // If we are loading the texture, or waiting for the ready signal handler to complete, inform
347 // caller that they need to wait.
348 loadingStatus = ( loadState == TextureManager::LoadState::LOADING ||
349 loadState == TextureManager::LoadState::WAITING_FOR_MASK ||
350 loadState == TextureManager::LoadState::MASK_APPLYING ||
351 loadState == TextureManager::LoadState::MASK_APPLIED ||
352 loadState == TextureManager::LoadState::NOT_STARTED ||
358 textureRectSize = desiredSize;
362 if( ! atlasingStatus && textureSet )
364 Sampler sampler = Sampler::New();
365 sampler.SetWrapMode( wrapModeU, wrapModeV );
366 textureSet.SetSampler( 0u, sampler );
372 TextureManager::TextureId TextureManager::RequestLoad(
373 const VisualUrl& url,
374 const ImageDimensions desiredSize,
375 FittingMode::Type fittingMode,
376 Dali::SamplingMode::Type samplingMode,
377 const UseAtlas useAtlas,
378 TextureUploadObserver* observer,
379 bool orientationCorrection,
380 TextureManager::ReloadPolicy reloadPolicy,
381 TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
383 return RequestLoadInternal( url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, useAtlas,
384 false, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy,
385 preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u );
388 TextureManager::TextureId TextureManager::RequestLoad(
389 const VisualUrl& url,
390 TextureId maskTextureId,
392 const ImageDimensions desiredSize,
393 FittingMode::Type fittingMode,
394 Dali::SamplingMode::Type samplingMode,
395 const UseAtlas useAtlas,
397 TextureUploadObserver* observer,
398 bool orientationCorrection,
399 TextureManager::ReloadPolicy reloadPolicy,
400 TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
402 return RequestLoadInternal( url, maskTextureId, contentScale, desiredSize, fittingMode, samplingMode, useAtlas,
403 cropToMask, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy,
404 preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u );
407 TextureManager::TextureId TextureManager::RequestMaskLoad( const VisualUrl& maskUrl )
409 // Use the normal load procedure to get the alpha mask.
410 auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
411 return RequestLoadInternal( maskUrl, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL,
412 SamplingMode::NO_FILTER, NO_ATLAS, false, StorageType::KEEP_PIXEL_BUFFER, NULL, true,
413 TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u );
416 TextureManager::TextureId TextureManager::RequestLoadInternal(
417 const VisualUrl& url,
418 TextureId maskTextureId,
420 const ImageDimensions desiredSize,
421 FittingMode::Type fittingMode,
422 Dali::SamplingMode::Type samplingMode,
425 StorageType storageType,
426 TextureUploadObserver* observer,
427 bool orientationCorrection,
428 TextureManager::ReloadPolicy reloadPolicy,
429 TextureManager::MultiplyOnLoad& preMultiplyOnLoad,
430 Dali::AnimatedImageLoading animatedImageLoading,
431 uint32_t frameIndex )
433 // First check if the requested Texture is cached.
434 bool isAnimatedImage = ( animatedImageLoading ) ? true : false;
436 TextureHash textureHash = INITIAL_CACHE_NUMBER;
437 int cacheIndex = INVALID_CACHE_INDEX;
438 if(storageType != StorageType::RETURN_PIXEL_BUFFER && !isAnimatedImage)
440 textureHash = GenerateHash(url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId);
442 // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
443 cacheIndex = FindCachedTexture(textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, preMultiplyOnLoad);
446 TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
447 // Check if the requested Texture exists in the cache.
448 if( cacheIndex != INVALID_CACHE_INDEX )
450 if ( TextureManager::ReloadPolicy::CACHED == reloadPolicy )
452 // Mark this texture being used by another client resource. Forced reload would replace the current texture
453 // without the need for incrementing the reference count.
454 ++( mTextureInfoContainer[ cacheIndex ].referenceCount );
456 textureId = mTextureInfoContainer[ cacheIndex ].textureId;
458 // Update preMultiplyOnLoad value. It should be changed according to preMultiplied value of the cached info.
459 preMultiplyOnLoad = mTextureInfoContainer[ cacheIndex ].preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
461 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) Using cached texture id@%d, textureId=%d\n",
462 url.GetUrl().c_str(), observer, cacheIndex, textureId );
465 if( textureId == INVALID_TEXTURE_ID ) // There was no caching, or caching not required
467 // We need a new Texture.
468 textureId = GenerateUniqueTextureId();
469 bool preMultiply = ( preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD );
470 mTextureInfoContainer.push_back( TextureInfo( textureId, maskTextureId, url.GetUrl(),
471 desiredSize, contentScale, fittingMode, samplingMode,
472 false, cropToMask, useAtlas, textureHash, orientationCorrection,
473 preMultiply, animatedImageLoading, frameIndex ) );
474 cacheIndex = mTextureInfoContainer.size() - 1u;
476 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) New texture, cacheIndex:%d, textureId=%d\n",
477 url.GetUrl().c_str(), observer, cacheIndex, textureId );
480 // The below code path is common whether we are using the cache or not.
481 // The textureInfoIndex now refers to either a pre-existing cached TextureInfo,
482 // or a new TextureInfo just created.
483 TextureInfo& textureInfo( mTextureInfoContainer[ cacheIndex ] );
484 textureInfo.maskTextureId = maskTextureId;
485 textureInfo.storageType = storageType;
486 textureInfo.orientationCorrection = orientationCorrection;
488 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::General, "TextureInfo loadState:%s\n",
489 GET_LOAD_STATE_STRING(textureInfo.loadState ) );
491 // Force reloading of texture by setting loadState unless already loading or cancelled.
492 if ( TextureManager::ReloadPolicy::FORCED == reloadPolicy &&
493 TextureManager::LoadState::LOADING != textureInfo.loadState &&
494 TextureManager::LoadState::WAITING_FOR_MASK != textureInfo.loadState &&
495 TextureManager::LoadState::MASK_APPLYING != textureInfo.loadState &&
496 TextureManager::LoadState::MASK_APPLIED != textureInfo.loadState &&
497 TextureManager::LoadState::CANCELLED != textureInfo.loadState )
499 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Verbose, "TextureManager::RequestLoad( url=%s observer=%p ) ForcedReload cacheIndex:%d, textureId=%d\n",
500 url.GetUrl().c_str(), observer, cacheIndex, textureId );
502 textureInfo.loadState = TextureManager::LoadState::NOT_STARTED;
505 // Check if we should add the observer.
506 // Only do this if we have not loaded yet and it will not have loaded by the end of this method.
507 switch( textureInfo.loadState )
509 case TextureManager::LoadState::LOAD_FAILED: // Failed notifies observer which then stops observing.
510 case TextureManager::LoadState::NOT_STARTED:
512 LoadOrQueueTexture( textureInfo, observer ); // If called inside NotifyObservers, queues until afterwards
515 case TextureManager::LoadState::LOADING:
516 case TextureManager::LoadState::WAITING_FOR_MASK:
517 case TextureManager::LoadState::MASK_APPLYING:
518 case TextureManager::LoadState::MASK_APPLIED:
520 ObserveTexture( textureInfo, observer );
523 case TextureManager::LoadState::UPLOADED:
527 LoadOrQueueTexture( textureInfo, observer );
531 case TextureManager::LoadState::CANCELLED:
533 // A cancelled texture hasn't finished loading yet. Treat as a loading texture
534 // (it's ref count has already been incremented, above)
535 textureInfo.loadState = TextureManager::LoadState::LOADING;
536 ObserveTexture( textureInfo, observer );
539 case TextureManager::LoadState::LOAD_FINISHED:
541 // Loading has already completed.
542 if( observer && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER )
544 LoadOrQueueTexture( textureInfo, observer );
550 // Return the TextureId for which this Texture can now be referenced by externally.
554 void TextureManager::Remove( const TextureManager::TextureId textureId, TextureUploadObserver* observer )
556 int textureInfoIndex = GetCacheIndexFromId( textureId );
557 if( textureInfoIndex != INVALID_INDEX )
559 TextureInfo& textureInfo( mTextureInfoContainer[ textureInfoIndex ] );
561 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise,
562 "TextureManager::Remove(%d) url:%s\n cacheIdx:%d loadState:%s reference count = %d\n",
563 textureId, textureInfo.url.GetUrl().c_str(),
564 textureInfoIndex, GET_LOAD_STATE_STRING( textureInfo.loadState ), textureInfo.referenceCount );
566 // Decrement the reference count and check if this is the last user of this Texture.
567 if( --textureInfo.referenceCount <= 0 )
569 // This is the last remove for this Texture.
570 textureInfo.referenceCount = 0;
571 bool removeTextureInfo = false;
573 // If loaded, we can remove the TextureInfo and the Atlas (if atlased).
574 if( textureInfo.loadState == LoadState::UPLOADED )
576 if( textureInfo.atlas )
578 textureInfo.atlas.Remove( textureInfo.atlasRect );
580 removeTextureInfo = true;
582 else if( textureInfo.loadState == LoadState::LOADING )
584 // We mark the textureInfo for removal.
585 // Once the load has completed, this method will be called again.
586 textureInfo.loadState = LoadState::CANCELLED;
590 // In other states, we are not waiting for a load so we are safe to remove the TextureInfo data.
591 removeTextureInfo = true;
594 // If the state allows us to remove the TextureInfo data, we do so.
595 if( removeTextureInfo )
597 // Permanently remove the textureInfo struct.
598 mTextureInfoContainer.erase( mTextureInfoContainer.begin() + textureInfoIndex );
604 // Remove element from the LoadQueue
605 for( auto&& element : mLoadQueue )
607 if( element.mObserver == observer )
609 mLoadQueue.Erase( &element );
617 VisualUrl TextureManager::GetVisualUrl( TextureId textureId )
619 VisualUrl visualUrl("");
620 int cacheIndex = GetCacheIndexFromId( textureId );
622 if( cacheIndex != INVALID_CACHE_INDEX )
624 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "TextureManager::GetVisualUrl. Using cached texture id=%d, textureId=%d\n",
625 cacheIndex, textureId );
627 TextureInfo& cachedTextureInfo( mTextureInfoContainer[ cacheIndex ] );
628 visualUrl = cachedTextureInfo.url;
633 TextureManager::LoadState TextureManager::GetTextureState( TextureId textureId )
635 LoadState loadState = TextureManager::LoadState::NOT_STARTED;
637 int cacheIndex = GetCacheIndexFromId( textureId );
638 if( cacheIndex != INVALID_CACHE_INDEX )
640 TextureInfo& cachedTextureInfo( mTextureInfoContainer[ cacheIndex ] );
641 loadState = cachedTextureInfo.loadState;
645 for( auto&& elem : mExternalTextures )
647 if( elem.textureId == textureId )
649 loadState = LoadState::UPLOADED;
657 TextureManager::LoadState TextureManager::GetTextureStateInternal( TextureId textureId )
659 LoadState loadState = TextureManager::LoadState::NOT_STARTED;
661 int cacheIndex = GetCacheIndexFromId( textureId );
662 if( cacheIndex != INVALID_CACHE_INDEX )
664 TextureInfo& cachedTextureInfo( mTextureInfoContainer[ cacheIndex ] );
665 loadState = cachedTextureInfo.loadState;
671 TextureSet TextureManager::GetTextureSet( TextureId textureId )
673 TextureSet textureSet;// empty handle
675 int cacheIndex = GetCacheIndexFromId( textureId );
676 if( cacheIndex != INVALID_CACHE_INDEX )
678 TextureInfo& cachedTextureInfo( mTextureInfoContainer[ cacheIndex ] );
679 textureSet = cachedTextureInfo.textureSet;
683 for( auto&& elem : mExternalTextures )
685 if( elem.textureId == textureId )
687 textureSet = elem.textureSet;
695 std::string TextureManager::AddExternalTexture( TextureSet& textureSet )
697 TextureManager::ExternalTextureInfo info;
698 info.textureId = GenerateUniqueTextureId();
699 info.textureSet = textureSet;
700 mExternalTextures.emplace_back( info );
701 return VisualUrl::CreateTextureUrl( std::to_string( info.textureId ) );
704 TextureSet TextureManager::RemoveExternalTexture( const std::string& url )
706 if( url.size() > 0u )
708 // get the location from the Url
709 VisualUrl parseUrl( url );
710 if( VisualUrl::TEXTURE == parseUrl.GetProtocolType() )
712 std::string location = parseUrl.GetLocation();
713 if( location.size() > 0u )
715 TextureId id = std::stoi( location );
716 const auto end = mExternalTextures.end();
717 for( auto iter = mExternalTextures.begin(); iter != end; ++iter )
719 if( iter->textureId == id )
721 auto textureSet = iter->textureSet;
722 mExternalTextures.erase( iter );
732 void TextureManager::AddObserver( TextureManager::LifecycleObserver& observer )
734 // make sure an observer doesn't observe the same object twice
735 // otherwise it will get multiple calls to ObjectDestroyed()
736 DALI_ASSERT_DEBUG( mLifecycleObservers.End() == std::find( mLifecycleObservers.Begin(), mLifecycleObservers.End(), &observer));
737 mLifecycleObservers.PushBack( &observer );
740 void TextureManager::RemoveObserver( TextureManager::LifecycleObserver& observer)
742 // Find the observer...
743 auto endIter = mLifecycleObservers.End();
744 for( auto iter = mLifecycleObservers.Begin(); iter != endIter; ++iter)
746 if( (*iter) == &observer)
748 mLifecycleObservers.Erase( iter );
752 DALI_ASSERT_DEBUG(endIter != mLifecycleObservers.End());
755 void TextureManager::LoadOrQueueTexture( TextureInfo& textureInfo, TextureUploadObserver* observer )
757 switch( textureInfo.loadState )
759 case LoadState::NOT_STARTED:
760 case LoadState::LOAD_FAILED:
764 QueueLoadTexture( textureInfo, observer );
768 LoadTexture( textureInfo, observer );
772 case LoadState::UPLOADED:
776 QueueLoadTexture( textureInfo, observer );
780 // The Texture has already loaded. The other observers have already been notified.
781 // We need to send a "late" loaded notification for this observer.
782 observer->UploadComplete( true, textureInfo.textureId, textureInfo.textureSet,
783 textureInfo.useAtlas, textureInfo.atlasRect,
784 textureInfo.preMultiplied );
788 case LoadState::LOADING:
789 case LoadState::CANCELLED:
790 case LoadState::LOAD_FINISHED:
791 case LoadState::WAITING_FOR_MASK:
792 case LoadState::MASK_APPLYING:
793 case LoadState::MASK_APPLIED:
800 void TextureManager::QueueLoadTexture( TextureInfo& textureInfo, TextureUploadObserver* observer )
802 auto textureId = textureInfo.textureId;
803 mLoadQueue.PushBack( LoadQueueElement( textureId, observer) );
805 observer->DestructionSignal().Connect( this, &TextureManager::ObserverDestroyed );
808 void TextureManager::LoadTexture( TextureInfo& textureInfo, TextureUploadObserver* observer )
810 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "TextureManager::LoadTexture(): url:%s sync:%s\n",
811 textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously?"T":"F" );
813 textureInfo.loadState = LoadState::LOADING;
814 if( !textureInfo.loadSynchronously )
816 auto& loadersContainer = textureInfo.url.IsLocalResource() ? mAsyncLocalLoaders : mAsyncRemoteLoaders;
817 auto loadingHelperIt = loadersContainer.GetNext();
818 auto premultiplyOnLoad = ( textureInfo.preMultiplyOnLoad && textureInfo.maskTextureId == INVALID_TEXTURE_ID ) ?
819 DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
820 DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
821 if( textureInfo.animatedImageLoading )
823 loadingHelperIt->LoadAnimatedImage( textureInfo.textureId, textureInfo.animatedImageLoading, textureInfo.frameIndex );
827 loadingHelperIt->Load(textureInfo.textureId, textureInfo.url,
828 textureInfo.desiredSize, textureInfo.fittingMode,
829 textureInfo.samplingMode, textureInfo.orientationCorrection,
833 ObserveTexture( textureInfo, observer );
836 void TextureManager::ProcessQueuedTextures()
838 for( auto&& element : mLoadQueue )
840 if( !element.mObserver )
845 int cacheIndex = GetCacheIndexFromId( element.mTextureId );
846 if( cacheIndex != INVALID_CACHE_INDEX )
848 TextureInfo& textureInfo( mTextureInfoContainer[cacheIndex] );
849 if( textureInfo.loadState == LoadState::UPLOADED )
851 element.mObserver->UploadComplete( true, textureInfo.textureId, textureInfo.textureSet,
852 textureInfo.useAtlas, textureInfo.atlasRect,
853 textureInfo.preMultiplied );
855 else if ( textureInfo.loadState == LoadState::LOAD_FINISHED && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER )
857 element.mObserver->LoadComplete( true, textureInfo.pixelBuffer, textureInfo.url, textureInfo.preMultiplied );
861 LoadTexture( textureInfo, element.mObserver );
868 void TextureManager::ObserveTexture( TextureInfo& textureInfo,
869 TextureUploadObserver* observer )
871 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "TextureManager::ObserveTexture(): url:%s observer:%p\n",
872 textureInfo.url.GetUrl().c_str(), observer );
876 textureInfo.observerList.PushBack( observer );
877 observer->DestructionSignal().Connect( this, &TextureManager::ObserverDestroyed );
881 void TextureManager::AsyncLoadComplete( AsyncLoadingInfoContainerType& loadingContainer, uint32_t id,
882 Devel::PixelBuffer pixelBuffer )
884 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "TextureManager::AsyncLoadComplete( id:%d )\n", id );
886 if( loadingContainer.size() >= 1u )
888 AsyncLoadingInfo loadingInfo = loadingContainer.front();
890 if( loadingInfo.loadId == id )
892 int cacheIndex = GetCacheIndexFromId( loadingInfo.textureId );
893 if( cacheIndex != INVALID_CACHE_INDEX )
895 TextureInfo& textureInfo( mTextureInfoContainer[cacheIndex] );
897 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise,
898 " textureId:%d Url:%s CacheIndex:%d LoadState: %d\n",
899 textureInfo.textureId, textureInfo.url.GetUrl().c_str(), cacheIndex, textureInfo.loadState );
901 if( textureInfo.loadState != LoadState::CANCELLED )
903 // textureInfo can be invalidated after this call (as the mTextureInfoContainer may be modified)
904 PostLoad( textureInfo, pixelBuffer );
908 Remove( textureInfo.textureId, nullptr );
913 loadingContainer.pop_front();
917 void TextureManager::PostLoad( TextureInfo& textureInfo, Devel::PixelBuffer& pixelBuffer )
919 // Was the load successful?
920 if( pixelBuffer && ( pixelBuffer.GetWidth() != 0 ) && ( pixelBuffer.GetHeight() != 0 ) )
922 // No atlas support for now
923 textureInfo.useAtlas = NO_ATLAS;
924 textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
926 if( textureInfo.storageType == StorageType::UPLOAD_TO_TEXTURE )
928 // If there is a mask texture ID associated with this texture, then apply the mask
929 // if it's already loaded. If it hasn't, and the mask is still loading,
930 // wait for the mask to finish loading.
931 if( textureInfo.maskTextureId != INVALID_TEXTURE_ID )
933 if( textureInfo.loadState == LoadState::MASK_APPLYING )
935 textureInfo.loadState = LoadState::MASK_APPLIED;
936 UploadTexture( pixelBuffer, textureInfo );
937 NotifyObservers( textureInfo, true );
941 LoadState maskLoadState = GetTextureStateInternal( textureInfo.maskTextureId );
942 textureInfo.pixelBuffer = pixelBuffer; // Store the pixel buffer temporarily
943 if( maskLoadState == LoadState::LOADING )
945 textureInfo.loadState = LoadState::WAITING_FOR_MASK;
947 else if( maskLoadState == LoadState::LOAD_FINISHED )
949 // Send New Task to Thread
950 ApplyMask( textureInfo, textureInfo.maskTextureId );
956 UploadTexture( pixelBuffer, textureInfo );
957 NotifyObservers( textureInfo, true );
962 textureInfo.pixelBuffer = pixelBuffer; // Store the pixel data
963 textureInfo.loadState = LoadState::LOAD_FINISHED;
965 if( textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER )
967 NotifyObservers( textureInfo, true );
971 // Check if there was another texture waiting for this load to complete
972 // (e.g. if this was an image mask, and its load is on a different thread)
973 CheckForWaitingTexture( textureInfo );
979 textureInfo.loadState = LoadState::LOAD_FAILED;
980 CheckForWaitingTexture( textureInfo );
981 NotifyObservers( textureInfo, false );
985 void TextureManager::CheckForWaitingTexture( TextureInfo& maskTextureInfo )
987 // Search the cache, checking if any texture has this texture id as a
989 const unsigned int size = mTextureInfoContainer.size();
991 for( unsigned int cacheIndex = 0; cacheIndex < size; ++cacheIndex )
993 if( mTextureInfoContainer[cacheIndex].maskTextureId == maskTextureInfo.textureId &&
994 mTextureInfoContainer[cacheIndex].loadState == LoadState::WAITING_FOR_MASK )
996 TextureInfo& textureInfo( mTextureInfoContainer[cacheIndex] );
998 if( maskTextureInfo.loadState == LoadState::LOAD_FINISHED )
1000 // Send New Task to Thread
1001 ApplyMask( textureInfo, maskTextureInfo.textureId );
1005 textureInfo.pixelBuffer.Reset();
1006 textureInfo.loadState = LoadState::LOAD_FAILED;
1007 NotifyObservers( textureInfo, false );
1013 void TextureManager::ApplyMask( TextureInfo& textureInfo, TextureId maskTextureId )
1015 int maskCacheIndex = GetCacheIndexFromId( maskTextureId );
1016 if( maskCacheIndex != INVALID_CACHE_INDEX )
1018 Devel::PixelBuffer maskPixelBuffer = mTextureInfoContainer[maskCacheIndex].pixelBuffer;
1019 Devel::PixelBuffer pixelBuffer = textureInfo.pixelBuffer;
1020 textureInfo.pixelBuffer.Reset();
1022 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "TextureManager::ApplyMask(): url:%s sync:%s\n",
1023 textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously?"T":"F" );
1025 textureInfo.loadState = LoadState::MASK_APPLYING;
1026 auto& loadersContainer = textureInfo.url.IsLocalResource() ? mAsyncLocalLoaders : mAsyncRemoteLoaders;
1027 auto loadingHelperIt = loadersContainer.GetNext();
1028 auto premultiplyOnLoad = textureInfo.preMultiplyOnLoad ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
1029 DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
1030 loadingHelperIt->ApplyMask( textureInfo.textureId, pixelBuffer, maskPixelBuffer, textureInfo.scaleFactor, textureInfo.cropToMask, premultiplyOnLoad );
1034 void TextureManager::UploadTexture( Devel::PixelBuffer& pixelBuffer, TextureInfo& textureInfo )
1036 if( textureInfo.useAtlas != USE_ATLAS )
1038 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::General, " TextureManager::UploadTexture() New Texture for textureId:%d\n", textureInfo.textureId );
1040 // Check if this pixelBuffer is premultiplied
1041 textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
1043 auto& renderingAddOn = RenderingAddOn::Get();
1044 if( renderingAddOn.IsValid() )
1046 renderingAddOn.CreateGeometry( textureInfo.textureId, pixelBuffer );
1049 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, pixelBuffer.GetPixelFormat(),
1050 pixelBuffer.GetWidth(), pixelBuffer.GetHeight() );
1052 PixelData pixelData = Devel::PixelBuffer::Convert( pixelBuffer );
1053 texture.Upload( pixelData );
1054 if ( ! textureInfo.textureSet )
1056 textureInfo.textureSet = TextureSet::New();
1058 textureInfo.textureSet.SetTexture( 0u, texture );
1061 // Update the load state.
1062 // Note: This is regardless of success as we care about whether a
1063 // load attempt is in progress or not. If unsuccessful, a broken
1064 // image is still loaded.
1065 textureInfo.loadState = LoadState::UPLOADED;
1068 void TextureManager::NotifyObservers( TextureInfo& textureInfo, bool success )
1070 TextureId textureId = textureInfo.textureId;
1072 // If there is an observer: Notify the load is complete, whether successful or not,
1073 // and erase it from the list
1074 TextureInfo* info = &textureInfo;
1076 mQueueLoadFlag = true;
1078 while( info->observerList.Count() )
1080 TextureUploadObserver* observer = info->observerList[0];
1082 // During UploadComplete() a Control ResourceReady() signal is emitted.
1083 // During that signal the app may add remove /add Textures (e.g. via
1085 // It is possible for observers to be removed from the observer list,
1086 // and it is also possible for the mTextureInfoContainer to be modified,
1087 // invalidating the reference to the textureInfo struct.
1088 // Texture load requests for the same URL are deferred until the end of this
1090 DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "NotifyObservers() url:%s loadState:%s\n",
1091 textureInfo.url.GetUrl().c_str(), GET_LOAD_STATE_STRING(textureInfo.loadState ) );
1093 // It is possible for the observer to be deleted.
1094 // Disconnect and remove the observer first.
1095 observer->DestructionSignal().Disconnect( this, &TextureManager::ObserverDestroyed );
1097 info->observerList.Erase( info->observerList.begin() );
1099 if( info->storageType == StorageType::RETURN_PIXEL_BUFFER )
1101 observer->LoadComplete( success, info->pixelBuffer, info->url, info->preMultiplied );
1105 observer->UploadComplete( success, info->textureId, info->textureSet, info->useAtlas, info->atlasRect,
1106 info->preMultiplied );
1109 // Get the textureInfo from the container again as it may have been invalidated.
1110 int textureInfoIndex = GetCacheIndexFromId( textureId );
1111 if( textureInfoIndex == INVALID_CACHE_INDEX)
1113 break; // texture has been removed - can stop.
1115 info = &mTextureInfoContainer[ textureInfoIndex ];
1118 mQueueLoadFlag = false;
1119 ProcessQueuedTextures();
1121 if( info->storageType == StorageType::RETURN_PIXEL_BUFFER && info->observerList.Count() == 0 )
1123 Remove( info->textureId, nullptr );
1127 TextureManager::TextureId TextureManager::GenerateUniqueTextureId()
1129 return mCurrentTextureId++;
1132 int TextureManager::GetCacheIndexFromId( const TextureId textureId )
1134 const unsigned int size = mTextureInfoContainer.size();
1136 for( unsigned int i = 0; i < size; ++i )
1138 if( mTextureInfoContainer[i].textureId == textureId )
1144 return INVALID_CACHE_INDEX;
1147 TextureManager::TextureHash TextureManager::GenerateHash(
1148 const std::string& url,
1149 const ImageDimensions size,
1150 const FittingMode::Type fittingMode,
1151 const Dali::SamplingMode::Type samplingMode,
1152 const UseAtlas useAtlas,
1153 TextureId maskTextureId)
1155 std::string hashTarget( url );
1156 const size_t urlLength = hashTarget.length();
1157 const uint16_t width = size.GetWidth();
1158 const uint16_t height = size.GetWidth();
1160 // If either the width or height has been specified, include the resizing options in the hash
1161 if( width != 0 || height != 0 )
1163 // We are appending 5 bytes to the URL to form the hash input.
1164 hashTarget.resize( urlLength + 5u );
1165 char* hashTargetPtr = &( hashTarget[ urlLength ] );
1167 // Pack the width and height (4 bytes total).
1168 *hashTargetPtr++ = size.GetWidth() & 0xff;
1169 *hashTargetPtr++ = ( size.GetWidth() >> 8u ) & 0xff;
1170 *hashTargetPtr++ = size.GetHeight() & 0xff;
1171 *hashTargetPtr++ = ( size.GetHeight() >> 8u ) & 0xff;
1173 // Bit-pack the FittingMode, SamplingMode and atlasing.
1174 // FittingMode=2bits, SamplingMode=3bits, useAtlas=1bit
1175 *hashTargetPtr = ( fittingMode << 4u ) | ( samplingMode << 1 ) | useAtlas;
1179 // We are not including sizing information, but we still need an extra byte for atlasing.
1180 hashTarget.resize( urlLength + 1u );
1182 // Add the atlasing to the hash input.
1185 case UseAtlas::NO_ATLAS:
1187 hashTarget[ urlLength ] = 'f';
1190 case UseAtlas::USE_ATLAS:
1192 hashTarget[ urlLength ] = 't';
1198 if( maskTextureId != INVALID_TEXTURE_ID )
1200 auto textureIdIndex = hashTarget.length();
1201 hashTarget.resize( hashTarget.length() + sizeof( TextureId ) );
1202 unsigned char* hashTargetPtr = reinterpret_cast<unsigned char*>(&( hashTarget[ textureIdIndex ] ));
1204 // Append the texture id to the end of the URL byte by byte:
1205 // (to avoid SIGBUS / alignment issues)
1206 for( size_t byteIter = 0; byteIter < sizeof( TextureId ); ++byteIter )
1208 *hashTargetPtr++ = maskTextureId & 0xff;
1209 maskTextureId >>= 8u;
1213 return Dali::CalculateHash( hashTarget );
1216 int TextureManager::FindCachedTexture(
1217 const TextureManager::TextureHash hash,
1218 const std::string& url,
1219 const ImageDimensions size,
1220 const FittingMode::Type fittingMode,
1221 const Dali::SamplingMode::Type samplingMode,
1222 const bool useAtlas,
1223 TextureId maskTextureId,
1224 TextureManager::MultiplyOnLoad preMultiplyOnLoad)
1226 // Default to an invalid ID, in case we do not find a match.
1227 int cacheIndex = INVALID_CACHE_INDEX;
1229 // Iterate through our hashes to find a match.
1230 const unsigned int count = mTextureInfoContainer.size();
1231 for( unsigned int i = 0u; i < count; ++i )
1233 if( mTextureInfoContainer[i].hash == hash )
1235 // We have a match, now we check all the original parameters in case of a hash collision.
1236 TextureInfo& textureInfo( mTextureInfoContainer[i] );
1238 if( ( url == textureInfo.url.GetUrl() ) &&
1239 ( useAtlas == textureInfo.useAtlas ) &&
1240 ( maskTextureId == textureInfo.maskTextureId ) &&
1241 ( size == textureInfo.desiredSize ) &&
1242 ( ( size.GetWidth() == 0 && size.GetHeight() == 0 ) ||
1243 ( fittingMode == textureInfo.fittingMode &&
1244 samplingMode == textureInfo.samplingMode ) ) )
1246 // 1. If preMultiplyOnLoad is MULTIPLY_ON_LOAD, then textureInfo.preMultiplyOnLoad should be true. The premultiplication result can be different.
1247 // 2. If preMultiplyOnLoad is LOAD_WITHOUT_MULTIPLY, then textureInfo.preMultiplied should be false.
1248 if( ( preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD && textureInfo.preMultiplyOnLoad )
1249 || ( preMultiplyOnLoad == TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY && !textureInfo.preMultiplied ) )
1251 // The found Texture is a match.
1262 void TextureManager::ObserverDestroyed( TextureUploadObserver* observer )
1264 const unsigned int count = mTextureInfoContainer.size();
1265 for( unsigned int i = 0; i < count; ++i )
1267 TextureInfo& textureInfo( mTextureInfoContainer[i] );
1268 for( TextureInfo::ObserverListType::Iterator j = textureInfo.observerList.Begin();
1269 j != textureInfo.observerList.End(); )
1271 if( *j == observer )
1273 j = textureInfo.observerList.Erase( j );
1282 // Remove element from the LoadQueue
1283 for( auto&& element : mLoadQueue )
1285 if( element.mObserver == observer )
1287 element.mObserver = nullptr;
1293 TextureManager::AsyncLoadingHelper::AsyncLoadingHelper(TextureManager& textureManager)
1294 : AsyncLoadingHelper(Toolkit::AsyncImageLoader::New(), textureManager,
1295 AsyncLoadingInfoContainerType())
1299 void TextureManager::AsyncLoadingHelper::LoadAnimatedImage( TextureId textureId,
1300 Dali::AnimatedImageLoading animatedImageLoading,
1301 uint32_t frameIndex )
1303 mLoadingInfoContainer.push_back( AsyncLoadingInfo( textureId ) );
1304 auto id = DevelAsyncImageLoader::LoadAnimatedImage( mLoader, animatedImageLoading, frameIndex );
1305 mLoadingInfoContainer.back().loadId = id;
1308 void TextureManager::AsyncLoadingHelper::Load( TextureId textureId,
1309 const VisualUrl& url,
1310 ImageDimensions desiredSize,
1311 FittingMode::Type fittingMode,
1312 SamplingMode::Type samplingMode,
1313 bool orientationCorrection,
1314 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad )
1316 mLoadingInfoContainer.push_back( AsyncLoadingInfo( textureId ) );
1317 auto id = DevelAsyncImageLoader::Load( mLoader, url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad );
1318 mLoadingInfoContainer.back().loadId = id;
1321 void TextureManager::AsyncLoadingHelper::ApplyMask( TextureId textureId,
1322 Devel::PixelBuffer pixelBuffer,
1323 Devel::PixelBuffer maskPixelBuffer,
1326 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad )
1328 mLoadingInfoContainer.push_back( AsyncLoadingInfo( textureId ) );
1329 auto id = DevelAsyncImageLoader::ApplyMask( mLoader, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad );
1330 mLoadingInfoContainer.back().loadId = id;
1333 TextureManager::AsyncLoadingHelper::AsyncLoadingHelper(AsyncLoadingHelper&& rhs)
1334 : AsyncLoadingHelper(rhs.mLoader, rhs.mTextureManager, std::move(rhs.mLoadingInfoContainer))
1338 TextureManager::AsyncLoadingHelper::AsyncLoadingHelper(
1339 Toolkit::AsyncImageLoader loader,
1340 TextureManager& textureManager,
1341 AsyncLoadingInfoContainerType&& loadingInfoContainer)
1343 mTextureManager(textureManager),
1344 mLoadingInfoContainer(std::move(loadingInfoContainer))
1346 DevelAsyncImageLoader::PixelBufferLoadedSignal(mLoader).Connect(
1347 this, &AsyncLoadingHelper::AsyncLoadComplete);
1350 void TextureManager::AsyncLoadingHelper::AsyncLoadComplete(uint32_t id,
1351 Devel::PixelBuffer pixelBuffer )
1353 mTextureManager.AsyncLoadComplete( mLoadingInfoContainer, id, pixelBuffer );
1356 Geometry TextureManager::GetRenderGeometry(TextureId textureId, uint32_t& frontElements, uint32_t& backElements )
1358 return RenderingAddOn::Get().IsValid() ?
1359 RenderingAddOn::Get().GetGeometry( textureId, frontElements, backElements) :
1363 } // namespace Internal
1365 } // namespace Toolkit