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