2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali/internal/render/common/render-instruction-container.h>
21 #include <dali/internal/render/common/render-instruction.h>
32 RenderInstructionContainer::RenderInstructionContainer()
34 // array initialisation in ctor initializer list not supported until C++ 11
39 RenderInstructionContainer::~RenderInstructionContainer()
41 // OwnerContainer deletes the instructions
44 void RenderInstructionContainer::ResetAndReserve( BufferIndex bufferIndex, size_t capacityRequired )
46 mIndex[ bufferIndex ] = 0u;
47 size_t oldcapacity = mInstructions[ bufferIndex ].Capacity();
48 if( oldcapacity < capacityRequired )
50 mInstructions[ bufferIndex ].Reserve( capacityRequired );
52 for( ; oldcapacity < capacityRequired; ++oldcapacity )
54 mInstructions[ bufferIndex ].PushBack( new RenderInstruction );
57 // Note that we may have spare elements in the list, we don't remove them as that would
58 // decrease the capacity of our container and lead to possibly reallocating, which we hate
59 // RenderInstruction holds a lot of data so we keep them and recycle instead of new & delete
62 size_t RenderInstructionContainer::Count( BufferIndex bufferIndex )
64 // mIndex contains the number of instructions that have been really prepared and updated
65 // (from UpdateManager through GetNextInstruction)
66 return mIndex[ bufferIndex ];
69 RenderInstruction& RenderInstructionContainer::GetNextInstruction( BufferIndex bufferIndex )
71 // At protects against running out of space
72 return At( bufferIndex, mIndex[ bufferIndex ]++ );
75 RenderInstruction& RenderInstructionContainer::At( BufferIndex bufferIndex, size_t index )
77 DALI_ASSERT_DEBUG( index < mInstructions[ bufferIndex ].Count() );
79 return *mInstructions[ bufferIndex ][ index ];
83 } // namespace SceneGraph
85 } // namespace Internal