const uint32_t DEFAULT_ATLAS_SIZE( 1024u ); ///< This size can fit 8 by 8 images of average size 128 * 128
const Vector4 FULL_ATLAS_RECT( 0.0f, 0.0f, 1.0f, 1.0f ); ///< UV Rectangle that covers the full Texture
-const char * const BROKEN_IMAGE_URL( DALI_IMAGE_DIR "broken.png" ); ///< URL For the broken image placeholder
const int INVALID_INDEX( -1 ); ///< Invalid index used to represent a non-existant TextureInfo struct
const int INVALID_CACHE_INDEX( -1 ); ///< Invalid Cache index
TextureManager::TextureManager()
: mAsyncLocalLoaders( GetNumberOfLocalLoaderThreads(), [&]() { return AsyncLoadingHelper(*this); } ),
mAsyncRemoteLoaders( GetNumberOfRemoteLoaderThreads(), [&]() { return AsyncLoadingHelper(*this); } ),
+ mExternalTextures(),
+ mLifecycleObservers(),
+ mBrokenImageUrl(""),
mCurrentTextureId( 0 )
{
}
}
TextureSet TextureManager::LoadTexture(
- const VisualUrl& url, Dali::ImageDimensions desiredSize, Dali::FittingMode::Type fittingMode,
- Dali::SamplingMode::Type samplingMode, const MaskingDataPointer& maskInfo,
- bool synchronousLoading, TextureManager::TextureId& textureId, Vector4& textureRect,
- bool& atlasingStatus, bool& loadingStatus, Dali::WrapMode::Type wrapModeU,
- Dali::WrapMode::Type wrapModeV, TextureUploadObserver* textureObserver,
- AtlasUploadObserver* atlasObserver, ImageAtlasManagerPtr imageAtlasManager, bool orientationCorrection,
- TextureManager::ReloadPolicy reloadPolicy, TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
+ const VisualUrl& url, Dali::ImageDimensions desiredSize, Dali::FittingMode::Type fittingMode,
+ Dali::SamplingMode::Type samplingMode, const MaskingDataPointer& maskInfo,
+ bool synchronousLoading, TextureManager::TextureId& textureId, Vector4& textureRect,
+ Dali::ImageDimensions& textureRectSize, bool& atlasingStatus, bool& loadingStatus,
+ Dali::WrapMode::Type wrapModeU, Dali::WrapMode::Type wrapModeV, TextureUploadObserver* textureObserver,
+ AtlasUploadObserver* atlasObserver, ImageAtlasManagerPtr imageAtlasManager, bool orientationCorrection,
+ TextureManager::ReloadPolicy reloadPolicy, TextureManager::MultiplyOnLoad& preMultiplyOnLoad )
{
TextureSet textureSet;
{
// use broken image
textureSet = TextureSet::New();
- Devel::PixelBuffer pixelBuffer = LoadImageFromFile( BROKEN_IMAGE_URL );
+ Devel::PixelBuffer pixelBuffer = LoadImageFromFile( mBrokenImageUrl );
if( pixelBuffer )
{
PreMultiply( pixelBuffer, preMultiplyOnLoad );
textureSet = TextureSet::New();
textureSet.SetTexture( 0u, texture );
}
+ else
+ {
+ textureRectSize.SetWidth(data.GetWidth());
+ textureRectSize.SetHeight(data.GetHeight());
+ }
}
}
else
loadingStatus = true;
if( atlasingStatus )
{
- textureSet = imageAtlasManager->Add( textureRect, url.GetUrl(), desiredSize, fittingMode, true, atlasObserver );
+ textureSet = imageAtlasManager->Add( textureRect, url.GetUrl(), desiredSize, fittingMode, true, atlasObserver);
}
if( !textureSet ) // big image, no atlasing or atlasing failed
{
textureSet = GetTextureSet( textureId );
}
}
+ else
+ {
+ textureRectSize = desiredSize;
+ }
}
if( ! atlasingStatus && textureSet )
}
}
-const VisualUrl& TextureManager::GetVisualUrl( TextureId textureId )
+VisualUrl TextureManager::GetVisualUrl( TextureId textureId )
{
+ VisualUrl visualUrl("");
int cacheIndex = GetCacheIndexFromId( textureId );
- DALI_ASSERT_DEBUG( cacheIndex != INVALID_CACHE_INDEX && "TextureId out of range");
- TextureInfo& cachedTextureInfo( mTextureInfoContainer[ cacheIndex ] );
- return cachedTextureInfo.url;
+ if( cacheIndex != INVALID_CACHE_INDEX )
+ {
+ DALI_LOG_INFO( gTextureManagerLogFilter, Debug::Concise, "TextureManager::GetVisualUrl. Using cached texture id=%d, textureId=%d\n",
+ cacheIndex, textureId );
+
+ TextureInfo& cachedTextureInfo( mTextureInfoContainer[ cacheIndex ] );
+ visualUrl = cachedTextureInfo.url;
+ }
+ return visualUrl;
}
TextureManager::LoadState TextureManager::GetTextureState( TextureId textureId )
float contentScale, bool cropToMask )
{
int maskCacheIndex = GetCacheIndexFromId( maskTextureId );
- Devel::PixelBuffer maskPixelBuffer = mTextureInfoContainer[maskCacheIndex].pixelBuffer;
- pixelBuffer.ApplyMask( maskPixelBuffer, contentScale, cropToMask );
+ if( maskCacheIndex != INVALID_CACHE_INDEX )
+ {
+ Devel::PixelBuffer maskPixelBuffer = mTextureInfoContainer[maskCacheIndex].pixelBuffer;
+ pixelBuffer.ApplyMask( maskPixelBuffer, contentScale, cropToMask );
+ }
}
{
// We are not including sizing information, but we still need an extra byte for atlasing.
hashTarget.resize( urlLength + 1u );
+
// Add the atlasing to the hash input.
- hashTarget[ urlLength ] = useAtlas;
+ switch( useAtlas )
+ {
+ case UseAtlas::NO_ATLAS:
+ {
+ hashTarget[ urlLength ] = 'f';
+ break;
+ }
+ case UseAtlas::USE_ATLAS:
+ {
+ hashTarget[ urlLength ] = 't';
+ break;
+ }
+ }
}
if( maskTextureId != INVALID_TEXTURE_ID )
mTextureManager.AsyncLoadComplete(mLoadingInfoContainer, id, pixelBuffer);
}
+void TextureManager::SetBrokenImageUrl(const std::string& brokenImageUrl)
+{
+ mBrokenImageUrl = brokenImageUrl;
+}
+
} // namespace Internal
} // namespace Toolkit