Merge "Change PixelData to use the handle/body pattern" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / images / pixel-data-impl.h
1 #ifndef __DALI_INTERNAL_PIXEL_DATA_H__
2 #define __DALI_INTERNAL_PIXEL_DATA_H__
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/devel-api/images/pixel-data.h>
23 #include <dali/public-api/object/base-object.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 class PixelData;
32 typedef IntrusivePtr<PixelData> PixelDataPtr;
33
34 class PixelData : public BaseObject
35 {
36 public:
37
38   /**
39    * @brief Create a PixelData object.
40    *
41    * @param [in] buffer           The raw pixel data.
42    * @param [in] width            Buffer width in pixels
43    * @param [in] height           Buffer height in pixels
44    * @param [in] pixelFormat      The pixel format
45    * @param [in] releaseFunction  The function used to release the memory.
46    */
47   static PixelDataPtr New( unsigned char* buffer,
48                            unsigned int width,
49                            unsigned int height,
50                            Pixel::Format pixelFormat,
51                            Dali::PixelData::ReleaseFunction releaseFunction);
52
53   /**
54    * @brief Constructor.
55    *
56    * @param [in] buffer           The raw pixel data.
57    * @param [in] width            Buffer width in pixels
58    * @param [in] height           Buffer height in pixels
59    * @param [in] pixelFormat      The pixel format
60    * @param [in] releaseFunction  The function used to release the memory.
61    */
62   PixelData( unsigned char* buffer,
63              unsigned int width,
64              unsigned int height,
65              Pixel::Format pixelFormat,
66              Dali::PixelData::ReleaseFunction releaseFunction );
67
68 protected:
69
70   /**
71    * @brief Destructor.
72    *
73    * Release the pixel buffer if exists.
74    */
75   ~PixelData();
76
77 public:
78
79   /**
80    * Get the width of the buffer in pixels.
81    * @return The width of the buffer in pixels
82    */
83   unsigned int GetWidth() const;
84
85   /**
86    * Get the height of the buffer in pixels
87    * @return The height of the buffer in pixels
88    */
89   unsigned int GetHeight() const;
90
91   /**
92    * Get the pixel format
93    * @return The pixel format
94    */
95   Pixel::Format GetPixelFormat() const;
96
97   /**
98    * Get the pixel buffer if it's present.
99    * @return The buffer if exists, or NULL if there is no pixel buffer.
100    */
101   unsigned char* GetBuffer() const;
102
103 private:
104
105   /*
106    * Undefined copy constructor.
107    */
108   PixelData(const PixelData& other);
109
110   /*
111    * Undefined assignment operator.
112    */
113   PixelData& operator = (const PixelData& other);
114
115 private:
116
117   unsigned char* mBuffer;           ///< The raw pixel data.
118   unsigned int   mWidth;            ///< Buffer width in pixels.
119   unsigned int   mHeight;           ///< Buffer height in pixels.
120   Pixel::Format  mPixelFormat;      ///< Pixel format
121   Dali::PixelData::ReleaseFunction mReleaseFunction;  ///< Function for releasing memory
122 };
123
124 } // namespace Internal
125
126 /**
127  * Helper methods for public API
128  */
129 inline Internal::PixelData& GetImplementation( Dali::PixelData& handle )
130 {
131   DALI_ASSERT_ALWAYS( handle && "handle is empty" );
132
133   BaseObject& object = handle.GetBaseObject();
134
135   return static_cast<Internal::PixelData&>( object );
136 }
137
138 inline const Internal::PixelData& GetImplementation( const Dali::PixelData& handle )
139 {
140   DALI_ASSERT_ALWAYS( handle && "handle is empty" );
141
142   const BaseObject& object = handle.GetBaseObject();
143
144   return static_cast<const Internal::PixelData&>( object );
145 }
146
147 } // namespace Dali
148
149 #endif // __DALI_INTERNAL_PIXEL_DATA_H__