From 2c97b9f743493b56e6256fbce8ef5c3e2080572c Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Thu, 12 Nov 2015 11:20:46 +0000 Subject: [PATCH] Remove instances of finding a property before RegisterProperty This is because RegisterProperty checks whether the property has been registered before, and just calls SetProperty it it has been. Change-Id: I20a415edd05afd6d0b8f05171ea11c94e4f5cc57 --- .../devel-api/shader-effects/dissolve-effect.h | 173 ++++++++------------- .../accessibility-manager-impl.cpp | 32 +--- dali-toolkit/internal/builder/builder-actor.cpp | 11 +- .../controls/renderers/image/image-renderer.cpp | 11 +- .../focus-manager/keyboard-focus-manager-impl.cpp | 12 +- 5 files changed, 75 insertions(+), 164 deletions(-) diff --git a/dali-toolkit/devel-api/shader-effects/dissolve-effect.h b/dali-toolkit/devel-api/shader-effects/dissolve-effect.h index 4953e4d..0825a5d 100644 --- a/dali-toolkit/devel-api/shader-effects/dissolve-effect.h +++ b/dali-toolkit/devel-api/shader-effects/dissolve-effect.h @@ -29,53 +29,6 @@ namespace Toolkit { /** - * @brief Only registers the required property if it has not registered it before. - * - * @tparam T The type of the property. - * - * @param[in] actor The actor to register the property with. - * @param[in] name The name of the property. - * @param[in] value The value the property should be set to. - */ -template < typename T> -DALI_INTERNAL void SafeSetCustomProperty( Dali::Actor& actor, const std::string& name, const T& value ) -{ - Dali::Property::Index index = actor.GetPropertyIndex( name ); - if ( Dali::Property::INVALID_INDEX == index ) - { - index = actor.RegisterProperty( name, value ); - } - else - { - actor.SetProperty( index, value ); - } -} - -/** - * @brief Only registers the required property if it has not registered it before. - * - * @tparam T The type of the property. - * - * @param[in] actor The actor to register the property with. - * @param[in] name The name of the property. - * @param[in] value The value the property should be set to. - * @param[in] accessMode The accessMode required for the property. - */ -template < typename T> -DALI_INTERNAL void SafeSetCustomProperty( Dali::Actor& actor, const std::string& name, const T& value, Dali::Property::AccessMode accessMode ) -{ - Dali::Property::Index index = actor.GetPropertyIndex( name ); - if ( Dali::Property::INVALID_INDEX == index ) - { - index = actor.RegisterProperty( name, value, accessMode ); - } - else - { - actor.SetProperty( index, value ); - } -} - -/** * @brief Set the dissolve central line. * * Use one point (position) and one direction ( displacement ) vector to define this line @@ -89,72 +42,72 @@ DALI_INTERNAL void SafeSetCustomProperty( Dali::Actor& actor, const std::string& inline void DissolveEffectSetCentralLine( Actor& actor, const Vector2& position, const Vector2& displacement, float initialProgress ) { // the line passes through 'position' and has the direction of 'displacement' - float coefA, coefB, coefC; //line equation: Ax+By+C=0; - coefA = displacement.y; - coefB = -displacement.x; - coefC = -displacement.y*position.x + displacement.x*position.y; - - float inversedAABB = 1.f / (coefA*coefA+coefB*coefB); - float inversedSqrtAABB = sqrtf(inversedAABB); - float saddleA; - - //saddle surface(Hyperbolic paraboloid)function, used to calculate the dissolve starting time - //z = y*y/a/a - x*x/b/b - //with our selection of parameters(a and b), this value for any texture coordinate is between -1.0 and 1.0 - - Vector3 saddleParam; // [0]: a*a, [1]: b*b, [2] b - Vector2 translation; - Vector2 rotation; - float toNext = -1.f; - if( displacement.x > 0.f || (EqualsZero(displacement.x) && displacement.y > 0.f) ) - { - toNext = 1.f; - } - - if( (displacement.y * displacement.x < 0.0f) ) - { - //distance from (0,0) to the line - float distanceTopLeft = fabsf(coefC) * inversedSqrtAABB; - //distance from (1, 1 ) to the line - float distanceBottomRight = fabsf(coefA+coefB+coefC) * inversedSqrtAABB; - saddleA = std::max( distanceTopLeft, distanceBottomRight ); + float coefA, coefB, coefC; //line equation: Ax+By+C=0; + coefA = displacement.y; + coefB = -displacement.x; + coefC = -displacement.y*position.x + displacement.x*position.y; + + float inversedAABB = 1.f / (coefA*coefA+coefB*coefB); + float inversedSqrtAABB = sqrtf(inversedAABB); + float saddleA; + + //saddle surface(Hyperbolic paraboloid)function, used to calculate the dissolve starting time + //z = y*y/a/a - x*x/b/b + //with our selection of parameters(a and b), this value for any texture coordinate is between -1.0 and 1.0 + + Vector3 saddleParam; // [0]: a*a, [1]: b*b, [2] b + Vector2 translation; + Vector2 rotation; + float toNext = -1.f; + if( displacement.x > 0.f || (EqualsZero(displacement.x) && displacement.y > 0.f) ) + { + toNext = 1.f; + } - //foot of a perpendicular: (1,0) to the line - float footX1 = ( coefB*coefB - coefA*coefC) * inversedAABB; - float footY1 = (-coefA*coefB - coefB*coefC) * inversedAABB; - //foot of a perpendicular: (0,1) to the line - float footX2 = (-coefA*coefB - coefA*coefC) * inversedAABB; - float footY2 = ( coefA*coefA - coefB*coefC) * inversedAABB; - saddleParam[1] = (footX1-footX2)*(footX1-footX2) + (footY1-footY2)*(footY1-footY2); - translation = Vector2(-footX2,-footY2); - } - else - { - //distance from(1,0) to the line - float distanceTopRight = fabsf(coefA+coefC) * inversedSqrtAABB; - //distance from(0,1) to the line - float distanceBottomLeft = fabsf(coefB+coefC) * inversedSqrtAABB; - saddleA = std::max( distanceTopRight, distanceBottomLeft ); - //foot of a perpendicular: (0,0) to the line - float footX3 = (-coefA*coefC) * inversedAABB; - float footY3 = (-coefB*coefC) * inversedAABB; - //foot of a perpendicular: (1.0,1.0) to the line - float footX4 = ( coefB*coefB - coefA*coefB - coefA*coefC) * inversedAABB; - float footY4 = (-coefA*coefB + coefA*coefA- coefB*coefC) * inversedAABB; - saddleParam[1] = (footX3-footX4)*(footX3-footX4) + (footY3-footY4)*(footY3-footY4); - translation = Vector2(-footX3, -footY3); - } + if( (displacement.y * displacement.x < 0.0f) ) + { + //distance from (0,0) to the line + float distanceTopLeft = fabsf(coefC) * inversedSqrtAABB; + //distance from (1, 1 ) to the line + float distanceBottomRight = fabsf(coefA+coefB+coefC) * inversedSqrtAABB; + saddleA = std::max( distanceTopLeft, distanceBottomRight ); + + //foot of a perpendicular: (1,0) to the line + float footX1 = ( coefB*coefB - coefA*coefC) * inversedAABB; + float footY1 = (-coefA*coefB - coefB*coefC) * inversedAABB; + //foot of a perpendicular: (0,1) to the line + float footX2 = (-coefA*coefB - coefA*coefC) * inversedAABB; + float footY2 = ( coefA*coefA - coefB*coefC) * inversedAABB; + saddleParam[1] = (footX1-footX2)*(footX1-footX2) + (footY1-footY2)*(footY1-footY2); + translation = Vector2(-footX2,-footY2); + } + else + { + //distance from(1,0) to the line + float distanceTopRight = fabsf(coefA+coefC) * inversedSqrtAABB; + //distance from(0,1) to the line + float distanceBottomLeft = fabsf(coefB+coefC) * inversedSqrtAABB; + saddleA = std::max( distanceTopRight, distanceBottomLeft ); + //foot of a perpendicular: (0,0) to the line + float footX3 = (-coefA*coefC) * inversedAABB; + float footY3 = (-coefB*coefC) * inversedAABB; + //foot of a perpendicular: (1.0,1.0) to the line + float footX4 = ( coefB*coefB - coefA*coefB - coefA*coefC) * inversedAABB; + float footY4 = (-coefA*coefB + coefA*coefA- coefB*coefC) * inversedAABB; + saddleParam[1] = (footX3-footX4)*(footX3-footX4) + (footY3-footY4)*(footY3-footY4); + translation = Vector2(-footX3, -footY3); + } - saddleParam[2] = sqrtf(saddleParam[1]); - saddleParam[0] = saddleA*saddleA; - rotation = Vector2(-displacement.x, displacement.y); - rotation.Normalize(); + saddleParam[2] = sqrtf(saddleParam[1]); + saddleParam[0] = saddleA*saddleA; + rotation = Vector2(-displacement.x, displacement.y); + rotation.Normalize(); - SafeSetCustomProperty( actor, "uSaddleParam", saddleParam ); - SafeSetCustomProperty( actor, "uTranslation", translation ); - SafeSetCustomProperty( actor, "uRotation", rotation ); - SafeSetCustomProperty( actor, "uToNext", toNext ); - SafeSetCustomProperty( actor, "uPercentage", initialProgress, Dali::Property::ANIMATABLE ); + actor.RegisterProperty( "uSaddleParam", saddleParam ); + actor.RegisterProperty( "uTranslation", translation ); + actor.RegisterProperty( "uRotation", rotation ); + actor.RegisterProperty( "uToNext", toNext ); + actor.RegisterProperty( "uPercentage", initialProgress, Dali::Property::ANIMATABLE ); } /** * @brief Create a new Dissolve effect diff --git a/dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp b/dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp index 3e14751..15ed920 100644 --- a/dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp +++ b/dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp @@ -191,12 +191,8 @@ void AccessibilityManager::SetFocusOrder(Actor actor, const unsigned int order) // Firstly delete the actor from the focus chain if it's already there with a different focus order. mFocusIDContainer.erase(GetFocusOrder(actor)); - // Create actor focusable property if not already created. - Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE); - if(propertyActorFocusable == Property::INVALID_INDEX) - { - propertyActorFocusable = actor.RegisterProperty( ACTOR_FOCUSABLE, true, Property::READ_WRITE ); - } + // Create/retrieve actor focusable property + Property::Index propertyActorFocusable = actor.RegisterProperty( ACTOR_FOCUSABLE, true, Property::READ_WRITE ); if(order == 0) { @@ -512,16 +508,8 @@ void AccessibilityManager::SetFocusGroup(Actor actor, bool isFocusGroup) { if(actor) { - // Create focus group property if not already created. - Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP); - if(propertyIsFocusGroup == Property::INVALID_INDEX) - { - actor.RegisterProperty( IS_FOCUS_GROUP, isFocusGroup, Property::READ_WRITE ); - } - else - { - actor.SetProperty(propertyIsFocusGroup, isFocusGroup); - } + // Create/Set focus group property. + actor.RegisterProperty( IS_FOCUS_GROUP, isFocusGroup, Property::READ_WRITE ); } } @@ -667,16 +655,8 @@ void AccessibilityManager::SetFocusable(Actor actor, bool focusable) { if(actor) { - // Create actor focusable property if not already created. - Property::Index propertyActorFocusable = actor.GetPropertyIndex(ACTOR_FOCUSABLE); - if(propertyActorFocusable == Property::INVALID_INDEX) - { - actor.RegisterProperty( ACTOR_FOCUSABLE, focusable, Property::READ_WRITE ); - } - else - { - actor.SetProperty(propertyActorFocusable, focusable); - } + // Create/Set actor focusable property. + actor.RegisterProperty( ACTOR_FOCUSABLE, focusable, Property::READ_WRITE ); } } diff --git a/dali-toolkit/internal/builder/builder-actor.cpp b/dali-toolkit/internal/builder/builder-actor.cpp index d04e7e8..69bf0e6 100644 --- a/dali-toolkit/internal/builder/builder-actor.cpp +++ b/dali-toolkit/internal/builder/builder-actor.cpp @@ -81,18 +81,11 @@ Actor SetupActor( const TreeNode& child, Actor& actor, const Replacement& consta const TreeNode::KeyNodePair& keyChild = *iter; std::string key( keyChild.first ); - Property::Index index = actor.GetPropertyIndex( key ); Property::Value value; if( SetPropertyFromNode( keyChild.second, value, constant )) { - if( Property::INVALID_INDEX == index ) - { - actor.RegisterProperty( key, value, Property::READ_WRITE ); - } - else - { - actor.SetProperty( index, value ); - } + // Register/Set property. + actor.RegisterProperty( key, value, Property::READ_WRITE ); } } } diff --git a/dali-toolkit/internal/controls/renderers/image/image-renderer.cpp b/dali-toolkit/internal/controls/renderers/image/image-renderer.cpp index 27c6af5..f142d59 100644 --- a/dali-toolkit/internal/controls/renderers/image/image-renderer.cpp +++ b/dali-toolkit/internal/controls/renderers/image/image-renderer.cpp @@ -756,15 +756,8 @@ void ImageRenderer::SetTextureRectUniform( const Vector4& textureRect ) { if( mImpl->mRenderer ) { - Property::Index index = mImpl->mRenderer.GetPropertyIndex( TEXTURE_RECT_UNIFORM_NAME ); - if( index == Property::INVALID_INDEX ) - { - index = mImpl->mRenderer.RegisterProperty( TEXTURE_RECT_UNIFORM_NAME, textureRect ); - } - else - { - mImpl->mRenderer.SetProperty( index, textureRect ); - } + // Register/Set property. + mImpl->mRenderer.RegisterProperty( TEXTURE_RECT_UNIFORM_NAME, textureRect ); } } diff --git a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp index ae7d741..a950b35 100644 --- a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp +++ b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp @@ -393,16 +393,8 @@ void KeyboardFocusManager::SetAsFocusGroup(Actor actor, bool isFocusGroup) { if(actor) { - // Create focus group property if not already created. - Property::Index propertyIsFocusGroup = actor.GetPropertyIndex(IS_FOCUS_GROUP_PROPERTY_NAME); - if(propertyIsFocusGroup == Property::INVALID_INDEX) - { - actor.RegisterProperty(IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE ); - } - else - { - actor.SetProperty(propertyIsFocusGroup, isFocusGroup); - } + // Create/Set focus group property. + actor.RegisterProperty( IS_FOCUS_GROUP_PROPERTY_NAME, isFocusGroup, Property::READ_WRITE ); } } -- 2.7.4