2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/render/common/render-instruction.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/internal/render/common/render-tracker.h>
24 #include <dali/public-api/common/constants.h> // for Color::BLACK
32 RenderInstruction::RenderInstruction()
33 : mRenderTracker(nullptr),
35 mIsViewportSet(false),
36 mIsClearColorSet(false),
37 mIgnoreRenderToFbo(false),
38 mFrameBuffer(nullptr),
40 mNextFreeRenderList(0)
42 // reserve 6 lists, which is enough for three layers with opaque and transparent things on
43 mRenderLists.Reserve(6);
46 RenderInstruction::~RenderInstruction() = default;
48 RenderList& RenderInstruction::GetNextFreeRenderList(size_t capacityRequired)
50 // check if we have enough lists, we can only be one behind at worst
51 if(mRenderLists.Count() <= mNextFreeRenderList)
53 mRenderLists.PushBack(new RenderList); // Push a new empty render list
56 // check capacity of the list and reserve if not big enough
57 if(mRenderLists[mNextFreeRenderList]->Capacity() < capacityRequired)
59 mRenderLists[mNextFreeRenderList]->Reserve(capacityRequired);
62 // return the list mNextFreeRenderList points to and increase by one
63 return *mRenderLists[mNextFreeRenderList++];
66 void RenderInstruction::UpdateCompleted()
68 // lets do some housekeeping, remove any lists that were not needed because
69 // application might have removed a layer permanently
70 RenderListContainer::Iterator iter = mRenderLists.Begin();
71 RenderListContainer::ConstIterator end = mRenderLists.End();
72 for(; iter != end; ++iter)
74 // tell the list to do its housekeeping
75 (*iter)->ReleaseUnusedItems();
78 // release any extra lists
79 if(mRenderLists.Count() > mNextFreeRenderList)
81 mRenderLists.Resize(mNextFreeRenderList);
85 RenderListContainer::SizeType RenderInstruction::RenderListCount() const
87 return mNextFreeRenderList;
90 const RenderList* RenderInstruction::GetRenderList(RenderListContainer::SizeType index) const
92 DALI_ASSERT_DEBUG((index < mNextFreeRenderList) && (index < mRenderLists.Size()) && "Renderlist index out of container bounds");
94 // Return null if the caller has passed an invalid index:
95 if(index >= std::min(mNextFreeRenderList, mRenderLists.Size()))
100 return mRenderLists[index];
103 void RenderInstruction::Reset(Camera* camera,
104 Render::FrameBuffer* frameBuffer,
105 const Viewport* viewport,
106 const Vector4* clearColor)
109 mViewport = viewport ? *viewport : Viewport();
110 mIsViewportSet = nullptr != viewport;
111 mClearColor = clearColor ? *clearColor : Color::BLACK;
112 mIsClearColorSet = nullptr != clearColor;
113 mRenderTracker = nullptr;
114 mNextFreeRenderList = 0;
115 mFrameBuffer = frameBuffer;
117 RenderListContainer::Iterator iter = mRenderLists.Begin();
118 RenderListContainer::ConstIterator end = mRenderLists.End();
119 for(; iter != end; ++iter)
121 // since mRenderLists is a vector of RenderLists we dont want to clear it
122 // as it ends up releasing and later reallocating loads of vectors
123 // reset the renderlist
128 std::size_t RenderInstruction::GetCapacity()
130 std::size_t capacity{0u};
131 RenderListContainer::Iterator iter = mRenderLists.Begin();
132 RenderListContainer::ConstIterator end = mRenderLists.End();
133 for(; iter != end; ++iter)
135 capacity += ((*iter)->GetCachedItemCount() * (sizeof(RenderItem) + sizeof(RenderItem*)));
136 capacity += sizeof(RenderList);
138 capacity += sizeof(RenderInstruction);
142 } // namespace SceneGraph
144 } // namespace Internal