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