X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fvisual-base-impl.cpp;h=81126c3ffb17626d2c4af735b9be3669d8f46e8b;hb=b7e3a56ad86f6f45b9cd126647a6161757c3674e;hp=1911b95565fc14e825f16b9df63cdd4f5b868b91;hpb=3de07b3d83f48fa5b08f24af1f7f721a4923eec9;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/visual-base-impl.cpp b/dali-toolkit/internal/visuals/visual-base-impl.cpp index 1911b95..81126c3 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -25,6 +25,7 @@ #include //INTERNAL HEARDER +#include #include #include #include @@ -134,16 +135,16 @@ void Visual::Base::Initialize() if(IsRoundedCornerRequired()) { - mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius); - mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy); + 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.RegisterProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth); - mImpl->mBorderlineColorIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor); - mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset); + 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); } @@ -167,6 +168,7 @@ void Visual::Base::SetCustomShader(const Property::Map& shaderMap) void Visual::Base::SetProperties(const Property::Map& propertyMap) { + bool needUpdateShader = false; for(size_t i = 0; i < propertyMap.Count(); ++i) { const KeyValuePair& pair = propertyMap.GetKeyValue(i); @@ -294,6 +296,31 @@ 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())) + { + // Unusual case. SetProperty called after OnInitialize(). + // Assume that DoAction call UPDATE_PROPERTY. + // We must regist properies into renderer, and update shader. + + // 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); + + // Change the shader must not be occured many times. we always have to use borderline feature. + mImpl->mAlwaysUsingBorderline = true; + + // Change shader + needUpdateShader = true; + } break; } case Toolkit::DevelVisual::Property::BORDERLINE_COLOR: @@ -303,6 +330,11 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap) { mImpl->mBorderlineColor = color; } + + if(mImpl->mBorderlineColorIndex != Property::INVALID_INDEX) + { + mImpl->mRenderer.SetProperty(mImpl->mBorderlineColorIndex, mImpl->mBorderlineColor); + } break; } case Toolkit::DevelVisual::Property::BORDERLINE_OFFSET: @@ -312,6 +344,11 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap) { mImpl->mBorderlineOffset = offset; } + + if(mImpl->mBorderlineOffsetIndex != Property::INVALID_INDEX) + { + mImpl->mRenderer.SetProperty(mImpl->mBorderlineOffsetIndex, mImpl->mBorderlineOffset); + } break; } case Toolkit::DevelVisual::Property::CORNER_RADIUS: @@ -337,6 +374,33 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap) mImpl->mCornerRadius = Vector4(radius, radius, radius, radius); } } + + if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX) + { + mImpl->mRenderer.SetProperty(mImpl->mCornerRadiusIndex, mImpl->mCornerRadius); + } + else if(DALI_UNLIKELY(mImpl->mRenderer && IsRoundedCornerRequired())) + { + // Unusual case. SetProperty called after OnInitialize(). + // Assume that DoAction call UPDATE_PROPERTY. + // We must regist properies into renderer, and update shader. + + // 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); + + // 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); + } + + // Change shader + needUpdateShader = true; + } break; } case Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY: @@ -350,6 +414,15 @@ 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)) + { + // 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); + } break; } default: @@ -365,6 +438,11 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap) } DoSetProperties(propertyMap); + + if(DALI_UNLIKELY(needUpdateShader)) + { + UpdateShader(); + } } void Visual::Base::SetTransformAndSize(const Property::Map& transform, Size controlSize) @@ -423,6 +501,20 @@ void Visual::Base::GetNaturalSize(Vector2& naturalSize) void Visual::Base::DoAction(const Property::Index actionId, const Property::Value attributes) { OnDoAction(actionId, attributes); + + // Check if action is valid for this visual type and perform action if possible + switch(actionId) + { + case DevelVisual::Action::UPDATE_PROPERTY: + { + const Property::Map* map = attributes.GetMap(); + if(map) + { + SetProperties(*map); + } + break; + } + } } void Visual::Base::SetDepthIndex(int index) @@ -614,7 +706,7 @@ void Visual::Base::RegisterMixColor() // (Color and Primitive visuals will register their own and save to this index) if(mImpl->mMixColorIndex == Property::INVALID_INDEX) { - mImpl->mMixColorIndex = mImpl->mRenderer.RegisterProperty( + mImpl->mMixColorIndex = mImpl->mRenderer.RegisterUniqueProperty( Toolkit::Visual::Property::MIX_COLOR, MIX_COLOR, Vector3(mImpl->mMixColor)); @@ -738,7 +830,9 @@ Property::Index Visual::Base::GetPropertyIndex(Property::Key key) // Leave keyIndex as INVALID_KEY - it can still be registered against the string key. } Property::Value value = shader.GetProperty(index); - index = mImpl->mRenderer.RegisterProperty(keyIndex, keyName, value); + + // We already know that mRenderer didn't have property. So we can assume that it is unique. + index = mImpl->mRenderer.RegisterUniqueProperty(keyIndex, keyName, value); } } return index; @@ -958,16 +1052,16 @@ Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key 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_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))) { mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL); // Register borderline properties - mImpl->mBorderlineWidthIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth); - mImpl->mBorderlineColorIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor); - mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset); + 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); // Borderline is animated now. we always have to use borderline feature. mImpl->mAlwaysUsingBorderline = true; @@ -980,15 +1074,15 @@ Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key) 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))) { // Register CORNER_RADIUS property - mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius); - mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy); + mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius); + mImpl->mRenderer.RegisterUniqueProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy); - // ConerRadius is animated now. we always have to use corner radius feature. + // CornerRadius is animated now. we always have to use corner radius feature. mImpl->mAlwaysUsingCornerRadius = true; if(!IsBorderlineRequired()) { - // If mNeedBorderline is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it. + // 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); } @@ -1004,6 +1098,21 @@ Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key) 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; + } + if(index == mImpl->mCornerRadiusIndex) + { + // CornerRadius is animated now. we always have to use corner radius feature. + mImpl->mAlwaysUsingCornerRadius = true; + } + } return Dali::Property(mImpl->mRenderer, index); }