From 87791e64cbdb8a3edb9f5fdd823fb34deadb083a Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Mon, 29 Jun 2015 13:07:44 +0100 Subject: [PATCH] Performance optimizing actor-impl & relayout controller - Store child actors as intrusive pointers rather than handles - Stop using public handles in internal code in actor (removes about a dozen unnecessary GetImplementation calls) - Stop calling Stage::GetCurrent().GetSize every size negotiation, store it internally instead Change-Id: I18615aa1f8d2c736cd8502fa02de55e9146a1ef6 --- .../src/dali-internal/CMakeLists.txt | 1 - .../utc-Dali-Internal-RelayoutController.cpp | 486 ------------------ automated-tests/src/dali/utc-Dali-Actor.cpp | 22 +- dali/internal/common/core-impl.cpp | 7 +- dali/internal/event/actors/actor-impl.cpp | 85 ++- dali/internal/event/actors/actor-impl.h | 5 +- .../event/events/hit-test-algorithm-impl.cpp | 6 +- .../relayout-controller-impl.cpp | 31 +- .../relayout-controller-impl.h | 19 +- dali/public-api/actors/actor.cpp | 11 +- 10 files changed, 88 insertions(+), 585 deletions(-) delete mode 100644 automated-tests/src/dali-internal/utc-Dali-Internal-RelayoutController.cpp diff --git a/automated-tests/src/dali-internal/CMakeLists.txt b/automated-tests/src/dali-internal/CMakeLists.txt index 17a9b50b9..97bb58920 100644 --- a/automated-tests/src/dali-internal/CMakeLists.txt +++ b/automated-tests/src/dali-internal/CMakeLists.txt @@ -12,7 +12,6 @@ SET(TC_SOURCES utc-Dali-Internal-Image-Culling.cpp utc-Dali-Internal-FixedSizeMemoryPool.cpp utc-Dali-Internal-MemoryPoolObjectAllocator.cpp - utc-Dali-Internal-RelayoutController.cpp utc-Dali-Internal-FrustumCulling.cpp ) diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-RelayoutController.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-RelayoutController.cpp deleted file mode 100644 index a6103590a..000000000 --- a/automated-tests/src/dali-internal/utc-Dali-Internal-RelayoutController.cpp +++ /dev/null @@ -1,486 +0,0 @@ -/* - * Copyright (c) 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include -#include -#include - -#include -#include - -using namespace Dali; - -void utc_dali_internal_relayout_controller_startup(void) -{ - test_return_value = TET_UNDEF; -} - -void utc_dali_internal_relayout_controller_cleanup(void) -{ - test_return_value = TET_PASS; -} - -namespace -{ - -// Properties to attach to actors for testing -const std::string REQUEST_WIDTH( "REQUEST_WIDTH" ); -const std::string REQUEST_HEIGHT( "REQUEST_HEIGHT" ); -const std::string EXPECTED_WIDTH_DIRTY( "EXPECTED_WIDTH_DIRTY" ); -const std::string EXPECTED_HEIGHT_DIRTY( "EXPECTED_HEIGHT_DIRTY" ); - -/** - * Check to see that the desired test results were achieved - */ -void CheckResults( Actor root ) -{ - const bool expectedWidthDirty = root.GetProperty( root.GetPropertyIndex( EXPECTED_WIDTH_DIRTY ) ).Get< bool >(); - const bool expectedHeightDirty = root.GetProperty( root.GetPropertyIndex( EXPECTED_HEIGHT_DIRTY ) ).Get< bool >(); - - Internal::Actor& rootImpl = GetImplementation( root ); - - DALI_TEST_CHECK( rootImpl.IsLayoutDirty( Dimension::WIDTH ) == expectedWidthDirty ); - DALI_TEST_CHECK( rootImpl.IsLayoutDirty( Dimension::HEIGHT ) == expectedHeightDirty ); - - for( unsigned int i = 0, numChildren = root.GetChildCount(); i < numChildren; ++i ) - { - Actor child = root.GetChildAt( i ); - - CheckResults( child ); - } -} - -/** - * Create a new actor and enable relayout on it - * - * @return Return the new actor - */ -Actor NewRelayoutActor( bool expectedWidthDirty, bool expectedHeightDirty, ResizePolicy::Type widthPolicy, ResizePolicy::Type heightPolicy ) -{ - Actor actor = Actor::New(); - - actor.SetResizePolicy( widthPolicy, Dimension::WIDTH ); - actor.SetResizePolicy( heightPolicy, Dimension::HEIGHT ); - - // Expected results for this actor - actor.RegisterProperty( EXPECTED_WIDTH_DIRTY, expectedWidthDirty, Property::READ_WRITE ); - actor.RegisterProperty( EXPECTED_HEIGHT_DIRTY, expectedHeightDirty, Property::READ_WRITE ); - - return actor; -} - -/** - * Create a new root actor and enable relayout on it - * - * @return Return the new actor - */ -Actor NewRelayoutRootActor( bool requestWidth, bool requestHeight, bool expectedWidthDirty, bool expectedHeightDirty, ResizePolicy::Type widthPolicy, ResizePolicy::Type heightPolicy ) -{ - Actor actor = NewRelayoutActor( expectedWidthDirty, expectedHeightDirty, widthPolicy, heightPolicy ); - - // Add properties to configure testing - actor.RegisterProperty( REQUEST_WIDTH, requestWidth, Property::READ_WRITE ); - actor.RegisterProperty( REQUEST_HEIGHT, requestHeight, Property::READ_WRITE ); - - return actor; -} - -void TestTree( TestApplication& application, Actor root, Actor entryPoint = Actor() ) -{ - // Render and notify - clear the flags - application.SendNotification(); - application.Render(); - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( true ); - - const bool widthRequest = root.GetProperty( root.GetPropertyIndex( REQUEST_WIDTH ) ).Get< bool >(); - const bool heightRequest = root.GetProperty( root.GetPropertyIndex( REQUEST_HEIGHT ) ).Get< bool >(); - - const Dimension::Type dimensions = Dimension::Type( ( ( widthRequest ) ? Dimension::WIDTH : 0 ) | ( ( heightRequest ) ? Dimension::HEIGHT : 0 ) ); - - controller->RequestRelayout( ( entryPoint ) ? entryPoint : root, dimensions ); - - CheckResults( root ); -} - -} // anonymous namespace - -int UtcDaliRelayoutControllerGet(void) -{ - TestApplication application; - - Internal::RelayoutController* relayoutController = Internal::RelayoutController::Get(); - - DALI_TEST_CHECK( relayoutController ); - - END_TEST; -} - -int UtcDaliRelayoutControllerRequestRelayout(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - Internal::Actor& actorImpl = GetImplementation( actor ); - - // Request default enable (false) - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->RequestRelayout( actor ); - - DALI_TEST_CHECK( !actorImpl.IsLayoutDirty() ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_SingleActor(void) -{ - TestApplication application; - - // Construct scene - Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIXED, ResizePolicy::FIXED ); - - TestTree( application, parent ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_FixedParent(void) -{ - TestApplication application; - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( false ); - - // Construct scene - Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIXED, ResizePolicy::FIXED ); - - // Add a child - Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - parent.Add( child ); - - TestTree( application, parent ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_NaturalParent(void) -{ - TestApplication application; - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( false ); - - // Construct scene - Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::USE_NATURAL_SIZE ); - - // Add a child - Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - parent.Add( child ); - - // Run the test - TestTree( application, parent ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_FillParent(void) -{ - TestApplication application; - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( false ); - - // Construct scene - Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FILL_TO_PARENT ); - - // Add a child - Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - parent.Add( child ); - - // Run the test - TestTree( application, parent ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_FitParent(void) -{ - TestApplication application; - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( false ); - - // Construct scene - Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIT_TO_CHILDREN, ResizePolicy::FIT_TO_CHILDREN ); - - // Add a child - Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - parent.Add( child ); - - // Run the test - TestTree( application, parent ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_DepParent1(void) -{ - TestApplication application; - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( false ); - - // Construct scene - Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::DIMENSION_DEPENDENCY, ResizePolicy::FIT_TO_CHILDREN ); - - // Add a child - Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - parent.Add( child ); - - // Run the test - TestTree( application, parent ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_DepParent2(void) -{ - TestApplication application; - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( false ); - - // Construct scene - Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIT_TO_CHILDREN, ResizePolicy::DIMENSION_DEPENDENCY ); - - Actor child = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - parent.Add( child ); - - - // Run the test - TestTree( application, parent ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_Child1(void) -{ - TestApplication application; - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( false ); - - // Construct scene - Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIT_TO_CHILDREN, ResizePolicy::FIT_TO_CHILDREN ); - - // Add a child - Actor child = NewRelayoutActor( true, true, ResizePolicy::FIXED, ResizePolicy::FIXED ); - parent.Add( child ); - - // Run the test - TestTree( application, parent, child ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_Child2(void) -{ - TestApplication application; - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( false ); - - // Construct scene - Actor parent = NewRelayoutRootActor( true, true, false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - - // Add a child - Actor child = NewRelayoutActor( true, true, ResizePolicy::FIXED, ResizePolicy::FIXED ); - parent.Add( child ); - - // Run the test - TestTree( application, parent, child ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_Complex1(void) -{ - TestApplication application; - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( false ); - - // Construct scene - Actor parent = NewRelayoutRootActor( true, true, true, true, ResizePolicy::FIXED, ResizePolicy::FIXED ); - - // Add children - Actor child1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED ); - parent.Add( child1 ); - - Actor child2 = NewRelayoutActor( false, true, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT ); - parent.Add( child2 ); - - Actor child3 = NewRelayoutActor( false, false, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::FIXED ); - parent.Add( child3 ); - - // Grand children 1 - Actor grandChild1_1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED ); - child1.Add( grandChild1_1 ); - - Actor grandChild1_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT ); - child1.Add( grandChild1_2 ); - - // Grand children 2 - Actor grandChild2_1 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - child2.Add( grandChild2_1 ); - - Actor grandChild2_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - child2.Add( grandChild2_2 ); - - // Run the test - TestTree( application, parent ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_Complex2(void) -{ - TestApplication application; - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( false ); - - // Construct scene - Actor parent = NewRelayoutRootActor( true, false, true, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - - // Add children - Actor child1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED ); - parent.Add( child1 ); - - Actor child2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT ); - parent.Add( child2 ); - - Actor child3 = NewRelayoutActor( false, false, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::FIXED ); - parent.Add( child3 ); - - // Grand children 1 - Actor grandChild1_1 = NewRelayoutActor( true, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED ); - child1.Add( grandChild1_1 ); - - Actor grandChild1_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT ); - child1.Add( grandChild1_2 ); - - // Grand children 2 - Actor grandChild2_1 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - child2.Add( grandChild2_1 ); - - Actor grandChild2_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - child2.Add( grandChild2_2 ); - - // Run the test - TestTree( application, parent ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_Complex3(void) -{ - TestApplication application; - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( false ); - - // Construct scene - Actor parent = NewRelayoutRootActor( false, true, false, true, ResizePolicy::FIXED, ResizePolicy::FIXED ); - - // Add children - Actor child1 = NewRelayoutActor( false, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED ); - parent.Add( child1 ); - - Actor child2 = NewRelayoutActor( false, true, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT ); - parent.Add( child2 ); - - Actor child3 = NewRelayoutActor( false, false, ResizePolicy::USE_NATURAL_SIZE, ResizePolicy::FIXED ); - parent.Add( child3 ); - - // Grand children 1 - Actor grandChild1_1 = NewRelayoutActor( false, false, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED ); - child1.Add( grandChild1_1 ); - - Actor grandChild1_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FILL_TO_PARENT ); - child1.Add( grandChild1_2 ); - - // Grand children 2 - Actor grandChild2_1 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - child2.Add( grandChild2_1 ); - - Actor grandChild2_2 = NewRelayoutActor( false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - child2.Add( grandChild2_2 ); - - // Run the test - TestTree( application, parent ); - - END_TEST; -} - -int UtcDaliRelayoutController_Relayout_Dependency(void) -{ - TestApplication application; - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( false ); - - // Construct scene - Actor parent = NewRelayoutRootActor( true, true, false, false, ResizePolicy::FIXED, ResizePolicy::FIXED ); - - // Add a child - Actor child = NewRelayoutActor( true, true, ResizePolicy::FILL_TO_PARENT, ResizePolicy::FIXED ); - child.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - parent.Add( child ); - - // Run the test - TestTree( application, parent, child ); - - END_TEST; -} - -int UtcDaliRelayoutControllerRequestRelayoutTree(void) -{ - TestApplication application; - - Actor actor = Actor::New(); - - Internal::Actor& actorImpl = GetImplementation( actor ); - - // Check if flag is set - DALI_TEST_CHECK( !actorImpl.IsLayoutDirty() ); - - Internal::RelayoutController* controller = Internal::RelayoutController::Get(); - controller->SetEnabled( true ); - - // Request default enable (false) - controller->RequestRelayoutTree( actor ); - - DALI_TEST_CHECK( !actorImpl.IsLayoutDirty() ); - - END_TEST; -} - diff --git a/automated-tests/src/dali/utc-Dali-Actor.cpp b/automated-tests/src/dali/utc-Dali-Actor.cpp index 44a83f3f9..0c79181d2 100644 --- a/automated-tests/src/dali/utc-Dali-Actor.cpp +++ b/automated-tests/src/dali/utc-Dali-Actor.cpp @@ -454,24 +454,10 @@ int UtcDaliActorRemoveN(void) // add child back parent.Add(child); - // try illegal Remove - try - { - parent.Remove( parent ); - tet_printf("Assertion test failed - no Exception\n" ); - tet_result(TET_FAIL); - } - catch(Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "this != &child", TEST_LOCATION); - DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION ); - } - catch(...) - { - tet_printf("Assertion test failed - wrong Exception\n" ); - tet_result(TET_FAIL); - } + DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION ); + // try Remove self, its a no-op + parent.Remove( parent ); + DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION ); // try Remove empty try diff --git a/dali/internal/common/core-impl.cpp b/dali/internal/common/core-impl.cpp index f0a10acb9..5d11734fc 100644 --- a/dali/internal/common/core-impl.cpp +++ b/dali/internal/common/core-impl.cpp @@ -234,12 +234,13 @@ void Core::ContextDestroyed() mRenderManager->ContextDestroyed(); } -void Core::SurfaceResized(unsigned int width, unsigned int height) +void Core::SurfaceResized( unsigned int width, unsigned int height ) { - mStage->SetSize(width, height); + mStage->SetSize( width, height ); + mRelayoutController->SetStageSize( width, height ); } -void Core::SetDpi(unsigned int dpiHorizontal, unsigned int dpiVertical) +void Core::SetDpi( unsigned int dpiHorizontal, unsigned int dpiVertical ) { mPlatform.SetDpi( dpiHorizontal, dpiVertical ); mStage->SetDpi( Vector2( dpiHorizontal , dpiVertical) ); diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index 85dba95ae..9cd7f4129 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -437,7 +437,7 @@ void Actor::Add( Actor& child ) if( !child.mParent ) { // Do this first, since user callbacks from within SetParent() may need to remove child - mChildren->push_back( Dali::Actor( &child ) ); + mChildren->push_back( ActorPtr( &child ) ); // SetParent asserts that child can be added child.SetParent( this ); @@ -486,11 +486,11 @@ void Actor::Insert( unsigned int index, Actor& child ) { ActorIter it = mChildren->begin(); std::advance( it, index ); - mChildren->insert( it, Dali::Actor( &child ) ); + mChildren->insert( it, ActorPtr( &child ) ); } else { - mChildren->push_back( Dali::Actor( &child ) ); + mChildren->push_back( ActorPtr( &child ) ); } // SetParent asserts that child can be added child.SetParent( this, index ); @@ -513,32 +513,30 @@ void Actor::Insert( unsigned int index, Actor& child ) void Actor::Remove( Actor& child ) { - DALI_ASSERT_ALWAYS( this != &child && "Cannot remove actor from itself" ); - - Dali::Actor removed; - - if( !mChildren ) + if( (this == &child) || (!mChildren) ) { - // no children + // no children or removing itself return; } + ActorPtr removed; + // Find the child in mChildren, and unparent it ActorIter end = mChildren->end(); for( ActorIter iter = mChildren->begin(); iter != end; ++iter ) { - Actor& actor = GetImplementation( *iter ); + ActorPtr actor = (*iter); - if( &actor == &child ) + if( actor.Get() == &child ) { // Keep handle for OnChildRemove notification - removed = Dali::Actor( &actor ); + removed = actor; // Do this first, since user callbacks from within SetParent() may need to add the child mChildren->erase( iter ); - DALI_ASSERT_DEBUG( actor.GetParent() == this ); - actor.SetParent( NULL ); + DALI_ASSERT_DEBUG( actor->GetParent() == this ); + actor->SetParent( NULL ); break; } @@ -547,7 +545,7 @@ void Actor::Remove( Actor& child ) if( removed ) { // Notification for derived classes - OnChildRemove( GetImplementation( removed ) ); + OnChildRemove( *(removed.Get()) ); // Only put in a relayout request if there is a suitable dependency if( RelayoutDependentOnChildren() ) @@ -573,11 +571,11 @@ unsigned int Actor::GetChildCount() const return ( NULL != mChildren ) ? mChildren->size() : 0; } -Dali::Actor Actor::GetChildAt( unsigned int index ) const +ActorPtr Actor::GetChildAt( unsigned int index ) const { DALI_ASSERT_ALWAYS( index < GetChildCount() ); - return ( ( mChildren ) ? ( *mChildren )[ index ] : Dali::Actor() ); + return ( ( mChildren ) ? ( *mChildren )[ index ] : ActorPtr() ); } ActorPtr Actor::FindChildByName( const std::string& actorName ) @@ -592,7 +590,7 @@ ActorPtr Actor::FindChildByName( const std::string& actorName ) ActorIter end = mChildren->end(); for( ActorIter iter = mChildren->begin(); iter != end; ++iter ) { - child = GetImplementation( *iter ).FindChildByName( actorName ); + child = (*iter)->FindChildByName( actorName ); if( child ) { @@ -615,7 +613,7 @@ ActorPtr Actor::FindChildById( const unsigned int id ) ActorIter end = mChildren->end(); for( ActorIter iter = mChildren->begin(); iter != end; ++iter ) { - child = GetImplementation( *iter ).FindChildById( id ); + child = (*iter)->FindChildById( id ); if( child ) { @@ -1745,17 +1743,17 @@ void Actor::SetDynamicsRoot(bool flag) ActorIter end = mChildren->end(); for( ActorIter iter = mChildren->begin(); iter != end; ++iter ) { - Actor& child = GetImplementation(*iter); + ActorPtr child = (*iter); - if( child.GetDynamicsBody() ) + if( child->GetDynamicsBody() ) { if( mIsDynamicsRoot ) { - child.ConnectDynamics(); + child->ConnectDynamics(); } else { - child.DisconnectDynamics(); + child->DisconnectDynamics(); } } } @@ -2369,8 +2367,7 @@ Actor::~Actor() ActorConstIter endIter = mChildren->end(); for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter ) { - Actor& actor = GetImplementation( *iter ); - actor.SetParent( NULL ); + (*iter)->SetParent( NULL ); } } delete mChildren; @@ -2420,8 +2417,7 @@ void Actor::ConnectToStage( unsigned int parentDepth, int index ) const ActorIter endIter = connectionList.end(); for( ActorIter iter = connectionList.begin(); iter != endIter; ++iter ) { - Actor& actor = GetImplementation( *iter ); - actor.NotifyStageConnection(); + (*iter)->NotifyStageConnection(); } RelayoutRequest(); @@ -2440,7 +2436,7 @@ void Actor::RecursiveConnectToStage( ActorContainer& connectionList, unsigned in OnStageConnectionInternal(); // This stage is atomic; avoid emitting callbacks until all Actors are connected - connectionList.push_back( Dali::Actor( this ) ); + connectionList.push_back( ActorPtr( this ) ); // Recursively connect children if( mChildren ) @@ -2448,8 +2444,7 @@ void Actor::RecursiveConnectToStage( ActorContainer& connectionList, unsigned in ActorConstIter endIter = mChildren->end(); for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter ) { - Actor& actor = GetImplementation( *iter ); - actor.RecursiveConnectToStage( connectionList, depth+1 ); + (*iter)->RecursiveConnectToStage( connectionList, depth+1 ); } } } @@ -2527,8 +2522,7 @@ void Actor::DisconnectFromStage() const ActorIter endIter = disconnectionList.end(); for( ActorIter iter = disconnectionList.begin(); iter != endIter; ++iter ) { - Actor& actor = GetImplementation( *iter ); - actor.NotifyStageDisconnection(); + (*iter)->NotifyStageDisconnection(); } } @@ -2542,13 +2536,12 @@ void Actor::RecursiveDisconnectFromStage( ActorContainer& disconnectionList ) ActorConstIter endIter = mChildren->end(); for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter ) { - Actor& actor = GetImplementation( *iter ); - actor.RecursiveDisconnectFromStage( disconnectionList ); + (*iter)->RecursiveDisconnectFromStage( disconnectionList ); } } // This stage is atomic; avoid emitting callbacks until all Actors are disconnected - disconnectionList.push_back( Dali::Actor( this ) ); + disconnectionList.push_back( ActorPtr( this ) ); // Notification for internal derived classes OnStageDisconnectionInternal(); @@ -4206,14 +4199,13 @@ float Actor::NegotiateFromChildren( Dimension::Type dimension ) for( unsigned int i = 0, count = GetChildCount(); i < count; ++i ) { - Dali::Actor child = GetChildAt( i ); - Actor& childImpl = GetImplementation( child ); + ActorPtr child = GetChildAt( i ); - if( !childImpl.RelayoutDependentOnParent( dimension ) ) + if( !child->RelayoutDependentOnParent( dimension ) ) { // Calculate the min and max points that the children range across - float childPosition = GetDimensionValue( childImpl.GetTargetPosition(), dimension ); - float dimensionSize = childImpl.GetRelayoutSize( dimension ); + float childPosition = GetDimensionValue( child->GetTargetPosition(), dimension ); + float dimensionSize = child->GetRelayoutSize( dimension ); maxDimensionPoint = std::max( maxDimensionPoint, childPosition + dimensionSize ); } } @@ -4342,13 +4334,12 @@ void Actor::NegotiateDimension( Dimension::Type dimension, const Vector2& alloca { for( unsigned int i = 0, count = GetChildCount(); i < count; ++i ) { - Dali::Actor child = GetChildAt( i ); - Actor& childImpl = GetImplementation( child ); + ActorPtr child = GetChildAt( i ); // Only relayout child first if it is not dependent on this actor - if( !childImpl.RelayoutDependentOnParent( dimension ) ) + if( !child->RelayoutDependentOnParent( dimension ) ) { - childImpl.NegotiateDimension( dimension, allocatedSize, recursionStack ); + child->NegotiateDimension( dimension, allocatedSize, recursionStack ); } } } @@ -4497,12 +4488,12 @@ void Actor::NegotiateSize( const Vector2& allocatedSize, RelayoutContainer& cont for( unsigned int i = 0, count = GetChildCount(); i < count; ++i ) { - Dali::Actor child = GetChildAt( i ); + ActorPtr child = GetChildAt( i ); // Only relayout if required - if( GetImplementation( child ).RelayoutRequired() ) + if( child->RelayoutRequired() ) { - container.Add( child, newBounds ); + container.Add( Dali::Actor( child.Get() ), newBounds ); } } } diff --git a/dali/internal/event/actors/actor-impl.h b/dali/internal/event/actors/actor-impl.h index 9cac06dd8..759d295a8 100644 --- a/dali/internal/event/actors/actor-impl.h +++ b/dali/internal/event/actors/actor-impl.h @@ -58,8 +58,7 @@ class RenderTask; class Renderer; struct DynamicsData; -typedef IntrusivePtr< Actor > ActorPtr; -typedef std::vector< Dali::Actor > ActorContainer; // Store handles to return via public-api +typedef std::vector< ActorPtr > ActorContainer; typedef ActorContainer::iterator ActorIter; typedef ActorContainer::const_iterator ActorConstIter; @@ -233,7 +232,7 @@ public: /** * @copydoc Dali::Actor::GetChildAt */ - Dali::Actor GetChildAt( unsigned int index ) const; + ActorPtr GetChildAt( unsigned int index ) const; /** * Retrieve a reference to Actor's children. diff --git a/dali/internal/event/events/hit-test-algorithm-impl.cpp b/dali/internal/event/events/hit-test-algorithm-impl.cpp index 67b5ed65c..ab52bb571 100644 --- a/dali/internal/event/events/hit-test-algorithm-impl.cpp +++ b/dali/internal/event/events/hit-test-algorithm-impl.cpp @@ -258,10 +258,10 @@ HitActor HitTestWithinLayer( Actor& actor, for( ActorIter iter = children.begin(), endIter = children.end(); iter != endIter; ++iter ) { // Descend tree only if... - if ( !iter->IsLayer() && // Child is NOT a layer, hit testing current layer only or Child is not a layer and we've inherited the stencil draw mode - ( isStencil || hitCheck.DescendActorHierarchy( &GetImplementation( *iter ) ) ) ) // We are a stencil OR we can descend into child hierarchy + if ( !(*iter)->IsLayer() && // Child is NOT a layer, hit testing current layer only or Child is not a layer and we've inherited the stencil draw mode + ( isStencil || hitCheck.DescendActorHierarchy( ( *iter ).Get() ) ) ) // We are a stencil OR we can descend into child hierarchy { - HitActor currentHit( HitTestWithinLayer( GetImplementation(*iter), + HitActor currentHit( HitTestWithinLayer( (*iter->Get()), renderTask, exclusives, rayOrigin, diff --git a/dali/internal/event/size-negotiation/relayout-controller-impl.cpp b/dali/internal/event/size-negotiation/relayout-controller-impl.cpp index 9c2120af3..9efe523b9 100644 --- a/dali/internal/event/size-negotiation/relayout-controller-impl.cpp +++ b/dali/internal/event/size-negotiation/relayout-controller-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 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. @@ -15,8 +15,7 @@ * */ -// FILE HEADER - +// CLASS HEADER #include "relayout-controller-impl.h" // EXTERNAL INCLUDES @@ -26,13 +25,12 @@ #endif // defined(DEBUG_ENABLED) // INTERNAL INCLUDES -#include -#include #include #include #include #include #include +#include #include namespace Dali @@ -93,7 +91,7 @@ void PrintHierarchy() if ( gLogFilter->IsEnabledFor( Debug::Verbose ) ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "---------- ROOT LAYER ----------\n" ); - PrintChildren( Dali::Stage().GetCurrent().GetRootLayer(), 0 ); + PrintChildren( Stage::GetCurrent()->GetRootLayer(), 0 ); } } @@ -107,16 +105,12 @@ void PrintHierarchy() } // unnamed namespace -RelayoutController* RelayoutController::Get() -{ - return &ThreadLocalStorage::Get().GetRelayoutController(); -} - RelayoutController::RelayoutController( Integration::RenderController& controller ) : mRenderController( controller ), mRelayoutInfoAllocator(), mSlotDelegate( this ), mRelayoutStack( new MemoryPoolRelayoutContainer( mRelayoutInfoAllocator ) ), + mStageSize(), // zero initialized mRelayoutConnection( false ), mRelayoutFlag( false ), mEnabled( false ), @@ -132,6 +126,17 @@ RelayoutController::~RelayoutController() delete mRelayoutStack; } +RelayoutController* RelayoutController::Get() +{ + return &ThreadLocalStorage::Get().GetRelayoutController(); +} + +void RelayoutController::SetStageSize( unsigned int width, unsigned int height ) +{ + mStageSize.width = width; + mStageSize.height = height; +} + void RelayoutController::QueueActor( Dali::Actor& actor, RelayoutContainer& actors, Vector2 size ) { if( GetImplementation( actor ).RelayoutRequired() ) @@ -434,8 +439,6 @@ void RelayoutController::Relayout() // 1. Finds all top-level controls from the dirty list and allocate them the size of the stage // These controls are paired with the parent/stage size and added to the stack. - const Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); - for( RawActorList::Iterator it = mDirtyLayoutSubTrees.Begin(), itEnd = mDirtyLayoutSubTrees.End(); it != itEnd; ++it ) { BaseObject* dirtyActor = *it; @@ -450,7 +453,7 @@ void RelayoutController::Relayout() if( actor.OnStage() ) { Dali::Actor parent = actor.GetParent(); - QueueActor( actor, *mRelayoutStack, ( parent ) ? Vector2( parent.GetTargetSize() ) : stageSize ); + QueueActor( actor, *mRelayoutStack, ( parent ) ? Vector2( parent.GetTargetSize() ) : mStageSize ); } } } diff --git a/dali/internal/event/size-negotiation/relayout-controller-impl.h b/dali/internal/event/size-negotiation/relayout-controller-impl.h index 5b6e63553..d8e7bfa20 100644 --- a/dali/internal/event/size-negotiation/relayout-controller-impl.h +++ b/dali/internal/event/size-negotiation/relayout-controller-impl.h @@ -64,6 +64,13 @@ public: */ static RelayoutController* Get(); + /** + * Set the stage size + * @param width of the stage + * @param height of the stage + */ + void SetStageSize( unsigned int width, unsigned int height ); + /** * @brief Request to relayout the given actor and all sub-actors of it. * @@ -207,11 +214,13 @@ private: RawActorList mDirtyLayoutSubTrees; ///< List of roots of sub trees that are dirty MemoryPoolRelayoutContainer* mRelayoutStack; ///< Stack for relayouting - bool mRelayoutConnection : 1; ///< Whether EventProcessingFinishedSignal signal is connected. - bool mRelayoutFlag : 1; ///< Relayout flag to avoid unnecessary calls - bool mEnabled : 1; ///< Initially disabled. Must be enabled at some point. - bool mPerformingRelayout : 1; ///< The relayout controller is currently performing a relayout - bool mProcessingCoreEvents : 1; ///< Whether core is processing events. + + Vector2 mStageSize; ///< size of the stage + bool mRelayoutConnection : 1; ///< Whether EventProcessingFinishedSignal signal is connected. + bool mRelayoutFlag : 1; ///< Relayout flag to avoid unnecessary calls + bool mEnabled : 1; ///< Initially disabled. Must be enabled at some point. + bool mPerformingRelayout : 1; ///< The relayout controller is currently performing a relayout + bool mProcessingCoreEvents : 1; ///< Whether core is processing events. }; diff --git a/dali/public-api/actors/actor.cpp b/dali/public-api/actors/actor.cpp index 8f75cd34e..fe27d7a1d 100644 --- a/dali/public-api/actors/actor.cpp +++ b/dali/public-api/actors/actor.cpp @@ -128,19 +128,20 @@ unsigned int Actor::GetChildCount() const Actor Actor::GetChildAt(unsigned int index) const { - return GetImplementation(*this).GetChildAt(index); + Internal::ActorPtr child = GetImplementation(*this).GetChildAt( index ); + return Actor( child.Get() ); } Actor Actor::FindChildByName(const std::string& actorName) { - Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName); - return Actor(child.Get()); + Internal::ActorPtr child = GetImplementation(*this).FindChildByName( actorName ); + return Actor( child.Get() ); } Actor Actor::FindChildById(const unsigned int id) { - Internal::ActorPtr child = GetImplementation(*this).FindChildById(id); - return Actor(child.Get()); + Internal::ActorPtr child = GetImplementation(*this).FindChildById( id ); + return Actor( child.Get() ); } Actor Actor::GetParent() const -- 2.34.1