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();
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
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.
*
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
*
mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
}
mBorderSizeIndex = (mImpl->mRenderer).RegisterProperty( SIZE_NAME, mBorderSize );
+
+ actor.AddRenderer( mImpl->mRenderer );
}
void BorderVisual::DoCreatePropertyMap( Property::Map& map ) const
public: // from Visual
/**
- * @copydoc Visual::SetClipRect
+ * @copydoc Visual::Base::SetClipRect
*/
virtual void SetClipRect( const Rect<int>& clipRect );
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;
void ColorVisual::DoSetOnStage( Actor& actor )
{
InitializeRenderer();
+
+ actor.AddRenderer( mImpl->mRenderer );
}
void ColorVisual::DoCreatePropertyMap( Property::Map& map ) const
public: // from Visual
/**
- * @copydoc Visual::SetSize
+ * @copydoc Visual::Base::SetSize
*/
virtual void SetSize( const Vector2& size );
/**
- * @copydoc Visual::SetClipRect
+ * @copydoc Visual::Base::SetClipRect
*/
virtual void SetClipRect( const Rect<int>& clipRect );
/**
- * @copydoc Visual::SetOffset
+ * @copydoc Visual::Base::SetOffset
*/
virtual void SetOffset( const Vector2& offset );
/**
- * @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 );
void GradientVisual::DoSetOnStage( Actor& actor )
{
InitializeRenderer();
+
+ actor.AddRenderer( mImpl->mRenderer );
}
void GradientVisual::DoCreatePropertyMap( Property::Map& map ) const
public: // from Visual
/**
- * @copydoc Visual::SetSize
+ * @copydoc Visual::Base::SetSize
*/
virtual void SetSize( const Vector2& size );
/**
- * @copydoc Visual::SetClipRect
+ * @copydoc Visual::Base::SetClipRect
*/
virtual void SetClipRect( const Rect<int>& clipRect );
/**
- * @copydoc Visual::SetOffset
+ * @copydoc Visual::Base::SetOffset
*/
virtual void SetOffset( const Vector2& offset );
/**
- * @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 );
{
InitializeRenderer( mImage );
}
+
+ actor.AddRenderer( mImpl->mRenderer );
}
void ImageVisual::DoSetOffStage( Actor& actor )
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::SetClipRect
+ * @copydoc Visual::Base::SetClipRect
*/
virtual void SetClipRect( const Rect<int>& clipRect );
/**
- * @copydoc Visual::SetOffset
+ * @copydoc Visual::Base::SetOffset
*/
virtual void SetOffset( const Vector2& offset );
/**
- * @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 );
void MeshVisual::DoSetOnStage( Actor& actor )
{
InitializeRenderer();
+
+ actor.AddRenderer( mImpl->mRenderer );
}
void MeshVisual::DoCreatePropertyMap( Property::Map& map ) const
public: // from Visual
/**
- * @copydoc Visual::SetSize
+ * @copydoc Visual::Base::SetSize
*/
virtual void SetSize( const Vector2& size );
/**
- * @copydoc Visual::SetClipRect
+ * @copydoc Visual::Base::SetClipRect
*/
virtual void SetClipRect( const Rect<int>& clipRect );
/**
- * @copydoc Visual::SetOffset
+ * @copydoc Visual::Base::SetOffset
*/
virtual void SetOffset( const Vector2& offset );
/**
- * @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 );
{
ApplyImageToSampler();
}
+
+ actor.AddRenderer( mImpl->mRenderer );
}
void NPatchVisual::DoSetOffStage( Actor& actor )
public: // from Visual
/**
- * @copydoc Visual::GetNaturalSize
+ * @copydoc Visual::Base::GetNaturalSize
*/
virtual void GetNaturalSize( Vector2& naturalSize ) const;
/**
- * @copydoc Visual::SetClipRect
+ * @copydoc Visual::Base::SetClipRect
*/
virtual void SetClipRect( const Rect<int>& clipRect );
/**
- * @copydoc Visual::SetOffset
+ * @copydoc Visual::Base::SetOffset
*/
virtual void SetOffset( const Vector2& offset );
/**
- * @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 );
void PrimitiveVisual::DoSetOnStage( Actor& actor )
{
InitializeRenderer();
+
+ actor.AddRenderer( mImpl->mRenderer );
}
void PrimitiveVisual::DoCreatePropertyMap( Property::Map& map ) const
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::SetClipRect
+ * @copydoc Visual::Base::SetClipRect
*/
virtual void SetClipRect( const Rect<int>& clipRect );
/**
- * @copydoc Visual::SetOffset
+ * @copydoc Visual::Base::SetOffset
*/
virtual void SetOffset( const Vector2& offset );
/**
- * @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 );
{
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 )
actor.RemoveRenderer( mImpl->mRenderer );
mImpl->mRenderer.Reset();
+ mPlacementActor.Reset();
}
void SvgVisual::GetNaturalSize( Vector2& naturalSize ) const
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();
+ }
}
}
*
*/
+//EXTERNAL INCLUDES
+#include <dali/devel-api/object/weak-handle.h>
+
// INTERNAL INCLUDES
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
#include <dali-toolkit/internal/visuals/image-atlas-manager.h>
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 );
ImageAtlasManager& mAtlasManager;
std::string mImageUrl;
NSVGimage* mParsedImage;
+ WeakHandle<Actor> mPlacementActor;
};
void 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;
}
return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
}
-void Base::DoSetOnStage( Actor& actor )
-{
-}
-
void Base::DoSetOffStage( Actor& actor )
{
actor.RemoveRenderer( mImpl->mRenderer );
/**
* @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
void WireframeVisual::DoSetOnStage( Actor& actor )
{
InitializeRenderer();
+
+ actor.AddRenderer( mImpl->mRenderer );
}
void WireframeVisual::DoCreatePropertyMap( Property::Map& map ) const
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;