Revert "[Tizen] Restore Uploaded signal for BufferImage and ResourceImage"
[platform/core/uifw/dali-core.git] / dali / internal / event / images / buffer-image-impl.h
index 9dbd3c2..008c8a0 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_BUFFER_IMAGE_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  */
 
+// EXTERNAL INCLUDES
+#include <stdint.h> // for uint32_t
+
 // INTERNAL INCLUDES
 #include <dali/integration-api/bitmap.h> // For Integration::BitmapPtr
 #include <dali/public-api/object/ref-object.h>
-#include <dali/public-api/images/buffer-image.h>
-#include <dali/public-api/images/image.h>
 #include <dali/internal/event/images/image-impl.h>
+#include <dali/public-api/images/image.h>
+#include <dali/public-api/images/buffer-image.h>
 
 namespace Dali
 {
@@ -34,9 +37,6 @@ namespace Internal
 class BufferImage;
 typedef IntrusivePtr<BufferImage> BufferImagePtr;
 
-class ResourceClient;
-class ResourceManager;
-
 /**
  * BufferImage represents an image resource that can be added to actors etc.
  * Its pixel buffer data is provided by the application developer.
@@ -54,33 +54,34 @@ public:
    * @param [in] width       image width in pixels
    * @param [in] height      image height in pixels
    * @param [in] pixelformat the pixel format (rgba 32 bit by default)
-   * @param [in] releasePol  optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
    */
   static BufferImagePtr New( unsigned int width,
                              unsigned int height,
-                             Pixel::Format pixelformat,
-                             ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT );
+                             Pixel::Format pixelformat );
 
   /**
-   * Create a new BufferImage, which uses external data source.
+   * @DEPRECATED_1_1.5. Support for externally owned Pixel Buffers is due to be removed TBA. It is recommended that a BufferImage owned Buffer be used instead.
+   *
+   * @brief Create a new BufferImage, which uses external data source.
+   *
    * Pixel buffer has to be allocated by application.
-   * Application holds ownership of the buffer.
+   * An internal copy is made of the Pixel Buffer, which can then be freed by the Application, unless if there will be a call to Update() later.
+   * The buffer should only be freed when there is no chance of an Update() being called again.
+   * Obtaining the buffer with GetBuffer() and altering the contents, then Update() will not work with externally owned buffers.
    * For better performance and portability use power of two dimensions.
    * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
-   * @note  in case releasePol is "OffStage", application has to call Update() whenever image is re-added to the stage
+   *
    * @param [in] pixBuf      pixel buffer. has to be allocated by application.
    * @param [in] width       image width in pixels
    * @param [in] height      image height in pixels
    * @param [in] pixelformat the pixel format (rgba 32 bit by default)
    * @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 BufferImagePtr New( Integration::PixelBuffer* pixBuf,
+  static BufferImagePtr New( PixelBuffer* pixBuf,
                              unsigned int width,
                              unsigned int height,
                              Pixel::Format pixelformat,
-                             unsigned int stride,
-                             ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT );
+                             unsigned int stride );
 
   /**
    * Create a new BufferImage.
@@ -91,33 +92,31 @@ public:
    * @param [in] width image width in pixels
    * @param [in] height image height in pixels
    * @param [in] pixelformat the pixel format (rgba 32 bit by default)
-   * @param [in] releasePol optionally release memory when image is not visible on screen (default: keep image data until Image object is alive).
    */
   BufferImage(unsigned int width,
               unsigned int height,
-              Pixel::Format pixelformat,
-              ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT);
+              Pixel::Format pixelformat );
 
   /**
    * Create a new BufferImage, which uses external data source.
    * Pixel buffer has to be allocated by application.
-   * Application holds ownership of the buffer.
+   * An internal copy is made of the Pixel Buffer, which can then be freed by the Application, unless if there will be a call to Update() later.
+   * The buffer should only be freed when there is no chance of Update() being called again.
+   * Note: obtaining the buffer with GetBuffer(), writing changes, then Update() will cause any changes to be lost.
+   * In this case, the BufferImage will update from the external buffer and so changes should be written there.
    * For better performance and portability use power of two dimensions.
    * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
-   * @note  in case releasePol is "OffStage", application has to call Update() whenever image is re-added to the stage
    * @param [in] pixBuf      pixel buffer. has to be allocated by application.
    * @param [in] width       image width in pixels
    * @param [in] height      image height in pixels
    * @param [in] pixelformat the pixel format (rgba 32 bit by default)
    * @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).
    */
-  BufferImage(Integration::PixelBuffer* pixBuf,
+  BufferImage(PixelBuffer* pixBuf,
               unsigned int width,
               unsigned int height,
               Pixel::Format pixelformat,
-              unsigned int stride,
-              ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT);
+              unsigned int stride );
 
 protected:
   /**
@@ -130,7 +129,7 @@ public:
    * Notify Dali that the contents of the buffer have changed.
    * @param [in] updateArea area that has changed in buffer. An empty rect means the whole buffer has changed.
    */
-  void Update (RectArea& updateArea);
+  void Update( const RectArea& updateArea);
 
   /**
    * @copydoc Dali::BufferImage::IsDataExternal
@@ -143,49 +142,59 @@ public:
    * Upload the modified contents with Update().
    * @return the pixel buffer
    */
-  Integration::PixelBuffer* GetBuffer();
+  PixelBuffer* GetBuffer() const
+  {
+    return ( mExternalBuffer ? mExternalBuffer : mInternalBuffer );
+  }
 
   /**
    * Returns buffer size in bytes.
    * @return the buffer size in bytes
    */
-  unsigned int GetBufferSize() const;
+  unsigned int GetBufferSize() const
+  {
+    return mBufferSize;
+  }
 
   /**
    * Returns buffer stride (in bytes).
    * @return the buffer stride
    */
-  unsigned int GetBufferStride() const;
+  unsigned int GetBufferStride() const
+  {
+    return mByteStride;
+  }
 
   /**
    * Get the pixel format
    * @return The pixel format
    */
-  Pixel::Format GetPixelFormat() const;
+  Pixel::Format GetPixelFormat() const
+  {
+    return mPixelFormat;
+  }
 
-protected: // From Resource
-  /**
-   * @copydoc Dali::Internal::Image::Connect
-   */
-  virtual void Connect();
+private:
 
-  /**
-   * @copydoc Dali::Internal::Image::Disconnect
-   */
-  virtual void Disconnect();
+  void SetupBuffer( unsigned int width,
+                    unsigned int height,
+                    Pixel::Format pixelformat,
+                    unsigned int byteStride );
 
-  /**
-   * Get the bitmap from local cache or ticket.
-   **/
-  Integration::Bitmap * GetBitmap() const;
+  void UploadArea( const RectArea& area );
 
-private:
-  bool mIsDataExternal; ///< whether application holds ownership of pixel buffer or not
+  void UpdateBufferArea( PixelBuffer* src, PixelBuffer* dest, const RectArea& area );
 
-  ResourceClient*            mResourceClient;
+private:
 
-protected:
-  Integration::BitmapPtr     mBitmapCached;
+  PixelBuffer*                 mInternalBuffer;       ///< NULL if the data is supplied by an external buffer.
+  PixelBuffer*                 mExternalBuffer;       ///< NULL if there is no external pixel data (this is never owned by BufferImage).
+  uint32_t                     mBufferSize;           ///< size of the pixel buffer.
+  uint32_t                     mByteStride;           ///< width of the pixel buffer in bytes.
+  uint32_t                     mBytesPerPixel;        ///< width of a pixel in bytes.
+  uint32_t                     mBufferWidth;          ///< cached pixel width of bitmap used for transport.
+  Pixel::Format                mPixelFormat;          ///< pixel format of bitmap.
+  ResourcePolicy::Discardable  mResourcePolicy;       ///< whether to discard the pixel buffer when removed from the stage or to retain the data.
 };
 
 } // namespace Internal