1 #ifndef __DALI_INTERNAL_BUFFER_IMAGE_H__
2 #define __DALI_INTERNAL_BUFFER_IMAGE_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/integration-api/bitmap.h> // For Integration::BitmapPtr
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali/internal/event/images/image-impl.h>
25 #include <dali/public-api/images/image.h>
26 #include <dali/public-api/images/buffer-image.h>
35 typedef IntrusivePtr<BufferImage> BufferImagePtr;
38 class ResourceManager;
41 * BufferImage represents an image resource that can be added to actors etc.
42 * Its pixel buffer data is provided by the application developer.
43 * Pixel buffer memory allocation can be handled by dali or application.
45 class BufferImage : public Image
49 * Create a new BufferImage.
50 * Also a pixel buffer for image data is allocated.
51 * Dali has ownership of the buffer.
52 * For better performance and portability use power of two dimensions.
53 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
54 * @param [in] width image width in pixels
55 * @param [in] height image height in pixels
56 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
58 static BufferImagePtr New( unsigned int width,
60 Pixel::Format pixelformat );
63 * @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.
65 * @brief Create a new BufferImage, which uses external data source.
67 * Pixel buffer has to be allocated by application.
68 * 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.
69 * The buffer should only be freed when there is no chance of an Update() being called again.
70 * Obtaining the buffer with GetBuffer() and altering the contents, then Update() will not work with externally owned buffers.
71 * For better performance and portability use power of two dimensions.
72 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
74 * @param [in] pixBuf pixel buffer. has to be allocated by application.
75 * @param [in] width image width in pixels
76 * @param [in] height image height in pixels
77 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
78 * @param [in] stride the internal stride of the pixelbuffer in pixels
80 static BufferImagePtr New( PixelBuffer* pixBuf,
83 Pixel::Format pixelformat,
84 unsigned int stride );
87 * Create a new BufferImage.
88 * Also a pixel buffer for image data is allocated.
89 * Dali has ownership of the buffer.
90 * For better performance use power of two dimensions.
91 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
92 * @param [in] width image width in pixels
93 * @param [in] height image height in pixels
94 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
96 BufferImage(unsigned int width,
98 Pixel::Format pixelformat );
101 * Create a new BufferImage, which uses external data source.
102 * Pixel buffer has to be allocated by application.
103 * 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.
104 * The buffer should only be freed when there is no chance of Update() being called again.
105 * Note: obtaining the buffer with GetBuffer(), writing changes, then Update() will cause any changes to be lost.
106 * In this case, the BufferImage will update from the external buffer and so changes should be written there.
107 * For better performance and portability use power of two dimensions.
108 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
109 * @param [in] pixBuf pixel buffer. has to be allocated by application.
110 * @param [in] width image width in pixels
111 * @param [in] height image height in pixels
112 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
113 * @param [in] stride the internal stride of the pixelbuffer in pixels
115 BufferImage(PixelBuffer* pixBuf,
118 Pixel::Format pixelformat,
119 unsigned int stride );
123 * A reference counted object may only be deleted by calling Unreference()
125 virtual ~BufferImage();
129 * Notify Dali that the contents of the buffer have changed.
130 * @param [in] updateArea area that has changed in buffer. An empty rect means the whole buffer has changed.
132 void Update (RectArea& updateArea);
135 * @copydoc Dali::BufferImage::IsDataExternal
137 bool IsDataExternal() const;
140 * Returns the pixel buffer of the Image.
141 * The application developer can write to the buffer.
142 * Upload the modified contents with Update().
143 * @return the pixel buffer
145 PixelBuffer* GetBuffer() const
147 return ( mExternalBuffer ? mExternalBuffer : mInternalBuffer );
151 * Returns buffer size in bytes.
152 * @return the buffer size in bytes
154 unsigned int GetBufferSize() const
160 * Returns buffer stride (in bytes).
161 * @return the buffer stride
163 unsigned int GetBufferStride() const
169 * Get the pixel format
170 * @return The pixel format
172 Pixel::Format GetPixelFormat() const
178 * @brief Upload pixel data to another resource at an offset
180 * @param destId ResourceId of the destination
181 * @param xOffset x offset in the destination
182 * @param yOffset y offset in the destination
184 void UploadBitmap( ResourceId destId, std::size_t xOffset, std::size_t yOffset );
186 protected: // From Image
188 * @copydoc Dali::Internal::Image::Connect
190 virtual void Connect();
193 * @copydoc Dali::Internal::Image::Disconnect
195 virtual void Disconnect();
199 void SetupBuffer( unsigned int width,
201 Pixel::Format pixelformat,
202 unsigned int byteStride );
204 void CreateHostBitmap();
206 void UploadArea( ResourceId destId, const RectArea& area );
208 void UpdateBufferArea( PixelBuffer* src, PixelBuffer* dest, const RectArea& area );
212 PixelBuffer* mInternalBuffer; ///< NULL if the data is supplied by an external buffer.
213 PixelBuffer* mExternalBuffer; ///< NULL if there is no external pixel data (this is never owned by BufferImage).
214 ResourceClient* mResourceClient; ///< pointer to the resource client.
215 uint32_t mBufferSize; ///< size of the pixel buffer.
216 uint32_t mByteStride; ///< width of the pixel buffer in bytes.
217 uint32_t mBytesPerPixel; ///< width of a pixel in bytes.
218 uint32_t mBufferWidth; ///< cached pixel width of bitmap used for transport.
219 Pixel::Format mPixelFormat; ///< pixel format of bitmap.
220 ResourcePolicy::Discardable mResourcePolicy; ///< whether to discard the pixel buffer when removed from the stage or to retain the data.
223 } // namespace Internal
226 * Helper methods for public API.
228 inline Internal::BufferImage& GetImplementation(Dali::BufferImage& image)
230 DALI_ASSERT_ALWAYS( image && "BufferImage handle is empty" );
232 BaseObject& handle = image.GetBaseObject();
234 return static_cast<Internal::BufferImage&>(handle);
237 inline const Internal::BufferImage& GetImplementation(const Dali::BufferImage& image)
239 DALI_ASSERT_ALWAYS( image && "BufferImage handle is empty" );
241 const BaseObject& handle = image.GetBaseObject();
243 return static_cast<const Internal::BufferImage&>(handle);
248 #endif // __DALI_INTERNAL_BUFFER_IMAGE_H__