/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
RenderInstructionContainer::RenderInstructionContainer()
+: mInstructions{}
{
- // array initialisation in ctor initializer list not supported until C++ 11
- mIndex[ 0 ] = 0u;
- mIndex[ 1 ] = 0u;
}
RenderInstructionContainer::~RenderInstructionContainer()
{
- // OwnerContainer deletes the instructions
}
-void RenderInstructionContainer::ResetAndReserve( BufferIndex bufferIndex, size_t capacityRequired )
+void RenderInstructionContainer::ResetAndReserve( BufferIndex bufferIndex, uint32_t capacityRequired )
{
- mIndex[ bufferIndex ] = 0u;
- size_t oldcapacity = mInstructions[ bufferIndex ].Capacity();
- if( oldcapacity < capacityRequired )
+ // Only re-allocate if necessary.
+ if( mInstructions.size() < capacityRequired )
{
- mInstructions[ bufferIndex ].Reserve( capacityRequired );
- // add N new elements
- for( ; oldcapacity < capacityRequired; ++oldcapacity )
- {
- mInstructions[ bufferIndex ].PushBack( new RenderInstruction );
- }
+ mInstructions.reserve( capacityRequired );
}
- // Note that we may have spare elements in the list, we don't remove them as that would
- // decrease the capacity of our container and lead to possibly reallocating, which we hate
- // RenderInstruction holds a lot of data so we keep them and recycle instead of new & delete
+
+ mInstructions.clear();
}
-size_t RenderInstructionContainer::Count( BufferIndex bufferIndex )
+uint32_t RenderInstructionContainer::Count( BufferIndex bufferIndex )
{
- // mIndex contains the number of instructions that have been really prepared and updated
- // (from UpdateManager through GetNextInstruction)
- return mIndex[ bufferIndex ];
+ return static_cast<uint32_t>( mInstructions.size() );
}
-RenderInstruction& RenderInstructionContainer::GetNextInstruction( BufferIndex bufferIndex )
+RenderInstruction& RenderInstructionContainer::At( BufferIndex bufferIndex, uint32_t index )
{
- // At protects against running out of space
- return At( bufferIndex, mIndex[ bufferIndex ]++ );
+ DALI_ASSERT_DEBUG( index < mInstructions.size() );
+
+ return *mInstructions[ index ];
}
-RenderInstruction& RenderInstructionContainer::At( BufferIndex bufferIndex, size_t index )
+void RenderInstructionContainer::PushBack( BufferIndex bufferIndex, RenderInstruction* renderInstruction )
{
- DALI_ASSERT_DEBUG( index < mInstructions[ bufferIndex ].Count() );
-
- return *mInstructions[ bufferIndex ][ index ];
+ mInstructions.push_back( renderInstruction );
}
-void RenderInstructionContainer::DiscardCurrentInstruction( BufferIndex bufferIndex )
+void RenderInstructionContainer::DiscardCurrentInstruction( BufferIndex updateBufferIndex )
{
- mIndex[ bufferIndex ]--;
+ mInstructions.pop_back();
}
} // namespace SceneGraph