Removed unneeded includes of Dali::Atlas
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / atlas / atlas-manager.h
1 #ifndef DALI_TOOLKIT_ATLAS_MANAGER_H
2 #define DALI_TOOLKIT_ATLAS_MANAGER_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 // EXTERNAL INCLUDES
21 #include <stdint.h>
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/images/buffer-image.h>
24 #include <dali/public-api/rendering/texture-set.h>
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Internal DALI_INTERNAL
33 {
34
35 class AtlasManager;
36
37 } // namespace Internal
38
39 class AtlasManager : public BaseHandle
40 {
41 public:
42
43   typedef uint32_t SizeType;
44   typedef SizeType AtlasId;
45   typedef SizeType ImageId;
46
47   struct AtlasSize
48   {
49     SizeType mWidth;              ///< width of the atlas in pixels
50     SizeType mHeight;             ///< height of the atlas in pixels
51     SizeType mBlockWidth;         ///< width of a block in pixels
52     SizeType mBlockHeight;        ///< height of a block in pixels
53   };
54
55   /**
56    * Metrics structures to describe Atlas Manager state
57    *
58    */
59   struct AtlasMetricsEntry
60   {
61     AtlasSize mSize;                 ///< size of atlas and blocks
62     SizeType mBlocksUsed;            ///< number of blocks used in the atlas
63     SizeType mTotalBlocks;           ///< total blocks used by atlas
64     Pixel::Format mPixelFormat;      ///< pixel format of the atlas
65   };
66
67   struct Metrics
68   {
69     Metrics()
70     : mAtlasCount( 0u ),
71       mTextureMemoryUsed( 0u )
72     {}
73
74     ~Metrics()
75     {}
76
77     SizeType mAtlasCount;                               ///< number of atlases
78     SizeType mTextureMemoryUsed;                        ///< texture memory used by atlases
79     Dali::Vector< AtlasMetricsEntry > mAtlasMetrics;    ///< container of atlas information
80   };
81
82   struct Vertex2D
83   {
84     Vector2 mPosition;        ///< Vertex posiiton
85     Vector2 mTexCoords;       ///< Vertex texture co-ordinates
86     Vector4 mColor;           ///< Vertex color
87   };
88
89   struct Mesh2D
90   {
91     Vector< Vertex2D > mVertices;       ///< container of vertices
92     Vector< unsigned short > mIndices;        ///< container of indices
93   };
94
95   /**
96    * Create an AtlasManager handle; this can be initialised with AtlasManager::New()
97    * Calling member functions with an uninitialised handle is not allowed.
98    */
99   AtlasManager();
100
101   /**
102    * @brief Get new instance of AtlasManager object.
103    *
104    * @return A handle to the AtlasManager control.
105    */
106   static AtlasManager New();
107
108   /**
109    * @brief Destructor
110    *
111    * This is non-virtual since derived Handle types must not contain data or virtual methods.
112    */
113   ~AtlasManager();
114
115   /**
116    * Policy on failing to add an image
117    */
118   enum AddFailPolicy
119   {
120     FAIL_ON_ADD_FAILS,
121     FAIL_ON_ADD_CREATES
122   };
123
124   /**
125    * @brief Container to hold result of placing texture into atlas
126    */
127   struct AtlasSlot
128   {
129     ImageId mImageId;                           ///< Id of stored Image
130     AtlasId mAtlasId;                           ///< Id of Atlas containing this slot
131   };
132
133   typedef Dali::Vector< AtlasManager::AtlasSlot > slotContainer;
134
135   /**
136    * @brief Create a blank atlas of specific dimensions and pixel format with a certain block size
137    *
138    * @param[in] size desired atlas dimensions
139    * @param[in] pixelformat format of a pixel in atlas
140    *
141    * @return atlas Id
142    */
143   AtlasId CreateAtlas( const AtlasSize& size, Pixel::Format pixelformat = Pixel::RGBA8888 );
144
145   /**
146    * @brief Set the policy on failure to add an image to an atlas
147    *
148    * @param policy policy to carry out if add fails
149    */
150   void SetAddPolicy( AddFailPolicy policy );
151
152   /**
153    * @brief Attempts to add an image to the most suitable atlas
154    *
155    * @details Add Policy may dictate that a new atlas is created if it can't presently be placed.
156    *          If an add is made before an atlas is created under this policy,
157    *          then a default size atlas will be created
158    *
159    * @param[in] image PixelData object containing the image data
160    * @param[out] slot result of add operation
161    * @param[in] atlas optional preferred atlas
162    *
163    * @return true if a new atlas was created
164    */
165   bool Add( const PixelData& image,
166             AtlasSlot& slot,
167             AtlasId atlas = 0 );
168
169   /**
170    * @brief Remove previously added bitmapimage from atlas
171    *
172    * @param[in] id ImageId returned in the AtlasSlot from the add operation
173    *
174    * @return if true then image has been removed from the atlas
175    */
176   bool Remove( ImageId id );
177
178   /**
179    * @brief Generate mesh data for a previously added image
180    *
181    * @param[in] id Image Id returned in the AtlasSlot from the add operation
182    * @param[in] position position of the resulting mesh in model space
183    * @param[out] mesh Mesh Data Object to populate with mesh data
184    * @param[in] addReference Whether to increase the internal reference count for image or not
185    */
186   void GenerateMeshData( ImageId id,
187                          const Vector2& position,
188                          Mesh2D& mesh,
189                          bool addReference = true );
190
191   /**
192    * @brief Get the BufferImage containing an atlas
193    *
194    * @param[in] atlas AtlasId returned when atlas was created
195    *
196    * @return Atlas Handle
197    */
198   Dali::Texture GetAtlasContainer( AtlasId atlas ) const;
199
200   /**
201    * @brief Get the Id of the atlas containing an image
202    *
203    * @param[in] id ImageId
204    *
205    * @return Atlas Id
206    */
207   AtlasId GetAtlas( ImageId id );
208   /**
209    * @brief Get the current size of an atlas
210    *
211    * @param[in] atlas AtlasId
212    *
213    * @return AtlasSize structure for the atlas
214    */
215   const AtlasSize& GetAtlasSize( AtlasId atlas );
216
217   /**
218    * @brief Get the number of blocks available in an atlas
219    *
220    * @param[in] atlas AtlasId
221    *
222    * @return Number of blocks free in this atlas
223    */
224   SizeType GetFreeBlocks( AtlasId atlas );
225
226   /**
227    * @brief Sets the pixel area of any new atlas and also the individual block size
228    *
229    * @param[in] size Atlas size structure
230    *
231    * @param blockSize pixel area in atlas for a block
232    */
233   void SetNewAtlasSize( const AtlasSize& size );
234
235   /**
236    * @brief Get the number of atlases created
237    *
238    * @return number of atlases
239    */
240   SizeType GetAtlasCount() const;
241
242   /**
243    * @brief Get the pixel format used by an atlas
244    *
245    * @param[in] atlas AtlasId
246    *
247    * @return Pixel format used by this atlas
248    */
249   Pixel::Format GetPixelFormat( AtlasId atlas ) const;
250
251   /**
252    * @brief Fill in a metrics structure showing current status of this Atlas Manager
253    *
254    * @param[in] metrics metrics structure to be filled
255    */
256   void GetMetrics( Metrics& metrics );
257
258   /**
259    * @brief Get TextureSet used by atlas
260    *
261    * @param[in] atlas AtlasId
262    *
263    * @return TextureSet used by atlas
264    */
265   TextureSet GetTextures( AtlasId atlas ) const;
266
267   /**
268    * @brief Set the texture set used by an atlas
269    *
270    * @param[in] atlas AtlasId
271    * @param[in] textureSet The texture set to assign
272    */
273   void SetTextures( AtlasId atlas, TextureSet& textureSet );
274
275 private:
276
277   explicit DALI_INTERNAL AtlasManager(Internal::AtlasManager *impl);
278
279 };
280
281 } // namespace Toolkit
282
283 } // namespace Dali
284
285 #endif // DALI_TOOLKIT_ATLAS_MANAGER_H