Fix thread contention issues in messages and pan gestures.
[platform/core/uifw/dali-core.git] / dali / internal / render / queue / render-queue.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDER_QUEUE_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_QUEUE_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/devel-api/common/mutex.h>
23 #include <dali/internal/common/buffer-index.h>
24 #include <dali/internal/common/message-buffer.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 class MessageBase;
33
34 namespace SceneGraph
35 {
36
37 /**
38  * Allows messages to be queued for RenderManager, during the scene-graph Update.
39  */
40 class RenderQueue
41 {
42 public:
43
44   /**
45    * Create a new RenderQueue.
46    */
47   RenderQueue();
48
49   /**
50    * Non-virtual destructor; RenderQueue is not suitable as a base class.
51    */
52   ~RenderQueue();
53
54   /**
55    * Reserve space for another message in the queue; this must then be initialized by the caller.
56    * The message will be read from the next render-thread tick.
57    * @post Calling this method may invalidate any previously returned slots.
58    * @param[in] updateBufferIndex The current update buffer index.
59    * @param[in] size The message size with respect to the size of type "char".
60    * @return A pointer to the first char allocated for the message.
61    */
62   unsigned int* ReserveMessageSlot( BufferIndex updateBufferIndex, std::size_t size );
63
64   /**
65    * Process the batch of messages, which were queued in the previous update.
66    * @pre This message should only be called by RenderManager from within the render-thread.
67    * @param[in] bufferIndex The previous update buffer index.
68    */
69   void ProcessMessages( BufferIndex bufferIndex );
70
71 private:
72
73   /**
74    * Helper to retrieve the current container.
75    * The update-thread queues messages with one container, whilst the render-thread is processing the other.
76    * @param[in] bufferIndex The current buffer index.
77    * @return The container.
78    */
79   MessageBuffer* GetCurrentContainer( BufferIndex bufferIndex );
80
81   /**
82    * Helper to limit the buffer capacity i.e. after a frame when an extreme number of messages have been sent.
83    * @param[in] bufferIndex The current buffer index.
84    */
85   void LimitBufferCapacity( BufferIndex bufferIndex );
86
87   // Undefined
88   RenderQueue( const RenderQueue& );
89
90   // Undefined
91   RenderQueue& operator=( const RenderQueue& rhs );
92
93 private:
94
95   Dali::Mutex mMutex;        ///< Mutex to ensure access locking
96   MessageBuffer* container0; ///< Messages are queued here when the update buffer index == 0
97   MessageBuffer* container1; ///< Messages are queued here when the update buffer index == 1
98 };
99
100 } // namespace SceneGraph
101
102 } // namespace Internal
103
104 } // namespace Dali
105
106 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_QUEUE_H__