1 #ifndef DALI_INTERNAL_STAGE_H
2 #define DALI_INTERNAL_STAGE_H
5 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
45 class RenderController;
55 class AnimationPlaylist;
56 class PropertyNotificationManager;
64 * Implementation of Stage
66 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public ConnectionTracker
71 * @param[in] updateManager
73 static StagePtr New(SceneGraph::UpdateManager& updateManager);
76 * Initialize the stage.
77 * @param[in] scene The default scene (for main window).
79 void Initialize(Scene& scene);
82 * @copydoc Dali::Stage::GetCurrent()
83 * @note this version is for internal usage so it does not assert
85 static StagePtr GetCurrent();
88 * @copydoc Dali::Stage::IsInstalled().
90 static bool IsInstalled();
93 * @copydoc Dali::Stage::IsShuttingDown().
95 static bool IsShuttingDown();
98 * @copydoc Dali::Stage::GetObjectRegistry()
100 ObjectRegistry& GetObjectRegistry();
103 * Retrieve the root actor (not publically accessible).
104 * @return The root actor.
106 Layer& GetRootActor();
108 // Root actor accessors
111 * @copydoc Dali::Stage::Add()
113 void Add(Actor& actor);
116 * @copydoc Dali::Stage::Remove()
118 void Remove(Actor& actor);
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.
126 Vector2 GetSize() const;
129 * @copydoc Dali::Stage::GetRenderTaskList()
131 RenderTaskList& GetRenderTaskList() const;
134 * From RenderTaskDefaults; retrieve the default root actor.
135 * @return The default root actor.
137 Actor& GetDefaultRootActor() override;
140 * From RenderTaskDefaults; retrieve the default camera actor.
141 * @return The default camera actor.
143 CameraActor& GetDefaultCameraActor() const override;
148 * @copydoc Dali::Stage::GetLayerCount()
150 uint32_t GetLayerCount() const;
153 * @copydoc Dali::Stage::GetLayer()
155 Dali::Layer GetLayer(uint32_t depth) const;
158 * @copydoc Dali::Stage::GetRootLayer()
160 Dali::Layer GetRootLayer() const;
163 * Retrieve the ordered list of on-stage layers.
164 * @return The layer-list.
166 LayerList& GetLayerList();
171 * @copydoc Dali::Stage::SetBackgroundColor
173 void SetBackgroundColor(Vector4 color);
176 * @copydoc Dali::Stage::GetBackgroundColor
178 Vector4 GetBackgroundColor() const;
181 * @copydoc Dali::Stage::GetDpi
183 Vector2 GetDpi() const;
186 * @copydoc Dali::Stage::KeepRendering()
188 void KeepRendering(float durationSeconds);
191 * @copydoc Dali::DevelStage::SetRenderingBehavior()
193 void SetRenderingBehavior(DevelStage::Rendering renderingBehavior);
196 * @copydoc Dali::DevelStage::GetRenderingBehavior()
198 DevelStage::Rendering GetRenderingBehavior() const;
201 * Callback for Internal::Scene EventProcessingFinished signal
203 void OnEventProcessingFinished();
206 * Callback for Internal::Scene KeyEventSignal signal
208 void OnKeyEvent(const Dali::KeyEvent& event);
211 * Callback for Internal::Scene TouchedSignal signal
213 void OnTouchEvent(const Dali::TouchEvent& touch);
216 * Callback for Internal::Scene WheelEventSignal signal
218 void OnWheelEvent(const Dali::WheelEvent& event);
221 * Used by the EventProcessor to emit key event signals.
222 * @param[in] event The key event.
224 void EmitKeyEventSignal(const KeyEvent& event);
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.
231 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
234 * Emits the event processing finished signal.
236 * @see Dali::Stage::SignalEventProcessingFinished()
238 void EmitEventProcessingFinishedSignal();
241 * Emits the touched signal.
242 * @param[in] touch The touch event details.
244 void EmitTouchedSignal(const Dali::TouchEvent& touch);
247 * Used by the EventProcessor to emit wheel event signals.
248 * @param[in] event The wheel event.
250 void EmitWheelEventSignal(const WheelEvent& event);
253 * Emits the scene created.
255 void EmitSceneCreatedSignal();
258 * @copydoc Dali::Stage::KeyEventSignal()
260 Dali::Stage::KeyEventSignalType& KeyEventSignal();
263 * @copydoc Dali::Stage::SignalEventProcessingFinished()
265 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
268 * @copydoc Dali::Stage::TouchedSignal()
270 Dali::Stage::TouchEventSignalType& TouchedSignal();
273 * @copydoc Dali::Stage::WheelEventSignal()
275 Dali::Stage::WheelEventSignalType& WheelEventSignal();
278 * @copydoc Dali::Stage::ContextLostSignal()
280 Dali::Stage::ContextStatusSignal& ContextLostSignal();
283 * @copydoc Dali::Stage::ContextRegainedSignal()
285 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
288 * @copydoc Dali::Stage::SceneCreatedSignal()
290 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
293 * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
295 Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
298 * @copydoc Dali::DevelStage::AddFrameCallback()
300 void AddFrameCallback(FrameCallbackInterface& frameCallback, Actor& rootActor);
303 * @copydoc Dali::DevelStage::AddFrameCallback()
305 void AddGlobalFrameCallback(FrameCallbackInterface& frameCallback);
308 * @copydoc Dali::DevelStage::RemoveFrameCallback()
310 void RemoveFrameCallback(FrameCallbackInterface& frameCallback);
313 * @copydoc Dali::DevelStage::NotifyFrameCallback
315 Dali::UpdateProxy::NotifySyncPoint NotifyFrameCallback(FrameCallbackInterface& frameCallback);
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.
326 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
328 private: // Implementation of ContextNotificationInterface:
330 * @copydoc Dali::Integration::NotifyContextLost();
332 void NotifyContextLost() override;
335 * @copydoc Dali::Integration::NotifyContextRegained();
337 void NotifyContextRegained() override;
341 * Protected constructor; see also Stage::New()
343 Stage(SceneGraph::UpdateManager& updateManager);
346 * A reference counted object may only be deleted by calling Unreference()
351 SceneGraph::UpdateManager& mUpdateManager;
353 IntrusivePtr<Scene> mScene;
355 // The key event signal
356 Dali::Stage::KeyEventSignalType mKeyEventSignal;
357 Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
359 // The event processing finished signal
360 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
362 // The touched signal
363 Dali::Stage::TouchEventSignalType mTouchedSignal;
365 // The wheel event signal
366 Dali::Stage::WheelEventSignalType mWheelEventSignal;
368 Dali::Stage::ContextStatusSignal mContextLostSignal;
369 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
371 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
373 DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
376 } // namespace Internal
378 // Helpers for public-api forwarding methods
380 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
382 DALI_ASSERT_ALWAYS(stage && "Stage handle is empty");
384 BaseObject& handle = stage.GetBaseObject();
386 return static_cast<Internal::Stage&>(handle);
389 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
391 DALI_ASSERT_ALWAYS(stage && "Stage handle is empty");
393 const BaseObject& handle = stage.GetBaseObject();
395 return static_cast<const Internal::Stage&>(handle);
400 #endif // DALI_INTERNAL_STAGE_H