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