Merge "(PropertyMap) Use vector-wrapper" into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / images / atlas-impl.h
1 #ifndef __DALI_INTERNAL_ATLAS_H__
2 #define __DALI_INTERNAL_ATLAS_H__
3
4 /*
5  * Copyright (c) 2015 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/public-api/images/atlas.h>
23 #include <dali/internal/event/images/image-impl.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 class ResourceClient;
32
33 /**
34  * @brief An Atlas is a large image containing multiple smaller images.
35  *
36  * Bitmap images must be uploaded at a specified position, to populate the Atlas.
37  * The client is reponsible for generating the appropriate geometry (UV coordinates),
38  * needed to draw images within the Atlas.
39  */
40 class Atlas : public Image
41 {
42 public:
43
44   /**
45    * @brief Create a new Atlas.
46    *
47    * @pre width & height are greater than zero.
48    * The maximum size of the atlas is limited by GL_MAX_TEXTURE_SIZE.
49    * @param [in] width       The atlas width in pixels.
50    * @param [in] height      The atlas height in pixels.
51    * @param [in] pixelFormat The pixel format (rgba 32 bit by default).
52    * @return A pointer to a new Atlas.
53    */
54   static Atlas* New( std::size_t width,
55                      std::size_t height,
56                      Pixel::Format pixelFormat = Pixel::RGBA8888 );
57
58   /**
59    * @brief Upload a buffer image to the atlas.
60    *
61    * @pre The bitmap pixel format must match the Atlas format.
62    * @param [in] bufferImage The buffer image to upload.
63    * @param [in] xOffset Specifies an offset in the x direction within the atlas.
64    * @param [in] yOffset Specifies an offset in the y direction within the atlas.
65    * @return True if the bitmap fits within the atlas at the specified offset.
66    */
67   bool Upload( const BufferImage& bufferImage,
68                std::size_t xOffset,
69                std::size_t yOffset );
70
71 protected:
72
73   /**
74    * @brief Protected constructor.
75    *
76    * @pre width & height are greater than zero.
77    * The maximum size of the atlas is limited by GL_MAX_TEXTURE_SIZE.
78    * @param [in] width       The atlas width in pixels.
79    * @param [in] height      The atlas height in pixels.
80    * @param [in] pixelFormat The pixel format (rgba 32 bit by default).
81    */
82   Atlas( std::size_t width,
83          std::size_t height,
84          Pixel::Format pixelFormat );
85
86   /**
87    * A reference counted object may only be deleted by calling Unreference()
88    */
89   virtual ~Atlas();
90
91   /**
92    * @copydoc Dali::Internal::Image::Connect
93    */
94   virtual void Connect();
95
96   /**
97    * @copydoc Dali::Internal::Image::Disconnect
98    */
99   virtual void Disconnect();
100
101 private:
102
103   /**
104    * Helper for Upload methods
105    * @return True if the bitmap fits within the atlas at the specified offset
106    */
107   bool IsWithin( const BufferImage& bufferImage,
108                  std::size_t xOffset,
109                  std::size_t yOffset );
110
111   /**
112    * Helper to create the Atlas resource
113    */
114   void AllocateAtlas();
115
116   /**
117    * Helper to release the Atlas resource
118    */
119   void ReleaseAtlas();
120
121 private:
122
123   ResourceClient& mResourceClient;
124
125   Pixel::Format mPixelFormat;
126 };
127
128 } // namespace Internal
129
130 /**
131  * Helper methods for public API.
132  */
133 inline Internal::Atlas& GetImplementation(Dali::Atlas& image)
134 {
135   DALI_ASSERT_ALWAYS( image && "Atlas handle is empty" );
136
137   BaseObject& handle = image.GetBaseObject();
138
139   return static_cast<Internal::Atlas&>(handle);
140 }
141
142 inline const Internal::Atlas& GetImplementation(const Dali::Atlas& image)
143 {
144   DALI_ASSERT_ALWAYS( image && "Atlas handle is empty" );
145
146   const BaseObject& handle = image.GetBaseObject();
147
148   return static_cast<const Internal::Atlas&>(handle);
149 }
150
151 } // namespace Dali
152
153 #endif // __DALI_INTERNAL_ATLAS_H__