X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fsvg%2Fsvg-visual.cpp;h=b6f95205af934672d51babe71ffd3e03f5c2428e;hb=78c772dd32c14bd500d6d3378ffa3a6e87dc60fa;hp=ec19635ff53dadbb73fa834920a30776db42847c;hpb=f3e45e41c5f16ccc2538b283897ed6efb07e4ea9;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.cpp b/dali-toolkit/internal/visuals/svg/svg-visual.cpp index ec19635..b6f9520 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.cpp +++ b/dali-toolkit/internal/visuals/svg/svg-visual.cpp @@ -19,46 +19,43 @@ #include "svg-visual.h" // INTERNAL INCLUDES -#include #include -#include -#include #include +#include +#include +#include #include // EXTERNAL INCLUDES -#include #include +#include #include 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; @@ -90,7 +87,13 @@ void SvgVisual::OnInitialize() Shader shader; if(!mImpl->mCustomShader) { - shader = mImageVisualShaderFactory.GetShader(mFactoryCache, mAttemptAtlasing, true, IsRoundedCornerRequired()); + shader = mImageVisualShaderFactory.GetShader( + mFactoryCache, + mAttemptAtlasing ? TextureAtlas::ENABLED : TextureAtlas::DISABLED, + DefaultTextureWrapMode::APPLY, + IsRoundedCornerRequired() ? RoundedCorner::ENABLED : RoundedCorner::DISABLED, + IsBorderlineRequired() ? Borderline::ENABLED : Borderline::DISABLED + ); } else { @@ -105,42 +108,42 @@ void SvgVisual::OnInitialize() 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; } @@ -158,13 +161,13 @@ void SvgVisual::DoSetProperty( Property::Index index, const Property::Value& val } } -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) @@ -187,36 +190,36 @@ void SvgVisual::DoSetOnScene( Actor& actor ) } } -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 } @@ -231,8 +234,8 @@ void SvgVisual::Load() { 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; @@ -249,15 +252,15 @@ void SvgVisual::Load() } } -void SvgVisual::AddRasterizationTask( const Vector2& size ) +void SvgVisual::AddRasterizationTask(const Vector2& size) { - if( mImpl->mRenderer ) + if(mImpl->mRenderer) { - unsigned int width = static_cast(size.width); - unsigned int height = static_cast( size.height ); + unsigned int width = static_cast(size.width); + unsigned int height = static_cast(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()) @@ -268,76 +271,75 @@ void SvgVisual::AddRasterizationTask( const Vector2& size ) } 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) { @@ -352,19 +354,19 @@ void SvgVisual::ApplyRasterizedImage( VectorImageRenderer vectorRenderer, PixelD 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; } } @@ -377,8 +379,8 @@ void SvgVisual::OnSetTransform() 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