Merge "Making DALi core internals typesafe using guaranteed types; uint8_t, uint32_t...
[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) 2018 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/internal/common/buffer-index.h>
23 #include <dali/internal/common/message-buffer.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 class MessageBase;
32
33 namespace SceneGraph
34 {
35
36 /**
37  * Allows messages to be queued for RenderManager, during the scene-graph Update.
38  */
39 class RenderQueue
40 {
41 public:
42
43   /**
44    * Create a new RenderQueue.
45    */
46   RenderQueue();
47
48   /**
49    * Non-virtual destructor; RenderQueue is not suitable as a base class.
50    */
51   ~RenderQueue();
52
53   /**
54    * Reserve space for another message in the queue; this must then be initialized by the caller.
55    * The message will be read from the next render-thread tick.
56    * @post Calling this method may invalidate any previously returned slots.
57    * @param[in] updateBufferIndex The current update buffer index.
58    * @param[in] size The message size with respect to the size of type "char".
59    * @return A pointer to the first char allocated for the message.
60    */
61   uint32_t* ReserveMessageSlot( BufferIndex updateBufferIndex, std::size_t size );
62
63   /**
64    * Process the batch of messages, which were queued in the previous update.
65    * @pre This message should only be called by RenderManager from within the render-thread.
66    * @param[in] bufferIndex The previous update buffer index.
67    */
68   void ProcessMessages( BufferIndex bufferIndex );
69
70 private:
71
72   /**
73    * Helper to retrieve the current container.
74    * The update-thread queues messages with one container, whilst the render-thread is processing the other.
75    * @param[in] bufferIndex The current buffer index.
76    * @return The container.
77    */
78   MessageBuffer* GetCurrentContainer( BufferIndex bufferIndex );
79
80   /**
81    * Helper to limit the buffer capacity i.e. after a frame when an extreme number of messages have been sent.
82    * @param[in] bufferIndex The current buffer index.
83    */
84   void LimitBufferCapacity( BufferIndex bufferIndex );
85
86   // Undefined
87   RenderQueue( const RenderQueue& );
88
89   // Undefined
90   RenderQueue& operator=( const RenderQueue& rhs );
91
92 private:
93
94   MessageBuffer* container0; ///< Messages are queued here when the update buffer index == 0
95   MessageBuffer* container1; ///< Messages are queued here when the update buffer index == 1
96 };
97
98 } // namespace SceneGraph
99
100 } // namespace Internal
101
102 } // namespace Dali
103
104 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_QUEUE_H__