Merge "Updated all code to new format" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / common / stage-impl.h
1 #ifndef DALI_INTERNAL_STAGE_H
2 #define DALI_INTERNAL_STAGE_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/devel-api/common/stage-devel.h>
23 #include <dali/devel-api/common/stage.h>
24 #include <dali/integration-api/context-notifier.h>
25 #include <dali/internal/common/owner-pointer.h>
26 #include <dali/internal/event/actors/layer-impl.h>
27 #include <dali/internal/event/common/event-thread-services.h>
28 #include <dali/internal/event/common/object-registry-impl.h>
29 #include <dali/internal/event/common/stage-def.h>
30 #include <dali/internal/event/render-tasks/render-task-defaults.h>
31 #include <dali/internal/event/render-tasks/render-task-impl.h>
32 #include <dali/internal/update/manager/update-manager.h>
33 #include <dali/public-api/math/vector2.h>
34 #include <dali/public-api/math/vector3.h>
35 #include <dali/public-api/math/vector4.h>
36 #include <dali/public-api/object/base-object.h>
37 #include <dali/public-api/object/ref-object.h>
38
39 namespace Dali
40 {
41 struct Vector2;
42
43 namespace Integration
44 {
45 class RenderController;
46 }
47
48 namespace Internal
49 {
50 namespace SceneGraph
51 {
52 class UpdateManager;
53 }
54
55 class AnimationPlaylist;
56 class PropertyNotificationManager;
57 class Layer;
58 class LayerList;
59 class CameraActor;
60 class RenderTaskList;
61 class Scene;
62
63 /**
64  * Implementation of Stage
65  */
66 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public ConnectionTracker
67 {
68 public:
69   /**
70    * Create the stage
71    * @param[in] updateManager
72    */
73   static StagePtr New(SceneGraph::UpdateManager& updateManager);
74
75   /**
76    * Initialize the stage.
77    * @param[in] scene The default scene (for main window).
78    */
79   void Initialize(Scene& scene);
80
81   /**
82    * @copydoc Dali::Stage::GetCurrent()
83    * @note this version is for internal usage so it does not assert
84    */
85   static StagePtr GetCurrent();
86
87   /**
88    * @copydoc Dali::Stage::IsInstalled().
89    */
90   static bool IsInstalled();
91
92   /**
93    * @copydoc Dali::Stage::GetObjectRegistry()
94    */
95   ObjectRegistry& GetObjectRegistry();
96
97   /**
98    * Retrieve the root actor (not publically accessible).
99    * @return The root actor.
100    */
101   Layer& GetRootActor();
102
103   // Root actor accessors
104
105   /**
106    * @copydoc Dali::Stage::Add()
107    */
108   void Add(Actor& actor);
109
110   /**
111    * @copydoc Dali::Stage::Remove()
112    */
113   void Remove(Actor& actor);
114
115   /**
116    * Returns the size of the Stage in pixels as a Vector.
117    * The x component will be the width of the Stage in pixels
118    * The y component will be the height of the Stage in pixels
119    * @return The size of the Stage as a Vector.
120    */
121   Vector2 GetSize() const;
122
123   /**
124    * @copydoc Dali::Stage::GetRenderTaskList()
125    */
126   RenderTaskList& GetRenderTaskList() const;
127
128   /**
129    * From RenderTaskDefaults; retrieve the default root actor.
130    * @return The default root actor.
131    */
132   Actor& GetDefaultRootActor() override;
133
134   /**
135    * From RenderTaskDefaults; retrieve the default camera actor.
136    * @return The default camera actor.
137    */
138   CameraActor& GetDefaultCameraActor() override;
139
140   // Layers
141
142   /**
143    * @copydoc Dali::Stage::GetLayerCount()
144    */
145   uint32_t GetLayerCount() const;
146
147   /**
148    * @copydoc Dali::Stage::GetLayer()
149    */
150   Dali::Layer GetLayer(uint32_t depth) const;
151
152   /**
153    * @copydoc Dali::Stage::GetRootLayer()
154    */
155   Dali::Layer GetRootLayer() const;
156
157   /**
158    * Retrieve the ordered list of on-stage layers.
159    * @return The layer-list.
160    */
161   LayerList& GetLayerList();
162
163   // Misc
164
165   /**
166    * @copydoc Dali::Stage::SetBackgroundColor
167    */
168   void SetBackgroundColor(Vector4 color);
169
170   /**
171    * @copydoc Dali::Stage::GetBackgroundColor
172    */
173   Vector4 GetBackgroundColor() const;
174
175   /**
176    * @copydoc Dali::Stage::GetDpi
177    */
178   Vector2 GetDpi() const;
179
180   /**
181    * @copydoc Dali::Stage::KeepRendering()
182    */
183   void KeepRendering(float durationSeconds);
184
185   /**
186    * @copydoc Dali::DevelStage::SetRenderingBehavior()
187    */
188   void SetRenderingBehavior(DevelStage::Rendering renderingBehavior);
189
190   /**
191    * @copydoc Dali::DevelStage::GetRenderingBehavior()
192    */
193   DevelStage::Rendering GetRenderingBehavior() const;
194
195   /**
196    * Callback for Internal::Scene EventProcessingFinished signal
197    */
198   void OnEventProcessingFinished();
199
200   /**
201    * Callback for Internal::Scene KeyEventSignal signal
202    */
203   void OnKeyEvent(const Dali::KeyEvent& event);
204
205   /**
206    * Callback for Internal::Scene TouchedSignal signal
207    */
208   void OnTouchEvent(const Dali::TouchEvent& touch);
209
210   /**
211    * Callback for Internal::Scene WheelEventSignal signal
212    */
213   void OnWheelEvent(const Dali::WheelEvent& event);
214
215   /**
216    * Used by the EventProcessor to emit key event signals.
217    * @param[in] event The key event.
218    */
219   void EmitKeyEventSignal(const KeyEvent& event);
220
221   /**
222    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
223    * @param[in] event The key event.
224    * @return The return is true if KeyEvent is consumed, otherwise false.
225    */
226   bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
227
228   /**
229    * Emits the event processing finished signal.
230    *
231    * @see Dali::Stage::SignalEventProcessingFinished()
232    */
233   void EmitEventProcessingFinishedSignal();
234
235   /**
236    * Emits the touched signal.
237    * @param[in] touch The touch event details.
238    */
239   void EmitTouchedSignal(const Dali::TouchEvent& touch);
240
241   /**
242    * Used by the EventProcessor to emit wheel event signals.
243    * @param[in] event The wheel event.
244    */
245   void EmitWheelEventSignal(const WheelEvent& event);
246
247   /**
248    * Emits the scene created.
249    */
250   void EmitSceneCreatedSignal();
251
252   /**
253    * @copydoc Dali::Stage::KeyEventSignal()
254    */
255   Dali::Stage::KeyEventSignalType& KeyEventSignal();
256
257   /**
258    * @copydoc Dali::Stage::SignalEventProcessingFinished()
259    */
260   Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
261
262   /**
263     * @copydoc Dali::Stage::TouchedSignal()
264     */
265   Dali::Stage::TouchEventSignalType& TouchedSignal();
266
267   /**
268    * @copydoc Dali::Stage::WheelEventSignal()
269    */
270   Dali::Stage::WheelEventSignalType& WheelEventSignal();
271
272   /**
273    * @copydoc Dali::Stage::ContextLostSignal()
274    */
275   Dali::Stage::ContextStatusSignal& ContextLostSignal();
276
277   /**
278    * @copydoc Dali::Stage::ContextRegainedSignal()
279    */
280   Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
281
282   /**
283    * @copydoc Dali::Stage::SceneCreatedSignal()
284    */
285   Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
286
287   /**
288    * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
289    */
290   Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
291
292   /**
293    * @copydoc Dali::DevelStage::AddFrameCallback()
294    */
295   void AddFrameCallback(FrameCallbackInterface& frameCallback, Actor& rootActor);
296
297   /**
298    * @copydoc Dali::DevelStage::RemoveFrameCallback()
299    */
300   void RemoveFrameCallback(FrameCallbackInterface& frameCallback);
301
302   /**
303    * Connects a callback function with the object's signals.
304    * @param[in] object The object providing the signal.
305    * @param[in] tracker Used to disconnect the signal.
306    * @param[in] signalName The signal to connect to.
307    * @param[in] functor A newly allocated FunctorDelegate.
308    * @return True if the signal was connected.
309    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
310    */
311   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
312
313 private: // Implementation of ContextNotificationInterface:
314   /**
315    * @copydoc Dali::Integration::NotifyContextLost();
316    */
317   void NotifyContextLost() override;
318
319   /**
320    * @copydoc Dali::Integration::NotifyContextRegained();
321    */
322   void NotifyContextRegained() override;
323
324 private:
325   /**
326    * Protected constructor; see also Stage::New()
327    */
328   Stage(SceneGraph::UpdateManager& updateManager);
329
330   /**
331    * A reference counted object may only be deleted by calling Unreference()
332    */
333   ~Stage() override;
334
335 private:
336   SceneGraph::UpdateManager& mUpdateManager;
337
338   IntrusivePtr<Scene> mScene;
339
340   // The key event signal
341   Dali::Stage::KeyEventSignalType               mKeyEventSignal;
342   Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
343
344   // The event processing finished signal
345   Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
346
347   // The touched signal
348   Dali::Stage::TouchEventSignalType mTouchedSignal;
349
350   // The wheel event signal
351   Dali::Stage::WheelEventSignalType mWheelEventSignal;
352
353   Dali::Stage::ContextStatusSignal mContextLostSignal;
354   Dali::Stage::ContextStatusSignal mContextRegainedSignal;
355
356   Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
357
358   DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
359 };
360
361 } // namespace Internal
362
363 // Helpers for public-api forwarding methods
364
365 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
366 {
367   DALI_ASSERT_ALWAYS(stage && "Stage handle is empty");
368
369   BaseObject& handle = stage.GetBaseObject();
370
371   return static_cast<Internal::Stage&>(handle);
372 }
373
374 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
375 {
376   DALI_ASSERT_ALWAYS(stage && "Stage handle is empty");
377
378   const BaseObject& handle = stage.GetBaseObject();
379
380   return static_cast<const Internal::Stage&>(handle);
381 }
382
383 } // namespace Dali
384
385 #endif // DALI_INTERNAL_STAGE_H