Rendering API clean-up
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / atlas / atlas-manager-impl.h
1 #ifndef __DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H__
2 #define __DALI_TOOLKIT_ATLAS_MANAGER_IMPL_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/base-object.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/text/rendering/atlas/atlas-manager.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 class AtlasManager;
35
36 } // namespace Toolkit
37
38 namespace Toolkit
39 {
40
41 namespace Internal
42 {
43
44 typedef Dali::Vector< Toolkit::AtlasManager::AtlasSlot > slotContainer;
45
46 class AtlasManager;
47 typedef IntrusivePtr<AtlasManager> AtlasManagerPtr;
48
49 class AtlasManager : public Dali::BaseObject
50 {
51 public:
52
53   typedef uint32_t SizeType;
54   typedef SizeType AtlasId;
55   typedef SizeType ImageId;
56
57   /**
58    * @brief Internal storage of atlas attributes and image upload results
59    */
60   struct AtlasDescriptor
61   {
62     Dali::Atlas mAtlas;                                                 // atlas image
63     Toolkit::AtlasManager::AtlasSize mSize;                             // size of atlas
64     Pixel::Format mPixelFormat;                                         // pixel format used by atlas
65     BufferImage mHorizontalStrip;                                       // Image used to pad upload
66     BufferImage mVerticalStrip;                                         // Image used to pad upload
67     TextureSet mTextureSet;                                             // Texture set used for atlas texture
68     SizeType mTotalBlocks;                                              // total number of blocks in atlas
69     SizeType mAvailableBlocks;                                          // number of blocks available in atlas
70     Dali::Vector< SizeType > mFreeBlocksList;                           // unless there are any previously freed blocks
71   };
72
73   struct AtlasSlotDescriptor
74   {
75     SizeType mCount;                                                    // Reference count for this slot
76     SizeType mImageWidth;                                               // Width of image stored
77     SizeType mImageHeight;                                              // Height of image stored
78     AtlasId mAtlasId;                                                   // Image is stored in this Atlas
79     SizeType mBlock;                                                    // Block within atlas used for image
80   };
81
82   AtlasManager();
83
84   /**
85    * Create a new AtlasManager
86    */
87   static AtlasManagerPtr New();
88
89   virtual ~AtlasManager();
90
91   /**
92    * @copydoc: Toolkit::AtlasManager::CreateAtlas
93    */
94   AtlasId CreateAtlas( const Toolkit::AtlasManager::AtlasSize& size, Pixel::Format pixelformat );
95
96   /**
97    * @copydoc Toolkit::AtlasManager::SetAddPolicy
98    */
99   void SetAddPolicy( Toolkit::AtlasManager::AddFailPolicy policy );
100
101   /**
102    * @copydoc Toolkit::AtlasManager::Add
103    */
104   bool Add( const BufferImage& image,
105             Toolkit::AtlasManager::AtlasSlot& slot,
106             Toolkit::AtlasManager::AtlasId atlas );
107
108   /**
109    * @copydoc Toolkit::AtlasManager::GenerateMeshData
110    */
111   void GenerateMeshData( ImageId id,
112                          const Vector2& position,
113                          Toolkit::AtlasManager::Mesh2D& mesh,
114                          bool addReference );
115
116   /**
117    * @copydoc Toolkit::AtlasManager::Remove
118    */
119   bool Remove( ImageId id );
120
121   /**
122    * @copydoc Toolkit::AtlasManager::GetAtlasContainer
123    */
124   Dali::Atlas GetAtlasContainer( AtlasId atlas ) const;
125
126   /**
127    * @copydoc Toolkit::AtlasManager::GetAtlas
128    */
129   AtlasId GetAtlas( ImageId id ) const;
130
131   /**
132    * @copydoc Toolkit::AtlasManager::SetNewAtlasSize
133    */
134   void SetNewAtlasSize( const Toolkit::AtlasManager::AtlasSize& size );
135
136   /**
137    * @copydoc Toolkit::AtlasManager::GetAtlasSize
138    */
139   const Toolkit::AtlasManager::AtlasSize& GetAtlasSize( AtlasId atlas );
140
141   /**
142    * @copydoc Toolkit::AtlasManager::GetBlockSize
143    */
144   Vector2 GetBlockSize( AtlasId atlas );
145
146   /**
147    * @copydoc Toolkit::AtlasManager::GetFreeBlocks
148    */
149   SizeType GetFreeBlocks( AtlasId atlas ) const;
150
151   /*
152    * @copydoc Toolkit::AtlasManager::GetAtlasCount
153    */
154   SizeType GetAtlasCount() const;
155
156   /**
157    * @copydoc Toolkit::AtlasManager::GetPixelFormat
158    */
159   Pixel::Format GetPixelFormat( AtlasId atlas ) const;
160
161   /**
162    * @copydoc Toolkit::AtlasManager::GetMetrics
163    */
164   void GetMetrics( Toolkit::AtlasManager::Metrics& metrics );
165
166   /**
167    * @copydoc Toolkit::AtlasManager::GetTextures
168    */
169   TextureSet GetTextures( AtlasId atlas ) const;
170
171   /**
172    * @copydoc Toolkit::AtlasManager::SetTextures
173    */
174   void SetTextures( AtlasId atlas, TextureSet& textureSet );
175
176 private:
177
178   std::vector< AtlasDescriptor > mAtlasList;            // List of atlases created
179   Vector< AtlasSlotDescriptor > mImageList;             // List of bitmaps stored in atlases
180   Toolkit::AtlasManager::AtlasSize mNewAtlasSize;       // Atlas size to use in next creation
181   Toolkit::AtlasManager::AddFailPolicy mAddFailPolicy;  // Policy for faling to add an Image
182
183   SizeType CheckAtlas( SizeType atlas,
184                        SizeType width,
185                        SizeType height,
186                        Pixel::Format pixelFormat );
187
188   void UploadImage( const BufferImage& image,
189                     const AtlasSlotDescriptor& desc );
190
191 };
192
193 } // namespace Internal
194
195 inline const Internal::AtlasManager& GetImplementation(const Toolkit::AtlasManager& manager)
196 {
197   DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
198
199   const BaseObject& handle = manager.GetBaseObject();
200
201   return static_cast<const Internal::AtlasManager&>(handle);
202 }
203
204 inline Internal::AtlasManager& GetImplementation(Toolkit::AtlasManager& manager)
205 {
206   DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
207
208   BaseObject& handle = manager.GetBaseObject();
209
210   return static_cast<Internal::AtlasManager&>(handle);
211 }
212
213 } // namespace Toolkit
214
215 } // namespace Dali
216
217
218  #endif // __DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H__