X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fsvg%2Fsvg-visual.cpp;h=051affee8cc3191cb1cb20258a1c8a14dc976f7f;hp=bf7641d8c901ca42e767f5cc5aa85c5ace7c0eff;hb=5a6809a40da6a50d2edce9202466aa289ad96162;hpb=169a6db26753977f60fec8f1fe4bb671826d4173 diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.cpp b/dali-toolkit/internal/visuals/svg/svg-visual.cpp index bf7641d..051affe 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.cpp +++ b/dali-toolkit/internal/visuals/svg/svg-visual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,34 +18,17 @@ // CLASS HEADER #include "svg-visual.h" -// EXTERNAL INCLUDES -#include -#include -#include -#include -#include - // INTERNAL INCLUDES -#include -#include #include #include -#include #include -#include #include #include +#include +#include - -namespace -{ -const char * const UNITS("px"); - -// property name -const char * const IMAGE_ATLASING( "atlasing" ); - -const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); -} +// EXTERNAL INCLUDES +#include namespace Dali { @@ -56,27 +39,38 @@ namespace Toolkit namespace Internal { -SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties ) +namespace { - SvgVisualPtr svgVisual( new SvgVisual( factoryCache ) ); +// property name +const char * const UNITS("px"); + +const char * const IMAGE_ATLASING( "atlasing" ); + +const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); +} + +SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties ) +{ + SvgVisualPtr svgVisual( new SvgVisual( factoryCache, shaderFactory, imageUrl ) ); svgVisual->ParseFromUrl( imageUrl ); svgVisual->SetProperties( properties ); return svgVisual; } -SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl ) +SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl ) { - SvgVisualPtr svgVisual( new SvgVisual( factoryCache ) ); + SvgVisualPtr svgVisual( new SvgVisual( factoryCache, shaderFactory, imageUrl ) ); svgVisual->ParseFromUrl( imageUrl ); return svgVisual; } -SvgVisual::SvgVisual( VisualFactoryCache& factoryCache ) +SvgVisual::SvgVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl ) : Visual::Base( factoryCache, Visual::FittingMode::FILL ), + mImageVisualShaderFactory( shaderFactory ), mAtlasRect( FULL_TEXTURE_RECT ), - mImageUrl( ), + mImageUrl( imageUrl ), mParsedImage( NULL ), mPlacementActor(), mVisualSize(Vector2::ZERO), @@ -125,7 +119,20 @@ void SvgVisual::DoSetProperty( Property::Index index, const Property::Value& val void SvgVisual::DoSetOnStage( Actor& actor ) { - Shader shader = ImageVisual::GetImageShader( mFactoryCache, mAttemptAtlasing, true ); + Shader shader; + if( !mImpl->mCustomShader ) + { + shader = mImageVisualShaderFactory.GetShader( mFactoryCache, mAttemptAtlasing, true ); + } + else + { + shader = Shader::New( mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource() : mImpl->mCustomShader->mVertexShader, + mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource() : mImpl->mCustomShader->mFragmentShader, + mImpl->mCustomShader->mHints ); + + shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); + } + Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY ); TextureSet textureSet = TextureSet::New(); mImpl->mRenderer = Renderer::New( geometry, shader ); @@ -190,36 +197,44 @@ void SvgVisual::ParseFromUrl( const VisualUrl& imageUrl ) if( mImageUrl.IsLocalResource() ) { Vector2 dpi = Stage::GetCurrent().GetDpi(); - float meanDpi = (dpi.height + dpi.width) * 0.5f; - mParsedImage = nsvgParseFromFile( mImageUrl.GetUrl().c_str(), UNITS, meanDpi ); + float meanDpi = ( dpi.height + dpi.width ) * 0.5f; + Dali::Vector buffer; + if ( Dali::FileLoader::ReadFile( mImageUrl.GetUrl(), buffer ) ) + { + buffer.PushBack( '\0' ); + mParsedImage = nsvgParse( buffer.Begin(), UNITS, meanDpi ); + } } } void SvgVisual::AddRasterizationTask( const Vector2& size ) { - if( mImpl->mRenderer && mParsedImage ) + if( mImpl->mRenderer ) { unsigned int width = static_cast(size.width); unsigned int height = static_cast( size.height ); - RasterizingTaskPtr newTask = new RasterizingTask( this, mParsedImage, width, height ); + Vector2 dpi = Stage::GetCurrent().GetDpi(); + float meanDpi = ( dpi.height + dpi.width ) * 0.5f; + + RasterizingTaskPtr newTask = new RasterizingTask( this, mParsedImage, mImageUrl, meanDpi, width, height ); mFactoryCache.GetSVGRasterizationThread()->AddTask( newTask ); } } -void SvgVisual::ApplyRasterizedImage( PixelData rasterizedPixelData ) +void SvgVisual::ApplyRasterizedImage( NSVGimage* parsedSvg, PixelData rasterizedPixelData ) { - if( IsOnStage() ) + if( mParsedImage && IsOnStage() ) { TextureSet currentTextureSet = mImpl->mRenderer.GetTextures(); - if( mImpl->mFlags |= Impl::IS_ATLASING_APPLIED ) + if( mImpl->mFlags & Impl::IS_ATLASING_APPLIED ) { mFactoryCache.GetAtlasManager()->Remove( currentTextureSet, mAtlasRect ); } TextureSet textureSet; - if( mAttemptAtlasing ) + if( mAttemptAtlasing && !mImpl->mCustomShader ) { Vector4 atlasRect; textureSet = mFactoryCache.GetAtlasManager()->Add(atlasRect, rasterizedPixelData ); @@ -279,7 +294,7 @@ void SvgVisual::OnSetTransform() { Vector2 visualSize = mImpl->mTransform.GetVisualSize( mImpl->mControlSize ); - if( mParsedImage && IsOnStage() ) + if( IsOnStage() ) { if( visualSize != mVisualSize ) { @@ -287,6 +302,11 @@ void SvgVisual::OnSetTransform() mVisualSize = visualSize; } } + + if(mImpl->mRenderer) + { + mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT); + } } } // namespace Internal