} // unnamed namespace
-ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache )
-{
- return new ImageVisual( factoryCache );
-}
-
ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache,
const std::string& imageUrl,
ImageDimensions size,
return new ImageVisual( factoryCache, image );
}
-ImageVisual::ImageVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
- mImage(),
- mPixels(),
- mPixelArea( FULL_TEXTURE_RECT ),
- mPlacementActor(),
- mImageUrl(),
- mDesiredSize(),
- mFittingMode( FittingMode::DEFAULT ),
- mSamplingMode( SamplingMode::DEFAULT ),
- mWrapModeU( WrapMode::DEFAULT ),
- mWrapModeV( WrapMode::DEFAULT )
-{
-}
-
ImageVisual::ImageVisual( VisualFactoryCache& factoryCache,
const std::string& imageUrl,
ImageDimensions size,
void ImageVisual::DoSetProperties( const Property::Map& propertyMap )
{
- Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
- if( imageURLValue )
+ // Url is already received in constructor
+ Property::Value* fittingValue = propertyMap.Find( Toolkit::ImageVisual::Property::FITTING_MODE, IMAGE_FITTING_MODE );
+ if( fittingValue )
{
- imageURLValue->Get( mImageUrl );
- if( !mImageUrl.empty() )
- {
- mImage.Reset();
- }
-
- Property::Value* fittingValue = propertyMap.Find( Toolkit::ImageVisual::Property::FITTING_MODE, IMAGE_FITTING_MODE );
- if( fittingValue )
- {
- int value;
- Scripting::GetEnumerationProperty( *fittingValue, FITTING_MODE_TABLE, FITTING_MODE_TABLE_COUNT, value );
- mFittingMode = Dali::FittingMode::Type( value );
- }
-
- Property::Value* samplingValue = propertyMap.Find( Toolkit::ImageVisual::Property::SAMPLING_MODE, IMAGE_SAMPLING_MODE );
- if( samplingValue )
- {
- int value;
- Scripting::GetEnumerationProperty( *samplingValue, SAMPLING_MODE_TABLE, SAMPLING_MODE_TABLE_COUNT, value );
- mSamplingMode = Dali::SamplingMode::Type( value );
- }
+ int value;
+ Scripting::GetEnumerationProperty( *fittingValue, FITTING_MODE_TABLE, FITTING_MODE_TABLE_COUNT, value );
+ mFittingMode = Dali::FittingMode::Type( value );
+ }
- int desiredWidth = 0;
- Property::Value* desiredWidthValue = propertyMap.Find( Toolkit::ImageVisual::Property::DESIRED_WIDTH, IMAGE_DESIRED_WIDTH );
- if( desiredWidthValue )
- {
- desiredWidthValue->Get( desiredWidth );
- }
+ Property::Value* samplingValue = propertyMap.Find( Toolkit::ImageVisual::Property::SAMPLING_MODE, IMAGE_SAMPLING_MODE );
+ if( samplingValue )
+ {
+ int value;
+ Scripting::GetEnumerationProperty( *samplingValue, SAMPLING_MODE_TABLE, SAMPLING_MODE_TABLE_COUNT, value );
+ mSamplingMode = Dali::SamplingMode::Type( value );
+ }
- int desiredHeight = 0;
- Property::Value* desiredHeightValue = propertyMap.Find( Toolkit::ImageVisual::Property::DESIRED_HEIGHT, IMAGE_DESIRED_HEIGHT );
- if( desiredHeightValue )
- {
- desiredHeightValue->Get( desiredHeight );
- }
+ int desiredWidth = 0;
+ Property::Value* desiredWidthValue = propertyMap.Find( Toolkit::ImageVisual::Property::DESIRED_WIDTH, IMAGE_DESIRED_WIDTH );
+ if( desiredWidthValue )
+ {
+ desiredWidthValue->Get( desiredWidth );
+ }
- Property::Value* pixelAreaValue = propertyMap.Find( Toolkit::ImageVisual::Property::PIXEL_AREA, PIXEL_AREA_UNIFORM_NAME );
- if( pixelAreaValue )
- {
- pixelAreaValue->Get( mPixelArea );
- }
+ int desiredHeight = 0;
+ Property::Value* desiredHeightValue = propertyMap.Find( Toolkit::ImageVisual::Property::DESIRED_HEIGHT, IMAGE_DESIRED_HEIGHT );
+ if( desiredHeightValue )
+ {
+ desiredHeightValue->Get( desiredHeight );
+ }
- Property::Value* wrapModeValueU = propertyMap.Find( Toolkit::ImageVisual::Property::WRAP_MODE_U, IMAGE_WRAP_MODE_U );
- if( wrapModeValueU )
- {
- int value;
- Scripting::GetEnumerationProperty( *wrapModeValueU, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, value );
- mWrapModeU = Dali::WrapMode::Type( value );
- }
+ Property::Value* pixelAreaValue = propertyMap.Find( Toolkit::ImageVisual::Property::PIXEL_AREA, PIXEL_AREA_UNIFORM_NAME );
+ if( pixelAreaValue )
+ {
+ pixelAreaValue->Get( mPixelArea );
+ }
- Property::Value* wrapModeValueV = propertyMap.Find( Toolkit::ImageVisual::Property::WRAP_MODE_V, IMAGE_WRAP_MODE_V );
- if( wrapModeValueV )
- {
- int value;
- Scripting::GetEnumerationProperty( *wrapModeValueV, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, value );
- mWrapModeV = Dali::WrapMode::Type( value );
- }
+ Property::Value* wrapModeValueU = propertyMap.Find( Toolkit::ImageVisual::Property::WRAP_MODE_U, IMAGE_WRAP_MODE_U );
+ if( wrapModeValueU )
+ {
+ int value;
+ Scripting::GetEnumerationProperty( *wrapModeValueU, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, value );
+ mWrapModeU = Dali::WrapMode::Type( value );
+ }
- mDesiredSize = ImageDimensions( desiredWidth, desiredHeight );
+ Property::Value* wrapModeValueV = propertyMap.Find( Toolkit::ImageVisual::Property::WRAP_MODE_V, IMAGE_WRAP_MODE_V );
+ if( wrapModeValueV )
+ {
+ int value;
+ Scripting::GetEnumerationProperty( *wrapModeValueV, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, value );
+ mWrapModeV = Dali::WrapMode::Type( value );
}
+ mDesiredSize = ImageDimensions( desiredWidth, desiredHeight );
+
Property::Value* syncLoading = propertyMap.Find( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, SYNCHRONOUS_LOADING );
if( syncLoading )
{
mImpl->mFlags |= Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
// if sync loading is required, the loading should start immediately when new image url is set or the actor is off stage
// ( for on-stage actor with image url unchanged, resource loading is already finished)
- if( imageURLValue )
+ if( mImageUrl.size() > 0u )
{
LoadResourceSynchronously();
}
}
}
-void ImageVisual::GetNaturalSize( Vector2& naturalSize ) const
+void ImageVisual::GetNaturalSize( Vector2& naturalSize )
{
if(mImage)
{
void ImageVisual::InitializeRenderer( const std::string& imageUrl )
{
- if( imageUrl.empty() )
- {
- return;
- }
+ DALI_ASSERT_DEBUG( !mImpl->mRenderer && "Renderer should have been removed from stage and already reset before initialization" );
mImageUrl = imageUrl;
- mImpl->mRenderer.Reset();
mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
if( !mImpl->mCustomShader &&
void ImageVisual::InitializeRenderer( const Image& image )
{
+ DALI_ASSERT_DEBUG( !mImpl->mRenderer && "Renderer should have been removed from stage and already reset before initialization" );
+
mImpl->mFlags &= ~Impl::IS_FROM_CACHE;
// don't reuse CreateTextureSet
// reuse existing code for regular images
CreateRenderer( textures );
}
-
- if( image )
- {
- ApplyImageToSampler( image );
- }
+ ApplyImageToSampler( image );
}
void ImageVisual::UploadCompleted()
void ImageVisual::DoSetOnStage( Actor& actor )
{
- mPlacementActor = actor;
-
if( !mImageUrl.empty() )
{
InitializeRenderer( mImageUrl );
}
- else
+ else if ( mImage )
{
InitializeRenderer( mImage );
}
+ if ( !mImpl->mRenderer)
+ {
+ return;
+ }
+
+ mPlacementActor = actor;
+
if( mPixelArea != FULL_TEXTURE_RECT )
{
mImpl->mRenderer.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, mPixelArea );
void ImageVisual::DoSetOffStage( Actor& actor )
{
+ // Visual::Base::SetOffStage only calls DoSetOffStage if mRenderer exists (is on onstage)
+
//If we own the image then make sure we release it when we go off stage
+ actor.RemoveRenderer( mImpl->mRenderer);
if( !mImageUrl.empty() )
{
- actor.RemoveRenderer( mImpl->mRenderer );
CleanCache(mImageUrl);
mImage.Reset();
}
- else
- {
- actor.RemoveRenderer( mImpl->mRenderer );
- mImpl->mRenderer.Reset();
- }
+
+ mImpl->mRenderer.Reset();
mPlacementActor.Reset();
}
if( !shader )
{
shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_ATLAS_CLAMP );
+ shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_DEFAULT_WRAP, shader );
}
}
if( !shader )
{
shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_ATLAS_VARIOUS_WRAP );
+ shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_CUSTOM_WRAP, shader );
}
}
if( !shader )
{
shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_NO_ATLAS );
+ shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER, shader );
}
}
- shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
+
return shader;
}