Use modern construct 'using' instead of typedef.
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-list.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H
3
4 /*
5  * Copyright (c) 2018 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 <cstdint>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/math/rect.h>
26 #include <dali/devel-api/common/owner-container.h>
27 #include <dali/internal/render/common/render-item.h>
28
29 namespace Dali
30 {
31 using ClippingBox = Rect<int>;
32
33 namespace Internal
34 {
35
36 namespace Render
37 {
38 class Renderer;
39 }
40
41 namespace SceneGraph
42 {
43
44 class Layer;
45
46 using RenderItemContainer = OwnerContainer<RenderItem*>;
47
48 struct RenderList;
49 using RenderListContainer = OwnerContainer<RenderList*>;
50
51 /**
52  * The RenderList structure provides the renderer with a list of renderers.
53  */
54 struct RenderList
55 {
56 public:
57
58   /**
59    * Constructor
60    */
61   RenderList()
62   : mNextFree( 0 ),
63     mClippingBox( NULL ),
64     mSourceLayer( NULL ),
65     mHasColorRenderItems( false )
66   {
67   }
68
69   /**
70    * Destructor
71    */
72   ~RenderList()
73   {
74     // Pointer container deletes the render items
75     delete mClippingBox;
76   }
77
78   /**
79    * Reset the render list for next frame
80    */
81   void Reset()
82   {
83     // We don't want to delete and re-create the render items every frame
84     mNextFree = 0;
85
86     delete mClippingBox;
87     mClippingBox = NULL;
88   }
89
90   /**
91    * Reserve space in the render list
92    * @param size to reserve
93    */
94   void Reserve( RenderItemContainer::SizeType size )
95   {
96     mNextFree = 0;
97     mItems.Reserve( size );
98   }
99
100   /**
101    * @return the capacity of the render list
102    */
103   RenderItemContainer::SizeType Capacity()
104   {
105     return mItems.Capacity();
106   }
107
108   /**
109    * Get next free render item
110    * @return reference to the next available RenderItem
111    */
112   RenderItem& GetNextFreeItem()
113   {
114     // check if we have enough items, we can only be one behind at worst
115     if( mItems.Count() <= mNextFree )
116     {
117       mItems.PushBack( RenderItem::New() ); // Push a new empty render item
118     }
119     // get the item mNextFree points to and increase by one
120     RenderItem& item = *mItems[ mNextFree++ ];
121     return item;
122   }
123
124   /**
125    * Get item at a given position in the list
126    */
127   RenderItem& GetItem( uint32_t index ) const
128   {
129     DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
130     return *mItems[ index ];
131   }
132
133   /**
134    * Get renderer from an item in the list
135    */
136   const Render::Renderer& GetRenderer( uint32_t index ) const
137   {
138     DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
139     return *mItems[ index ]->mRenderer;
140   }
141
142   /**
143    * Get the number of real items
144    * Because of caching, the actual size may be bit more
145    * @return The number of items
146    */
147   uint32_t Count() const
148   {
149     return mNextFree;
150   }
151
152   /**
153    * @return the number of items cached by the list
154    */
155   uint32_t GetCachedItemCount() const
156   {
157     return static_cast<uint32_t>( mItems.Count() );
158   }
159
160   /**
161    * Tells the render list to reuse the items from the cache
162    */
163   void ReuseCachedItems()
164   {
165     mNextFree = static_cast<uint32_t>( mItems.Count() );
166   }
167
168   /**
169    * Predicate to inform if the list is empty
170    */
171   bool IsEmpty() const
172   {
173     return ( mNextFree == 0 );
174   }
175
176   /**
177    * Set clipping
178    * @param clipping on/off
179    * @param box for clipping
180    */
181   void SetClipping( bool clipping, const ClippingBox& box )
182   {
183     if( clipping )
184     {
185       delete mClippingBox;
186       mClippingBox = new ClippingBox( box );;
187     }
188   }
189
190   /**
191    * @return true if clipping is on
192    */
193   bool IsClipping() const
194   {
195     return ( NULL != mClippingBox );
196   }
197
198   /**
199    * @return the clipping box
200    */
201   const ClippingBox& GetClippingBox() const
202   {
203     return *mClippingBox;
204   }
205
206   /**
207    * @return the container (for sorting)
208    */
209   RenderItemContainer& GetContainer()
210   {
211     return mItems;
212   }
213
214   /**
215    * Do some housekeeping to keep memory consumption low
216    */
217   void ReleaseUnusedItems()
218   {
219     // release any non-used RenderItems
220     if( mItems.Count() > mNextFree )
221     {
222       mItems.Resize( mNextFree );
223     }
224   }
225
226   /**
227    * @return the source layer these renderitems originate from
228    */
229   Layer* GetSourceLayer() const
230   {
231     return mSourceLayer;
232   }
233
234   /**
235    * @param layer The layer these RenderItems originate from
236    */
237   void SetSourceLayer( Layer* layer )
238   {
239     mSourceLayer = layer;
240   }
241
242   /**
243    * Set if the RenderList contains color RenderItems
244    * @param[in] hasColorRenderItems True if it contains color RenderItems, false otherwise
245    */
246   void SetHasColorRenderItems( bool hasColorRenderItems )
247   {
248     mHasColorRenderItems = hasColorRenderItems;
249   }
250
251   /**
252    * Check if the RenderList contains color RenderItems
253    * @return true if the RenderList contains color RenderItems, false otherwise
254    */
255   bool HasColorRenderItems() const
256   {
257     return mHasColorRenderItems;
258   }
259
260 private:
261
262   /*
263    * Copy constructor and assignment operator not defined
264    */
265   RenderList( const RenderList& rhs );
266   const RenderList& operator=( const RenderList& rhs );
267
268   RenderItemContainer mItems; ///< Each item is a renderer and matrix pair
269   uint32_t mNextFree;         ///< index for the next free item to use
270
271   ClippingBox* mClippingBox;               ///< The clipping box, in window coordinates, when clipping is enabled
272   Layer*       mSourceLayer;              ///< The originating layer where the renderers are from
273   bool         mHasColorRenderItems : 1;  ///< True if list contains color render items
274
275 };
276
277
278 } // namespace SceneGraph
279
280 } // namespace Internal
281
282 } // namespace Dali
283
284 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H