1 #ifndef DALI_INTERNAL_STAGE_H
2 #define DALI_INTERNAL_STAGE_H
5 * Copyright (c) 2021 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::GetObjectRegistry()
95 ObjectRegistry& GetObjectRegistry();
98 * Retrieve the root actor (not publically accessible).
99 * @return The root actor.
101 Layer& GetRootActor();
103 // Root actor accessors
106 * @copydoc Dali::Stage::Add()
108 void Add(Actor& actor);
111 * @copydoc Dali::Stage::Remove()
113 void Remove(Actor& actor);
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.
121 Vector2 GetSize() const;
124 * @copydoc Dali::Stage::GetRenderTaskList()
126 RenderTaskList& GetRenderTaskList() const;
129 * From RenderTaskDefaults; retrieve the default root actor.
130 * @return The default root actor.
132 Actor& GetDefaultRootActor() override;
135 * From RenderTaskDefaults; retrieve the default camera actor.
136 * @return The default camera actor.
138 CameraActor& GetDefaultCameraActor() const override;
143 * @copydoc Dali::Stage::GetLayerCount()
145 uint32_t GetLayerCount() const;
148 * @copydoc Dali::Stage::GetLayer()
150 Dali::Layer GetLayer(uint32_t depth) const;
153 * @copydoc Dali::Stage::GetRootLayer()
155 Dali::Layer GetRootLayer() const;
158 * Retrieve the ordered list of on-stage layers.
159 * @return The layer-list.
161 LayerList& GetLayerList();
166 * @copydoc Dali::Stage::SetBackgroundColor
168 void SetBackgroundColor(Vector4 color);
171 * @copydoc Dali::Stage::GetBackgroundColor
173 Vector4 GetBackgroundColor() const;
176 * @copydoc Dali::Stage::GetDpi
178 Vector2 GetDpi() const;
181 * @copydoc Dali::Stage::KeepRendering()
183 void KeepRendering(float durationSeconds);
186 * @copydoc Dali::DevelStage::SetRenderingBehavior()
188 void SetRenderingBehavior(DevelStage::Rendering renderingBehavior);
191 * @copydoc Dali::DevelStage::GetRenderingBehavior()
193 DevelStage::Rendering GetRenderingBehavior() const;
196 * Callback for Internal::Scene EventProcessingFinished signal
198 void OnEventProcessingFinished();
201 * Callback for Internal::Scene KeyEventSignal signal
203 void OnKeyEvent(const Dali::KeyEvent& event);
206 * Callback for Internal::Scene TouchedSignal signal
208 void OnTouchEvent(const Dali::TouchEvent& touch);
211 * Callback for Internal::Scene WheelEventSignal signal
213 void OnWheelEvent(const Dali::WheelEvent& event);
216 * Used by the EventProcessor to emit key event signals.
217 * @param[in] event The key event.
219 void EmitKeyEventSignal(const KeyEvent& event);
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.
226 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
229 * Emits the event processing finished signal.
231 * @see Dali::Stage::SignalEventProcessingFinished()
233 void EmitEventProcessingFinishedSignal();
236 * Emits the touched signal.
237 * @param[in] touch The touch event details.
239 void EmitTouchedSignal(const Dali::TouchEvent& touch);
242 * Used by the EventProcessor to emit wheel event signals.
243 * @param[in] event The wheel event.
245 void EmitWheelEventSignal(const WheelEvent& event);
248 * Emits the scene created.
250 void EmitSceneCreatedSignal();
253 * @copydoc Dali::Stage::KeyEventSignal()
255 Dali::Stage::KeyEventSignalType& KeyEventSignal();
258 * @copydoc Dali::Stage::SignalEventProcessingFinished()
260 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
263 * @copydoc Dali::Stage::TouchedSignal()
265 Dali::Stage::TouchEventSignalType& TouchedSignal();
268 * @copydoc Dali::Stage::WheelEventSignal()
270 Dali::Stage::WheelEventSignalType& WheelEventSignal();
273 * @copydoc Dali::Stage::ContextLostSignal()
275 Dali::Stage::ContextStatusSignal& ContextLostSignal();
278 * @copydoc Dali::Stage::ContextRegainedSignal()
280 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
283 * @copydoc Dali::Stage::SceneCreatedSignal()
285 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
288 * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
290 Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
293 * @copydoc Dali::DevelStage::AddFrameCallback()
295 void AddFrameCallback(FrameCallbackInterface& frameCallback, Actor& rootActor);
298 * @copydoc Dali::DevelStage::RemoveFrameCallback()
300 void RemoveFrameCallback(FrameCallbackInterface& frameCallback);
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.
311 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
313 private: // Implementation of ContextNotificationInterface:
315 * @copydoc Dali::Integration::NotifyContextLost();
317 void NotifyContextLost() override;
320 * @copydoc Dali::Integration::NotifyContextRegained();
322 void NotifyContextRegained() override;
326 * Protected constructor; see also Stage::New()
328 Stage(SceneGraph::UpdateManager& updateManager);
331 * A reference counted object may only be deleted by calling Unreference()
336 SceneGraph::UpdateManager& mUpdateManager;
338 IntrusivePtr<Scene> mScene;
340 // The key event signal
341 Dali::Stage::KeyEventSignalType mKeyEventSignal;
342 Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
344 // The event processing finished signal
345 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
347 // The touched signal
348 Dali::Stage::TouchEventSignalType mTouchedSignal;
350 // The wheel event signal
351 Dali::Stage::WheelEventSignalType mWheelEventSignal;
353 Dali::Stage::ContextStatusSignal mContextLostSignal;
354 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
356 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
358 DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
361 } // namespace Internal
363 // Helpers for public-api forwarding methods
365 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
367 DALI_ASSERT_ALWAYS(stage && "Stage handle is empty");
369 BaseObject& handle = stage.GetBaseObject();
371 return static_cast<Internal::Stage&>(handle);
374 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
376 DALI_ASSERT_ALWAYS(stage && "Stage handle is empty");
378 const BaseObject& handle = stage.GetBaseObject();
380 return static_cast<const Internal::Stage&>(handle);
385 #endif // DALI_INTERNAL_STAGE_H