Automatically dis/connect registered visuals to stage 90/84390/16
authorXiangyin Ma <x1.ma@samsung.com>
Wed, 17 Aug 2016 13:47:51 +0000 (14:47 +0100)
committerXiangyin Ma <x1.ma@samsung.com>
Thu, 8 Sep 2016 12:55:06 +0000 (13:55 +0100)
Change-Id: Ia4808935cb603f107e0e40dc2a573e611cdb83e5

28 files changed:
automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp
dali-toolkit/devel-api/visual-factory/visual-base.h
dali-toolkit/internal/controls/buttons/button-impl.cpp
dali-toolkit/internal/controls/image-view/image-view-impl.cpp
dali-toolkit/internal/controls/image-view/image-view-impl.h
dali-toolkit/internal/visuals/border/border-visual.cpp
dali-toolkit/internal/visuals/border/border-visual.h
dali-toolkit/internal/visuals/color/color-visual.cpp
dali-toolkit/internal/visuals/color/color-visual.h
dali-toolkit/internal/visuals/gradient/gradient-visual.cpp
dali-toolkit/internal/visuals/gradient/gradient-visual.h
dali-toolkit/internal/visuals/image/batch-image-visual.cpp
dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/image/image-visual.h
dali-toolkit/internal/visuals/mesh/mesh-visual.cpp
dali-toolkit/internal/visuals/mesh/mesh-visual.h
dali-toolkit/internal/visuals/npatch/npatch-visual.cpp
dali-toolkit/internal/visuals/npatch/npatch-visual.h
dali-toolkit/internal/visuals/primitive/primitive-visual.cpp
dali-toolkit/internal/visuals/primitive/primitive-visual.h
dali-toolkit/internal/visuals/svg/svg-visual.cpp
dali-toolkit/internal/visuals/svg/svg-visual.h
dali-toolkit/internal/visuals/visual-base-impl.cpp
dali-toolkit/internal/visuals/visual-base-impl.h
dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp
dali-toolkit/internal/visuals/wireframe/wireframe-visual.h
dali-toolkit/public-api/controls/control-impl.cpp
dali-toolkit/public-api/controls/control-impl.h

index fe4c588cb1d4b371273eed4579a76b0678943570..b3c6795270b10c45348f8d2bbd0c5f42d23b3577 100644 (file)
@@ -1117,7 +1117,8 @@ int UtcDaliVisualFactoryGetSvgVisual(void)
   application.SendNotification();
   application.Render();
 
-  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+  // renderer is not added to actor until the rasterization is completed.
+  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
 
   EventThreadCallback* eventTrigger = EventThreadCallback::Get();
   CallbackBase* callback = eventTrigger->GetCallback();
@@ -1125,6 +1126,7 @@ int UtcDaliVisualFactoryGetSvgVisual(void)
   eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
   CallbackBase::Execute( *callback );
 
+  // renderer is added to actor
   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
 
   // waiting for the resource uploading
index 40864e5af1d59a16200ce10d7f3856e8c1610253..74ca64090d8fbd291672945b2a2e5b2ebf44b682 100644 (file)
@@ -116,7 +116,7 @@ public:
   float GetDepthIndex() const;
 
   /**
-   * @brief Visual needs to know when when the control is put on to the stage to add the renderer.
+   * @brief Visual needs to know when the control is put on to the stage to add the renderer.
    *
    * This function should be called when the control is put on to the stage.
    *
@@ -126,7 +126,7 @@ public:
   void SetOnStage( Actor& actor );
 
   /**
-   * @brief Visual needs to know when when the control is removed from the stage to remove the renderer.
+   * @brief Visual needs to know when the control is removed from the stage to remove the renderer.
    *
    * This function should be called when the control is removed from the stage
    *
index 53ccf416bf2426e9926060f51262cbd27ce68ecc..9bf32effb04b5d306950964a1de41612992bf3c9 100644 (file)
@@ -576,7 +576,6 @@ void Button::SetColor( const Vector4& color, Button::PaintState selectedState )
       visual = visualFactory.CreateVisual( map );
 
       RegisterVisual( visualIndex, placementActor, visual );
-      visual.SetOnStage( placementActor );
 
       SetupContent( *contentActor, placementActor ); //
       contentActor->SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
index 7962e2ec9e169f31d620568e1f47115810d68921..251e317730cfc46a5afc4e0ec3a7f1d322bca10a 100644 (file)
@@ -82,7 +82,8 @@ void ImageView::SetImage( Image image )
     mImage = image;
 
     Actor self( Self() );
-    InitializeVisual( self, mVisual, image );
+    mVisual =  Toolkit::VisualFactory::Get().CreateVisual( image );
+    RegisterVisual( Toolkit::ImageView::Property::IMAGE, self, mVisual  );
     mImageSize = image ? ImageDimensions( image.GetWidth(), image.GetHeight() ) : ImageDimensions( 0, 0 );
 
     RelayoutRequest();
@@ -96,7 +97,8 @@ void ImageView::SetImage( Property::Map map )
   mPropertyMap = map;
 
   Actor self( Self() );
-  InitializeVisual( self, mVisual, mPropertyMap );
+  mVisual =  Toolkit::VisualFactory::Get().CreateVisual( mPropertyMap );
+  RegisterVisual( Toolkit::ImageView::Property::IMAGE, self, mVisual  );
 
   Property::Value* widthValue = mPropertyMap.Find( "width" );
   if( widthValue )
@@ -138,7 +140,8 @@ void ImageView::SetImage( const std::string& url, ImageDimensions size )
     }
 
     Actor self( Self() );
-    InitializeVisual( self, mVisual, url, size );
+    mVisual =  Toolkit::VisualFactory::Get().CreateVisual( url, size );
+    RegisterVisual( Toolkit::ImageView::Property::IMAGE, self, mVisual  );
 
     mVisual.SetSize( mSizeSet );
 
@@ -231,28 +234,6 @@ float ImageView::GetWidthForHeight( float height )
 // Private methods
 //
 
-void ImageView::OnStageConnection( int depth )
-{
-  Control::OnStageConnection( depth );
-
-  if( mVisual )
-  {
-    CustomActor self = Self();
-    mVisual.SetOnStage( self );
-  }
-}
-
-void ImageView::OnStageDisconnection()
-{
-  if( mVisual )
-  {
-    CustomActor self = Self();
-    mVisual.SetOffStage( self );
-  }
-
-  Control::OnStageDisconnection();
-}
-
 void ImageView::OnSizeSet( const Vector3& targetSize )
 {
   Control::OnSizeSet( targetSize );
index 669a84f78a09d30aa46c42b3fc0784731964a902..f4f38b619b6c52a076a82c96ecdbca40db73d74f 100644 (file)
@@ -122,16 +122,6 @@ public:
 
 private: // From Control
 
-  /**
-   * @copydoc Toolkit::Control::OnStageConnect()
-   */
-  virtual void OnStageConnection( int depth );
-
-  /**
-   * @copydoc Toolkit::Control::OnStageDisconnection()
-   */
-  virtual void OnStageDisconnection();
-
   /**
    * @copydoc Toolkit::Control::OnSizeSet()
    */
index f5d8053e781fdf45f6a5ff8ee86d5b37a8ea2be8..7f7c7b5b012c68b4392e6272eb0bdc0787a48b7a 100644 (file)
@@ -147,6 +147,8 @@ void BorderVisual::DoSetOnStage( Actor& actor )
     mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
   }
   mBorderSizeIndex = (mImpl->mRenderer).RegisterProperty( Toolkit::BorderVisual::Property::SIZE, SIZE_NAME, mBorderSize );
+
+  actor.AddRenderer( mImpl->mRenderer );
 }
 
 void BorderVisual::DoCreatePropertyMap( Property::Map& map ) const
index b7ca048d84437fd00e9b866cf6444934cc97608e..8a442506c110ac786703c2cc71b74a419d40ee16 100644 (file)
@@ -64,17 +64,17 @@ public:
 protected:
 
   /**
-   * @copydoc Visual::DoInitialize
+   * @copydoc Visual::Base::DoInitialize
    */
   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
 
   /**
-   * @copydoc Visual::DoSetOnStage
+   * @copydoc Visual::Base::DoSetOnStage
    */
   virtual void DoSetOnStage( Actor& actor );
 
   /**
-   * @copydoc Visual::CreatePropertyMap
+   * @copydoc Visual::Base::CreatePropertyMap
    */
   virtual void DoCreatePropertyMap( Property::Map& map ) const;
 
index 572220b1f41ea4557577983ecdee5010112fd9a9..6406bccd100b01b3c07e1fa5393d2cac8aaa3b7b 100644 (file)
@@ -94,6 +94,8 @@ void ColorVisual::SetSize( const Vector2& size )
 void ColorVisual::DoSetOnStage( Actor& actor )
 {
   InitializeRenderer();
+
+  actor.AddRenderer( mImpl->mRenderer );
 }
 
 void ColorVisual::DoCreatePropertyMap( Property::Map& map ) const
index 9367ffabfe2193ef3735042b9615c8172fc2fdef..2805d6a04471b540edfbf5a344e3561047242b09 100644 (file)
@@ -58,24 +58,24 @@ public:
 public:  // from Visual
 
   /**
-   * @copydoc Visual::SetSize
+   * @copydoc Visual::Base::SetSize
    */
   virtual void SetSize( const Vector2& size );
 
   /**
-   * @copydoc Visual::CreatePropertyMap
+   * @copydoc Visual::Base::CreatePropertyMap
    */
   virtual void DoCreatePropertyMap( Property::Map& map ) const;
 
 protected:
 
   /**
-   * @copydoc Visual::DoInitialize
+   * @copydoc Visual::Base::DoInitialize
    */
   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
 
   /**
-   * @copydoc Visual::DoSetOnStage
+   * @copydoc Visual::Base::DoSetOnStage
    */
   virtual void DoSetOnStage( Actor& actor );
 
index 1588b838dd00cda702602039b800fc96ade27eee..41999ccfe47269e2f1312b1b9776d58a1e2ba2b1 100644 (file)
@@ -232,6 +232,8 @@ void GradientVisual::SetSize( const Vector2& size )
 void GradientVisual::DoSetOnStage( Actor& actor )
 {
   InitializeRenderer();
+
+  actor.AddRenderer( mImpl->mRenderer );
 }
 
 void GradientVisual::DoCreatePropertyMap( Property::Map& map ) const
index 9f2cad44988cda277bd7c4234725c3e0ec068c4a..2f5d06cdcb81a44c79dbddb6015d5b5ce19152d5 100644 (file)
@@ -94,23 +94,23 @@ public:
 public:  // from Visual
 
   /**
-   * @copydoc Visual::SetSize
+   * @copydoc Visual::Base::SetSize
    */
   virtual void SetSize( const Vector2& size );
 
   /**
-   * @copydoc Visual::CreatePropertyMap
+   * @copydoc Visual::Base::CreatePropertyMap
    */
   virtual void DoCreatePropertyMap( Property::Map& map ) const;
 
 protected:
   /**
-   * @copydoc Visual::DoInitialize
+   * @copydoc Visual::Base::DoInitialize
    */
   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
 
   /**
-   * @copydoc Visual::DoSetOnStage
+   * @copydoc Visual::Base::DoSetOnStage
    */
   virtual void DoSetOnStage( Actor& actor );
 
index 30eeeda069c90e3384590c845ce38bab4a3870a4..1ce668b18c8e6cb169bf083431586be34012bfb1 100644 (file)
@@ -227,6 +227,8 @@ void BatchImageVisual::DoSetOnStage( Actor& actor )
   }
   // Turn batching on, to send message it must be on stage
   mImpl->mRenderer.SetProperty( Dali::Renderer::Property::BATCHING_ENABLED, true );
+
+  actor.AddRenderer( mImpl->mRenderer );
 }
 
 void BatchImageVisual::DoSetOffStage( Actor& actor )
index 098432669ccd940efd4716991c14569c45edb0cc..540f7c2ecf56ab573253f95ff01f1016065eebd5 100644 (file)
@@ -588,6 +588,8 @@ void ImageVisual::DoSetOnStage( Actor& actor )
   {
     mImpl->mRenderer.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, mPixelArea );
   }
+
+  actor.AddRenderer( mImpl->mRenderer );
 }
 
 void ImageVisual::DoSetOffStage( Actor& actor )
index 64b3f4bd5dd5e708f4552bf607ea5db05ff64fdb..2c489133d2339645ead1ad605183b0b0651a58d2 100644 (file)
@@ -91,28 +91,28 @@ public:
 public:  // from Visual
 
   /**
-   * @copydoc Visual::GetNaturalSize
+   * @copydoc Visual::Base::GetNaturalSize
    */
   virtual void GetNaturalSize( Vector2& naturalSize ) const;
 
   /**
-   * @copydoc Visual::CreatePropertyMap
+   * @copydoc Visual::Base::CreatePropertyMap
    */
   virtual void DoCreatePropertyMap( Property::Map& map ) const;
 
 protected:
   /**
-   * @copydoc Visual::DoInitialize
+   * @copydoc Visual::Base::DoInitialize
    */
   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
 
   /**
-   * @copydoc Visual::DoSetOnStage
+   * @copydoc Visual::Base::DoSetOnStage
    */
   virtual void DoSetOnStage( Actor& actor );
 
   /**
-   * @copydoc Visual::DoSetOffStage
+   * @copydoc Visual::Base::DoSetOffStage
    */
   virtual void DoSetOffStage( Actor& actor );
 
index b995e91eafbe4ac4e07ca0ef1a381714b50411c2..eafe9e843d901cff58558ec45fedad9a676e7a85 100644 (file)
@@ -372,6 +372,8 @@ void MeshVisual::SetSize( const Vector2& size )
 void MeshVisual::DoSetOnStage( Actor& actor )
 {
   InitializeRenderer();
+
+  actor.AddRenderer( mImpl->mRenderer );
 }
 
 void MeshVisual::DoCreatePropertyMap( Property::Map& map ) const
index 67e1fe1ae989595941e733d31f1999cfbcf29124..4a2927c49960f366a941053947e658656240b65b 100644 (file)
@@ -70,24 +70,24 @@ public:
 public:  // from Visual
 
   /**
-   * @copydoc Visual::SetSize
+   * @copydoc Visual::Base::SetSize
    */
   virtual void SetSize( const Vector2& size );
 
   /**
-   * @copydoc Visual::CreatePropertyMap
+   * @copydoc Visual::Base::CreatePropertyMap
    */
   virtual void DoCreatePropertyMap( Property::Map& map ) const;
 
 protected:
 
   /**
-   * @copydoc Visual::DoInitialize
+   * @copydoc Visual::Base::DoInitialize
    */
   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
 
   /**
-   * @copydoc Visual::DoSetOnStage
+   * @copydoc Visual::Base::DoSetOnStage
    */
   virtual void DoSetOnStage( Actor& actor );
 
index 5dc9e04ccf1bbbd88a2c8b32f3b550397cbd9f69..3bf5728afdc40f3a488f769f07b6d3a4c3d18f03 100644 (file)
@@ -379,6 +379,8 @@ void NPatchVisual::DoSetOnStage( Actor& actor )
   {
     ApplyImageToSampler();
   }
+
+  actor.AddRenderer( mImpl->mRenderer );
 }
 
 void NPatchVisual::DoSetOffStage( Actor& actor )
index 498bcc26469f334b1930a7bd851f2a15f1fdc30c..a9933036c2845bc3f78ba132cdb8523218863e38 100644 (file)
@@ -68,29 +68,29 @@ public:
 public:  // from Visual
 
   /**
-   * @copydoc Visual::GetNaturalSize
+   * @copydoc Visual::Base::GetNaturalSize
    */
   virtual void GetNaturalSize( Vector2& naturalSize ) const;
 
   /**
-   * @copydoc Visual::CreatePropertyMap
+   * @copydoc Visual::Base::CreatePropertyMap
    */
   virtual void DoCreatePropertyMap( Property::Map& map ) const;
 
 protected:
 
   /**
-   * @copydoc Visual::DoInitialize
+   * @copydoc Visual::Base::DoInitialize
    */
   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
 
   /**
-   * @copydoc Visual::DoSetOnStage
+   * @copydoc Visual::Base::DoSetOnStage
    */
   virtual void DoSetOnStage( Actor& actor );
 
   /**
-   * @copydoc Visual::DoSetOffStage
+   * @copydoc Visual::Base::DoSetOffStage
    */
   virtual void DoSetOffStage( Actor& actor );
 
index fa40339804f7b8ab6787c9b24365d944aa592dad..6991f32d7113be4a2c72a01bc1055e24c8bd27a4 100644 (file)
@@ -383,6 +383,8 @@ void PrimitiveVisual::GetNaturalSize( Vector2& naturalSize ) const
 void PrimitiveVisual::DoSetOnStage( Actor& actor )
 {
   InitializeRenderer();
+
+  actor.AddRenderer( mImpl->mRenderer );
 }
 
 void PrimitiveVisual::DoCreatePropertyMap( Property::Map& map ) const
index 45b536b7096193e797eb5bd34902ad2091b6126b..054e9f0b8e4471a5df44d2e8c4d3ac0a1e877c1e 100644 (file)
@@ -111,29 +111,29 @@ public:
 public:  // from Visual
 
   /**
-   * @copydoc Visual::SetSize
+   * @copydoc Visual::Base::SetSize
    */
   virtual void SetSize( const Vector2& size );
 
   /**
-   * @copydoc Visual::GetNaturalSize
+   * @copydoc Visual::Base::GetNaturalSize
    */
   virtual void GetNaturalSize( Vector2& naturalSize ) const;
 
   /**
-   * @copydoc Visual::CreatePropertyMap
+   * @copydoc Visual::Base::CreatePropertyMap
    */
   virtual void DoCreatePropertyMap( Property::Map& map ) const;
 
 protected:
 
   /**
-   * @copydoc Visual::DoInitialize
+   * @copydoc Visual::Base::DoInitialize
    */
   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
 
   /**
-   * @copydoc Visual::DoSetOnStage
+   * @copydoc Visual::Base::DoSetOnStage
    */
   virtual void DoSetOnStage( Actor& actor );
 
index 569c6963bcdf2aa2a5d4c5d9367fbcd9c2b13218..832fd197ca0955589a92e36e7ec95b0e37acfe47 100644 (file)
@@ -104,6 +104,9 @@ void SvgVisual::DoSetOnStage( Actor& actor )
   {
     AddRasterizationTask( mImpl->mSize );
   }
+
+  // Hold the weak handle of the placement actor and delay the adding of renderer until the svg rasterization is finished.
+  mPlacementActor = actor;
 }
 
 void SvgVisual::DoSetOffStage( Actor& actor )
@@ -112,6 +115,7 @@ void SvgVisual::DoSetOffStage( Actor& actor )
 
   actor.RemoveRenderer( mImpl->mRenderer );
   mImpl->mRenderer.Reset();
+  mPlacementActor.Reset();
 }
 
 void SvgVisual::GetNaturalSize( Vector2& naturalSize ) const
@@ -232,11 +236,19 @@ void SvgVisual::ApplyRasterizedImage( PixelData rasterizedPixelData )
         TextureSetImage( textureSet, 0u, texture );
       }
     }
+
+    // Rasterized pixels are uploaded to texture. If weak handle is holding a placement actor, it is the time to add the renderer to actor.
+    Actor actor = mPlacementActor.GetHandle();
+    if( actor )
+    {
+      actor.AddRenderer( mImpl->mRenderer );
+      // reset the weak handle so that the renderer only get added to actor once
+      mPlacementActor.Reset();
+    }
   }
 }
 
 
-
 } // namespace Internal
 
 } // namespace Toolkit
index c5830356b31dcd634e8e726e34f5bc548242d7a9..81672e50645f1b4754848729a0f0e1b2a0a37bc5 100644 (file)
@@ -18,6 +18,9 @@
  *
  */
 
+//EXTERNAL INCLUDES
+#include <dali/devel-api/object/weak-handle.h>
+
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
 
@@ -61,34 +64,34 @@ public:
 public:  // from Visual
 
   /**
-   * @copydoc Visual::GetNaturalSize
+   * @copydoc Visual::Base::GetNaturalSize
    */
   virtual void GetNaturalSize( Vector2& naturalSize ) const;
 
   /**
-   * @copydoc Visual::SetSize
+   * @copydoc Visual::Base::SetSize
    */
   virtual void SetSize( const Vector2& size );
 
   /**
-   * @copydoc Visual::CreatePropertyMap
+   * @copydoc Visual::Base::CreatePropertyMap
    */
   virtual void DoCreatePropertyMap( Property::Map& map ) const;
 
 protected:
 
   /**
-   * @copydoc Visual::DoInitialize
+   * @copydoc Visual::Base::DoInitialize
    */
   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
 
   /**
-   * @copydoc Visual::DoSetOnStage
+   * @copydoc Visual::Base::DoSetOnStage
    */
   virtual void DoSetOnStage( Actor& actor );
 
   /**
-   * @copydoc Visual::DoSetOffStage
+   * @copydoc Visual::Base::DoSetOffStage
    */
   virtual void DoSetOffStage( Actor& actor );
 
@@ -129,6 +132,7 @@ private:
   Vector4              mAtlasRect;
   std::string          mImageUrl;
   NSVGimage*           mParsedImage;
+  WeakHandle<Actor>    mPlacementActor;
 
 };
 
index 58e4d38f10d85b9ad8842daf4ab6080cd1a79cda..8356de5c42e9b77b6639e2c09900d96c2382fa19 100644 (file)
@@ -105,12 +105,12 @@ float Visual::Base::GetDepthIndex() const
 
 void Visual::Base::SetOnStage( Actor& actor )
 {
+  // To display the actor correctly, renderer should not be added to actor until all required resources are ready.
+  // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
   DoSetOnStage( actor );
 
   mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
   mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
-  actor.AddRenderer( mImpl->mRenderer );
-
   mImpl->mFlags |= Impl::IS_ON_STAGE;
 }
 
@@ -146,10 +146,6 @@ bool Visual::Base::IsPreMultipliedAlphaEnabled() const
   return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
 }
 
-void Visual::Base::DoSetOnStage( Actor& actor )
-{
-}
-
 void Visual::Base::DoSetOffStage( Actor& actor )
 {
   actor.RemoveRenderer( mImpl->mRenderer );
index 8068dd860431e952eb04e6fb73a2e2a347a0a9ee..3820bd089647c32eed9e5cc2a6d4ab01644c12b8 100644 (file)
@@ -170,9 +170,11 @@ protected:
   /**
    * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
    *
+   * @note The derived class is required to create the renderer, and add it to the actor when all the resources are in place.
+   *
    * @param[in] actor The actor applying this visual.
    */
-  virtual void DoSetOnStage( Actor& actor );
+  virtual void DoSetOnStage( Actor& actor )=0;
 
   /**
    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
index 47474a61c7d04ce51a6757cd6428cfb82b6a0a35..4299eb69c94c7f2c4a221ba40c3a84dcf0c3a866 100644 (file)
@@ -76,6 +76,8 @@ WireframeVisual::~WireframeVisual()
 void WireframeVisual::DoSetOnStage( Actor& actor )
 {
   InitializeRenderer();
+
+  actor.AddRenderer( mImpl->mRenderer );
 }
 
 void WireframeVisual::DoCreatePropertyMap( Property::Map& map ) const
index b14452acb53db528c4ec6304c43f968b6b1e6545..c0d86825510fc6c094413d89380aae9e2cb6ad67 100644 (file)
@@ -53,12 +53,12 @@ public:
 protected:
 
   /**
-   * @copydoc Visual::DoSetOnStage
+   * @copydoc Visual::Base::DoSetOnStage
    */
   virtual void DoSetOnStage( Actor& actor );
 
   /**
-   * @copydoc Visual::CreatePropertyMap
+   * @copydoc Visual::Base::CreatePropertyMap
    */
   virtual void DoCreatePropertyMap( Property::Map& map ) const;
 
index 23745bbf5286c89d5f1db9eb72e0d0588678a61a..cc3546c0705fb4da9047c70a5b54a9a0de1ab631 100644 (file)
@@ -28,6 +28,7 @@
 #include <dali/public-api/object/type-registry-helper.h>
 #include <dali/public-api/rendering/renderer.h>
 #include <dali/public-api/size-negotiation/relayout-container.h>
+#include <dali/devel-api/common/owner-container.h>
 #include <dali/devel-api/scripting/scripting.h>
 #include <dali/integration-api/debug.h>
 
@@ -63,14 +64,16 @@ struct RegisteredVisual
   RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, Actor &aPlacementActor) : index(aIndex), visual(aVisual), placementActor(aPlacementActor) {}
 };
 
+typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisuals;
+
 /**
  *  Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter
  */
-bool FindVisual( Property::Index targetIndex, std::vector<RegisteredVisual>& visuals, std::vector<RegisteredVisual>::iterator& iter )
+bool FindVisual( Property::Index targetIndex, RegisteredVisuals& visuals, RegisteredVisuals::Iterator& iter )
 {
-  for ( iter = visuals.begin(); iter != visuals.end(); iter++ )
+  for ( iter = visuals.Begin(); iter != visuals.End(); iter++ )
   {
-    if ( (*iter).index ==  targetIndex )
+    if ( (*iter)->index ==  targetIndex )
     {
       return true;
     }
@@ -394,7 +397,7 @@ public:
   // Data
 
   Control& mControlImpl;
-  std::vector<RegisteredVisual> mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used.
+  RegisteredVisuals mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used.
   std::string mStyleName;
   Toolkit::Visual::Base mBackgroundVisual;   ///< The visual to render the background
   Vector4 mBackgroundColor;                       ///< The color of the background visual
@@ -475,7 +478,8 @@ void Control::SetBackgroundColor( const Vector4& color )
   Property::Map map;
   map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
   map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
-  InitializeVisual( self, mImpl->mBackgroundVisual, map );
+  mImpl->mBackgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( map );
+  RegisterVisual( Toolkit::Control::Property::BACKGROUND, self, mImpl->mBackgroundVisual );
   if( mImpl->mBackgroundVisual )
   {
     mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
@@ -490,7 +494,8 @@ Vector4 Control::GetBackgroundColor() const
 void Control::SetBackground( const Property::Map& map )
 {
   Actor self( Self() );
-  InitializeVisual( self, mImpl->mBackgroundVisual, map );
+  mImpl->mBackgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( map );
+  RegisterVisual( Toolkit::Control::Property::BACKGROUND, self, mImpl->mBackgroundVisual );
   if( mImpl->mBackgroundVisual )
   {
     mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
@@ -500,7 +505,8 @@ void Control::SetBackground( const Property::Map& map )
 void Control::SetBackgroundImage( Image image )
 {
   Actor self( Self() );
-  InitializeVisual( self, mImpl->mBackgroundVisual, image );
+  mImpl->mBackgroundVisual = Toolkit::VisualFactory::Get().CreateVisual( image );
+  RegisterVisual( Toolkit::Control::Property::BACKGROUND, self, mImpl->mBackgroundVisual );
   if( mImpl->mBackgroundVisual )
   {
     mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
@@ -653,63 +659,79 @@ void Control::KeyboardEnter()
   OnKeyboardEnter();
 }
 
-void Control::RegisterVisual( Property::Index index, Actor placementActor, Toolkit::Visual::Base visual )
+void Control::RegisterVisual( Property::Index index, Actor& placementActor, Toolkit::Visual::Base& visual )
 {
   bool visualReplaced ( false );
   Actor actorToRegister; // Null actor, replaced if placement actor not Self
+  Actor self = Self();
 
-  if ( placementActor != Self() ) // Prevent increasing ref count if actor self
+  if ( placementActor != self ) // Prevent increasing ref count if actor self
   {
     actorToRegister = placementActor;
   }
 
-  if ( !mImpl->mVisuals.empty() )
+  if ( !mImpl->mVisuals.Empty() )
   {
-      std::vector<RegisteredVisual>::iterator iter;
+      RegisteredVisuals::Iterator iter;
       // Check if visual (index) is already registered.  Replace if so.
       if ( FindVisual( index, mImpl->mVisuals, iter ) )
       {
-        (*iter).visual = visual;
-        (*iter).placementActor = actorToRegister;
+        if( (*iter)->visual && self.OnStage() )
+        {
+          if( (*iter)->placementActor )
+          {
+            (*iter)->visual.SetOffStage( (*iter)->placementActor );
+          }
+          else
+          {
+            (*iter)->visual.SetOffStage( self );
+          }
+        }
+        (*iter)->visual = visual;
+        (*iter)->placementActor = actorToRegister;
         visualReplaced = true;
       }
   }
 
   if ( !visualReplaced ) // New registration entry
   {
-    RegisteredVisual newVisual = RegisteredVisual( index, visual, actorToRegister );
-    mImpl->mVisuals.push_back( newVisual );
+    mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, actorToRegister ) );
+  }
+
+  if( visual && self.OnStage() )
+  {
+    visual.SetOnStage( placementActor );
   }
 }
 
 void Control::UnregisterVisual( Property::Index index )
 {
-   std::vector< RegisteredVisual >::iterator iter;
+   RegisteredVisuals::Iterator iter;
    if ( FindVisual( index, mImpl->mVisuals, iter ) )
    {
-     mImpl->mVisuals.erase( iter );
+     mImpl->mVisuals.Erase( iter );
    }
 }
 
-Toolkit::Visual::Base Control::GetVisual( Property::Index index )
+Toolkit::Visual::Base Control::GetVisual( Property::Index index ) const
 {
-  std::vector< RegisteredVisual >::iterator iter;
+  RegisteredVisuals::Iterator iter;
   if ( FindVisual( index, mImpl->mVisuals, iter ) )
   {
-    return (*iter).visual;
+    return (*iter)->visual;
   }
 
   return Toolkit::Visual::Base();
 }
 
-Actor Control::GetPlacementActor( Property::Index index )
+Actor Control::GetPlacementActor( Property::Index index ) const
 {
-  std::vector< RegisteredVisual >::iterator iter;
+  RegisteredVisuals::Iterator iter;
   if ( FindVisual( index, mImpl->mVisuals, iter ) )
   {
-    if( (*iter).placementActor )
+    if( (*iter)->placementActor )
     {
-      return (*iter).placementActor;
+      return (*iter)->placementActor;
     }
     else
     {
@@ -905,19 +927,41 @@ void Control::EmitKeyInputFocusSignal( bool focusGained )
 
 void Control::OnStageConnection( int depth )
 {
-  if( mImpl->mBackgroundVisual)
+  for(RegisteredVisuals::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
   {
-    Actor self( Self() );
-    mImpl->mBackgroundVisual.SetOnStage( self );
+    // Check whether the visual is empty, as it is allowed to register a placement actor without visual.
+    if( (*iter)->visual )
+    {
+      if( (*iter)->placementActor )
+      {
+        (*iter)->visual.SetOnStage( (*iter)->placementActor );
+      }
+      else
+      {
+        Actor self( Self() );
+        (*iter)->visual.SetOnStage( self );
+      }
+    }
   }
 }
 
 void Control::OnStageDisconnection()
 {
-  if( mImpl->mBackgroundVisual )
+  for(RegisteredVisuals::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
   {
-    Actor self( Self() );
-    mImpl->mBackgroundVisual.SetOffStage( self );
+    // Check whether the visual is empty, as it is allowed to register a placement actor without visual.
+    if( (*iter)->visual )
+    {
+      if( (*iter)->placementActor )
+      {
+        (*iter)->visual.SetOffStage( (*iter)->placementActor );
+      }
+      else
+      {
+        Actor self( Self() );
+        (*iter)->visual.SetOffStage( self );
+      }
+    }
   }
 }
 
index e8a71fe6ddde2d3ab3eff1d5b8ffac276beaecc8..97ed7d1c627df611bfda77a704d638bce93b8cd3 100644 (file)
@@ -305,8 +305,9 @@ protected: // For derived classes to call
    * @param[in] index The Property index of the visual, used to reference visual
    * @param[in] placementActor The actor used to by the visual.
    * @param[in] visual The visual to register
+   * @note Derived class must NOT call visual.SetOnStage(placementActor). It is the responsibility of the base class to connect/disconnect registered visual to stage.
    */
-   void RegisterVisual( Property::Index index, Actor placementActor, Toolkit::Visual::Base visual );
+   void RegisterVisual( Property::Index index, Actor& placementActor, Toolkit::Visual::Base& visual );
 
    /**
     * @brief Erase the entry matching the given index from the list of registered visuals
@@ -325,7 +326,7 @@ protected: // For derived classes to call
     * @return The registered visual if exist, otherwise empty handle.
     * @note For managing object life-cycle, do not store the returned visual as a member which increments its reference count.
     */
-   Toolkit::Visual::Base GetVisual( Property::Index index );
+   Toolkit::Visual::Base GetVisual( Property::Index index ) const;
 
    /**
     * @brief Retrieve the placement actor associated with the given index.
@@ -336,7 +337,7 @@ protected: // For derived classes to call
     * @return Then placement actor if exist, otherwise empty handle.
     * @note For managing object life-cycle, do not store the returned placement actor as a member which increments its reference count.
     */
-   Actor GetPlacementActor( Property::Index index );
+   Actor GetPlacementActor( Property::Index index ) const;
 
   /**
    * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal