-void ImageVisual::LoadResourceSynchronously()
-{
- if( mImageUrl.IsValid() )
- {
- Devel::PixelBuffer pixelBuffer = LoadImageFromFile( mImageUrl.GetUrl(), mDesiredSize, mFittingMode, mSamplingMode );
-
- if( pixelBuffer )
- {
- mPixels = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
- }
- mTextureLoading = false;
- }
-}
-
-TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, bool synchronousLoading, bool attemptAtlasing )
-{
- TextureSet textureSet;
-
- mTextureLoading = false;
-
- textureRect = FULL_TEXTURE_RECT;
- if( synchronousLoading )
- {
- if( !mPixels )
- {
- // use broken image
- textureSet = TextureSet::New();
- TextureSetImage( textureSet, 0u, VisualFactoryCache::GetBrokenVisualImage() );
- }
- else
- {
- if( attemptAtlasing )
- {
- textureSet = mFactoryCache.GetAtlasManager()->Add(textureRect, mPixels );
- mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
- }
- if( !textureSet ) // big image, no atlasing or atlasing failed
- {
- mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
- Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, mPixels.GetPixelFormat(),
- mPixels.GetWidth(), mPixels.GetHeight() );
- texture.Upload( mPixels );
- textureSet = TextureSet::New();
- textureSet.SetTexture( 0u, texture );
- }
- }
- }
- else
- {
- if( attemptAtlasing )
- {
- textureSet = mFactoryCache.GetAtlasManager()->Add( textureRect, mImageUrl.GetUrl(), mDesiredSize, mFittingMode, true, this );
- mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
- mTextureLoading = true;
- }
- if( !textureSet ) // big image, no atlasing or atlasing failed
- {
- mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
- TextureManager& textureManager = mFactoryCache.GetTextureManager();
- if( mAlphaMaskId == TextureManager::INVALID_TEXTURE_ID )
- {
- mTextureId = textureManager.RequestLoad( mImageUrl, mDesiredSize, mFittingMode,
- mSamplingMode, TextureManager::NO_ATLAS, this );
- }
- else
- {
- mTextureId = textureManager.RequestLoad( mImageUrl, mAlphaMaskId, mDesiredSize,
- mFittingMode, mSamplingMode,
- TextureManager::NO_ATLAS, this );
- }
-
- TextureManager::LoadState loadState = textureManager.GetTextureState( mTextureId );
-
- mTextureLoading = ( loadState == TextureManager::LOADING );
-
- if( loadState == TextureManager::UPLOADED )
- {
- // UploadComplete has already been called - keep the same texture set
- textureSet = textureManager.GetTextureSet(mTextureId);
- }
- }
- }
-
- if( ! (mImpl->mFlags & Impl::IS_ATLASING_APPLIED) && textureSet )
- {
- Sampler sampler = Sampler::New();
- sampler.SetWrapMode( mWrapModeU, mWrapModeV );
- textureSet.SetSampler( 0u, sampler );
- }
-
- return textureSet;
-}
-