1 #ifndef __DALI_INTERNAL_BITMAP_IMAGE_H__
2 #define __DALI_INTERNAL_BITMAP_IMAGE_H__
5 * Copyright (c) 2014 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/public-api/object/ref-object.h>
23 #include <dali/internal/event/images/image-impl.h>
24 #include <dali/public-api/images/image.h>
25 #include <dali/public-api/images/bitmap-image.h>
34 typedef IntrusivePtr<BitmapImage> BitmapImagePtr;
37 class ResourceManager;
40 * BitmapImage represents an image resource that can be added to actors etc.
41 * Its pixel buffer data is provided by the application developer.
42 * Pixel buffer memory allocation can be handled by dali or application.
44 class BitmapImage : public Image
48 * Create a new BitmapImage.
49 * Also a pixel buffer for image data is allocated.
50 * Dali has ownership of the buffer.
51 * For better performance and portability use power of two dimensions.
52 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
53 * @param [in] width image width in pixels
54 * @param [in] height image height in pixels
55 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
56 * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
58 static BitmapImagePtr New( unsigned int width,
60 Pixel::Format pixelformat,
61 ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT );
64 * Create a new BitmapImage, which uses external data source.
65 * Pixel buffer has to be allocated by application.
66 * Application holds ownership of the buffer.
67 * For better performance and portability use power of two dimensions.
68 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
69 * @note in case releasePol is "OffStage", application has to call Image::BufferUpdated() whenever image is re-added to the stage
70 * @param [in] pixBuf pixel buffer. has to be allocated by application.
71 * @param [in] width image width in pixels
72 * @param [in] height image height in pixels
73 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
74 * @param [in] stride the internal stride of the pixelbuffer in pixels
75 * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
77 static BitmapImagePtr New( PixelBuffer* pixBuf,
80 Pixel::Format pixelformat,
82 ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT );
85 * Create a new BitmapImage.
86 * Also a pixel buffer for image data is allocated.
87 * Dali has ownership of the buffer.
88 * For better performance use power of two dimensions.
89 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
90 * @param [in] width image width in pixels
91 * @param [in] height image height in pixels
92 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
93 * @param [in] releasePol optionally release memory when image is not visible on screen (default: keep image data until Image object is alive).
95 BitmapImage(unsigned int width,
97 Pixel::Format pixelformat,
98 ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT);
101 * Create a new BitmapImage, which uses external data source.
102 * Pixel buffer has to be allocated by application.
103 * Application holds ownership of the buffer.
104 * For better performance and portability use power of two dimensions.
105 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
106 * @note in case releasePol is "OffStage", application has to call Image::BufferUpdated() whenever image is re-added to the stage
107 * @param [in] pixBuf pixel buffer. has to be allocated by application.
108 * @param [in] width image width in pixels
109 * @param [in] height image height in pixels
110 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
111 * @param [in] stride the internal stride of the pixelbuffer in pixels
112 * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
114 BitmapImage(PixelBuffer* pixBuf,
117 Pixel::Format pixelformat,
119 ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT);
123 * A reference counted object may only be deleted by calling Unreference()
125 virtual ~BitmapImage();
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::BitmapImage::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 BufferUpdated.
143 * @return the pixel buffer
145 PixelBuffer* GetBuffer();
148 * Returns buffer size in bytes.
149 * @return the buffer size in bytes
151 unsigned int GetBufferSize() const;
154 * Returns buffer stride (in bytes).
155 * @return the buffer stride
157 unsigned int GetBufferStride() const;
160 * Get the pixel format
161 * @return The pixel format
163 Pixel::Format GetPixelFormat() const;
165 protected: // From Resource
167 * @copydoc Dali::Internal::Image::Connect
169 virtual void Connect();
172 * @copydoc Dali::Internal::Image::Disconnect
174 virtual void Disconnect();
177 * Get the bitmap from local cache or ticket.
179 Integration::Bitmap * GetBitmap() const;
182 bool mIsDataExternal; ///< whether application holds ownership of pixel buffer or not
184 ResourceClient* mResourceClient;
187 Integration::BitmapPtr mBitmapCached;
190 } // namespace Internal
193 * Helper methods for public API.
195 inline Internal::BitmapImage& GetImplementation(Dali::BitmapImage& image)
197 DALI_ASSERT_ALWAYS( image && "BitmapImage handle is empty" );
199 BaseObject& handle = image.GetBaseObject();
201 return static_cast<Internal::BitmapImage&>(handle);
204 inline const Internal::BitmapImage& GetImplementation(const Dali::BitmapImage& image)
206 DALI_ASSERT_ALWAYS( image && "BitmapImage handle is empty" );
208 const BaseObject& handle = image.GetBaseObject();
210 return static_cast<const Internal::BitmapImage&>(handle);
215 #endif // __DALI_INTERNAL_BITMAP_IMAGE_H__