Rendering API clean-up
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / bloom-view / bloom-view-impl.cpp
index 750d6fe..ab3a9c9 100644 (file)
@@ -83,8 +83,6 @@ const char* const BLOOM_SATURATION_PROPERTY_NAME = "uBloomSaturation";
 const char* const IMAGE_INTENSITY_PROPERTY_NAME = "uImageIntensity";
 const char* const IMAGE_SATURATION_PROPERTY_NAME = "uImageSaturation";
 
-const char* const EFFECT_IMAGE_NAME( "sEffect" );
-
 ///////////////////////////////////////////////////////
 //
 // Bloom shaders
@@ -149,6 +147,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 +171,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 +213,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 +222,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 +274,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();
@@ -304,6 +288,8 @@ void BloomView::OnInitialize()
 
 void BloomView::OnSizeSet(const Vector3& targetSize)
 {
+  Control::OnSizeSet( targetSize );
+
   mTargetSize = Vector2(targetSize);
   mChildrenRoot.SetSize(targetSize);
   mCompositeImageActor.SetSize(targetSize);
@@ -327,10 +313,27 @@ void BloomView::OnSizeSet(const Vector3& targetSize)
   }
 }
 
+void BloomView::OnChildAdd( Actor& child )
+{
+  Control::OnChildAdd( child );
+
+  if( child != mChildrenRoot && child != mInternalRoot)
+  {
+    mChildrenRoot.Add( child );
+  }
+}
+
+void BloomView::OnChildRemove( Actor& child )
+{
+  mChildrenRoot.Remove( child );
+
+  Control::OnChildRemove( 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;
 
@@ -388,16 +391,8 @@ void BloomView::AllocateResources()
 
     // use the completed blur in the first buffer and composite with the original child actors render
     mCompositeImageActor.SetImage( mRenderTargetForRenderingChildren );
-    Material material = mCompositeImageActor.GetRendererAt(0).GetMaterial();
-    int textureIndex = material.GetTextureIndex( EFFECT_IMAGE_NAME );
-    if( textureIndex == -1 )
-    {
-      material.AddTexture( mBlurExtractTarget, EFFECT_IMAGE_NAME );
-    }
-    else
-    {
-      material.SetTextureImage( textureIndex, mBlurExtractTarget );
-    }
+    TextureSet textureSet = mCompositeImageActor.GetRendererAt(0).GetTextures();
+    textureSet.SetImage( 1u, mBlurExtractTarget );
 
     // set up target actor for rendering result, i.e. the blurred image
     mTargetImageActor.SetImage(mOutputRenderTarget);
@@ -464,6 +459,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;
 }