Emscripten workarounds and llvm syntax fixes
[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) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/math/rect.h>
22 #include <dali/internal/render/common/render-item.h>
23 #include <dali/internal/common/owner-container.h>
24
25 namespace Dali
26 {
27
28 typedef Rect<int> ClippingBox;
29
30 namespace Internal
31 {
32
33 namespace SceneGraph
34 {
35
36 class Layer;
37 class Renderer;
38
39 class RenderItem;
40 typedef OwnerContainer< RenderItem* > RenderItemContainer;
41
42 struct RenderList;
43 typedef OwnerContainer< RenderList* > RenderListContainer;
44
45 /**
46  * The RenderList structure provides the renderer with a list of renderers and
47  * a set of flags to tell it what depth buffering is required.
48  */
49 struct RenderList
50 {
51 public:
52
53   /**
54    * The RenderFlags describe how the objects are rendered using the depth buffer.
55    */
56   enum RenderFlags
57   {
58     DEPTH_TEST     = 0x01, ///< If depth testing should be used
59     DEPTH_WRITE    = 0x02, ///< If the depth buffer is writable
60     DEPTH_CLEAR    = 0x04, ///< If the depth buffer should first be cleared
61     STENCIL_TEST   = 0x08, ///< If stencil testing should be used
62     STENCIL_WRITE  = 0x10, ///< If the stencil buffer is writable
63     STENCIL_CLEAR  = 0x20  ///< If the stencil buffer should first be cleared
64   };
65
66   /**
67    * Constructor
68    */
69   RenderList()
70   : mNextFree( 0 ),
71     mRenderFlags( 0u ),
72     mClippingBox( NULL ),
73     mSourceLayer( NULL )
74   {
75   }
76
77   /**
78    * Destructor
79    */
80   ~RenderList()
81   {
82     // pointer container deletes the render items
83     delete mClippingBox;
84   }
85
86   /**
87    * Clear the render flags
88    */
89   void ClearFlags()
90   {
91     mRenderFlags = 0u;
92   }
93
94   /**
95    * Set particular render flags
96    * @param[in] flags The set of flags to bitwise or with existing flags
97    */
98   void SetFlags( unsigned int flags )
99   {
100     mRenderFlags |= flags;
101   }
102
103   /**
104    * Retrieve the render flags.
105    * @return the render flags.
106    */
107   unsigned int GetFlags() const
108   {
109     return mRenderFlags;
110   }
111
112   /**
113    * Reset the render list for next frame
114    */
115   void Reset()
116   {
117     // we dont want to delete and re-create the render items every frame
118     mNextFree = 0;
119     mRenderFlags = 0u;
120
121     delete mClippingBox;
122     mClippingBox = NULL;
123   }
124
125   /**
126    * Reserve space in the render list
127    * @param size to reserve
128    */
129   void Reserve( RenderItemContainer::SizeType size )
130   {
131     mNextFree = 0;
132     mItems.Reserve( size );
133   }
134
135   /**
136    * @return the capacity of the render list
137    */
138   RenderItemContainer::SizeType Capacity()
139   {
140     return mItems.Capacity();
141   }
142
143   /**
144    * Get next free render item
145    * @return reference to the next available RenderItem
146    */
147   RenderItem& GetNextFreeItem()
148   {
149     // check if we have enough items, we can only be one behind at worst
150     if( mItems.Count() <= mNextFree )
151     {
152       mItems.PushBack( new RenderItem ); // Push a new empty render item
153     }
154     // get the item mNextFree points to and increase by one
155     RenderItem& item = *mItems[ mNextFree++ ];
156     item.Reset();
157     return item;
158   }
159
160   /**
161    * Get item at a given position in the list
162    */
163   RenderItem& GetItem( RenderItemContainer::SizeType index ) const
164   {
165     DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
166     return *mItems[ index ];
167   }
168
169   /**
170    * Get renderer from an item in the list
171    */
172   const Renderer* GetRenderer( RenderItemContainer::SizeType index ) const
173   {
174     DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
175     return mItems[ index ]->GetRenderer();
176   }
177
178   /**
179    * Get the number of real items
180    * Because of caching, the actual size may be bit more
181    * @return The number of items
182    */
183   RenderItemContainer::SizeType Count() const
184   {
185     return mNextFree;
186   }
187
188   /**
189    * @return the number of items cached by the list
190    */
191   RenderItemContainer::SizeType GetCachedItemCount() const
192   {
193     return mItems.Count();
194   }
195
196   /**
197    * Tells the render list to reuse the items from the cache
198    */
199   void ReuseCachedItems()
200   {
201     mNextFree = mItems.Count();
202   }
203
204   /**
205    * Predicate to inform if the list is empty
206    */
207   bool IsEmpty() const
208   {
209     return (mNextFree == 0);
210   }
211
212   /**
213    * Set clipping
214    * @param clipping on/off
215    * @param box for clipping
216    */
217   void SetClipping( bool clipping, const ClippingBox& box )
218   {
219     if( clipping )
220     {
221       ClippingBox* newBox = new ClippingBox( box );
222       delete mClippingBox;
223       mClippingBox = newBox;
224     }
225   }
226
227   /**
228    * @return true if clipping is on
229    */
230   bool IsClipping() const
231   {
232     return (NULL != mClippingBox);
233   }
234
235   /**
236    * @return the clipping box
237    */
238   const ClippingBox& GetClippingBox() const
239   {
240     return *mClippingBox;
241   }
242
243   /**
244    * @return the container (for sorting)
245    */
246   RenderItemContainer& GetContainer()
247   {
248     return mItems;
249   }
250
251   /**
252    * Do some housekeeping to keep memory consumption low
253    */
254   void ReleaseUnusedItems()
255   {
256     // release any non-used RenderItems
257     if( mItems.Count() > mNextFree )
258     {
259       mItems.Resize( mNextFree );
260     }
261   }
262
263   /**
264    * @return the source layer these renderitems originate from
265    */
266   Layer* GetSourceLayer()
267   {
268     return mSourceLayer;
269   }
270
271   /**
272    * @param layer these renderitems originate from
273    */
274   void SetSourceLayer( Layer* layer )
275   {
276     mSourceLayer = layer;
277   }
278
279 private:
280
281   /*
282    * Copy constructor and assignment operator not defined
283    */
284   RenderList( const RenderList& rhs );
285   const RenderList& operator=( const RenderList& rhs );
286
287   RenderItemContainer mItems; ///< Each item is a renderer and matrix pair
288   RenderItemContainer::SizeType mNextFree;              ///< index for the next free item to use
289
290   unsigned int mRenderFlags; ///< The render flags
291
292   ClippingBox* mClippingBox; ///< The clipping box, in window coordinates, when clipping is enabled
293   Layer* mSourceLayer;       ///< The originating layer where the renderers are from
294
295 };
296
297 } // namespace SceneGraph
298
299 } // namespace Internal
300
301 } // namespace Dali
302
303 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H__