Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-instruction-container.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 // CLASS HEADER
18 #include <dali/internal/render/common/render-instruction-container.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/internal/render/common/render-instruction.h>
22
23 namespace Dali
24 {
25
26 namespace Internal
27 {
28
29 namespace SceneGraph
30 {
31
32 RenderInstructionContainer::RenderInstructionContainer()
33 {
34   // array initialisation in ctor initializer list not supported until C++ 11
35   mIndex[ 0 ] = 0u;
36   mIndex[ 1 ] = 0u;
37 }
38
39 RenderInstructionContainer::~RenderInstructionContainer()
40 {
41   // OwnerContainer deletes the instructions
42 }
43
44 void RenderInstructionContainer::ResetAndReserve( BufferIndex bufferIndex, size_t capacityRequired )
45 {
46   mIndex[ bufferIndex ] = 0u;
47   size_t oldcapacity = mInstructions[ bufferIndex ].Capacity();
48   if( oldcapacity < capacityRequired )
49   {
50     mInstructions[ bufferIndex ].Reserve( capacityRequired );
51     // add N new elements
52     for( ; oldcapacity < capacityRequired; ++oldcapacity )
53     {
54       mInstructions[ bufferIndex ].PushBack( new RenderInstruction );
55     }
56   }
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
60 }
61
62 size_t RenderInstructionContainer::Count( BufferIndex bufferIndex )
63 {
64   // mIndex contains the number of instructions that have been really prepared and updated
65   // (from UpdateManager through GetNextInstruction)
66   return mIndex[ bufferIndex ];
67 }
68
69 RenderInstruction& RenderInstructionContainer::GetNextInstruction( BufferIndex bufferIndex )
70 {
71   // At protects against running out of space
72   return At( bufferIndex, mIndex[ bufferIndex ]++ );
73 }
74
75 RenderInstruction& RenderInstructionContainer::At( BufferIndex bufferIndex, size_t index )
76 {
77   DALI_ASSERT_DEBUG( index < mInstructions[ bufferIndex ].Count() );
78
79   return *mInstructions[ bufferIndex ][ index ];
80 }
81
82
83 } // namespace SceneGraph
84
85 } // namespace Internal
86
87 } // namespace Dali