1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
31 using ClippingBox = Rect<int>;
46 using RenderItemContainer = OwnerContainer<RenderItem*>;
49 using RenderListContainer = OwnerContainer<RenderList*>;
52 * The RenderList structure provides the renderer with a list of renderers.
65 mHasColorRenderItems( false )
74 // Pointer container deletes the render items
79 * Reset the render list for next frame
83 // We don't want to delete and re-create the render items every frame
91 * Reserve space in the render list
92 * @param size to reserve
94 void Reserve( RenderItemContainer::SizeType size )
97 mItems.Reserve( size );
101 * @return the capacity of the render list
103 RenderItemContainer::SizeType Capacity()
105 return mItems.Capacity();
109 * Get next free render item
110 * @return reference to the next available RenderItem
112 RenderItem& GetNextFreeItem()
114 // check if we have enough items, we can only be one behind at worst
115 if( mItems.Count() <= mNextFree )
117 mItems.PushBack( RenderItem::New() ); // Push a new empty render item
119 // get the item mNextFree points to and increase by one
120 RenderItem& item = *mItems[ mNextFree++ ];
125 * Get item at a given position in the list
127 RenderItem& GetItem( uint32_t index ) const
129 DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
130 return *mItems[ index ];
134 * Get renderer from an item in the list
136 const Render::Renderer& GetRenderer( uint32_t index ) const
138 DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
139 return *mItems[ index ]->mRenderer;
143 * Get the number of real items
144 * Because of caching, the actual size may be bit more
145 * @return The number of items
147 uint32_t Count() const
153 * @return the number of items cached by the list
155 uint32_t GetCachedItemCount() const
157 return static_cast<uint32_t>( mItems.Count() );
161 * Tells the render list to reuse the items from the cache
163 void ReuseCachedItems()
165 mNextFree = static_cast<uint32_t>( mItems.Count() );
169 * Predicate to inform if the list is empty
173 return ( mNextFree == 0 );
178 * @param clipping on/off
179 * @param box for clipping
181 void SetClipping( bool clipping, const ClippingBox& box )
186 mClippingBox = new ClippingBox( box );;
191 * @return true if clipping is on
193 bool IsClipping() const
195 return ( NULL != mClippingBox );
199 * @return the clipping box
201 const ClippingBox& GetClippingBox() const
203 return *mClippingBox;
207 * @return the container (for sorting)
209 RenderItemContainer& GetContainer()
215 * Do some housekeeping to keep memory consumption low
217 void ReleaseUnusedItems()
219 // release any non-used RenderItems
220 if( mItems.Count() > mNextFree )
222 mItems.Resize( mNextFree );
227 * @return the source layer these renderitems originate from
229 Layer* GetSourceLayer() const
235 * @param layer The layer these RenderItems originate from
237 void SetSourceLayer( Layer* layer )
239 mSourceLayer = layer;
243 * Set if the RenderList contains color RenderItems
244 * @param[in] hasColorRenderItems True if it contains color RenderItems, false otherwise
246 void SetHasColorRenderItems( bool hasColorRenderItems )
248 mHasColorRenderItems = hasColorRenderItems;
252 * Check if the RenderList contains color RenderItems
253 * @return true if the RenderList contains color RenderItems, false otherwise
255 bool HasColorRenderItems() const
257 return mHasColorRenderItems;
263 * Copy constructor and assignment operator not defined
265 RenderList( const RenderList& rhs );
266 const RenderList& operator=( const RenderList& rhs );
268 RenderItemContainer mItems; ///< Each item is a renderer and matrix pair
269 uint32_t mNextFree; ///< index for the next free item to use
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
278 } // namespace SceneGraph
280 } // namespace Internal
284 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H