[dali_2.3.33] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / update / queue / update-message-queue.h
1 #ifndef DALI_INTERNAL_UPDATE_MESSAGE_QUEUE_H
2 #define DALI_INTERNAL_UPDATE_MESSAGE_QUEUE_H
3
4 /*
5  * Copyright (c) 2023 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/update/common/scene-graph-buffers.h>
24
25 // EXTERNAL INCLUDES
26 #include <cstddef>
27
28 namespace Dali
29 {
30 namespace Integration
31 {
32 class RenderController;
33 }
34
35 namespace Internal
36 {
37 class MessageBase;
38
39 namespace SceneGraph
40 {
41 class SceneGraphBuffers;
42 }
43
44 namespace Update
45 {
46 /**
47  * Used by UpdateManager to receive messages from the event-thread.
48  */
49 class MessageQueue
50 {
51 public:
52   /**
53    * Create a new UpdateMessageQueue.
54    * @param[in] renderController After messages are flushed, we request a render from the RenderController.
55    * @param[in] sceneGraphBuffers Used to keep track of which buffers are being written or read.
56    */
57   MessageQueue(Integration::RenderController&       renderController,
58                const SceneGraph::SceneGraphBuffers& sceneGraphBuffers);
59
60   /**
61    * Destructor
62    */
63   ~MessageQueue();
64
65   /**
66    * Inform the queue that event processing has started
67    */
68   void EventProcessingStarted();
69
70   /**
71    * Inform the queue that event processing has finished
72    */
73   void EventProcessingFinished();
74
75   /**
76    * Reserve space for a message
77    * @param[in] size the message size with respect to the size of type 'char'
78    * @param[in] updateScene If set to true, denotes that the message will cause the scene graph node tree to require an update
79    * @return A pointer to the first char allocated for the message
80    */
81   uint32_t* ReserveMessageSlot(uint32_t size, bool updateScene);
82
83   /**
84    * Flushes the message queue
85    * @return true if there are messages to process
86    */
87   bool FlushQueue();
88
89   // Exclusive to UpdateManager
90
91   /**
92    * Called once per update; process the previously flushed messages.
93    * @param updateBufferIndex to use
94    * @return true if the scene graph node tree is updated
95    */
96   bool ProcessMessages(BufferIndex updateBufferIndex);
97
98   /**
99    * Query whether the queue was empty this frame.
100    */
101   bool WasEmpty() const;
102
103   /**
104    * Query whether the queue contains at least one message that requires that the scene-graph
105    * node tree be updated.
106    * @return A flag, true if the scene graph needs an update
107    */
108   bool IsSceneUpdateRequired() const;
109
110   /**
111    * Query for the capacity of the current message queue
112    */
113   std::size_t GetCapacity() const;
114
115 private:
116   /**
117    * Helper to call Process and destructor on each queued message
118    * @param[in] minorQueue The queue to process.
119    */
120   void ProcessMinorQueue(char* minorQueue);
121
122 private:
123   // Not copyable:
124   MessageQueue()                        = delete;
125   MessageQueue(const MessageQueue& rhs) = delete;
126   MessageQueue& operator=(const MessageQueue& rhs) = delete;
127
128 private:
129   struct Impl;
130   Impl* mImpl;
131 };
132
133 } // namespace Update
134
135 } // namespace Internal
136
137 } // namespace Dali
138
139 #endif // DALI_INTERNAL_UPDATE_MESSAGE_QUEUE_H