[3.0] Remove/move experimental features
[platform/core/uifw/dali-core.git] / dali / internal / event / images / buffer-image-impl.h
index 618846f..496eaac 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.
@@ -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( 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(PixelBuffer* pixBuf,
               unsigned int width,
               unsigned int height,
               Pixel::Format pixelformat,
-              unsigned int stride,
-              ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT);
+              unsigned int stride );
 
 protected:
   /**
@@ -143,27 +142,48 @@ public:
    * Upload the modified contents with Update().
    * @return the pixel buffer
    */
-  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
+  /**
+   * @brief Upload pixel data to another resource at an offset
+   *
+   * @param destId ResourceId of the destination
+   * @param xOffset x offset in the destination
+   * @param yOffset y offset in the destination
+   */
+  void UploadBitmap( ResourceId destId, std::size_t xOffset, std::size_t yOffset );
+
+protected: // From Image
   /**
    * @copydoc Dali::Internal::Image::Connect
    */
@@ -174,18 +194,30 @@ protected: // From Resource
    */
   virtual void Disconnect();
 
-  /**
-   * Get the bitmap from local cache or ticket.
-   **/
-  Integration::Bitmap * GetBitmap() const;
-
 private:
-  bool mIsDataExternal; ///< whether application holds ownership of pixel buffer or not
 
-  ResourceClient*            mResourceClient;
+  void SetupBuffer( unsigned int width,
+                    unsigned int height,
+                    Pixel::Format pixelformat,
+                    unsigned int byteStride );
 
-protected:
-  Integration::BitmapPtr     mBitmapCached;
+  void CreateHostBitmap();
+
+  void UploadArea( ResourceId destId, const RectArea& area );
+
+  void UpdateBufferArea( PixelBuffer* src, PixelBuffer* dest, const RectArea& area );
+
+private:
+
+  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).
+  ResourceClient*              mResourceClient;       ///< pointer to the resource client.
+  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