From 5a936aac073676657d48db5c42e5d2ad3f5cac9f Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Mon, 25 Apr 2022 19:41:39 +0900 Subject: [PATCH] Make some visual use DecoratedVisualRenderer Make some visual use DecoratedVisualRenderer s.t. use some properties as default : CORNER_RADIUS CORNER_RADIUS_POLICY BORDERLINE_WIDTH BORDERLINE_COLOR BORDERLINE_OFFSET BLUR_RADIUS Now BORDERLINE_WIDTH and BLUR_RADIUS informations can be accessed in dali-core level. So we can calculate update size Change-Id: Ib9d20d202a939acf70eac12f602b05c1451e1030 Signed-off-by: Eunki, Hong --- .../src/dali-toolkit/utc-Dali-Transition.cpp | 65 ++--- .../animated-image/animated-image-visual.cpp | 11 +- .../animated-vector-image-visual.cpp | 5 +- .../internal/visuals/color/color-visual.cpp | 76 ++++-- dali-toolkit/internal/visuals/color/color-visual.h | 13 +- .../internal/visuals/gradient/gradient-visual.cpp | 5 +- .../internal/visuals/image/image-visual.cpp | 11 +- dali-toolkit/internal/visuals/svg/svg-visual.cpp | 5 +- .../internal/visuals/visual-base-data-impl.cpp | 4 - .../internal/visuals/visual-base-data-impl.h | 4 - dali-toolkit/internal/visuals/visual-base-impl.cpp | 302 +++++++++++---------- dali-toolkit/internal/visuals/visual-base-impl.h | 5 + 12 files changed, 271 insertions(+), 235 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Transition.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Transition.cpp index 332e771..784af73 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Transition.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Transition.cpp @@ -24,6 +24,7 @@ #include #include #include +#include // for Renderer Property Index. #include #include @@ -287,18 +288,14 @@ int UtcDaliTransitionBetweenControlPair(void) DALI_TEST_NOT_EQUALS(destinationPosition, control2.GetCurrentProperty(Actor::Property::POSITION), 0.00001f, TEST_LOCATION); DALI_TEST_EQUALS(1, control2.GetRendererCount(), TEST_LOCATION); - Dali::Renderer renderer = control2.GetRendererAt(0); - Property::Index index = renderer.GetPropertyIndex(DevelVisual::Property::CORNER_RADIUS); - cornerRadius = renderer.GetCurrentProperty(index); + Dali::Renderer renderer = control2.GetRendererAt(0); + cornerRadius = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS); DALI_TEST_NOT_EQUALS(destinationRadiusV4, cornerRadius, 0.00001f, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_WIDTH); - borderlineWidth = renderer.GetCurrentProperty(index); + borderlineWidth = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH); DALI_TEST_NOT_EQUALS(destinationBorderlineWidth, borderlineWidth, 0.00001f, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_COLOR); - borderlineColor = renderer.GetCurrentProperty(index); + borderlineColor = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR); DALI_TEST_NOT_EQUALS(destinationBorderlineColor, borderlineColor, 0.00001f, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_OFFSET); - borderlineOffset = renderer.GetCurrentProperty(index); + borderlineOffset = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET); DALI_TEST_NOT_EQUALS(destinationBorderlineOffset, borderlineOffset, 0.00001f, TEST_LOCATION); application.SendNotification(); @@ -318,17 +315,13 @@ int UtcDaliTransitionBetweenControlPair(void) DALI_TEST_EQUALS(destinationOpacity, control2.GetCurrentProperty(Actor::Property::OPACITY), TEST_LOCATION); DALI_TEST_EQUALS(1, control2.GetRendererCount(), TEST_LOCATION); renderer = control2.GetRendererAt(0); - index = renderer.GetPropertyIndex(DevelVisual::Property::CORNER_RADIUS); - cornerRadius = renderer.GetCurrentProperty(index); + cornerRadius = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS); DALI_TEST_EQUALS(destinationRadiusV4, cornerRadius, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_WIDTH); - borderlineWidth = renderer.GetCurrentProperty(index); + borderlineWidth = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH); DALI_TEST_EQUALS(destinationBorderlineWidth, borderlineWidth, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_COLOR); - borderlineColor = renderer.GetCurrentProperty(index); + borderlineColor = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR); DALI_TEST_EQUALS(destinationBorderlineColor, borderlineColor, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_OFFSET); - borderlineOffset = renderer.GetCurrentProperty(index); + borderlineOffset = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET); DALI_TEST_EQUALS(destinationBorderlineOffset, borderlineOffset, TEST_LOCATION); END_TEST; @@ -431,21 +424,17 @@ int UtcDaliTransitionBetweenControlPair2(void) DALI_TEST_NOT_EQUALS(destinationPosition, control1.GetCurrentProperty(Actor::Property::POSITION), 0.00001f, TEST_LOCATION); DALI_TEST_EQUALS(1, control1.GetRendererCount(), TEST_LOCATION); - Dali::Renderer renderer = control1.GetRendererAt(0); - Property::Index index = renderer.GetPropertyIndex(DevelVisual::Property::CORNER_RADIUS); - cornerRadius = renderer.GetCurrentProperty(index); + Dali::Renderer renderer = control1.GetRendererAt(0); + cornerRadius = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS); DALI_TEST_NOT_EQUALS(destinationRadiusV4, cornerRadius, 0.00001f, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_WIDTH); - borderlineWidth = renderer.GetCurrentProperty(index); + borderlineWidth = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH); DALI_TEST_NOT_EQUALS(destinationBorderlineWidth, borderlineWidth, 0.00001f, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_COLOR); - borderlineColor = renderer.GetCurrentProperty(index); + borderlineColor = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR); DALI_TEST_NOT_EQUALS(destinationBorderlineColor, borderlineColor, 0.00001f, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_OFFSET); - borderlineOffset = renderer.GetCurrentProperty(index); + borderlineOffset = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET); DALI_TEST_NOT_EQUALS(destinationBorderlineOffset, borderlineOffset, 0.00001f, TEST_LOCATION); application.SendNotification(); @@ -465,20 +454,16 @@ int UtcDaliTransitionBetweenControlPair2(void) DALI_TEST_EQUALS(1, control1.GetRendererCount(), TEST_LOCATION); renderer = control1.GetRendererAt(0); - index = renderer.GetPropertyIndex(DevelVisual::Property::CORNER_RADIUS); - cornerRadius = renderer.GetCurrentProperty(index); + cornerRadius = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS); DALI_TEST_EQUALS(destinationRadiusV4, cornerRadius, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_WIDTH); - borderlineWidth = renderer.GetCurrentProperty(index); + borderlineWidth = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH); DALI_TEST_EQUALS(destinationBorderlineWidth, borderlineWidth, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_COLOR); - borderlineColor = renderer.GetCurrentProperty(index); + borderlineColor = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR); DALI_TEST_EQUALS(destinationBorderlineColor, borderlineColor, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_OFFSET); - borderlineOffset = renderer.GetCurrentProperty(index); + borderlineOffset = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET); DALI_TEST_EQUALS(destinationBorderlineOffset, borderlineOffset, TEST_LOCATION); // every actor properties of control1 are returned to the source properties. @@ -494,20 +479,16 @@ int UtcDaliTransitionBetweenControlPair2(void) // after next update, renderer properties are returned to the source properties. DALI_TEST_EQUALS(1, control1.GetRendererCount(), TEST_LOCATION); renderer = control1.GetRendererAt(0); - index = renderer.GetPropertyIndex(DevelVisual::Property::CORNER_RADIUS); - cornerRadius = renderer.GetCurrentProperty(index); + cornerRadius = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS); DALI_TEST_EQUALS(sourceRadiusV4, cornerRadius, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_WIDTH); - borderlineWidth = renderer.GetCurrentProperty(index); + borderlineWidth = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH); DALI_TEST_EQUALS(sourceBorderlineWidth, borderlineWidth, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_COLOR); - borderlineColor = renderer.GetCurrentProperty(index); + borderlineColor = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR); DALI_TEST_EQUALS(sourceBorderlineColor, borderlineColor, TEST_LOCATION); - index = renderer.GetPropertyIndex(DevelVisual::Property::BORDERLINE_OFFSET); - borderlineOffset = renderer.GetCurrentProperty(index); + borderlineOffset = renderer.GetCurrentProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET); DALI_TEST_EQUALS(sourceBorderlineOffset, borderlineOffset, TEST_LOCATION); END_TEST; diff --git a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp index a334e2f..382d52b 100644 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include #include // INTERNAL INCLUDES @@ -46,7 +47,7 @@ namespace Internal { namespace { -const int CUSTOM_PROPERTY_COUNT(10); // ltr, wrap, pixel area, crop to mask, mask texture ratio + border/corner +const int CUSTOM_PROPERTY_COUNT(5); // ltr, wrap, pixel area, crop to mask, mask texture ratio // stop behavior DALI_ENUM_TO_STRING_TABLE_BEGIN(STOP_BEHAVIOR) @@ -177,7 +178,7 @@ void AnimatedImageVisual::CreateImageCache() if(mAnimatedImageLoading) { - mImageCache = new RollingAnimatedImageCache(textureManager, mAnimatedImageLoading, mMaskingData, *this, mCacheSize, mBatchSize, IsSynchronousLoadingRequired(),mFactoryCache.GetPreMultiplyOnLoad()); + mImageCache = new RollingAnimatedImageCache(textureManager, mAnimatedImageLoading, mMaskingData, *this, mCacheSize, mBatchSize, IsSynchronousLoadingRequired(), mFactoryCache.GetPreMultiplyOnLoad()); } else if(mImageUrls) { @@ -730,7 +731,7 @@ void AnimatedImageVisual::OnInitialize() Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY); - mImpl->mRenderer = VisualRenderer::New(geometry, shader); + mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader); mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT); // Register transform properties @@ -979,8 +980,8 @@ void AnimatedImageVisual::CheckMaskTexture() { if(mMaskingData && !mMaskingData->mPreappliedMasking) { - bool maskLoadFailed = true; - TextureSet textures = mImpl->mRenderer.GetTextures(); + bool maskLoadFailed = true; + TextureSet textures = mImpl->mRenderer.GetTextures(); if(textures && textures.GetTextureCount() >= TEXTURE_COUNT_FOR_GPU_ALPHA_MASK) { maskLoadFailed = false; diff --git a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp index f4e3059..1017ae0 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp @@ -23,6 +23,7 @@ #include #include #include +#include // INTERNAL INCLUDES #include @@ -44,7 +45,7 @@ namespace Internal { namespace { -const int CUSTOM_PROPERTY_COUNT(6); // 5 transform properties + pixel area, +const int CUSTOM_PROPERTY_COUNT(1); // pixel area, const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); @@ -299,7 +300,7 @@ void AnimatedVectorImageVisual::OnInitialize(void) Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY); - mImpl->mRenderer = VisualRenderer::New(geometry, shader); + mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader); mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT); TextureSet textureSet = TextureSet::New(); diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index ba5e0c6..09fd60e 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include //INTERNAL INCLUDES #include @@ -41,7 +42,7 @@ namespace Internal { namespace { -const int CUSTOM_PROPERTY_COUNT(6); // Blur Radius + border/corner +const int CUSTOM_PROPERTY_COUNT(0); VisualFactoryCache::ShaderType SHADER_TYPE_TABLE[6] = { @@ -73,7 +74,6 @@ ColorVisualPtr ColorVisual::New(VisualFactoryCache& factoryCache, const Property ColorVisual::ColorVisual(VisualFactoryCache& factoryCache) : Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::COLOR), mBlurRadius(0.0f), - mBlurRadiusIndex(Property::INVALID_INDEX), mAlwaysUsingBlurRadius(false) { } @@ -117,25 +117,26 @@ void ColorVisual::DoSetProperties(const Property::Map& propertyMap) DALI_LOG_ERROR("ColorVisual:DoSetProperties:: BLUR_RADIUS property has incorrect type: %d\n", blurRadiusValue->GetType()); } - if(mBlurRadiusIndex != Property::INVALID_INDEX) - { - mImpl->mRenderer.SetProperty(mBlurRadiusIndex, mBlurRadius); - } - else if(DALI_UNLIKELY(mImpl->mRenderer && (!EqualsZero(mBlurRadius) || mAlwaysUsingBlurRadius))) + if(DALI_UNLIKELY(mImpl->mRenderer)) { // Unusual case. SetProperty called after OnInitialize(). // Assume that DoAction call UPDATE_PROPERTY. - // We must regist properies into renderer, and update shader. - - // BlurRadius added by this action. Regist property to renderer. - mBlurRadiusIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_NAME, mBlurRadius); - mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + DownCast(mImpl->mRenderer).RegisterBlurRadiusUniform(); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BLUR_RADIUS, mBlurRadius); - // Change the shader must not be occured many times. we always have to use blur feature. - mAlwaysUsingBlurRadius = true; - - // Change shader - UpdateShader(); + // Check whether we must update shader. + if(!mAlwaysUsingBlurRadius && IsBlurRequired()) + { + // Change the shader must not be occured many times. we always have to use blur feature. + mAlwaysUsingBlurRadius = true; + + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + // Change shader + if(!mImpl->mCustomShader) + { + UpdateShader(); + } + } } } } @@ -159,10 +160,10 @@ void ColorVisual::DoCreatePropertyMap(Property::Map& map) const map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR); map.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, mImpl->mMixColor); - if(mImpl->mRenderer && mBlurRadiusIndex != Property::INVALID_INDEX) + if(mImpl->mRenderer) { // Update values from Renderer - float blurRadius = mImpl->mRenderer.GetProperty(mBlurRadiusIndex); + float blurRadius = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::BLUR_RADIUS); map.Insert(Toolkit::DevelColorVisual::Property::BLUR_RADIUS, blurRadius); } else @@ -208,14 +209,15 @@ void ColorVisual::OnInitialize() Shader shader = GenerateShader(); - mImpl->mRenderer = VisualRenderer::New(geometry, shader); + mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader); mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT); mImpl->mRenderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, Vector3(mImpl->mMixColor)); - if(!EqualsZero(mBlurRadius)) + if(mAlwaysUsingBlurRadius || !EqualsZero(mBlurRadius)) { - mBlurRadiusIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_NAME, mBlurRadius); + DownCast(mImpl->mRenderer).RegisterBlurRadiusUniform(); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BLUR_RADIUS, mBlurRadius); mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); } @@ -230,7 +232,7 @@ Shader ColorVisual::GenerateShader() const bool roundedCorner = IsRoundedCornerRequired(); bool borderline = IsBorderlineRequired(); - bool blur = !EqualsZero(mBlurRadius) || mAlwaysUsingBlurRadius; + bool blur = IsBlurRequired(); int shaderTypeFlag = ColorVisualRequireFlag::DEFAULT; if(roundedCorner) @@ -287,23 +289,39 @@ Dali::Property ColorVisual::OnGetPropertyObject(Dali::Property::Key key) if((key.type == Property::Key::INDEX && key.indexKey == DevelColorVisual::Property::BLUR_RADIUS) || (key.type == Property::Key::STRING && key.stringKey == BLUR_RADIUS_NAME)) { - mBlurRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_NAME, mBlurRadius); + const bool updateShader = !mImpl->mCustomShader && !IsBlurRequired(); // Blur is animated now. we always have to use blur feature. mAlwaysUsingBlurRadius = true; - mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); - - // Change shader - UpdateShader(); + if(updateShader) + { + // Update each values to renderer + DownCast(mImpl->mRenderer).RegisterBlurRadiusUniform(); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BLUR_RADIUS, mBlurRadius); - return Dali::Property(mImpl->mRenderer, mBlurRadiusIndex); + // Change shader + UpdateShader(); + } + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + return Dali::Property(mImpl->mRenderer, DecoratedVisualRenderer::Property::BLUR_RADIUS); } Handle handle; return Dali::Property(handle, Property::INVALID_INDEX); } +bool ColorVisual::IsBlurRequired() const +{ + float blurRadius = mBlurRadius; + if(mImpl->mRenderer) + { + // Update values from Renderer + blurRadius = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::BLUR_RADIUS); + } + return mAlwaysUsingBlurRadius || !EqualsZero(blurRadius); +} + } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/visuals/color/color-visual.h b/dali-toolkit/internal/visuals/color/color-visual.h index bb8bc95..0a8a8b2 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.h +++ b/dali-toolkit/internal/visuals/color/color-visual.h @@ -123,6 +123,14 @@ protected: */ Dali::Property OnGetPropertyObject(Dali::Property::Key key) override; +protected: + /** + * @brief Query whether the visual requires to be blur. + * + * @return Returns true if the blur is required, false otherwise. + */ + bool IsBlurRequired() const; + private: // Undefined ColorVisual(const ColorVisual& colorRenderer); @@ -131,9 +139,8 @@ private: ColorVisual& operator=(const ColorVisual& colorRenderer); private: - float mBlurRadius; ///< The blur radius - Property::Index mBlurRadiusIndex; ///< The blur radius property index - bool mAlwaysUsingBlurRadius : 1; ///< Whether we need the blur radius in shader always. + float mBlurRadius; ///< The blur radius + bool mAlwaysUsingBlurRadius : 1; ///< Whether we need the blur radius in shader always. }; } // namespace Internal diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp index 4bbae24..ea84e5e 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include // INTERNAL INCLUDES @@ -46,7 +47,7 @@ namespace Internal { namespace { -const int CUSTOM_PROPERTY_COUNT(6); // alignment + corner/border +const int CUSTOM_PROPERTY_COUNT(1); // alignment DALI_ENUM_TO_STRING_TABLE_BEGIN(UNITS) DALI_ENUM_TO_STRING_WITH_SCOPE(Toolkit::GradientVisual::Units, OBJECT_BOUNDING_BOX) @@ -261,7 +262,7 @@ void GradientVisual::OnInitialize() sampler.SetWrapMode(wrap, wrap); textureSet.SetSampler(0u, sampler); - mImpl->mRenderer = VisualRenderer::New(geometry, shader); + mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader); mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT); mImpl->mRenderer.SetTextures(textureSet); diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index 44c9fac..ef71786 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include // for strlen() // INTERNAL HEADERS @@ -51,7 +52,7 @@ namespace Internal { namespace { -const int CUSTOM_PROPERTY_COUNT(12); // ltr, wrap, pixel area, atlas, pixalign, crop to mask, mask texture ratio + border/corner +const int CUSTOM_PROPERTY_COUNT(7); // ltr, wrap, pixel area, atlas, pixalign, crop to mask, mask texture ratio // fitting modes DALI_ENUM_TO_STRING_TABLE_BEGIN(FITTING_MODE) @@ -582,7 +583,7 @@ void ImageVisual::OnInitialize() Shader shader = GenerateShader(); // Create the renderer - mImpl->mRenderer = VisualRenderer::New(geometry, shader); + mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader); mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT); //Register transform properties @@ -1057,7 +1058,7 @@ Shader ImageVisual::GenerateShader() const if(useStandardShader) { - bool requiredAlphaMaskingOnRendering = (mMaskingData && !mMaskingData->mMaskImageLoadingFailed) ? !mMaskingData->mPreappliedMasking : false; + bool requiredAlphaMaskingOnRendering = (mMaskingData && !mMaskingData->mMaskImageLoadingFailed) ? !mMaskingData->mPreappliedMasking : false; // Create and cache the standard shader shader = mImageVisualShaderFactory.GetShader( mFactoryCache, @@ -1133,8 +1134,8 @@ void ImageVisual::CheckMaskTexture() { if(mMaskingData && !mMaskingData->mPreappliedMasking) { - bool maskLoadFailed = true; - TextureSet textures = mImpl->mRenderer.GetTextures(); + bool maskLoadFailed = true; + TextureSet textures = mImpl->mRenderer.GetTextures(); if(textures && textures.GetTextureCount() >= TEXTURE_COUNT_FOR_GPU_ALPHA_MASK) { if(mMaskingData->mCropToMask) diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.cpp b/dali-toolkit/internal/visuals/svg/svg-visual.cpp index a92f7f8..9d0a2cc 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.cpp +++ b/dali-toolkit/internal/visuals/svg/svg-visual.cpp @@ -29,6 +29,7 @@ // EXTERNAL INCLUDES #include #include +#include namespace Dali { @@ -38,7 +39,7 @@ namespace Internal { namespace { -const int CUSTOM_PROPERTY_COUNT(6); // atlas + corner/border +const int CUSTOM_PROPERTY_COUNT(1); // atlas // property name const Dali::Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); @@ -85,7 +86,7 @@ void SvgVisual::OnInitialize() { Shader shader = GenerateShader(); Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY); - mImpl->mRenderer = VisualRenderer::New(geometry, shader); + mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader); mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT); Vector2 dpi = Stage::GetCurrent().GetDpi(); diff --git a/dali-toolkit/internal/visuals/visual-base-data-impl.cpp b/dali-toolkit/internal/visuals/visual-base-data-impl.cpp index 2616b2a..49a14de 100644 --- a/dali-toolkit/internal/visuals/visual-base-data-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-data-impl.cpp @@ -126,10 +126,6 @@ Internal::Visual::Base::Impl::Impl(FittingMode fittingMode, Toolkit::Visual::Typ mCornerRadius(Vector4::ZERO), mCornerRadiusPolicy(1.0f), mDepthIndex(0.0f), - mBorderlineWidthIndex(Property::INVALID_INDEX), - mBorderlineColorIndex(Property::INVALID_INDEX), - mBorderlineOffsetIndex(Property::INVALID_INDEX), - mCornerRadiusIndex(Property::INVALID_INDEX), mFittingMode(fittingMode), mFlags(0), mResourceStatus(Toolkit::Visual::ResourceStatus::PREPARING), diff --git a/dali-toolkit/internal/visuals/visual-base-data-impl.h b/dali-toolkit/internal/visuals/visual-base-data-impl.h index f462be2..568af24 100644 --- a/dali-toolkit/internal/visuals/visual-base-data-impl.h +++ b/dali-toolkit/internal/visuals/visual-base-data-impl.h @@ -127,10 +127,6 @@ struct Base::Impl Vector4 mCornerRadius; float mCornerRadiusPolicy; int mDepthIndex; - Property::Index mBorderlineWidthIndex; - Property::Index mBorderlineColorIndex; - Property::Index mBorderlineOffsetIndex; - Property::Index mCornerRadiusIndex; FittingMode mFittingMode; ///< How the contents should fit the view int mFlags; Toolkit::Visual::ResourceStatus mResourceStatus; diff --git a/dali-toolkit/internal/visuals/visual-base-impl.cpp b/dali-toolkit/internal/visuals/visual-base-impl.cpp index 960a9fd..ab8f434 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-impl.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include //INTERNAL HEARDER @@ -135,22 +136,16 @@ void Visual::Base::Initialize() if(mImpl->mRenderer) { RegisterMixColor(); + RegisterDecoration(); - if(IsRoundedCornerRequired()) - { - mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius); - mImpl->mRenderer.RegisterUniqueProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy); - - mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); - } if(IsBorderlineRequired()) { - mImpl->mBorderlineWidthIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth); - mImpl->mBorderlineColorIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor); - mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset); - mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL); } + else if(IsRoundedCornerRequired()) + { + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + } } } @@ -300,29 +295,28 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap) mImpl->mBorderlineWidth = width; } - if(mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX) - { - mImpl->mRenderer.SetProperty(mImpl->mBorderlineWidthIndex, mImpl->mBorderlineWidth); - } - else if(DALI_UNLIKELY(mImpl->mRenderer && IsBorderlineRequired())) + if(DALI_UNLIKELY(mImpl->mRenderer)) { // Unusual case. SetProperty called after OnInitialize(). // Assume that DoAction call UPDATE_PROPERTY. - // We must regist properies into renderer, and update shader. + DownCast(mImpl->mRenderer).RegisterBorderlineUniform(); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth); - // Borderline added by this action. Register property to renderer. - mImpl->mBorderlineWidthIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth); - mImpl->mBorderlineColorIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor); - mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset); - - // Make Blend mode ON_WITHOUT_CULL for transparent mix color. - mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL); + // Check whether we must update shader. + if(!mImpl->mAlwaysUsingBorderline && IsBorderlineRequired()) + { + // Make Blend mode ON_WITHOUT_CULL for transparent mix color. + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL); - // Change the shader must not be occured many times. we always have to use borderline feature. - mImpl->mAlwaysUsingBorderline = true; + // Change the shader must not be occured many times. we always have to use borderline feature. + mImpl->mAlwaysUsingBorderline = true; - // Change shader - needUpdateShader = true; + // Change shader + if(!mImpl->mCustomShader) + { + needUpdateShader = true; + } + } } break; } @@ -334,9 +328,11 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap) mImpl->mBorderlineColor = color; } - if(mImpl->mBorderlineColorIndex != Property::INVALID_INDEX) + if(DALI_UNLIKELY(mImpl->mRenderer)) { - mImpl->mRenderer.SetProperty(mImpl->mBorderlineColorIndex, mImpl->mBorderlineColor); + // Unusual case. SetProperty called after OnInitialize(). + // Assume that DoAction call UPDATE_PROPERTY. + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor); } break; } @@ -348,9 +344,11 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap) mImpl->mBorderlineOffset = offset; } - if(mImpl->mBorderlineOffsetIndex != Property::INVALID_INDEX) + if(DALI_UNLIKELY(mImpl->mRenderer)) { - mImpl->mRenderer.SetProperty(mImpl->mBorderlineOffsetIndex, mImpl->mBorderlineOffset); + // Unusual case. SetProperty called after OnInitialize(). + // Assume that DoAction call UPDATE_PROPERTY. + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset); } break; } @@ -378,32 +376,33 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap) } } - if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX) - { - mImpl->mRenderer.SetProperty(mImpl->mCornerRadiusIndex, mImpl->mCornerRadius); - } - else if(DALI_UNLIKELY(mImpl->mRenderer && IsRoundedCornerRequired())) + if(DALI_UNLIKELY(mImpl->mRenderer)) { // Unusual case. SetProperty called after OnInitialize(). // Assume that DoAction call UPDATE_PROPERTY. - // We must regist properies into renderer, and update shader. + DownCast(mImpl->mRenderer).RegisterCornerRadiusUniform(); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS, mImpl->mCornerRadius); - // CornerRadius added by this action. Regist property to renderer. - mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius); - mImpl->mRenderer.RegisterUniqueProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy); + // Check whether we must update shader. + if(!mImpl->mAlwaysUsingCornerRadius && IsRoundedCornerRequired()) + { + // Change the shader must not be occured many times. we always have to use corner radius feature. + mImpl->mAlwaysUsingCornerRadius = true; - // Change the shader must not be occured many times. we always have to use corner radius feature. - mImpl->mAlwaysUsingCornerRadius = true; + if(!IsBorderlineRequired()) + { + // If IsBorderlineRequired is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it. + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + } - if(!IsBorderlineRequired()) - { - // If IsBorderlineRequired is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it. - mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + // Change shader + if(!mImpl->mCustomShader) + { + needUpdateShader = true; + } } - - // Change shader - needUpdateShader = true; } + break; } case Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY: @@ -417,14 +416,11 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap) case Toolkit::Visual::Transform::Policy::ABSOLUTE: { mImpl->mCornerRadiusPolicy = policy; - if(DALI_UNLIKELY(mImpl->mRenderer && mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)) + if(DALI_UNLIKELY(mImpl->mRenderer)) { // Unusual case. SetProperty called after OnInitialize(). // Assume that DoAction call UPDATE_PROPERTY. - // We must update properies result into renderer - // Note : mImpl->mCornerRadiusIndex is not INVALID_INDEX. - // So CornerRadiusPolicy property is already registed. - mImpl->mRenderer.SetProperty(mImpl->mRenderer.GetPropertyIndex(CORNER_RADIUS_POLICY), mImpl->mCornerRadiusPolicy); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy); } break; } @@ -572,21 +568,15 @@ void Visual::Base::CreatePropertyMap(Property::Map& map) const mImpl->mTransform.mOffset = mImpl->mRenderer.GetProperty(VisualRenderer::Property::TRANSFORM_OFFSET); mImpl->mTransform.mSize = mImpl->mRenderer.GetProperty(VisualRenderer::Property::TRANSFORM_SIZE); - if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX) - { - mImpl->mCornerRadius = mImpl->mRenderer.GetProperty(mImpl->mCornerRadiusIndex); - } - if(mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX) + if(IsTypeAvailableForCornerRadius(mImpl->mType)) { - mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty(mImpl->mBorderlineWidthIndex); + mImpl->mCornerRadius = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS); } - if(mImpl->mBorderlineColorIndex != Property::INVALID_INDEX) + if(IsTypeAvailableForBorderline(mImpl->mType)) { - mImpl->mBorderlineColor = mImpl->mRenderer.GetProperty(mImpl->mBorderlineColorIndex); - } - if(mImpl->mBorderlineOffsetIndex != Property::INVALID_INDEX) - { - mImpl->mBorderlineOffset = mImpl->mRenderer.GetProperty(mImpl->mBorderlineOffsetIndex); + mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH); + mImpl->mBorderlineColor = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR); + mImpl->mBorderlineOffset = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET); } } @@ -675,12 +665,13 @@ bool Visual::Base::IsRoundedCornerRequired() const // If VisualType doesn't support rounded corner, always return false. if(IsTypeAvailableForCornerRadius(mImpl->mType)) { - if(mImpl->mRenderer && mImpl->mCornerRadiusIndex != Property::INVALID_INDEX) + if(mImpl->mRenderer) { // Update values from Renderer - mImpl->mCornerRadius = mImpl->mRenderer.GetProperty(mImpl->mCornerRadiusIndex); + Property::Value value = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS); + value.Get(mImpl->mCornerRadius); } - return !(mImpl->mCornerRadius == Vector4::ZERO) || mImpl->mAlwaysUsingCornerRadius; + return mImpl->mAlwaysUsingCornerRadius || !(mImpl->mCornerRadius == Vector4::ZERO); } return false; } @@ -690,12 +681,13 @@ bool Visual::Base::IsBorderlineRequired() const // If VisualType doesn't support borderline, always return false. if(IsTypeAvailableForBorderline(mImpl->mType)) { - if(mImpl->mRenderer && mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX) + if(mImpl->mRenderer) { // Update values from Renderer - mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty(mImpl->mBorderlineWidthIndex); + Property::Value value = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH); + value.Get(mImpl->mBorderlineWidth); } - return !EqualsZero(mImpl->mBorderlineWidth) || mImpl->mAlwaysUsingBorderline; + return mImpl->mAlwaysUsingBorderline || !EqualsZero(mImpl->mBorderlineWidth); } return false; } @@ -722,6 +714,32 @@ void Visual::Base::RegisterMixColor() } } +void Visual::Base::RegisterDecoration() +{ + if(mImpl->mRenderer) + { + if(IsTypeAvailableForCornerRadius(mImpl->mType)) + { + if(mImpl->mAlwaysUsingCornerRadius || !(mImpl->mCornerRadius == Vector4::ZERO)) + { + DownCast(mImpl->mRenderer).RegisterCornerRadiusUniform(); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS, mImpl->mCornerRadius); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy); + } + } + if(IsTypeAvailableForBorderline(mImpl->mType)) + { + if(mImpl->mAlwaysUsingBorderline || !EqualsZero(mImpl->mBorderlineWidth)) + { + DownCast(mImpl->mRenderer).RegisterBorderlineUniform(); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset); + } + } + } +} + void Visual::Base::SetMixColor(const Vector4& color) { mImpl->mMixColor = color; @@ -920,6 +938,22 @@ Property::Index Visual::Base::GetPropertyIndex(Property::Key key) { return VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA; } + case Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS: + { + return DecoratedVisualRenderer::Property::CORNER_RADIUS; + } + case Dali::Toolkit::DevelVisual::Property::BORDERLINE_WIDTH: + { + return DecoratedVisualRenderer::Property::BORDERLINE_WIDTH; + } + case Dali::Toolkit::DevelVisual::Property::BORDERLINE_COLOR: + { + return DecoratedVisualRenderer::Property::BORDERLINE_COLOR; + } + case Dali::Toolkit::DevelVisual::Property::BORDERLINE_OFFSET: + { + return DecoratedVisualRenderer::Property::BORDERLINE_OFFSET; + } } Property::Index index = mImpl->mRenderer.GetPropertyIndex(key); @@ -1121,9 +1155,9 @@ Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key) return Dali::Property(handle, Property::INVALID_INDEX); } - // Default animatable properties from VisualRenderer switch(GetIntKey(key)) { + // Default animatable properties from VisualRenderer case Toolkit::Visual::Property::MIX_COLOR: { return Dali::Property(mImpl->mRenderer, VisualRenderer::Property::VISUAL_MIX_COLOR); @@ -1140,85 +1174,79 @@ Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key) { return Dali::Property(mImpl->mRenderer, VisualRenderer::Property::TRANSFORM_SIZE); } - default: - { - if(key.type == Property::Key::INDEX && - ((mImpl->mType == Toolkit::Visual::COLOR && key.indexKey == ColorVisual::Property::MIX_COLOR) || - (mImpl->mType == Toolkit::Visual::PRIMITIVE && key.indexKey == PrimitiveVisual::Property::MIX_COLOR))) - { - return Dali::Property(mImpl->mRenderer, VisualRenderer::Property::VISUAL_MIX_COLOR); - } - } - } - // Other cases - Property::Index index = GetPropertyIndex(key); - if(index == Property::INVALID_INDEX) - { - if(IsTypeAvailableForBorderline(mImpl->mType) && - ((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_WIDTH) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_WIDTH) || - (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_COLOR) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_COLOR) || - (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_OFFSET) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_OFFSET))) + // Default animatable properties from DecoratedVisualRenderer + case Toolkit::DevelVisual::Property::CORNER_RADIUS: { - mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL); - - // Register borderline properties - mImpl->mBorderlineWidthIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth); - mImpl->mBorderlineColorIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor); - mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset); + if(IsTypeAvailableForCornerRadius(mImpl->mType)) + { + const bool updateShader = !mImpl->mCustomShader && !IsRoundedCornerRequired(); - // Borderline is animated now. we always have to use borderline feature. - mImpl->mAlwaysUsingBorderline = true; + // CornerRadius is animated now. we always have to use corner radius feature. + mImpl->mAlwaysUsingCornerRadius = true; - index = mImpl->mRenderer.GetPropertyIndex(key); + if(updateShader) + { + // Update each values to renderer + DownCast(mImpl->mRenderer).RegisterCornerRadiusUniform(); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS, mImpl->mCornerRadius); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy); - // Change shader - UpdateShader(); + // Change shader + UpdateShader(); + } + if(!IsBorderlineRequired()) + { + // If IsBorderlineRequired is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it. + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + } + return Dali::Property(mImpl->mRenderer, DecoratedVisualRenderer::Property::CORNER_RADIUS); + } + break; } - else if(IsTypeAvailableForCornerRadius(mImpl->mType) && ((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::CORNER_RADIUS) || (key.type == Property::Key::STRING && key.stringKey == CORNER_RADIUS))) + case Toolkit::DevelVisual::Property::BORDERLINE_WIDTH: + case Toolkit::DevelVisual::Property::BORDERLINE_COLOR: + case Toolkit::DevelVisual::Property::BORDERLINE_OFFSET: { - // Register CORNER_RADIUS property - mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius); - mImpl->mRenderer.RegisterUniqueProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy); + if(IsTypeAvailableForBorderline(mImpl->mType)) + { + const bool updateShader = !mImpl->mCustomShader && !IsBorderlineRequired(); - // CornerRadius is animated now. we always have to use corner radius feature. - mImpl->mAlwaysUsingCornerRadius = true; + // Borderline is animated now. we always have to use borderline feature. + mImpl->mAlwaysUsingBorderline = true; - if(!IsBorderlineRequired()) - { - // If IsBorderlineRequired is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it. - mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); - } + if(updateShader) + { + // Update each values to renderer + DownCast(mImpl->mRenderer).RegisterBorderlineUniform(); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset); - index = mImpl->mCornerRadiusIndex; + // Change shader + UpdateShader(); + } + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL); - // Change shader - UpdateShader(); - } - else - { - // We can't find the property in the base class. - // Request to child class - return OnGetPropertyObject(key); - } - } - else - { - if(index == mImpl->mBorderlineWidthIndex || - index == mImpl->mBorderlineColorIndex || - index == mImpl->mBorderlineOffsetIndex) - { - // Borderline is animated now. we always have to use borderline feature. - mImpl->mAlwaysUsingBorderline = true; + return Dali::Property(mImpl->mRenderer, GetPropertyIndex(key)); + } + break; } - if(index == mImpl->mCornerRadiusIndex) + // Special case for MIX_COLOR + default: { - // CornerRadius is animated now. we always have to use corner radius feature. - mImpl->mAlwaysUsingCornerRadius = true; + if(key.type == Property::Key::INDEX && + ((mImpl->mType == Toolkit::Visual::COLOR && key.indexKey == ColorVisual::Property::MIX_COLOR) || + (mImpl->mType == Toolkit::Visual::PRIMITIVE && key.indexKey == PrimitiveVisual::Property::MIX_COLOR))) + { + return Dali::Property(mImpl->mRenderer, VisualRenderer::Property::VISUAL_MIX_COLOR); + } } } - return Dali::Property(mImpl->mRenderer, index); + // We can't find the property in the base class. + // Request to child class + return OnGetPropertyObject(key); } } // namespace Internal diff --git a/dali-toolkit/internal/visuals/visual-base-impl.h b/dali-toolkit/internal/visuals/visual-base-impl.h index 20b0bd9..bdcb193 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.h +++ b/dali-toolkit/internal/visuals/visual-base-impl.h @@ -422,6 +422,11 @@ private: void RegisterMixColor(); /** + * Register the uniform on the DecoratedVisualRenderer and store the property index if necessary. + */ + void RegisterDecoration(); + + /** * Find the matching property on the renderer or shader. If it's a shader * property, register it on the renderer in order to animate it for this * visual independently. -- 2.7.4