#include "svg-visual.h"
// INTERNAL INCLUDES
-#include <dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h>
#include <dali-toolkit/internal/visuals/image-atlas-manager.h>
-#include <dali-toolkit/internal/visuals/visual-string-constants.h>
-#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
#include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
+#include <dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h>
+#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
// EXTERNAL INCLUDES
-#include <dali/devel-api/common/stage.h>
#include <dali/devel-api/adaptor-framework/file-loader.h>
+#include <dali/devel-api/common/stage.h>
#include <dali/integration-api/debug.h>
namespace Dali
{
-
namespace Toolkit
{
-
namespace Internal
{
-
namespace
{
// property name
const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
-}
+} // namespace
-SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties )
+SvgVisualPtr SvgVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties)
{
- SvgVisualPtr svgVisual( new SvgVisual( factoryCache, shaderFactory, imageUrl ) );
+ SvgVisualPtr svgVisual(new SvgVisual(factoryCache, shaderFactory, imageUrl));
svgVisual->Load();
svgVisual->SetProperties(properties);
svgVisual->Initialize();
return svgVisual;
}
-SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl )
+SvgVisualPtr SvgVisual::New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl)
{
- SvgVisualPtr svgVisual( new SvgVisual( factoryCache, shaderFactory, imageUrl ) );
+ SvgVisualPtr svgVisual(new SvgVisual(factoryCache, shaderFactory, imageUrl));
svgVisual->Load();
svgVisual->Initialize();
return svgVisual;
mImpl->mRenderer = Renderer::New(geometry, shader);
}
-void SvgVisual::DoSetProperties( const Property::Map& propertyMap )
+void SvgVisual::DoSetProperties(const Property::Map& propertyMap)
{
// url already passed in from constructor
- for( Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter )
+ for(Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter)
{
- KeyValuePair keyValue = propertyMap.GetKeyValue( iter );
- if( keyValue.first.type == Property::Key::INDEX )
+ KeyValuePair keyValue = propertyMap.GetKeyValue(iter);
+ if(keyValue.first.type == Property::Key::INDEX)
{
- DoSetProperty( keyValue.first.indexKey, keyValue.second );
+ DoSetProperty(keyValue.first.indexKey, keyValue.second);
}
- else if( keyValue.first == IMAGE_ATLASING )
+ else if(keyValue.first == IMAGE_ATLASING)
{
- DoSetProperty( Toolkit::ImageVisual::Property::ATLASING, keyValue.second );
+ DoSetProperty(Toolkit::ImageVisual::Property::ATLASING, keyValue.second);
}
- else if( keyValue.first == SYNCHRONOUS_LOADING )
+ else if(keyValue.first == SYNCHRONOUS_LOADING)
{
- DoSetProperty( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second );
+ DoSetProperty(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second);
}
}
}
-void SvgVisual::DoSetProperty( Property::Index index, const Property::Value& value )
+void SvgVisual::DoSetProperty(Property::Index index, const Property::Value& value)
{
- switch( index )
+ switch(index)
{
case Toolkit::ImageVisual::Property::ATLASING:
{
- value.Get( mAttemptAtlasing );
+ value.Get(mAttemptAtlasing);
break;
}
case Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING:
{
bool sync = false;
- if( value.Get( sync ) )
+ if(value.Get(sync))
{
- if( sync )
+ if(sync)
{
mImpl->mFlags |= Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
}
}
}
-void SvgVisual::DoSetOnScene( Actor& actor )
+void SvgVisual::DoSetOnScene(Actor& actor)
{
TextureSet textureSet = TextureSet::New();
- mImpl->mRenderer.SetTextures( textureSet );
+ mImpl->mRenderer.SetTextures(textureSet);
// Register transform properties
- mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
+ mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
// Defer the rasterisation task until we get given a size (by Size Negotiation algorithm)
}
}
-void SvgVisual::DoSetOffScene( Actor& actor )
+void SvgVisual::DoSetOffScene(Actor& actor)
{
- mFactoryCache.GetSVGRasterizationThread()->RemoveTask( this );
+ mFactoryCache.GetSVGRasterizationThread()->RemoveTask(this);
- actor.RemoveRenderer( mImpl->mRenderer );
+ actor.RemoveRenderer(mImpl->mRenderer);
mPlacementActor.Reset();
// Reset the visual size to zero so that when adding the actor back to stage the SVG rasterization is forced
mVisualSize = Vector2::ZERO;
}
-void SvgVisual::GetNaturalSize( Vector2& naturalSize )
+void SvgVisual::GetNaturalSize(Vector2& naturalSize)
{
naturalSize.x = mDefaultWidth;
naturalSize.y = mDefaultHeight;
}
-void SvgVisual::DoCreatePropertyMap( Property::Map& map ) const
+void SvgVisual::DoCreatePropertyMap(Property::Map& map) const
{
map.Clear();
- map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::SVG );
- if( mImageUrl.IsValid() )
+ map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::SVG);
+ if(mImageUrl.IsValid())
{
- map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() );
- map.Insert( Toolkit::ImageVisual::Property::ATLASING, mAttemptAtlasing );
+ map.Insert(Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl());
+ map.Insert(Toolkit::ImageVisual::Property::ATLASING, mAttemptAtlasing);
}
- map.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, IsSynchronousLoadingRequired() );
+ map.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, IsSynchronousLoadingRequired());
}
-void SvgVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
+void SvgVisual::DoCreateInstancePropertyMap(Property::Map& map) const
{
// Do nothing
}
{
buffer.PushBack('\0');
- Vector2 dpi = Stage::GetCurrent().GetDpi();
- float meanDpi = (dpi.height + dpi.width) * 0.5f;
+ Vector2 dpi = Stage::GetCurrent().GetDpi();
+ float meanDpi = (dpi.height + dpi.width) * 0.5f;
if(!mVectorRenderer.Load(buffer, meanDpi))
{
mLoadFailed = true;
}
}
-void SvgVisual::AddRasterizationTask( const Vector2& size )
+void SvgVisual::AddRasterizationTask(const Vector2& size)
{
- if( mImpl->mRenderer )
+ if(mImpl->mRenderer)
{
- unsigned int width = static_cast<unsigned int>(size.width);
- unsigned int height = static_cast<unsigned int>( size.height );
+ unsigned int width = static_cast<unsigned int>(size.width);
+ unsigned int height = static_cast<unsigned int>(size.height);
- Vector2 dpi = Stage::GetCurrent().GetDpi();
- float meanDpi = ( dpi.height + dpi.width ) * 0.5f;
+ Vector2 dpi = Stage::GetCurrent().GetDpi();
+ float meanDpi = (dpi.height + dpi.width) * 0.5f;
RasterizingTaskPtr newTask = new RasterizingTask(this, mVectorRenderer, mImageUrl, meanDpi, width, height);
if(IsSynchronousLoadingRequired() && mImageUrl.IsLocalResource())
}
else
{
- mFactoryCache.GetSVGRasterizationThread()->AddTask( newTask );
+ mFactoryCache.GetSVGRasterizationThread()->AddTask(newTask);
}
}
}
-void SvgVisual::ApplyRasterizedImage( VectorImageRenderer vectorRenderer, PixelData rasterizedPixelData, bool isLoaded )
+void SvgVisual::ApplyRasterizedImage(VectorImageRenderer vectorRenderer, PixelData rasterizedPixelData, bool isLoaded)
{
if(isLoaded && rasterizedPixelData && IsOnScene())
{
TextureSet currentTextureSet = mImpl->mRenderer.GetTextures();
- if( mImpl->mFlags & Impl::IS_ATLASING_APPLIED )
+ if(mImpl->mFlags & Impl::IS_ATLASING_APPLIED)
{
- mFactoryCache.GetAtlasManager()->Remove( currentTextureSet, mAtlasRect );
+ mFactoryCache.GetAtlasManager()->Remove(currentTextureSet, mAtlasRect);
}
TextureSet textureSet;
- if( mAttemptAtlasing && !mImpl->mCustomShader )
+ if(mAttemptAtlasing && !mImpl->mCustomShader)
{
Vector4 atlasRect;
- textureSet = mFactoryCache.GetAtlasManager()->Add(atlasRect, rasterizedPixelData );
- if( textureSet ) // atlasing
+ textureSet = mFactoryCache.GetAtlasManager()->Add(atlasRect, rasterizedPixelData);
+ if(textureSet) // atlasing
{
- if( textureSet != currentTextureSet )
+ if(textureSet != currentTextureSet)
{
- mImpl->mRenderer.SetTextures( textureSet );
+ mImpl->mRenderer.SetTextures(textureSet);
}
- mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, atlasRect );
+ mImpl->mRenderer.RegisterProperty(ATLAS_RECT_UNIFORM_NAME, atlasRect);
mAtlasRect = atlasRect;
mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
}
}
- if( !textureSet ) // no atlasing - mAttemptAtlasing is false or adding to atlas is failed
+ if(!textureSet) // no atlasing - mAttemptAtlasing is false or adding to atlas is failed
{
- Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, Pixel::RGBA8888,
- rasterizedPixelData.GetWidth(), rasterizedPixelData.GetHeight() );
- texture.Upload( rasterizedPixelData );
+ Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, Pixel::RGBA8888, rasterizedPixelData.GetWidth(), rasterizedPixelData.GetHeight());
+ texture.Upload(rasterizedPixelData);
mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
- if( mAtlasRect == FULL_TEXTURE_RECT )
+ if(mAtlasRect == FULL_TEXTURE_RECT)
{
textureSet = currentTextureSet;
}
else
{
textureSet = TextureSet::New();
- mImpl->mRenderer.SetTextures( textureSet );
+ mImpl->mRenderer.SetTextures(textureSet);
- mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, FULL_TEXTURE_RECT );
+ mImpl->mRenderer.RegisterProperty(ATLAS_RECT_UNIFORM_NAME, FULL_TEXTURE_RECT);
mAtlasRect = FULL_TEXTURE_RECT;
}
- if( textureSet )
+ if(textureSet)
{
- textureSet.SetTexture( 0, texture );
+ textureSet.SetTexture(0, 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 )
+ if(actor)
{
- actor.AddRenderer( mImpl->mRenderer );
+ actor.AddRenderer(mImpl->mRenderer);
// reset the weak handle so that the renderer only get added to actor once
mPlacementActor.Reset();
}
// Svg loaded and ready to display
- ResourceReady( Toolkit::Visual::ResourceStatus::READY );
+ ResourceReady(Toolkit::Visual::ResourceStatus::READY);
}
else if(!isLoaded || !rasterizedPixelData)
{
actor.AddRenderer(mImpl->mRenderer);
}
- ResourceReady( Toolkit::Visual::ResourceStatus::FAILED );
+ ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
}
}
void SvgVisual::OnSetTransform()
{
- Vector2 visualSize = mImpl->mTransform.GetVisualSize( mImpl->mControlSize );
+ Vector2 visualSize = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
if(IsOnScene() && !mLoadFailed)
{
- if( visualSize != mVisualSize )
+ if(visualSize != mVisualSize)
{
- AddRasterizationTask( visualSize );
+ AddRasterizationTask(visualSize);
mVisualSize = visualSize;
}
}
bool SvgVisual::IsResourceReady() const
{
- return ( mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY ||
- mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::FAILED );
+ return (mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY ||
+ mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::FAILED);
}
} // namespace Internal