Updated all code to new format
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-scene.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_SCENE_H
2 #define DALI_INTERNAL_SCENE_GRAPH_SCENE_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 // INTERNAL INCLUDES
21 #include <dali/integration-api/scene.h>
22 #include <dali/internal/common/message.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/render/common/render-instruction-container.h>
25 #include <dali/public-api/common/vector-wrapper.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 class Context;
32
33 namespace SceneGraph
34 {
35 class RenderInstructionContainer;
36
37 class Scene
38 {
39 public:
40   /**
41    * Constructor
42    * @param[in] surface The render surface
43    */
44   Scene();
45
46   /**
47    * Destructor
48    */
49   virtual ~Scene();
50
51   /**
52    * Creates a scene object in the GPU.
53    * @param[in] context The GL context
54    */
55   void Initialize(Context& context);
56
57   /**
58    * Gets the context holding the GL state of rendering for the scene
59    * @return the context
60    */
61   Context* GetContext();
62
63   /**
64    * Gets the render instructions for the scene
65    * @return the render instructions
66    */
67   RenderInstructionContainer& GetRenderInstructions();
68
69   /**
70    * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
71    *
72    * @param[in] callback The function to call
73    * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
74    *
75    * @note A callback of the following type may be used:
76    * @code
77    *   void MyFunction( int frameId );
78    * @endcode
79    * This callback will be deleted once it is called.
80    *
81    * @note Ownership of the callback is passed onto this class.
82    */
83   void AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId);
84
85   /**
86    * @brief Adds a callback that is called when the frame is displayed on the display.
87    *
88    * @param[in] callback The function to call
89    * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
90    *
91    * @note A callback of the following type may be used:
92    * @code
93    *   void MyFunction( int frameId );
94    * @endcode
95    * This callback will be deleted once it is called.
96    *
97    * @note Ownership of the callback is passed onto this class.
98    */
99   void AddFramePresentedCallback(CallbackBase* callback, int32_t frameId);
100
101   /**
102    * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver.
103    *
104    * @param[out] callbacks The callback list
105    */
106   void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
107
108   /**
109    * @brief Gets the callback list that is called when the frame is displayed on the display.
110    *
111    * @param[out] callbacks The callback list
112    */
113   void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
114
115   /**
116    * @brief Sets whether rendering should be skipped or not.
117    * @param[in] skip true if rendering should be skipped.
118    */
119   void SetSkipRendering(bool skip);
120
121   /**
122    * @brief Query whether rendering should be skipped or not.
123    * @return true if rendering should be skipped, false otherwise.
124    */
125   bool IsRenderingSkipped() const;
126
127   /**
128    * Set the surface rectangle when surface is resized.
129    *
130    * @param[in] scene The resized scene.
131    * @param[in] rect The retangle representing the surface.
132    */
133   void SetSurfaceRect(const Rect<int32_t>& rect);
134
135   /**
136    * Get the surface rectangle.
137    *
138    * @return the current surface rectangle
139    */
140   const Rect<int32_t>& GetSurfaceRect() const;
141
142   /**
143    * Set the surface orientation when surface is rotated.
144    *
145    * @param[in] scene The rotated scene.
146    * @param[in] orientation The orientation value representing the surface.
147    */
148   void SetSurfaceOrientation(int32_t orientation);
149
150   /**
151    * Get the surface orientation.
152    *
153    * @return the current surface orientation
154    */
155   int32_t GetSurfaceOrientation() const;
156
157   /**
158    * Query wheter the surface rect is changed or not.
159    * @return true if the surface rect is changed.
160    */
161   bool IsSurfaceRectChanged();
162
163 private:
164   Context* mContext; ///< The context holding the GL state of rendering for the scene, not owned
165
166   // Render instructions describe what should be rendered during RenderManager::RenderScene()
167   // Update manager updates instructions for the next frame while we render the current one
168
169   RenderInstructionContainer mInstructions; ///< Render instructions for the scene
170
171   Dali::Integration::Scene::FrameCallbackContainer mFrameRenderedCallbacks;  ///< Frame rendered callbacks
172   Dali::Integration::Scene::FrameCallbackContainer mFramePresentedCallbacks; ///< Frame presented callbacks
173
174   bool mSkipRendering; ///< A flag to skip rendering
175
176   Rect<int32_t> mSurfaceRect;        ///< The rectangle of surface which is related ot this scene.
177   int32_t       mSurfaceOrientation; ///< The orientation of surface which is related of this scene
178   bool          mSurfaceRectChanged; ///< The flag of surface's rectangle is changed when is resized, moved or rotated.
179 };
180
181 /// Messages
182 inline void AddFrameRenderedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId)
183 {
184   using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
185
186   // Reserve some memory inside the message queue
187   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
188
189   // Construct message in the message queue memory; note that delete should not be called on the return value
190   new(slot) LocalType(&scene, &Scene::AddFrameRenderedCallback, const_cast<CallbackBase*>(callback), frameId);
191 }
192
193 inline void AddFramePresentedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId)
194 {
195   using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
196
197   // Reserve some memory inside the message queue
198   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
199
200   // Construct message in the message queue memory; note that delete should not be called on the return value
201   new(slot) LocalType(&scene, &Scene::AddFramePresentedCallback, const_cast<CallbackBase*>(callback), frameId);
202 }
203
204 inline void SetSurfaceRectMessage(EventThreadServices& eventThreadServices, const Scene& scene, const Rect<int32_t>& rect)
205 {
206   using LocalType = MessageValue1<Scene, Rect<int32_t> >;
207
208   // Reserve some memory inside the message queue
209   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
210
211   // Construct message in the message queue memory; note that delete should not be called on the return value
212   new(slot) LocalType(&scene, &Scene::SetSurfaceRect, rect);
213 }
214
215 inline void SetSurfaceOrientationMessage(EventThreadServices& eventThreadServices, const Scene& scene, int32_t orientation)
216 {
217   using LocalType = MessageValue1<Scene, int32_t>;
218
219   // Reserve some memory inside the message queue
220   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
221
222   // Construct message in the message queue memory; note that delete should not be called on the return value
223   new(slot) LocalType(&scene, &Scene::SetSurfaceOrientation, orientation);
224 }
225
226 } // namespace SceneGraph
227
228 } // namespace Internal
229
230 } // namespace Dali
231
232 #endif // DALI_INTERNAL_SCENE_GRAPH_SCENE_H