#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
#include <dali-toolkit/third-party/nanosvg/nanosvg.h>
#include <dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h>
#include <dali-toolkit/internal/visuals/image/image-visual.h>
+#include <dali-toolkit/internal/visuals/image-atlas-manager.h>
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
namespace Internal
{
-SvgVisual::SvgVisual( VisualFactoryCache& factoryCache, ImageAtlasManager& atlasManager )
+SvgVisual::SvgVisual( VisualFactoryCache& factoryCache )
: Visual::Base( factoryCache ),
mAtlasRect( FULL_TEXTURE_RECT ),
- mAtlasManager( atlasManager ),
mParsedImage( NULL )
{
// the rasterized image is with pre-multiplied alpha format
}
}
-bool SvgVisual::IsSvgUrl( const std::string& url )
-{
- return url.substr( url.find_last_of(".") + 1 ) == "svg";
-}
-
void SvgVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap )
{
- Property::Value* imageURLValue = propertyMap.Find( IMAGE_URL_NAME );
+ Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
if( imageURLValue )
{
std::string imageUrl;
void SvgVisual::DoSetOnStage( Actor& actor )
{
- Shader shader = ImageVisual::GetImageShader( mFactoryCache );
+ Shader shader = ImageVisual::GetImageShader( mFactoryCache, true, true );
Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
if( !geometry )
{
{
AddRasterizationTask( mImpl->mSize );
}
+
+ // Hold the weak handle of the placement actor and delay the adding of renderer until the svg rasterization is finished.
+ mPlacementActor = actor;
}
void SvgVisual::DoSetOffStage( Actor& actor )
actor.RemoveRenderer( mImpl->mRenderer );
mImpl->mRenderer.Reset();
+ mPlacementActor.Reset();
}
void SvgVisual::GetNaturalSize( Vector2& naturalSize ) const
void SvgVisual::DoCreatePropertyMap( Property::Map& map ) const
{
map.Clear();
- map.Insert( RENDERER_TYPE, IMAGE_RENDERER );
+ map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
if( !mImageUrl.empty() )
{
- map.Insert( IMAGE_URL_NAME, mImageUrl );
+ map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl );
}
}
+void SvgVisual::DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue )
+{
+ // TODO
+}
+
+Dali::Property::Value SvgVisual::DoGetProperty( Dali::Property::Index index )
+{
+ // TODO
+ return Dali::Property::Value();
+}
+
void SvgVisual::SetImage( const std::string& imageUrl, ImageDimensions size )
{
if( mImageUrl != imageUrl )
TextureSet currentTextureSet = mImpl->mRenderer.GetTextures();
if( mAtlasRect != FULL_TEXTURE_RECT )
{
- mAtlasManager.Remove( currentTextureSet, mAtlasRect );
+ mFactoryCache.GetAtlasManager()->Remove( currentTextureSet, mAtlasRect );
}
Vector4 atlasRect;
- TextureSet textureSet = mAtlasManager.Add(atlasRect, rasterizedPixelData );
+ TextureSet textureSet = mFactoryCache.GetAtlasManager()->Add(atlasRect, rasterizedPixelData );
if( textureSet ) // atlasing
{
if( textureSet != currentTextureSet )
}
mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, atlasRect );
mAtlasRect = atlasRect;
+ mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
}
else // no atlasing
{
Atlas texture = Atlas::New( rasterizedPixelData.GetWidth(), rasterizedPixelData.GetHeight() );
texture.Upload( rasterizedPixelData, 0, 0 );
+ mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
if( mAtlasRect == FULL_TEXTURE_RECT )
{
TextureSetImage( textureSet, 0u, texture );
}
}
+
+ // Rasterized pixels are uploaded to texture. If weak handle is holding a placement actor, it is the time to add the renderer to actor.
+ Actor actor = mPlacementActor.GetHandle();
+ if( actor )
+ {
+ actor.AddRenderer( mImpl->mRenderer );
+ // reset the weak handle so that the renderer only get added to actor once
+ mPlacementActor.Reset();
+ }
}
}
-
} // namespace Internal
} // namespace Toolkit