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