1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H
5 * Copyright (c) 2023 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/devel-api/common/owner-container.h>
26 #include <dali/public-api/math/rect.h>
28 #include <dali/graphics-api/graphics-controller.h>
29 #include <dali/internal/common/owner-key-container.h>
30 #include <dali/internal/render/common/render-item.h>
34 using ClippingBox = Rect<int>;
47 using RenderItemContainer = OwnerKeyContainer<RenderItem>;
50 using RenderListContainer = OwnerContainer<RenderList*>;
53 * The RenderList structure provides the renderer manager with a list of renderers.
63 mClippingBox(nullptr),
64 mSourceLayer(nullptr),
65 mHasColorRenderItems(false)
74 // Pointer container deletes the render items
79 * Copy constructor and assignment operator not defined
81 RenderList(const RenderList& rhs) = delete;
82 const RenderList& operator=(const RenderList& rhs) = delete;
85 * Reset the render list for next frame
89 // We don't want to delete and re-create the render items every frame
93 mClippingBox = nullptr;
97 * Reserve space in the render list
98 * @param size to reserve
100 void Reserve(RenderItemContainer::SizeType size)
103 mItems.Reserve(size);
107 * @return the capacity of the render list
109 RenderItemContainer::SizeType Capacity()
111 return mItems.Capacity();
115 * Get next free render item
116 * @return reference to the next available RenderItem
118 RenderItem& GetNextFreeItem()
120 // check if we have enough items, we can only be one behind at worst
121 if(mItems.Count() <= mNextFree)
123 mItems.PushBack(RenderItem::NewKey()); // Push a new empty render item
125 // get the item mNextFree points to and increase by one
126 RenderItem* item = mItems[mNextFree++].Get();
131 * Get item at a given position in the list
133 RenderItem& GetItem(uint32_t index) const
135 DALI_ASSERT_DEBUG(index < GetCachedItemCount());
136 RenderItem* item = mItems[index].Get();
140 RenderItemKey GetItemKey(uint32_t index) const
142 DALI_ASSERT_DEBUG(index < GetCachedItemCount());
143 return mItems[index];
147 * Get renderer from an item in the list
149 Render::RendererKey GetRenderer(uint32_t index) const
151 DALI_ASSERT_DEBUG(index < GetCachedItemCount());
152 return mItems[index]->mRenderer;
156 * Get the number of real items
157 * Because of caching, the actual size may be bit more
158 * @return The number of items
160 uint32_t Count() const
166 * @return the number of items cached by the list
168 uint32_t GetCachedItemCount() const
170 return static_cast<uint32_t>(mItems.Count());
174 * Tells the render list to reuse the items from the cache
176 void ReuseCachedItems()
178 mNextFree = static_cast<uint32_t>(mItems.Count());
182 * Predicate to inform if the list is empty
186 return (mNextFree == 0);
191 * @param clipping on/off
192 * @param box for clipping
194 void SetClipping(bool clipping, const ClippingBox& box)
199 mClippingBox = new ClippingBox(box);
204 * @return true if clipping is on
206 bool IsClipping() const
208 return (nullptr != mClippingBox);
212 * @return the clipping box
214 const ClippingBox& GetClippingBox() const
216 return *mClippingBox;
220 * @return the container (for sorting)
222 RenderItemContainer& GetContainer()
228 * Do some housekeeping to keep memory consumption low
230 void ReleaseUnusedItems()
232 // release any non-used RenderItems
233 if(mItems.Count() > mNextFree)
235 mItems.Resize(mNextFree);
240 * @return the source layer these renderitems originate from
242 Layer* GetSourceLayer() const
248 * @param layer The layer these RenderItems originate from
250 void SetSourceLayer(Layer* layer)
252 mSourceLayer = layer;
256 * Set if the RenderList contains color RenderItems
257 * @param[in] hasColorRenderItems True if it contains color RenderItems, false otherwise
259 void SetHasColorRenderItems(bool hasColorRenderItems)
261 mHasColorRenderItems = hasColorRenderItems;
265 * Check if the RenderList contains color RenderItems
266 * @return true if the RenderList contains color RenderItems, false otherwise
268 bool HasColorRenderItems() const
270 return mHasColorRenderItems;
273 Graphics::CommandBuffer& GetCommandBuffer(Graphics::Controller& controller)
275 if(!mGraphicsCommandBuffer)
277 mGraphicsCommandBuffer = controller.CreateCommandBuffer(
278 Graphics::CommandBufferCreateInfo().SetLevel(Graphics::CommandBufferLevel::SECONDARY), nullptr);
280 return *mGraphicsCommandBuffer.get();
283 const Graphics::CommandBuffer* GetCommandBuffer() const
285 return mGraphicsCommandBuffer.get();
289 RenderItemContainer mItems; ///< Container of render items
290 uint32_t mNextFree; ///< index for the next free item to use
292 mutable Graphics::UniquePtr<Graphics::CommandBuffer> mGraphicsCommandBuffer{nullptr};
294 ClippingBox* mClippingBox; ///< The clipping box, in window coordinates, when clipping is enabled
295 Layer* mSourceLayer; ///< The originating layer where the renderers are from
296 bool mHasColorRenderItems : 1; ///< True if list contains color render items
299 } // namespace SceneGraph
301 } // namespace Internal
305 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H