2 * Copyright (c) 2014 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-container.h>
22 #include <dali/internal/render/common/render-instruction.h>
33 RenderInstructionContainer::RenderInstructionContainer()
35 // array initialisation in ctor initializer list not supported until C++ 11
40 RenderInstructionContainer::~RenderInstructionContainer()
42 // OwnerContainer deletes the instructions
45 void RenderInstructionContainer::ResetAndReserve( BufferIndex bufferIndex, size_t capacityRequired )
47 mIndex[ bufferIndex ] = 0u;
48 size_t oldcapacity = mInstructions[ bufferIndex ].Capacity();
49 if( oldcapacity < capacityRequired )
51 mInstructions[ bufferIndex ].Reserve( capacityRequired );
53 for( ; oldcapacity < capacityRequired; ++oldcapacity )
55 mInstructions[ bufferIndex ].PushBack( new RenderInstruction );
58 // Note that we may have spare elements in the list, we don't remove them as that would
59 // decrease the capacity of our container and lead to possibly reallocating, which we hate
60 // RenderInstruction holds a lot of data so we keep them and recycle instead of new & delete
63 size_t RenderInstructionContainer::Count( BufferIndex bufferIndex )
65 // mIndex contains the number of instructions that have been really prepared and updated
66 // (from UpdateManager through GetNextInstruction)
67 return mIndex[ bufferIndex ];
70 RenderInstruction& RenderInstructionContainer::GetNextInstruction( BufferIndex bufferIndex )
72 // At protects against running out of space
73 return At( bufferIndex, mIndex[ bufferIndex ]++ );
76 RenderInstruction& RenderInstructionContainer::At( BufferIndex bufferIndex, size_t index )
78 DALI_ASSERT_DEBUG( index < mInstructions[ bufferIndex ].Count() );
80 return *mInstructions[ bufferIndex ][ index ];
83 void RenderInstructionContainer::DiscardCurrentInstruction( BufferIndex bufferIndex )
85 mIndex[ bufferIndex ]--;
88 } // namespace SceneGraph
90 } // namespace Internal