From 6f7631cee170290998ced6ea28f75c65ebb24f05 Mon Sep 17 00:00:00 2001 From: Xiangyin Ma Date: Wed, 23 Mar 2016 16:28:58 +0000 Subject: [PATCH] Stop Overriding Actor::Add() & Actor::Remove() Change-Id: I81213f1888d0469eb5b02bc5e9686d70ba79f113 --- .../devel-api/controls/bloom-view/bloom-view.cpp | 10 ----- .../devel-api/controls/bloom-view/bloom-view.h | 24 ---------- .../devel-api/controls/shadow-view/shadow-view.cpp | 10 ----- .../devel-api/controls/shadow-view/shadow-view.h | 24 ---------- .../controls/bloom-view/bloom-view-impl.cpp | 52 +++++++++++----------- .../internal/controls/bloom-view/bloom-view-impl.h | 16 +++++-- .../gaussian-blur-view/gaussian-blur-view-impl.cpp | 37 ++++++++++----- .../gaussian-blur-view/gaussian-blur-view-impl.h | 12 +++++ .../controls/shadow-view/shadow-view-impl.cpp | 25 +++++------ .../controls/shadow-view/shadow-view-impl.h | 21 +++++---- .../gaussian-blur-view/gaussian-blur-view.h | 2 + 11 files changed, 100 insertions(+), 133 deletions(-) diff --git a/dali-toolkit/devel-api/controls/bloom-view/bloom-view.cpp b/dali-toolkit/devel-api/controls/bloom-view/bloom-view.cpp index c7cfc9e..2f71883 100644 --- a/dali-toolkit/devel-api/controls/bloom-view/bloom-view.cpp +++ b/dali-toolkit/devel-api/controls/bloom-view/bloom-view.cpp @@ -77,16 +77,6 @@ BloomView BloomView::DownCast( BaseHandle handle ) return Control::DownCast(handle); } -void BloomView::Add(Actor child) -{ - GetImpl(*this).Add(child); -} - -void BloomView::Remove(Actor child) -{ - GetImpl(*this).Remove(child); -} - void BloomView::Activate() { GetImpl(*this).Activate(); diff --git a/dali-toolkit/devel-api/controls/bloom-view/bloom-view.h b/dali-toolkit/devel-api/controls/bloom-view/bloom-view.h index 0d37cea..9353f13 100644 --- a/dali-toolkit/devel-api/controls/bloom-view/bloom-view.h +++ b/dali-toolkit/devel-api/controls/bloom-view/bloom-view.h @@ -154,30 +154,6 @@ public: const float downsampleWidthScale, const float downsampleHeightScale); /** - * Adds a child Actor to this Actor. - * NOTE! if the child already has a parent, it will be removed from old parent - * and reparented to this actor. This may change childs position, color, shader effect, - * scale etc as it now inherits them from this actor - * @pre This Actor (the parent) has been initialized. - * @pre The child actor has been initialized. - * @pre The child actor is not the same as the parent actor. - * @pre The actor is not the Root actor - * @param [in] child The child. - * @post The child will be referenced by its parent. This means that the child will be kept alive, - * even if the handle passed into this method is reset or destroyed. - */ - void Add(Actor child); - - /** - * Removes a child Actor from this Actor. - * If the actor was not a child of this actor, this is a no-op. - * @pre This Actor (the parent) has been initialized. - * @pre The child actor is not the same as the parent actor. - * @param [in] child The child. - */ - void Remove(Actor child); - - /** * Start rendering the BloomView. Must be called after you Add() it to the stage. */ void Activate(); diff --git a/dali-toolkit/devel-api/controls/shadow-view/shadow-view.cpp b/dali-toolkit/devel-api/controls/shadow-view/shadow-view.cpp index 5afc638..a969dc2 100644 --- a/dali-toolkit/devel-api/controls/shadow-view/shadow-view.cpp +++ b/dali-toolkit/devel-api/controls/shadow-view/shadow-view.cpp @@ -84,16 +84,6 @@ ShadowView ShadowView::DownCast( BaseHandle handle ) return Control::DownCast(handle); } -void ShadowView::Add(Actor child) -{ - GetImpl(*this).Add(child); -} - -void ShadowView::Remove(Actor child) -{ - GetImpl(*this).Remove(child); -} - void ShadowView::SetShadowPlaneBackground(Actor shadowPlaneBackground) { GetImpl(*this).SetShadowPlaneBackground(shadowPlaneBackground); diff --git a/dali-toolkit/devel-api/controls/shadow-view/shadow-view.h b/dali-toolkit/devel-api/controls/shadow-view/shadow-view.h index d6039f2..9ddea7c 100644 --- a/dali-toolkit/devel-api/controls/shadow-view/shadow-view.h +++ b/dali-toolkit/devel-api/controls/shadow-view/shadow-view.h @@ -154,30 +154,6 @@ public: static ShadowView New(float downsampleWidthScale, float downsampleHeightScale); /** - * Adds a child Actor to this Actor. - * NOTE! if the child already has a parent, it will be removed from old parent - * and reparented to this actor. This may change childs position, color, shader effect, - * scale etc as it now inherits them from this actor - * @pre This Actor (the parent) has been initialized. - * @pre The child actor has been initialized. - * @pre The child actor is not the same as the parent actor. - * @pre The actor is not the Root actor - * @param [in] child The child. - * @post The child will be referenced by its parent. This means that the child will be kept alive, - * even if the handle passed into this method is reset or destroyed. - */ - void Add(Actor child); - - /** - * Removes a child Actor from this Actor. - * If the actor was not a child of this actor, this is a no-op. - * @pre This Actor (the parent) has been initialized. - * @pre The child actor is not the same as the parent actor. - * @param [in] child The child. - */ - void Remove(Actor child); - - /** * Set the Shadow Plane Background for the shadow effect. * * @param[in] shadowPlaneBackground An actor representing the shadow diff --git a/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp b/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp index 750d6fe..4d088d1 100644 --- a/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp +++ b/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp @@ -149,6 +149,7 @@ BloomView::BloomView() , mTargetSize(Vector2::ZERO) , mLastSize(Vector2::ZERO) , mChildrenRoot(Actor::New()) + , mInternalRoot(Actor::New() ) , mBloomThresholdPropertyIndex(Property::INVALID_INDEX) , mBlurStrengthPropertyIndex(Property::INVALID_INDEX) , mBloomIntensityPropertyIndex(Property::INVALID_INDEX) @@ -172,6 +173,7 @@ BloomView::BloomView( const unsigned int blurNumSamples, const float blurBellCur , mTargetSize(Vector2::ZERO) , mLastSize(Vector2::ZERO) , mChildrenRoot(Actor::New()) + , mInternalRoot(Actor::New()) , mBloomThresholdPropertyIndex(Property::INVALID_INDEX) , mBlurStrengthPropertyIndex(Property::INVALID_INDEX) , mBloomIntensityPropertyIndex(Property::INVALID_INDEX) @@ -213,24 +215,6 @@ Toolkit::BloomView BloomView::New(const unsigned int blurNumSamples, const float return handle; } -///////////////////////////////////////////////////////////// -// for creating a subtree for all user added child actors, so that we can have them exclusive to the mRenderChildrenTask and our other actors exclusive to our other tasks -// TODO: overloading Actor::Add()/Remove() not nice since breaks polymorphism. Need another method to pass ownership of added child actors to our internal actor root. -void BloomView::Add(Actor child) -{ - mChildrenRoot.Add(child); -} - -void BloomView::Remove(Actor child) -{ - mChildrenRoot.Remove(child); -} - - - - - - /////////////////////////////////////////////////////////// // // Private methods @@ -240,6 +224,7 @@ void BloomView::OnInitialize() { // root actor to parent all user added actors, needed to allow us to set that subtree as exclusive for our child render task mChildrenRoot.SetParentOrigin( ParentOrigin::CENTER ); + mInternalRoot.SetParentOrigin( ParentOrigin::CENTER ); ////////////////////////////////////////////////////// // Create actors @@ -291,12 +276,13 @@ void BloomView::OnInitialize() //////////////////////////////// // Connect to actor tree Self().Add( mChildrenRoot ); - Self().Add( mBloomExtractImageActor ); - Self().Add( mGaussianBlurView ); - Self().Add( mCompositeImageActor ); - Self().Add( mTargetImageActor ); - Self().Add( mRenderDownsampledCamera ); - Self().Add( mRenderFullSizeCamera ); + Self().Add( mInternalRoot ); + mInternalRoot.Add( mBloomExtractImageActor ); + mInternalRoot.Add( mGaussianBlurView ); + mInternalRoot.Add( mCompositeImageActor ); + mInternalRoot.Add( mTargetImageActor ); + mInternalRoot.Add( mRenderDownsampledCamera ); + mInternalRoot.Add( mRenderFullSizeCamera ); // bind properties for / set shader constants to defaults SetupProperties(); @@ -327,10 +313,23 @@ void BloomView::OnSizeSet(const Vector3& targetSize) } } +void BloomView::OnControlChildAdd( Actor& child ) +{ + if( child != mChildrenRoot && child != mInternalRoot) + { + mChildrenRoot.Add( child ); + } +} + +void BloomView::OnControlChildRemove( Actor& child ) +{ + mChildrenRoot.Remove( child ); +} + void BloomView::AllocateResources() { // size of render targets etc is based on the size of this actor, ignoring z - if(mTargetSize != mLastSize) + if(mTargetSize != mLastSize || !mActivated) { mLastSize = mTargetSize; @@ -464,6 +463,9 @@ void BloomView::Deactivate() // stop render tasks processing // Note: render target resources are automatically freed since we set the Image::Unused flag RemoveRenderTasks(); + mRenderTargetForRenderingChildren.Reset(); + mBloomExtractTarget.Reset(); + mOutputRenderTarget.Reset(); mActivated = false; } diff --git a/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.h b/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.h index 207ce92..cc42f64 100644 --- a/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.h +++ b/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.h @@ -70,10 +70,6 @@ public: static Dali::Toolkit::BloomView New(); static Dali::Toolkit::BloomView New( const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat, const float downsampleWidthScale, const float downsampleHeightScale); - - void Add(Actor child); - void Remove(Actor child); - void Activate(); void Deactivate(); @@ -89,6 +85,16 @@ private: virtual void OnInitialize(); virtual void OnSizeSet(const Vector3& targetSize); + /** + * @copydoc Control::OnControlChildAdd() + */ + virtual void OnControlChildAdd( Actor& child ); + + /** + * @copydoc Control::OnControlChildRemove() + */ + virtual void OnControlChildRemove( Actor& child ); + void AllocateResources(); void CreateRenderTasks(); void RemoveRenderTasks(); @@ -117,6 +123,8 @@ private: ///////////////////////////////////////////////////////////// // for creating a subtree for all user added child actors, so that we can have them exclusive to the mRenderChildrenTask and our other actors exclusive to our other tasks Actor mChildrenRoot; + // for creating a subtree for the internal actors + Actor mInternalRoot; ///////////////////////////////////////////////////////////// // for mapping offscreen renders to render target sizes diff --git a/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp b/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp index 0cdde34..8a608f1 100644 --- a/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp +++ b/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp @@ -37,7 +37,6 @@ // pixel format / size - set from JSON // aspect ratio property needs to be able to be constrained also for cameras, not possible currently. Therefore changing aspect ratio of GaussianBlurView won't currently work // default near clip value -// mChildrenRoot Add()/Remove() overloads - better solution // Manager object - re-use render targets if there are multiple GaussianBlurViews created @@ -133,6 +132,7 @@ GaussianBlurView::GaussianBlurView() , mTargetSize(Vector2::ZERO) , mLastSize(Vector2::ZERO) , mChildrenRoot(Actor::New()) + , mInternalRoot(Actor::New()) , mBlurStrengthPropertyIndex(Property::INVALID_INDEX) , mActivated( false ) { @@ -156,6 +156,7 @@ GaussianBlurView::GaussianBlurView( const unsigned int numSamples, const float b , mTargetSize(Vector2::ZERO) , mLastSize(Vector2::ZERO) , mChildrenRoot(Actor::New()) + , mInternalRoot(Actor::New()) , mBlurStrengthPropertyIndex(Property::INVALID_INDEX) , mActivated( false ) { @@ -199,7 +200,7 @@ Toolkit::GaussianBlurView GaussianBlurView::New(const unsigned int numSamples, c ///////////////////////////////////////////////////////////// // for creating a subtree for all user added child actors, so that we can have them exclusive to the mRenderChildrenTask and our other actors exclusive to our other tasks -// TODO: overloading Actor::Add()/Remove() not nice since breaks polymorphism. Need another method to pass ownership of added child actors to our internal actor root. +// DEPRECATED: overloading Actor::Add()/Remove() not nice since breaks polymorphism. Need another method to pass ownership of added child actors to our internal actor root. void GaussianBlurView::Add(Actor child) { mChildrenRoot.Add(child); @@ -250,6 +251,7 @@ void GaussianBlurView::OnInitialize() { // root actor to parent all user added actors, needed to allow us to set that subtree as exclusive for our child render task mChildrenRoot.SetParentOrigin(ParentOrigin::CENTER); + mInternalRoot.SetParentOrigin(ParentOrigin::CENTER); ////////////////////////////////////////////////////// // Create shaders @@ -277,7 +279,8 @@ void GaussianBlurView::OnInitialize() mImageActorVertBlur.SetProperty( Toolkit::ImageView::Property::IMAGE, rendererMap ); // Register a property that the user can control to fade the blur in / out via the GaussianBlurView object - mBlurStrengthPropertyIndex = Self().RegisterProperty(GAUSSIAN_BLUR_VIEW_STRENGTH_PROPERTY_NAME, GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH); + Actor self = Self(); + mBlurStrengthPropertyIndex = self.RegisterProperty(GAUSSIAN_BLUR_VIEW_STRENGTH_PROPERTY_NAME, GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH); // Create an ImageActor for compositing the blur and the original child actors render if(!mBlurUserImage) @@ -287,7 +290,7 @@ void GaussianBlurView::OnInitialize() mImageActorComposite.SetOpacity(GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH); // ensure alpha is enabled for this object and set default value Constraint blurStrengthConstraint = Constraint::New( mImageActorComposite, Actor::Property::COLOR_ALPHA, EqualToConstraint()); - blurStrengthConstraint.AddSource( ParentSource(mBlurStrengthPropertyIndex) ); + blurStrengthConstraint.AddSource( Source( self, mBlurStrengthPropertyIndex) ); blurStrengthConstraint.Apply(); // Create an ImageActor for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task @@ -303,9 +306,9 @@ void GaussianBlurView::OnInitialize() ////////////////////////////////////////////////////// // Connect to actor tree - Self().Add( mImageActorComposite ); - Self().Add( mTargetActor ); - Self().Add( mRenderFullSizeCamera ); + mInternalRoot.Add( mImageActorComposite ); + mInternalRoot.Add( mTargetActor ); + mInternalRoot.Add( mRenderFullSizeCamera ); } @@ -319,9 +322,10 @@ void GaussianBlurView::OnInitialize() ////////////////////////////////////////////////////// // Connect to actor tree Self().Add( mChildrenRoot ); - Self().Add( mImageActorHorizBlur ); - Self().Add( mImageActorVertBlur ); - Self().Add( mRenderDownsampledCamera ); + Self().Add( mInternalRoot ); + mInternalRoot.Add( mImageActorHorizBlur ); + mInternalRoot.Add( mImageActorVertBlur ); + mInternalRoot.Add( mRenderDownsampledCamera ); } @@ -353,6 +357,19 @@ void GaussianBlurView::OnSizeSet(const Vector3& targetSize) } } +void GaussianBlurView::OnControlChildAdd( Actor& child ) +{ + if( child != mChildrenRoot && child != mInternalRoot) + { + mChildrenRoot.Add( child ); + } +} + +void GaussianBlurView::OnControlChildRemove( Actor& child ) +{ + mChildrenRoot.Remove( child ); +} + void GaussianBlurView::AllocateResources() { // size of render targets etc is based on the size of this actor, ignoring z diff --git a/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.h b/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.h index 7f38489..1d8332e 100644 --- a/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.h +++ b/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.h @@ -98,6 +98,16 @@ private: virtual void OnInitialize(); virtual void OnSizeSet(const Vector3& targetSize); + /** + * @copydoc Control::OnControlChildAdd() + */ + virtual void OnControlChildAdd( Actor& child ); + + /** + * @copydoc Control::OnControlChildRemove() + */ + virtual void OnControlChildRemove( Actor& child ); + void SetBlurBellCurveWidth(float blurBellCurveWidth); float CalcGaussianWeight(float x); void SetShaderConstants(); @@ -138,6 +148,8 @@ private: ///////////////////////////////////////////////////////////// // for creating a subtree for all user added child actors, so that we can have them exclusive to the mRenderChildrenTask and our other actors exclusive to our other tasks Actor mChildrenRoot; + // for creating a subtree for the internal actors + Actor mInternalRoot; ///////////////////////////////////////////////////////////// // for mapping offscreen renders to render target sizes diff --git a/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp b/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp index 950c819..d3f3f87 100644 --- a/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp +++ b/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp @@ -36,7 +36,6 @@ // pixel format / size - set from JSON // aspect ratio property needs to be able to be constrained also for cameras. (now do-able) // default near clip value -// mChildrenRoot Add()/Remove() overloads - better solution ///////////////////////////////////////////////////////// @@ -148,19 +147,6 @@ Toolkit::ShadowView ShadowView::New(float downsampleWidthScale, float downsample return handle; } -///////////////////////////////////////////////////////////// -// for creating a subtree for all user added child actors. -// TODO: overloading Actor::Add()/Remove() not nice since breaks polymorphism. Need another method to pass ownership of added child actors to our internal actor root. -void ShadowView::Add(Actor child) -{ - mChildrenRoot.Add(child); -} - -void ShadowView::Remove(Actor child) -{ - mChildrenRoot.Remove(child); -} - void ShadowView::SetShadowPlaneBackground(Actor shadowPlaneBackground) { mShadowPlaneBg = shadowPlaneBackground; @@ -307,8 +293,17 @@ void ShadowView::OnInitialize() blurStrengthConstraint.Apply(); } -void ShadowView::OnSizeSet(const Vector3& targetSize) +void ShadowView::OnControlChildAdd( Actor& child ) +{ + if( child != mChildrenRoot && child != mBlurRootActor) + { + mChildrenRoot.Add( child ); + } +} + +void ShadowView::OnControlChildRemove( Actor& child ) { + mChildrenRoot.Remove( child ); } void ShadowView::ConstrainCamera() diff --git a/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.h b/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.h index 68e1c33..9f7d9d6 100644 --- a/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.h +++ b/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.h @@ -72,16 +72,6 @@ public: static Dali::Toolkit::ShadowView New(float downsampleWidthScale, float downsampleHeightScale); /** - * @copydoc Dali::Toolkit::ShadowView::Add(Actor child) - */ - void Add(Actor child); - - /** - * @copydoc Dali::Toolkit::ShadowView::Remove(Actor child) - */ - void Remove(Actor child); - - /** * @copydoc Dali::Toolkit::ShadowView::SetShadowPlaneBackground(Actor shadowPlaneBackground) */ void SetShadowPlaneBackground(Actor shadowPlaneBackground); @@ -126,7 +116,16 @@ public: private: virtual void OnInitialize(); - virtual void OnSizeSet(const Vector3& targetSize); + + /** + * @copydoc Control::OnControlChildAdd() + */ + virtual void OnControlChildAdd( Actor& child ); + + /** + * @copydoc Control::OnControlChildRemove() + */ + virtual void OnControlChildRemove( Actor& child ); /** * Constrain the camera actor to the position of the point light, pointing diff --git a/dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h b/dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h index 15d7fcc..524943d 100644 --- a/dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h +++ b/dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h @@ -187,6 +187,7 @@ public: bool blurUserImage = false); /** + * @DEPRECATED_1_1.28 Use Actor::Add(Actor) instead * @brief Adds a child Actor to this Actor. * @SINCE_1_0.0 * @param [in] child The child. @@ -203,6 +204,7 @@ public: void Add(Actor child); /** + * @DEPRECATED_1_1.28 Use Actor::Remove(Actor) instead * @brief Removes a child Actor from this Actor. * * If the actor was not a child of this actor, this is a no-op. -- 2.7.4