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