2 * Copyright (c) 2020 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/public-api/common/constants.h> // for Color::BLACK
23 #include <dali/internal/render/common/render-tracker.h>
24 #include <dali/integration-api/debug.h>
35 RenderInstruction::RenderInstruction()
36 : mRenderTracker( NULL ),
38 mIsViewportSet( false ),
39 mIsClearColorSet( false ),
40 mIgnoreRenderToFbo( false ),
43 mNextFreeRenderList( 0 )
45 // reserve 6 lists, which is enough for three layers with opaque and transparent things on
46 mRenderLists.Reserve( 6 );
49 RenderInstruction::~RenderInstruction()
50 { // pointer container releases the renderlists
53 RenderList& RenderInstruction::GetNextFreeRenderList( size_t capacityRequired )
55 // check if we have enough lists, we can only be one behind at worst
56 if( mRenderLists.Count() <= mNextFreeRenderList )
58 mRenderLists.PushBack( new RenderList ); // Push a new empty render list
61 // check capacity of the list and reserve if not big enough
62 if( mRenderLists[ mNextFreeRenderList ]->Capacity() < capacityRequired )
64 mRenderLists[ mNextFreeRenderList ]->Reserve( capacityRequired );
67 // return the list mNextFreeRenderList points to and increase by one
68 return *mRenderLists[ mNextFreeRenderList++ ];
71 void RenderInstruction::UpdateCompleted()
73 // lets do some housekeeping, remove any lists that were not needed because
74 // application might have removed a layer permanently
75 RenderListContainer::Iterator iter = mRenderLists.Begin();
76 RenderListContainer::ConstIterator end = mRenderLists.End();
77 for( ;iter != end; ++iter )
79 // tell the list to do its housekeeping
80 (*iter)->ReleaseUnusedItems();
83 // release any extra lists
84 if( mRenderLists.Count() > mNextFreeRenderList )
86 mRenderLists.Resize( mNextFreeRenderList );
90 RenderListContainer::SizeType RenderInstruction::RenderListCount() const
92 return mNextFreeRenderList;
95 const RenderList* RenderInstruction::GetRenderList( RenderListContainer::SizeType index ) const
97 DALI_ASSERT_DEBUG( (index < mNextFreeRenderList ) && (index < mRenderLists.Size()) && "Renderlist index out of container bounds" );
99 // Return null if the caller has passed an invalid index:
100 if( index >= std::min( mNextFreeRenderList, mRenderLists.Size() ) )
105 return mRenderLists[ index ];
108 void RenderInstruction::Reset( Camera* camera,
109 Render::FrameBuffer* frameBuffer,
110 const Viewport* viewport,
111 const Vector4* clearColor )
114 mViewport = viewport ? *viewport : Viewport();
115 mIsViewportSet = NULL != viewport;
116 mClearColor = clearColor ? *clearColor : Color::BLACK;
117 mIsClearColorSet = NULL != clearColor;
118 mRenderTracker = NULL;
119 mNextFreeRenderList = 0;
120 mFrameBuffer = frameBuffer;
122 RenderListContainer::Iterator iter = mRenderLists.Begin();
123 RenderListContainer::ConstIterator end = mRenderLists.End();
124 for( ;iter != end; ++iter )
126 // since mRenderLists is a vector of RenderLists we dont want to clear it
127 // as it ends up releasing and later reallocating loads of vectors
128 // reset the renderlist
133 } // namespace SceneGraph
135 } // namespace Internal