[dali_2.3.24] Merge branch '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) 2024 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::IsShuttingDown().
94    */
95   static bool IsShuttingDown();
96
97   /**
98    * @copydoc Dali::Stage::GetObjectRegistry()
99    */
100   ObjectRegistry& GetObjectRegistry();
101
102   /**
103    * Retrieve the root actor (not publically accessible).
104    * @return The root actor.
105    */
106   Layer& GetRootActor();
107
108   // Root actor accessors
109
110   /**
111    * @copydoc Dali::Stage::Add()
112    */
113   void Add(Actor& actor);
114
115   /**
116    * @copydoc Dali::Stage::Remove()
117    */
118   void Remove(Actor& actor);
119
120   /**
121    * Returns the size of the Stage in pixels as a Vector.
122    * The x component will be the width of the Stage in pixels
123    * The y component will be the height of the Stage in pixels
124    * @return The size of the Stage as a Vector.
125    */
126   Vector2 GetSize() const;
127
128   /**
129    * @copydoc Dali::Stage::GetRenderTaskList()
130    */
131   RenderTaskList& GetRenderTaskList() const;
132
133   /**
134    * From RenderTaskDefaults; retrieve the default root actor.
135    * @return The default root actor.
136    */
137   Actor& GetDefaultRootActor() override;
138
139   /**
140    * From RenderTaskDefaults; retrieve the default camera actor.
141    * @return The default camera actor.
142    */
143   CameraActor& GetDefaultCameraActor() const override;
144
145   // Layers
146
147   /**
148    * @copydoc Dali::Stage::GetLayerCount()
149    */
150   uint32_t GetLayerCount() const;
151
152   /**
153    * @copydoc Dali::Stage::GetLayer()
154    */
155   Dali::Layer GetLayer(uint32_t depth) const;
156
157   /**
158    * @copydoc Dali::Stage::GetRootLayer()
159    */
160   Dali::Layer GetRootLayer() const;
161
162   /**
163    * Retrieve the ordered list of on-stage layers.
164    * @return The layer-list.
165    */
166   LayerList& GetLayerList();
167
168   // Misc
169
170   /**
171    * @copydoc Dali::Stage::SetBackgroundColor
172    */
173   void SetBackgroundColor(Vector4 color);
174
175   /**
176    * @copydoc Dali::Stage::GetBackgroundColor
177    */
178   Vector4 GetBackgroundColor() const;
179
180   /**
181    * @copydoc Dali::Stage::GetDpi
182    */
183   Vector2 GetDpi() const;
184
185   /**
186    * @copydoc Dali::Stage::KeepRendering()
187    */
188   void KeepRendering(float durationSeconds);
189
190   /**
191    * @copydoc Dali::DevelStage::SetRenderingBehavior()
192    */
193   void SetRenderingBehavior(DevelStage::Rendering renderingBehavior);
194
195   /**
196    * @copydoc Dali::DevelStage::GetRenderingBehavior()
197    */
198   DevelStage::Rendering GetRenderingBehavior() const;
199
200   /**
201    * Callback for Internal::Scene EventProcessingFinished signal
202    */
203   void OnEventProcessingFinished();
204
205   /**
206    * Callback for Internal::Scene KeyEventSignal signal
207    */
208   void OnKeyEvent(const Dali::KeyEvent& event);
209
210   /**
211    * Callback for Internal::Scene TouchedSignal signal
212    */
213   void OnTouchEvent(const Dali::TouchEvent& touch);
214
215   /**
216    * Callback for Internal::Scene WheelEventSignal signal
217    */
218   void OnWheelEvent(const Dali::WheelEvent& event);
219
220   /**
221    * Used by the EventProcessor to emit key event signals.
222    * @param[in] event The key event.
223    */
224   void EmitKeyEventSignal(const KeyEvent& event);
225
226   /**
227    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
228    * @param[in] event The key event.
229    * @return The return is true if KeyEvent is consumed, otherwise false.
230    */
231   bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
232
233   /**
234    * Emits the event processing finished signal.
235    *
236    * @see Dali::Stage::SignalEventProcessingFinished()
237    */
238   void EmitEventProcessingFinishedSignal();
239
240   /**
241    * Emits the touched signal.
242    * @param[in] touch The touch event details.
243    */
244   void EmitTouchedSignal(const Dali::TouchEvent& touch);
245
246   /**
247    * Used by the EventProcessor to emit wheel event signals.
248    * @param[in] event The wheel event.
249    */
250   void EmitWheelEventSignal(const WheelEvent& event);
251
252   /**
253    * Emits the scene created.
254    */
255   void EmitSceneCreatedSignal();
256
257   /**
258    * @copydoc Dali::Stage::KeyEventSignal()
259    */
260   Dali::Stage::KeyEventSignalType& KeyEventSignal();
261
262   /**
263    * @copydoc Dali::Stage::SignalEventProcessingFinished()
264    */
265   Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
266
267   /**
268     * @copydoc Dali::Stage::TouchedSignal()
269     */
270   Dali::Stage::TouchEventSignalType& TouchedSignal();
271
272   /**
273    * @copydoc Dali::Stage::WheelEventSignal()
274    */
275   Dali::Stage::WheelEventSignalType& WheelEventSignal();
276
277   /**
278    * @copydoc Dali::Stage::ContextLostSignal()
279    */
280   Dali::Stage::ContextStatusSignal& ContextLostSignal();
281
282   /**
283    * @copydoc Dali::Stage::ContextRegainedSignal()
284    */
285   Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
286
287   /**
288    * @copydoc Dali::Stage::SceneCreatedSignal()
289    */
290   Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
291
292   /**
293    * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
294    */
295   Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
296
297   /**
298    * @copydoc Dali::DevelStage::AddFrameCallback()
299    */
300   void AddFrameCallback(FrameCallbackInterface& frameCallback, Actor& rootActor);
301
302   /**
303    * @copydoc Dali::DevelStage::AddFrameCallback()
304    */
305   void AddGlobalFrameCallback(FrameCallbackInterface& frameCallback);
306
307   /**
308    * @copydoc Dali::DevelStage::RemoveFrameCallback()
309    */
310   void RemoveFrameCallback(FrameCallbackInterface& frameCallback);
311
312   /**
313    * @copydoc Dali::DevelStage::NotifyFrameCallback
314    */
315   Dali::UpdateProxy::NotifySyncPoint NotifyFrameCallback(FrameCallbackInterface& frameCallback);
316
317   /**
318    * Connects a callback function with the object's signals.
319    * @param[in] object The object providing the signal.
320    * @param[in] tracker Used to disconnect the signal.
321    * @param[in] signalName The signal to connect to.
322    * @param[in] functor A newly allocated FunctorDelegate.
323    * @return True if the signal was connected.
324    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
325    */
326   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
327
328 private: // Implementation of ContextNotificationInterface:
329   /**
330    * @copydoc Dali::Integration::NotifyContextLost();
331    */
332   void NotifyContextLost() override;
333
334   /**
335    * @copydoc Dali::Integration::NotifyContextRegained();
336    */
337   void NotifyContextRegained() override;
338
339 private:
340   /**
341    * Protected constructor; see also Stage::New()
342    */
343   Stage(SceneGraph::UpdateManager& updateManager);
344
345   /**
346    * A reference counted object may only be deleted by calling Unreference()
347    */
348   ~Stage() override;
349
350 private:
351   SceneGraph::UpdateManager& mUpdateManager;
352
353   IntrusivePtr<Scene> mScene;
354
355   // The key event signal
356   Dali::Stage::KeyEventSignalType               mKeyEventSignal;
357   Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
358
359   // The event processing finished signal
360   Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
361
362   // The touched signal
363   Dali::Stage::TouchEventSignalType mTouchedSignal;
364
365   // The wheel event signal
366   Dali::Stage::WheelEventSignalType mWheelEventSignal;
367
368   Dali::Stage::ContextStatusSignal mContextLostSignal;
369   Dali::Stage::ContextStatusSignal mContextRegainedSignal;
370
371   Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
372
373   DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
374 };
375
376 } // namespace Internal
377
378 // Helpers for public-api forwarding methods
379
380 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
381 {
382   DALI_ASSERT_ALWAYS(stage && "Stage handle is empty");
383
384   BaseObject& handle = stage.GetBaseObject();
385
386   return static_cast<Internal::Stage&>(handle);
387 }
388
389 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
390 {
391   DALI_ASSERT_ALWAYS(stage && "Stage handle is empty");
392
393   const BaseObject& handle = stage.GetBaseObject();
394
395   return static_cast<const Internal::Stage&>(handle);
396 }
397
398 } // namespace Dali
399
400 #endif // DALI_INTERNAL_STAGE_H