Added object sizes to platform abstraction in profiling section
authorDavid Steele <david.steele@partner.samsung.com>
Mon, 12 May 2014 13:23:13 +0000 (14:23 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 29 May 2014 14:05:40 +0000 (15:05 +0100)
[Problem]      No measure of object sizes in object profiler
[Cause]        New requirement
[Solution]     Use constants to accumulate sizes of related objects (keeps number of constants small)
Added Image as a registered type (Requires that object registration is done as a second stage
process; also requires that all newly allocated objects are stored to an intrusive pointer (otherwise
signal generation creates a handle, triggers, then throws the handle away and deletes the new object...)

Change-Id: I1b9c0a427fa7b2ed67f93cde94a50377c0ed560d
[Verification] Build Repo
Signed-off-by: David Steele <david.steele@partner.samsung.com>
19 files changed:
dali/integration-api/profiling.cpp
dali/integration-api/profiling.h
dali/internal/event/actors/camera-actor-impl.cpp
dali/internal/event/actors/layer-impl.h
dali/internal/event/common/object-registry-impl.h
dali/internal/event/events/hit-test-algorithm-impl.cpp
dali/internal/event/images/bitmap-image-impl.cpp
dali/internal/event/images/bitmap-image-impl.h
dali/internal/event/images/encoded-buffer-image-impl.cpp
dali/internal/event/images/encoded-buffer-image-impl.h
dali/internal/event/images/frame-buffer-image-impl.cpp
dali/internal/event/images/frame-buffer-image-impl.h
dali/internal/event/images/image-impl.cpp
dali/internal/event/images/image-impl.h
dali/internal/event/images/nine-patch-image-impl.cpp
dali/internal/event/images/nine-patch-image-impl.h
dali/public-api/images/encoded-buffer-image.cpp
dali/public-api/images/frame-buffer-image.cpp
dali/public-api/images/image.cpp

index 3ee01c5..c8199b3 100644 (file)
 #include <dali/integration-api/profiling.h>
 
 // INTERNAL INCLUDES
+#include <dali/integration-api/bitmap.h>
+
 #include <dali/internal/event/common/thread-local-storage.h>
 #include <dali/internal/event/events/gesture-event-processor.h>
 
+#include <dali/internal/event/actors/actor-impl.h>
+#include <dali/internal/event/actors/camera-actor-impl.h>
+#include <dali/internal/event/actors/text-actor-impl.h>
+#include <dali/internal/event/actors/image-actor-impl.h>
+#include <dali/internal/event/actors/mesh-actor-impl.h>
+#include <dali/internal/event/actors/layer-impl.h>
+
+#include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
+#include <dali/internal/event/actor-attachments/camera-attachment-impl.h>
+#include <dali/internal/event/actor-attachments/text-attachment-impl.h>
+#include <dali/internal/event/actor-attachments/image-attachment-impl.h>
+#include <dali/internal/event/actor-attachments/mesh-attachment-impl.h>
+
+#include <dali/internal/event/animation/animation-impl.h>
+#include <dali/internal/event/animation/animator-connector.h>
+#include <dali/internal/event/animation/constraint-impl.h>
+#include <dali/internal/event/animation/active-constraint-impl.h>
+#include <dali/internal/update/animation/property-accessor.h>
+#include <dali/internal/update/animation/scene-graph-animation.h>
+#include <dali/internal/update/animation/scene-graph-constraint.h>
+
+
+#include <dali/internal/event/images/image-impl.h>
+#include <dali/internal/event/images/image-factory-cache.h>
+#include <dali/internal/common/text-parameters.h>
+#include <dali/internal/event/modeling/mesh-impl.h>
+#include <dali/internal/event/modeling/material-impl.h>
+
+#include <dali/internal/event/resources/resource-ticket.h>
+#include <dali/internal/event/resources/image-ticket.h>
+
+#include <dali/internal/update/nodes/node.h>
+#include <dali/internal/update/nodes/scene-graph-layer.h>
+#include <dali/internal/update/modeling/internal-mesh-data.h>
+#include <dali/internal/update/modeling/scene-graph-animatable-mesh.h>
+#include <dali/internal/update/modeling/scene-graph-material.h>
+#include <dali/internal/update/modeling/scene-graph-mesh.h>
+
+#include <dali/internal/update/node-attachments/node-attachment.h>
+#include <dali/internal/update/node-attachments/scene-graph-camera-attachment.h>
+#include <dali/internal/update/node-attachments/scene-graph-image-attachment.h>
+#include <dali/internal/update/node-attachments/scene-graph-mesh-attachment.h>
+#include <dali/internal/update/node-attachments/scene-graph-text-attachment.h>
+
+#include <dali/internal/update/resources/bitmap-metadata.h>
+
+#include <dali/internal/render/gl-resources/bitmap-texture.h>
+
+#include <dali/internal/render/renderers/render-material.h>
+#include <dali/internal/render/renderers/scene-graph-image-renderer.h>
+#include <dali/internal/render/renderers/scene-graph-text-renderer.h>
+#include <dali/internal/render/renderers/scene-graph-mesh-renderer.h>
+
 using Dali::Internal::GestureEventProcessor;
 using Dali::Internal::ThreadLocalStorage;
 
@@ -55,6 +110,70 @@ void SetPanGesturePredictionMode( int mode )
   eventProcessor.SetPanGesturePredictionMode(mode);
 }
 
+namespace Profiling
+{
+
+const int ANIMATION_MEMORY_SIZE(
+  sizeof( Internal::Animation ) +
+  sizeof( Internal::AnimatorConnector<float> ) +
+  sizeof( Internal::SceneGraph::Animation ) );
+const int CONSTRAINT_MEMORY_SIZE(
+  sizeof( Internal::Constraint ) +
+  sizeof( Internal::SceneGraph::Constraint<float, Internal::PropertyAccessor<float> > ) +
+  sizeof( Internal::ActiveConstraint<float> ) );
+const int ACTOR_MEMORY_SIZE(
+  sizeof( Internal::Actor ) +
+  sizeof( Internal::ActorAttachment ) +
+  sizeof( Internal::SceneGraph::Node ) +
+  sizeof( Internal::SceneGraph::NodeAttachment ));
+const int CAMERA_ACTOR_MEMORY_SIZE(
+  sizeof( Internal::CameraActor ) +
+  sizeof( Internal::CameraAttachment ) +
+  sizeof( Internal::SceneGraph::Node ) +
+  sizeof( Internal::SceneGraph::CameraAttachment ) );
+const int TEXT_ACTOR_MEMORY_SIZE(
+  sizeof( Internal::TextActor ) +
+  sizeof( Internal::TextAttachment ) +
+  sizeof( Internal::SceneGraph::Node ) +
+  sizeof( Internal::SceneGraph::TextAttachment ) +
+  sizeof( Internal::TextParameters ) +
+  sizeof( Internal::SceneGraph::TextRenderer ) );
+const int MESH_ACTOR_MEMORY_SIZE(
+  sizeof( Internal::MeshActor ) +
+  sizeof( Internal::MeshAttachment ) +
+  sizeof( Internal::SceneGraph::Node ) +
+  sizeof( Internal::SceneGraph::MeshAttachment ) +
+  sizeof( Internal::SceneGraph::MeshRenderer ) );
+const int IMAGE_ACTOR_MEMORY_SIZE(
+  sizeof( Internal::ImageActor ) +
+  sizeof( Internal::ImageAttachment ) +
+  sizeof( Internal::SceneGraph::Node ) +
+  sizeof( Internal::SceneGraph::ImageAttachment ) +
+  sizeof( Internal::SceneGraph::ImageRenderer ));
+const int LAYER_MEMORY_SIZE(
+  sizeof( Internal::Layer ) +
+  sizeof( Internal::ActorAttachment ) +
+  sizeof( Internal::SceneGraph::Layer ) +
+  sizeof( Internal::SceneGraph::NodeAttachment ) );
+const int IMAGE_MEMORY_SIZE(
+  sizeof( Internal::Image ) +
+  sizeof( Internal::ImageFactoryCache::Request ) +
+  sizeof( Integration::Bitmap ) +
+  sizeof( Internal::BitmapMetadata ) +
+  sizeof( Internal::BitmapTexture ) +
+  sizeof( Internal::ImageTicket ) );
+const int MESH_MEMORY_SIZE(
+  sizeof( Internal::Mesh ) +
+  sizeof( Internal::MeshData ) +
+  sizeof( Internal::SceneGraph::Mesh ) +
+  sizeof( Internal::ResourceTicket ) );
+const int MATERIAL_MEMORY_SIZE(
+  sizeof( Internal::Material ) +
+  sizeof( Internal::SceneGraph::Material ) +
+  sizeof( Internal::SceneGraph::RenderMaterial ) );
+
+} // namespace Profiling
+
 } // namespace Integration
 
 } // namespace Dali
index 3bd3d94..9a35141 100644 (file)
@@ -52,6 +52,23 @@ DALI_IMPORT_API void EnableProfiling( ProfilingType type );
  */
 DALI_IMPORT_API void SetPanGesturePredictionMode( int mode );
 
+
+namespace Profiling
+{
+
+DALI_IMPORT_API extern const int ANIMATION_MEMORY_SIZE;    ///< Total size of animation and associated internal objects
+DALI_IMPORT_API extern const int CONSTRAINT_MEMORY_SIZE;   ///< Total size of constraint and associated internal objects
+DALI_IMPORT_API extern const int ACTOR_MEMORY_SIZE;        ///< Total size of actor and associated internal objects
+DALI_IMPORT_API extern const int CAMERA_ACTOR_MEMORY_SIZE; ///< Total size of camera actor and associated internal objects
+DALI_IMPORT_API extern const int TEXT_ACTOR_MEMORY_SIZE;   ///< Total size of text actor and associated internal objects
+DALI_IMPORT_API extern const int MESH_ACTOR_MEMORY_SIZE;   ///< Total size of mesh actor and associated internal objects
+DALI_IMPORT_API extern const int IMAGE_ACTOR_MEMORY_SIZE;  ///< Total size of image actor and associated internal objects
+DALI_IMPORT_API extern const int LAYER_MEMORY_SIZE;        ///< Total size of layer and associated internal objects
+DALI_IMPORT_API extern const int IMAGE_MEMORY_SIZE;        ///< Total size of image and associated internal objects
+DALI_IMPORT_API extern const int MESH_MEMORY_SIZE;         ///< Total size of mesh and associated internal objects
+DALI_IMPORT_API extern const int MATERIAL_MEMORY_SIZE;     ///< Total size of material and associated internal objects
+} // namespace Profiling
+
 } // namespace Integration
 
 } // namespace Dali
index 9ca6909..9427706 100644 (file)
@@ -17,6 +17,9 @@
 // CLASS HEADER
 #include <dali/internal/event/actors/camera-actor-impl.h>
 
+// EXTERNAL INCLUDES
+#include <cmath>
+
 // INTERNAL INCLUDES
 #include <dali/public-api/common/stage.h>
 #include <dali/public-api/object/type-registry.h>
index a97956a..2ee330d 100644 (file)
@@ -21,7 +21,6 @@
 #include <dali/public-api/actors/layer.h>
 #include <dali/internal/event/actors/actor-impl.h>
 #include <dali/internal/event/actors/actor-declarations.h>
-#include <dali/internal/event/images/frame-buffer-image-impl.h>
 
 namespace Dali
 {
@@ -73,7 +72,7 @@ public:
    */
   void OnInitialize();
 
-   /**
+  /**
    * Query the current depth of the layer
    */
   unsigned int GetDepth() const;
@@ -258,7 +257,6 @@ private:
   LayerList* mLayerList; ///< Only valid when layer is on-stage
 
   // These properties not animatable; the actor side has the most up-to-date values
-  FrameBufferImagePtr mFrameBufferImage;        ///< Ticket for offscreen render target
   ClippingBox mClippingBox;                     ///< The clipping box, in window coordinates
   Dali::Layer::SortFunctionType mSortFunction;  ///< Used to sort semi-transparent geometry
 
index e57e75b..ec917d6 100644 (file)
@@ -58,9 +58,12 @@ public:
   static ObjectRegistryPtr New();
 
   /**
-   * Registers the Object into the Object Registry, Which notifies
-   * about this object creation to its observers.
+   * Registers the Object into the Object Registry, which notifies
+   * about this object creation to its observers using signals. As
+   * the signals use a BaseHandle, the object must already have a
+   * ref-count > 0, otherwise it will get deleted on signal completion.
    * @pre The object is not already registered.
+   * @pre the object is ref counted (held in an intrusive pointer)
    * @param[in] object Pointer to the object.
    */
   void RegisterObject( Dali::BaseObject* object );
index 7ebf256..3d6a7db 100644 (file)
@@ -30,6 +30,7 @@
 #include <dali/internal/event/common/system-overlay-impl.h>
 #include <dali/internal/event/common/stage-impl.h>
 #include <dali/internal/event/common/projection.h>
+#include <dali/internal/event/images/frame-buffer-image-impl.h>
 #include <dali/internal/event/render-tasks/render-task-impl.h>
 #include <dali/internal/event/render-tasks/render-task-list-impl.h>
 
index e8cf9b7..4a8445e 100644 (file)
@@ -30,16 +30,16 @@ namespace Dali
 namespace Internal
 {
 
-BitmapImage* BitmapImage::New( unsigned int width, unsigned int height, Pixel::Format pixelformat, LoadPolicy loadPol, ReleasePolicy releasePol )
+BitmapImagePtr BitmapImage::New( unsigned int width, unsigned int height, Pixel::Format pixelformat, LoadPolicy loadPol, ReleasePolicy releasePol )
 {
-  BitmapImage* internal = new BitmapImage( width, height, pixelformat, loadPol, releasePol );
+  BitmapImagePtr internal = new BitmapImage( width, height, pixelformat, loadPol, releasePol );
   internal->Initialize();
   return internal;
 }
 
-BitmapImage* BitmapImage::New( PixelBuffer* pixBuf, unsigned int width, unsigned int height, Pixel::Format pixelformat, unsigned int stride, ReleasePolicy releasePol )
+BitmapImagePtr BitmapImage::New( PixelBuffer* pixBuf, unsigned int width, unsigned int height, Pixel::Format pixelformat, unsigned int stride, ReleasePolicy releasePol )
 {
-  BitmapImage* internal = new BitmapImage( pixBuf, width, height, pixelformat, stride, releasePol );
+  BitmapImagePtr internal = new BitmapImage( pixBuf, width, height, pixelformat, stride, releasePol );
   internal->Initialize();
   return internal;
 }
@@ -48,8 +48,8 @@ BitmapImage::BitmapImage(unsigned int width, unsigned int height, Pixel::Format
 : Image(loadPol, releasePol),
   mIsDataExternal(false)
 {
-  Initialize();
-
+  ThreadLocalStorage& tls = ThreadLocalStorage::Get();
+  mResourceClient = &tls.GetResourceClient();
   mWidth  = width;
   mHeight = height;
 
@@ -63,7 +63,8 @@ BitmapImage::BitmapImage(PixelBuffer* pixBuf, unsigned int width, unsigned int h
 : Image(ImageLoadPolicyDefault, releasePol),
   mIsDataExternal(true)
 {
-  Initialize();
+  ThreadLocalStorage& tls = ThreadLocalStorage::Get();
+  mResourceClient = &tls.GetResourceClient();
   mWidth  = width;
   mHeight = height;
   Integration::Bitmap* bitmap = new BitmapExternal(pixBuf, width, height, pixelformat, stride);
@@ -146,12 +147,6 @@ unsigned int BitmapImage::GetBufferStride() const
   return bufferStride;
 }
 
-void BitmapImage::Initialize()
-{
-  ThreadLocalStorage& tls = ThreadLocalStorage::Get();
-  mResourceClient = &tls.GetResourceClient();
-}
-
 void BitmapImage::Connect()
 {
   ++mConnectionCount;
index 4d35241..dabbfec 100644 (file)
@@ -55,11 +55,11 @@ public:
    * @param [in] loadPol     controls time of loading a resource from the filesystem (default: load when Image is created).
    * @param [in] releasePol  optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
    */
-  static BitmapImage* New( unsigned int width,
-                           unsigned int height,
-                           Pixel::Format pixelformat,
-                           LoadPolicy loadPol=ImageLoadPolicyDefault,
-                           ReleasePolicy releasePol=ImageReleasePolicyDefault);
+  static BitmapImagePtr New( unsigned int width,
+                             unsigned int height,
+                             Pixel::Format pixelformat,
+                             LoadPolicy loadPol=ImageLoadPolicyDefault,
+                             ReleasePolicy releasePol=ImageReleasePolicyDefault);
 
   /**
    * Create a new BitmapImage, which uses external data source.
@@ -75,12 +75,12 @@ public:
    * @param [in] stride      the internal stride of the pixelbuffer in pixels
    * @param [in] releasePol  optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
    */
-  static BitmapImage* New( PixelBuffer* pixBuf,
-                           unsigned int width,
-                           unsigned int height,
-                           Pixel::Format pixelformat,
-                           unsigned int stride,
-                           ReleasePolicy releasePol=ImageReleasePolicyDefault );
+  static BitmapImagePtr New( PixelBuffer* pixBuf,
+                             unsigned int width,
+                             unsigned int height,
+                             Pixel::Format pixelformat,
+                             unsigned int stride,
+                             ReleasePolicy releasePol=ImageReleasePolicyDefault );
 
   /**
    * Create a new BitmapImage.
@@ -159,13 +159,6 @@ public:
    */
   unsigned int GetBufferStride() const;
 
-private:
-
-  /**
-   * Initializes internal data.
-   */
-  void Initialize();
-
 protected: // From Resource
   /**
    * @copydoc Dali::Internal::Image::Connect
index 42cfa52..ef62388 100644 (file)
@@ -27,10 +27,10 @@ namespace Dali
 namespace Internal
 {
 
-Dali::EncodedBufferImage EncodedBufferImage::New( const uint8_t * const encodedImage,
-                   const std::size_t encodedImageByteCount,
-                   const ImageAttributes& attributes,
-                   const ReleasePolicy releasePol )
+EncodedBufferImagePtr EncodedBufferImage::New( const uint8_t * const encodedImage,
+                                               const std::size_t encodedImageByteCount,
+                                               const ImageAttributes& attributes,
+                                               const ReleasePolicy releasePol )
 {
   DALI_ASSERT_DEBUG( encodedImage && "Null image pointer passed-in for decoding from memory." );
   DALI_ASSERT_DEBUG( encodedImageByteCount > 0U && "Zero size passed for image resource in memory buffer." );
@@ -39,9 +39,8 @@ Dali::EncodedBufferImage EncodedBufferImage::New( const uint8_t * const encodedI
   // input buffer by reading both ends of it:
   DALI_ASSERT_ALWAYS( static_cast<int>( encodedImage[0] + encodedImage[encodedImageByteCount-1] ) != -1 );
 
-  EncodedBufferImage* const image = new EncodedBufferImage( releasePol );
-  // Make sure that this image object cannot leak if we throw:
-  Dali::EncodedBufferImage publicImage(image);
+  EncodedBufferImagePtr image( new EncodedBufferImage( releasePol ) );
+  image->Initialize(); // Second stage initialization
 
   // Replicate the functionality of ImageFactory::load() without the filesystem caching:
   Dali::Integration::BitmapResourceType resourceType( attributes );
@@ -69,7 +68,7 @@ Dali::EncodedBufferImage EncodedBufferImage::New( const uint8_t * const encodedI
     imageTicket->AddObserver( *image );
   }
 
-  return publicImage;
+  return image;
 }
 
 } // namespace Internal
index d3c46ef..66ec874 100644 (file)
@@ -68,10 +68,10 @@ public:
    * be recreated by dali, the default of Never will usually make sense.
    * @return A pointer to a newly allocated object, or null on error.
    */
-  static Dali::EncodedBufferImage New(const uint8_t * const encodedImage,
-                   const std::size_t encodedImageByteCount,
-                   const ImageAttributes& attributes,
-                   const ReleasePolicy releasePol=Dali::Image::Never);
+  static EncodedBufferImagePtr New(const uint8_t * const encodedImage,
+                                   const std::size_t encodedImageByteCount,
+                                   const ImageAttributes& attributes,
+                                   const ReleasePolicy releasePol=Dali::Image::Never);
 };
 
 } // namespace Internal
index 90cfda1..e20e2c4 100644 (file)
@@ -31,6 +31,27 @@ FrameBufferImage::~FrameBufferImage()
 {
 }
 
+FrameBufferImagePtr  FrameBufferImage::New(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy)
+{
+  FrameBufferImagePtr image = new FrameBufferImage(width, height, pixelFormat, releasePolicy);
+  image->Initialize();
+  return image;
+}
+
+FrameBufferImagePtr  FrameBufferImage::New( NativeImage& nativeImage )
+{
+  FrameBufferImagePtr image = new FrameBufferImage(nativeImage);
+  image->Initialize();
+  return image;
+}
+
+FrameBufferImagePtr  FrameBufferImage::New( NativeImage& nativeImage, ReleasePolicy releasePolicy )
+{
+  FrameBufferImagePtr image = new FrameBufferImage(nativeImage, releasePolicy);
+  image->Initialize();
+  return image;
+}
+
 FrameBufferImage::FrameBufferImage(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy)
 : Image(Dali::Image::Immediate, releasePolicy),
   mPixelFormat(pixelFormat)
@@ -39,6 +60,7 @@ FrameBufferImage::FrameBufferImage(unsigned int width, unsigned int height, Pixe
   mHeight = height;
 }
 
+
 FrameBufferImage::FrameBufferImage( NativeImage& nativeImage )
 : Image(Dali::Image::Immediate),
   mNativeImage(&nativeImage),
@@ -48,6 +70,7 @@ FrameBufferImage::FrameBufferImage( NativeImage& nativeImage )
   mHeight = nativeImage.GetHeight();
 }
 
+
 FrameBufferImage::FrameBufferImage( NativeImage& nativeImage, ReleasePolicy releasePolicy )
 : Image(Dali::Image::Immediate, releasePolicy),
   mNativeImage(&nativeImage),
index 37be53b..473a80a 100644 (file)
@@ -36,16 +36,39 @@ typedef IntrusivePtr<FrameBufferImage> FrameBufferImagePtr;
 class FrameBufferImage : public Image
 {
 public:
-  /// @copydoc Dali::FrameBufferImage::FrameBufferImage
+  /**
+   * @copydoc Dali::FrameBufferImage::New(unsigned int, unsigned int, Pixel::Format)
+   */
+  static FrameBufferImagePtr  New(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy);
+
+  /**
+   * @copydoc Dali::FrameBufferImage::New(NativeImage&)
+   */
+  static FrameBufferImagePtr  New( NativeImage& nativeImage );
+
+  /**
+   * @copydoc Dali::FrameBufferImage::New(NativeImage&, ReleasePolicy)
+   */
+  static FrameBufferImagePtr  New( NativeImage& nativeImage, ReleasePolicy releasePolicy );
+
+  /**
+   * @copydoc Dali::FrameBufferImage::FrameBufferImage
+   */
   FrameBufferImage(unsigned int width, unsigned int height, Pixel::Format pixelFormat);
 
-  /// @copydoc Dali::FrameBufferImage::FrameBufferImage
+  /**
+   * @copydoc Dali::FrameBufferImage::FrameBufferImage
+   */
   FrameBufferImage(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy);
 
-  /// @copydoc Dali::FrameBufferImage::FrameBufferImage
+  /**
+   * @copydoc Dali::FrameBufferImage::FrameBufferImage
+   */
   FrameBufferImage(NativeImage& image);
 
-  /// @copydoc Dali::FrameBufferImage::FrameBufferImage
+  /**
+   * @copydoc Dali::FrameBufferImage::FrameBufferImage
+   */
   FrameBufferImage(NativeImage& image, ReleasePolicy releasePolicy);
 
 public: // From Image
index 2668f9a..25ec1fe 100644 (file)
@@ -19,6 +19,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/object/type-registry.h>
 
 #include <dali/integration-api/platform-abstraction.h>
 #include <dali/integration-api/debug.h>
@@ -37,6 +38,21 @@ namespace Dali
 namespace Internal
 {
 
+namespace
+{
+
+BaseHandle CreateImage()
+{
+  ImagePtr image = Image::New();
+  return Dali::Image(image.Get());
+}
+
+TypeRegistration mType( typeid(Dali::Image), typeid(Dali::BaseHandle), CreateImage );
+
+Dali::SignalConnectorType signalConnector1(mType, Dali::Image::SIGNAL_IMAGE_LOADING_FINISHED,    &Image::DoConnectSignal);
+Dali::SignalConnectorType signalConnector2(mType, Dali::Image::SIGNAL_IMAGE_UPLOADED,            &Image::DoConnectSignal);
+}
+
 Image::Image( LoadPolicy loadPol, ReleasePolicy releasePol )
 : mWidth(0),
   mHeight(0),
@@ -47,21 +63,24 @@ Image::Image( LoadPolicy loadPol, ReleasePolicy releasePol )
 {
 }
 
-Image* Image::New()
+ImagePtr Image::New()
 {
-  return new Image;
+  ImagePtr image = new Image;
+  image->Initialize();
+  return image;
 }
 
-Image* Image::New( const std::string& filename, const Dali::ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol )
+ImagePtr Image::New( const std::string& filename, const Dali::ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol )
 {
   if( IsNinePatchFileName(filename) )
   {
-    NinePatchImage* image = new NinePatchImage( filename, attributes, loadPol, releasePol );
+    NinePatchImagePtr image = NinePatchImage::New( filename, attributes, loadPol, releasePol );
     return image;
   }
   else
   {
-    Image* image = new Image( loadPol, releasePol );
+    ImagePtr image = new Image( loadPol, releasePol );
+    image->Initialize();
 
     if( ! filename.empty() )
     {
@@ -81,6 +100,7 @@ Image* Image::New( const std::string& filename, const Dali::ImageAttributes& att
       image->mTicket = image->mImageFactory.Load( image->mRequest.Get() );
       image->mTicket->AddObserver( *image );
     }
+
     // else lazily load image data later, only when it is needed to draw something:
 
     DALI_LOG_SET_OBJECT_STRING( image, filename );
@@ -89,11 +109,12 @@ Image* Image::New( const std::string& filename, const Dali::ImageAttributes& att
   }
 }
 
-Image* Image::New( NativeImage& nativeImg, LoadPolicy loadPol, ReleasePolicy releasePol )
+ImagePtr Image::New( NativeImage& nativeImg, LoadPolicy loadPol, ReleasePolicy releasePol )
 {
-  Image* image = new Image;
-  ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient();
+  ImagePtr image = new Image;
+  image->Initialize();
 
+  ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient();
 
   image->mWidth  = nativeImg.GetWidth();
   image->mHeight = nativeImg.GetHeight();
@@ -116,6 +137,11 @@ Image::~Image()
       mImageFactory.ReleaseTicket( mTicket.Get() );
     }
   }
+
+  if( Stage::IsInstalled() )
+  {
+    UnregisterObject();
+  }
 }
 
 bool Image::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
@@ -251,6 +277,11 @@ void Image::Disconnect()
   }
 }
 
+void Image::Initialize()
+{
+  RegisterObject();
+}
+
 void Image::SetTicket( ResourceTicket* ticket )
 {
   if( ticket == mTicket.Get() )
index 8fa94a0..84cd39c 100644 (file)
@@ -63,7 +63,7 @@ protected:
   virtual ~Image();
 
   /**
-   * Constructor
+   * Constructor, with default parameters
    */
   Image(LoadPolicy loadPol=ImageLoadPolicyDefault, ReleasePolicy releasePol=ImageReleasePolicyDefault);
 
@@ -72,7 +72,7 @@ public:
    * Creates a pointer to an uninitialized Image object.
    * @return a pointer to a newly created object.
    */
-  static Image* New();
+  static ImagePtr New();
 
   /**
    * Creates object and loads image from filesystem
@@ -84,14 +84,10 @@ public:
    * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
    * @return a pointer to a newly created object.
    */
-  static Image* New(const std::string& filename,
-                    const Dali::ImageAttributes& attributes=Dali::ImageAttributes::DEFAULT_ATTRIBUTES,
-                    LoadPolicy loadPol=ImageLoadPolicyDefault,
-                    ReleasePolicy releasePol=ImageReleasePolicyDefault);
-
-
-
-public:
+  static ImagePtr New( const std::string& filename,
+                       const Dali::ImageAttributes& attributes=Dali::ImageAttributes::DEFAULT_ATTRIBUTES,
+                       LoadPolicy loadPol=ImageLoadPolicyDefault,
+                       ReleasePolicy releasePol=ImageReleasePolicyDefault );
 
   /**
    * Creates object with already loaded NativeImage
@@ -102,9 +98,9 @@ public:
    * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
    * @return a pointer to a newly created object.
    */
-  static Image* New(NativeImage& nativeImg,
-                    LoadPolicy loadPol=ImageLoadPolicyDefault,
-                    ReleasePolicy releasePol=ImageReleasePolicyDefault);
+  static ImagePtr New( NativeImage& nativeImg,
+                       LoadPolicy loadPol=ImageLoadPolicyDefault,
+                       ReleasePolicy releasePol=ImageReleasePolicyDefault );
 
   /**
    * @copydoc Dali::Image::GetLoadingState()
@@ -234,6 +230,12 @@ public:
    */
   virtual void Disconnect();
 
+protected:
+  /**
+   * Second stage initialization
+   */
+  void Initialize();
+
 private:
 
   /**
index c655760..1e660ef 100644 (file)
@@ -140,7 +140,8 @@ NinePatchImage::NinePatchImage( const std::string& filename, const Dali::ImageAt
 : Image(Dali::Image::Immediate, Dali::Image::Never),
   mParsedBorder(false)
 {
-  Initialize();
+  ThreadLocalStorage& tls = ThreadLocalStorage::Get();
+  mResourceClient = &tls.GetResourceClient();
 
   Integration::PlatformAbstraction& platformAbstraction = Internal::ThreadLocalStorage::Get().GetPlatformAbstraction();
 
@@ -216,12 +217,6 @@ Internal::BitmapImagePtr NinePatchImage::CreateCroppedBitmapImage()
   return cropped;
 }
 
-void NinePatchImage::Initialize()
-{
-  ThreadLocalStorage& tls = ThreadLocalStorage::Get();
-  mResourceClient = &tls.GetResourceClient();
-}
-
 void NinePatchImage::Connect()
 {
   if( mConnectionCount == 0 && !mTicket )
index ea757a1..df68813 100644 (file)
@@ -111,11 +111,6 @@ public:
    */
   BitmapImagePtr CreateCroppedBitmapImage();
 
-private:
-  /**
-   * Initializes internal data.
-   */
-  void Initialize();
 
 protected: // From Resource
   /**
index bf26a39..489ff1e 100644 (file)
@@ -36,14 +36,16 @@ EncodedBufferImage::EncodedBufferImage(Internal::EncodedBufferImage* internal)
 
 EncodedBufferImage EncodedBufferImage::New(const uint8_t * const encodedImage, const std::size_t encodedImageByteCount, const ImageAttributes& attributes, const ReleasePolicy releasePol)
 {
-  EncodedBufferImage image = Internal::EncodedBufferImage::New(encodedImage, encodedImageByteCount, attributes, releasePol);
+  Internal::EncodedBufferImagePtr internal=Internal::EncodedBufferImage::New(encodedImage, encodedImageByteCount, attributes, releasePol);
+  EncodedBufferImage image(internal.Get());
   return image;
 }
 
 EncodedBufferImage EncodedBufferImage::New(const uint8_t * const encodedImage, const std::size_t encodedImageByteCount)
 {
   ImageAttributes attributes;
-  EncodedBufferImage image = Internal::EncodedBufferImage::New(encodedImage, encodedImageByteCount, attributes, Dali::Image::Never);
+  Internal::EncodedBufferImagePtr internal = Internal::EncodedBufferImage::New(encodedImage, encodedImageByteCount, attributes, Dali::Image::Never);
+  EncodedBufferImage image( internal.Get() );
   return image;
 }
 
index 81efeea..ed09a7c 100644 (file)
@@ -42,29 +42,37 @@ FrameBufferImage::~FrameBufferImage()
 FrameBufferImage FrameBufferImage::New(unsigned int width, unsigned int height, Pixel::Format pixelformat)
 {
   Dali::Vector2 stageSize = Stage::GetCurrent().GetSize();
-  return FrameBufferImage(new Internal::FrameBufferImage((0 == width) ? stageSize.width : width,
-                                                         (0 == height) ? stageSize.height : height,
-                                                         pixelformat,
-                                                         Dali::Image::Never));
+  Internal::FrameBufferImagePtr internal = Internal::FrameBufferImage::New(
+    (0 == width) ? stageSize.width : width,
+    (0 == height) ? stageSize.height : height,
+    pixelformat,
+    Dali::Image::Never);
+
+  return FrameBufferImage(internal.Get());
 }
 
 FrameBufferImage FrameBufferImage::New(unsigned int width, unsigned int height, Pixel::Format pixelformat, ReleasePolicy releasePolicy)
 {
   Dali::Vector2 stageSize = Stage::GetCurrent().GetSize();
-  return FrameBufferImage(new Internal::FrameBufferImage((0 == width) ? stageSize.width : width,
-                                                         (0 == height) ? stageSize.height : height,
-                                                         pixelformat,
-                                                         releasePolicy));
+  Internal::FrameBufferImagePtr internal = Internal::FrameBufferImage::New(
+    (0 == width) ? stageSize.width : width,
+    (0 == height) ? stageSize.height : height,
+    pixelformat,
+    releasePolicy);
+
+  return FrameBufferImage(internal.Get());
 }
 
 FrameBufferImage FrameBufferImage::New( NativeImage& image, ReleasePolicy releasePolicy )
 {
-  return FrameBufferImage(new Internal::FrameBufferImage( image, releasePolicy ));
+  Internal::FrameBufferImagePtr internal = Internal::FrameBufferImage::New( image, releasePolicy );
+  return FrameBufferImage(internal.Get());
 }
 
 FrameBufferImage FrameBufferImage::New( NativeImage& image )
 {
-  return FrameBufferImage(new Internal::FrameBufferImage( image ));
+  Internal::FrameBufferImagePtr internal = Internal::FrameBufferImage::New( image );
+  return FrameBufferImage(internal.Get());
 }
 
 FrameBufferImage FrameBufferImage::DownCast( BaseHandle handle )
index b79d1dc..eddbd7c 100644 (file)
@@ -51,70 +51,70 @@ Image::~Image()
 
 Image Image::New(const std::string& filename)
 {
-  Internal::Image* internal = Internal::Image::New(filename);
-  return Image(internal);
+  Internal::ImagePtr internal = Internal::Image::New(filename);
+  return Image(internal.Get());
 }
 
 Image Image::New(const std::string& filename, LoadPolicy loadPol, ReleasePolicy releasePol)
 {
-  Internal::Image* internal = Internal::Image::New(filename,
-                                                   Dali::ImageAttributes::DEFAULT_ATTRIBUTES,
-                                                   loadPol, releasePol);
-  return Image(internal);
+  Internal::ImagePtr internal = Internal::Image::New(filename,
+                                                     Dali::ImageAttributes::DEFAULT_ATTRIBUTES,
+                                                     loadPol, releasePol);
+  return Image(internal.Get());
 }
 
 Image Image::New(const std::string& filename, const ImageAttributes& attributes)
 {
-  Internal::Image* internal = Internal::Image::New(filename, attributes);
-  return Image(internal);
+  Internal::ImagePtr internal = Internal::Image::New(filename, attributes);
+  return Image(internal.Get());
 }
 
 Image Image::New(const std::string& filename, const ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol)
 {
-  Internal::Image* internal = Internal::Image::New(filename, attributes, loadPol, releasePol);
-  return Image(internal);
+  Internal::ImagePtr internal = Internal::Image::New(filename, attributes, loadPol, releasePol);
+  return Image(internal.Get());
 }
 
 Image Image::NewDistanceField(const std::string& filename)
 {
   ImageAttributes attributes = ImageAttributes::NewDistanceField();
-  Internal::Image* internal = Internal::Image::New(filename, attributes);
-  return Image(internal);
+  Internal::ImagePtr internal = Internal::Image::New(filename, attributes);
+  return Image(internal.Get());
 }
 
 Image Image::NewDistanceField(const std::string& filename, LoadPolicy loadPol, ReleasePolicy releasePol)
 {
   ImageAttributes attributes = ImageAttributes::NewDistanceField();
-  Internal::Image* internal = Internal::Image::New(filename, attributes, loadPol, releasePol);
-  return Image(internal);
+  Internal::ImagePtr internal = Internal::Image::New(filename, attributes, loadPol, releasePol);
+  return Image(internal.Get());
 }
 
 Image Image::NewDistanceField(const std::string& filename, const ImageAttributes& attributes)
 {
   DALI_ASSERT_DEBUG(attributes.IsDistanceField());
 
-  Internal::Image* internal = Internal::Image::New(filename, attributes);
-  return Image(internal);
+  Internal::ImagePtr internal = Internal::Image::New(filename, attributes);
+  return Image(internal.Get());
 }
 
 Image Image::NewDistanceField(const std::string& filename, const ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol)
 {
   DALI_ASSERT_DEBUG(attributes.IsDistanceField());
 
-  Internal::Image* internal = Internal::Image::New(filename, attributes, loadPol, releasePol);
-  return Image(internal);
+  Internal::ImagePtr internal = Internal::Image::New(filename, attributes, loadPol, releasePol);
+  return Image(internal.Get());
 }
 
 Image Image::New(NativeImage& nativeImg)
 {
-  Internal::Image* internal = Internal::Image::New(nativeImg);
-  return Image(internal);
+  Internal::ImagePtr internal = Internal::Image::New(nativeImg);
+  return Image(internal.Get());
 }
 
 Image Image::New(NativeImage& nativeImg, LoadPolicy loadPol, ReleasePolicy releasePol)
 {
-  Internal::Image* internal = Internal::Image::New(nativeImg, loadPol, releasePol);
-  return Image(internal);
+  Internal::ImagePtr internal = Internal::Image::New(nativeImg, loadPol, releasePol);
+  return Image(internal.Get());
 }
 
 Image Image::DownCast( BaseHandle handle )