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