Remove some dead and non-thread safe internal uniforms
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / atlas-manager / 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/atlas-manager/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     Material mMaterial;                                                 // material used for atlas texture
68     Image mImage;
69     SizeType mTotalBlocks;                                              // total number of blocks in atlas
70     SizeType mAvailableBlocks;                                          // number of blocks available in atlas
71     Dali::Vector< SizeType > mFreeBlocksList;                           // unless there are any previously freed blocks
72   };
73
74   struct AtlasSlotDescriptor
75   {
76     SizeType mCount;                                                    // Reference count for this slot
77     SizeType mImageWidth;                                               // Width of image stored
78     SizeType mImageHeight;                                              // Height of image stored
79     AtlasId mAtlasId;                                                   // Image is stored in this Atlas
80     Dali::Vector< SizeType > mBlocksList;                               // List of blocks within atlas used for image
81   };
82
83   AtlasManager();
84
85   /**
86    * Create a new AtlasManager
87    */
88   static AtlasManagerPtr New();
89
90   virtual ~AtlasManager();
91
92   /**
93    * @copydoc: Toolkit::AtlasManager::CreateAtlas
94    */
95   AtlasId CreateAtlas( const Toolkit::AtlasManager::AtlasSize& size, Pixel::Format pixelformat );
96
97   /**
98    * @copydoc Toolkit::AtlasManager::SetAddPolicy
99    */
100   void SetAddPolicy( Toolkit::AtlasManager::AddFailPolicy policy );
101
102   /**
103    * @copydoc Toolkit::AtlasManager::Add
104    */
105   void Add( const BufferImage& image,
106             Toolkit::AtlasManager::AtlasSlot& slot,
107             Toolkit::AtlasManager::AtlasId atlas );
108
109   /**
110    * @copydoc Toolkit::AtlasManager::GenerateMeshData
111    */
112   void GenerateMeshData( ImageId id,
113                          const Vector2& position,
114                          Toolkit::AtlasManager::Mesh2D& mesh,
115                          bool addReference );
116
117   /**
118    * @copydoc Toolkit::AtlasManager::StitchMesh
119    */
120   void StitchMesh( Toolkit::AtlasManager::Mesh2D& first,
121                    const Toolkit::AtlasManager::Mesh2D& second,
122                    bool optimize );
123
124   /**
125    * @copydoc Toolkit::AtlasManager::Remove
126    */
127   bool Remove( ImageId id );
128
129   /**
130    * @copydoc Toolkit::AtlasManager::GetAtlasContainer
131    */
132   Dali::Atlas GetAtlasContainer( AtlasId atlas ) const;
133
134   /**
135    * @copydoc Toolkit::AtlasManager::GetAtlas
136    */
137   AtlasId GetAtlas( ImageId id ) const;
138
139   /**
140    * @copydoc Toolkit::AtlasManager::SetNewAtlasSize
141    */
142   void SetNewAtlasSize( const Toolkit::AtlasManager::AtlasSize& size );
143
144   /**
145    * @copydoc Toolkit::AtlasManager::GetAtlasSize
146    */
147   const Toolkit::AtlasManager::AtlasSize& GetAtlasSize( AtlasId atlas );
148
149   /**
150    * @copydoc Toolkit::AtlasManager::GetBlockSize
151    */
152   Vector2 GetBlockSize( AtlasId atlas );
153
154   /**
155    * @copydoc Toolkit::AtlasManager::GetFreeBlocks
156    */
157   SizeType GetFreeBlocks( AtlasId atlas ) const;
158
159   /*
160    * @copydoc Toolkit::AtlasManager::GetAtlasCount
161    */
162   SizeType GetAtlasCount() const;
163
164   /**
165    * @copydoc Toolkit::AtlasManager::GetPixelFormat
166    */
167   Pixel::Format GetPixelFormat( AtlasId atlas );
168
169   /**
170    * @copydoc Toolkit::AtlasManager::GetMetrics
171    */
172   void GetMetrics( Toolkit::AtlasManager::Metrics& metrics );
173
174   /**
175    * @copydoc Toolkit::AtlasManager::GetMaterial
176    */
177   Material GetMaterial( AtlasId atlas ) const;
178
179 /**
180    * @copydoc Toolkit::AtlasManager::GetImage
181    */
182   Image GetImage( AtlasId atlas ) const;
183
184 private:
185
186   std::vector< AtlasDescriptor > mAtlasList;            // List of atlases created
187   std::vector< AtlasSlotDescriptor > mImageList;        // List of bitmaps store in atlases
188   Toolkit::AtlasManager::AtlasSize mNewAtlasSize;       // Atlas size to use in next creation
189   Toolkit::AtlasManager::AddFailPolicy mAddFailPolicy;  // Policy for faling to add an Image
190
191   SizeType CheckAtlas( SizeType atlas,
192                        SizeType width,
193                        SizeType height,
194                        Pixel::Format pixelFormat,
195                        SizeType& blockArea );
196
197   void CreateMesh( SizeType atlas,
198                    SizeType imageWidth,
199                    SizeType imageHeight,
200                    const Vector2& position,
201                    SizeType widthInBlocks,
202                    SizeType heightInBlocks,
203                    Toolkit::AtlasManager::Mesh2D& mesh,
204                    AtlasSlotDescriptor& desc );
205
206   void OptimizeMesh( const Toolkit::AtlasManager::Mesh2D& in,
207                      Toolkit::AtlasManager::Mesh2D& out );
208
209   void UploadImage( const BufferImage& image,
210                     const AtlasSlotDescriptor& desc );
211
212   void PrintMeshData( const Toolkit::AtlasManager::Mesh2D& mesh );
213
214   Shader mShaderL8;
215   Shader mShaderRgba;
216
217 };
218
219 } // namespace Internal
220
221 inline const Internal::AtlasManager& GetImplementation(const Toolkit::AtlasManager& manager)
222 {
223   DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
224
225   const BaseObject& handle = manager.GetBaseObject();
226
227   return static_cast<const Internal::AtlasManager&>(handle);
228 }
229
230 inline Internal::AtlasManager& GetImplementation(Toolkit::AtlasManager& manager)
231 {
232   DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
233
234   BaseObject& handle = manager.GetBaseObject();
235
236   return static_cast<Internal::AtlasManager&>(handle);
237 }
238
239 } // namespace Toolkit
240
241 } // namespace Dali
242
243
244  #endif // __DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H__