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/queue/render-queue.h>
22 #include <dali/internal/common/message.h>
30 namespace // unnamed namespace
33 static const std::size_t INITIAL_BUFFER_SIZE = 32768;
34 static const std::size_t MAX_BUFFER_SIZE = 32768;
36 } // unnamed namespace
41 RenderQueue::RenderQueue()
45 container0 = new MessageBuffer( INITIAL_BUFFER_SIZE );
46 container1 = new MessageBuffer( INITIAL_BUFFER_SIZE );
49 RenderQueue::~RenderQueue()
53 for( MessageBuffer::Iterator iter = container0->Begin(); iter.IsValid(); iter.Next() )
55 MessageBase* message = reinterpret_cast< MessageBase* >( iter.Get() );
57 // Call virtual destructor explictly; since delete will not be called after placement new
58 message->~MessageBase();
66 for( MessageBuffer::Iterator iter = container1->Begin(); iter.IsValid(); iter.Next() )
68 MessageBase* message = reinterpret_cast< MessageBase* >( iter.Get() );
70 // Call virtual destructor explictly; since delete will not be called after placement new
71 message->~MessageBase();
78 unsigned int* RenderQueue::ReserveMessageSlot( BufferIndex updateBufferIndex, std::size_t size )
80 MessageBuffer* container = GetCurrentContainer( updateBufferIndex );
82 return container->ReserveMessageSlot( size );
85 void RenderQueue::ProcessMessages( BufferIndex bufferIndex )
87 MessageBuffer* container = GetCurrentContainer( bufferIndex );
89 for( MessageBuffer::Iterator iter = container->Begin(); iter.IsValid(); iter.Next() )
91 MessageBase* message = reinterpret_cast< MessageBase* >( iter.Get() );
93 message->Process( bufferIndex );
95 // Call virtual destructor explictly; since delete will not be called after placement new
96 message->~MessageBase();
101 LimitBufferCapacity( bufferIndex );
104 MessageBuffer* RenderQueue::GetCurrentContainer( BufferIndex bufferIndex )
106 MessageBuffer* container( NULL );
109 * The update-thread queues messages with one container,
110 * whilst the render-thread is processing the other.
114 container = container0;
118 container = container1;
124 void RenderQueue::LimitBufferCapacity( BufferIndex bufferIndex )
128 if( MAX_BUFFER_SIZE < container0->GetCapacity() )
132 container0 = new MessageBuffer( INITIAL_BUFFER_SIZE );
137 if( MAX_BUFFER_SIZE < container1->GetCapacity() )
141 container1 = new MessageBuffer( INITIAL_BUFFER_SIZE );
146 } // namespace SceneGraph
148 } // namespace Internal