Remove RenderSurface from Core
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-instruction-container.cpp
index 94ca612..4389f2f 100644 (file)
@@ -1,18 +1,19 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // CLASS HEADER
 #include <dali/internal/render/common/render-instruction-container.h>
@@ -30,55 +31,46 @@ namespace SceneGraph
 {
 
 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 updateBufferIndex )
+{
+  mInstructions.pop_back();
+}
 
 } // namespace SceneGraph