X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Ftexture-manager-impl.cpp;h=e79586351b4956c06851b08900555efcbf9f1e6d;hp=f0740874b39f7e7a3547b32f91449c6516fe525e;hb=93833d2c76d1cab9da6fce404739e95e093da911;hpb=4d305b893731daafafc293b92dc4fa25a896e929 diff --git a/dali-toolkit/internal/visuals/texture-manager-impl.cpp b/dali-toolkit/internal/visuals/texture-manager-impl.cpp index f074087..e795863 100644 --- a/dali-toolkit/internal/visuals/texture-manager-impl.cpp +++ b/dali-toolkit/internal/visuals/texture-manager-impl.cpp @@ -21,7 +21,9 @@ // EXTERNAL HEADERS #include #include +#include #include +#include #include #include #include @@ -30,6 +32,7 @@ // INTERNAL HEADERS #include #include +#include namespace { @@ -84,6 +87,13 @@ const int INVALID_CACHE_INDEX( -1 ); ///< Invalid Cache index } // Anonymous namespace +TextureManager::MaskingData::MaskingData() +: mAlphaMaskUrl(), + mAlphaMaskId( INVALID_TEXTURE_ID ), + mContentScaleFactor( 1.0f ), + mCropToMask( true ) +{ +} TextureManager::TextureManager() : mAsyncLocalLoaders( GetNumberOfLocalLoaderThreads(), [&]() { return AsyncLoadingHelper(*this); } ), @@ -92,6 +102,124 @@ TextureManager::TextureManager() { } +TextureSet TextureManager::LoadTexture( + 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) +{ + TextureSet textureSet; + + loadingStatus = false; + textureRect = FULL_ATLAS_RECT; + + if( VisualUrl::TEXTURE == url.GetProtocolType()) + { + std::string location = url.GetLocation(); + if( location.size() > 0u ) + { + TextureId id = std::stoi( location ); + for( auto&& elem : mExternalTextures ) + { + if( elem.textureId == id ) + { + return elem.textureSet; + } + } + } + } + else if( synchronousLoading ) + { + PixelData data; + if( url.IsValid() ) + { + Devel::PixelBuffer pixelBuffer = LoadImageFromFile( url.GetUrl(), desiredSize, fittingMode, samplingMode ); + if( pixelBuffer ) + { + data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer + } + } + if( !data ) + { + // use broken image + textureSet = TextureSet::New(); + Devel::PixelBuffer pixelBuffer = LoadImageFromFile( BROKEN_IMAGE_URL ); + if( pixelBuffer ) + { + data = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer + } + Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, data.GetPixelFormat(), + data.GetWidth(), data.GetHeight() ); + texture.Upload( data ); + textureSet = TextureSet::New(); + textureSet.SetTexture( 0u, texture ); + } + else + { + if( atlasingStatus ) // attempt atlasing + { + textureSet = imageAtlasManager->Add( textureRect, data ); + } + if( !textureSet ) // big image, no atlasing or atlasing failed + { + atlasingStatus = false; + Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, data.GetPixelFormat(), + data.GetWidth(), data.GetHeight() ); + texture.Upload( data ); + textureSet = TextureSet::New(); + textureSet.SetTexture( 0u, texture ); + } + } + } + else + { + loadingStatus = true; + if( atlasingStatus ) + { + textureSet = imageAtlasManager->Add( textureRect, url.GetUrl(), desiredSize, fittingMode, true, atlasObserver ); + } + if( !textureSet ) // big image, no atlasing or atlasing failed + { + atlasingStatus = false; + if( !maskInfo ) + { + textureId = RequestLoad( url, desiredSize, fittingMode, samplingMode, TextureManager::NO_ATLAS, textureObserver ); + } + else + { + textureId = RequestLoad( url, + maskInfo->mAlphaMaskId, + maskInfo->mContentScaleFactor, + desiredSize, + fittingMode, samplingMode, + TextureManager::NO_ATLAS, + maskInfo->mCropToMask, + textureObserver ); + } + + TextureManager::LoadState loadState = GetTextureState( textureId ); + loadingStatus = ( loadState == TextureManager::LOADING ); + + if( loadState == TextureManager::UPLOADED ) + { + // UploadComplete has already been called - keep the same texture set + textureSet = GetTextureSet( textureId ); + } + } + } + + if( ! atlasingStatus && textureSet ) + { + Sampler sampler = Sampler::New(); + sampler.SetWrapMode( wrapModeU, wrapModeV ); + textureSet.SetSampler( 0u, sampler ); + } + + return textureSet; +} + TextureManager::TextureId TextureManager::RequestLoad( const VisualUrl& url, const ImageDimensions desiredSize, @@ -123,7 +251,6 @@ TextureManager::TextureId TextureManager::RequestMaskLoad( const VisualUrl& mask return RequestLoadInternal( maskUrl, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, NO_ATLAS, false, KEEP_PIXEL_BUFFER, NULL ); } - TextureManager::TextureId TextureManager::RequestLoadInternal( const VisualUrl& url, TextureId maskTextureId, @@ -715,10 +842,6 @@ void TextureManager::ObserverDestroyed( TextureUploadObserver* observer ) } } -TextureManager::~TextureManager() -{ -} - TextureManager::AsyncLoadingHelper::AsyncLoadingHelper(TextureManager& textureManager) : AsyncLoadingHelper(Toolkit::AsyncImageLoader::New(), textureManager, AsyncLoadingInfoContainerType())