1 #ifndef DALI_INTERNAL_STAGE_H
2 #define DALI_INTERNAL_STAGE_H
5 * Copyright (c) 2020 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.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/math/vector2.h>
26 #include <dali/public-api/math/vector3.h>
27 #include <dali/public-api/math/vector4.h>
28 #include <dali/devel-api/common/stage-devel.h>
29 #include <dali/integration-api/context-notifier.h>
30 #include <dali/internal/common/owner-pointer.h>
31 #include <dali/internal/event/actors/layer-impl.h>
32 #include <dali/internal/event/common/event-thread-services.h>
33 #include <dali/internal/event/common/object-registry-impl.h>
34 #include <dali/internal/event/common/stage-def.h>
35 #include <dali/internal/event/render-tasks/render-task-defaults.h>
36 #include <dali/internal/update/manager/update-manager.h>
37 #include <dali/internal/event/render-tasks/render-task-impl.h>
46 class RenderController;
57 class AnimationPlaylist;
58 class PropertyNotificationManager;
66 * Implementation of Stage
68 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public ConnectionTracker
74 * @param[in] updateManager
76 static StagePtr New( SceneGraph::UpdateManager& updateManager );
79 * Initialize the stage.
80 * @param[in] scene The default scene (for main window).
82 void Initialize( Scene& scene );
85 * @copydoc Dali::Stage::GetCurrent()
86 * @note this version is for internal usage so it does not assert
88 static StagePtr GetCurrent();
91 * @copydoc Dali::Stage::IsInstalled().
93 static bool IsInstalled();
96 * @copydoc Dali::Stage::GetObjectRegistry()
98 ObjectRegistry& GetObjectRegistry();
101 * Retrieve the root actor (not publically accessible).
102 * @return The root actor.
104 Layer& GetRootActor();
106 // Root actor accessors
109 * @copydoc Dali::Stage::Add()
111 void Add( Actor& actor );
114 * @copydoc Dali::Stage::Remove()
116 void Remove( Actor& actor );
119 * Returns the size of the Stage in pixels as a Vector.
120 * The x component will be the width of the Stage in pixels
121 * The y component will be the height of the Stage in pixels
122 * @return The size of the Stage as a Vector.
124 Vector2 GetSize() const;
127 * @copydoc Dali::Stage::GetRenderTaskList()
129 RenderTaskList& GetRenderTaskList() const;
132 * From RenderTaskDefaults; retrieve the default root actor.
133 * @return The default root actor.
135 virtual Actor& GetDefaultRootActor();
138 * From RenderTaskDefaults; retrieve the default camera actor.
139 * @return The default camera actor.
141 virtual CameraActor& GetDefaultCameraActor();
146 * @copydoc Dali::Stage::GetLayerCount()
148 uint32_t GetLayerCount() const;
151 * @copydoc Dali::Stage::GetLayer()
153 Dali::Layer GetLayer( uint32_t depth ) const;
156 * @copydoc Dali::Stage::GetRootLayer()
158 Dali::Layer GetRootLayer() const;
161 * Retrieve the ordered list of on-stage layers.
162 * @return The layer-list.
164 LayerList& GetLayerList();
169 * @copydoc Dali::Stage::SetBackgroundColor
171 void SetBackgroundColor(Vector4 color);
174 * @copydoc Dali::Stage::GetBackgroundColor
176 Vector4 GetBackgroundColor() const;
179 * @copydoc Dali::Stage::GetDpi
181 Vector2 GetDpi() const;
184 * @copydoc Dali::Stage::KeepRendering()
186 void KeepRendering( float durationSeconds );
189 * @copydoc Dali::DevelStage::SetRenderingBehavior()
191 void SetRenderingBehavior( DevelStage::Rendering renderingBehavior );
194 * @copydoc Dali::DevelStage::GetRenderingBehavior()
196 DevelStage::Rendering GetRenderingBehavior() const;
199 * Callback for Internal::Scene EventProcessingFinished signal
201 void OnEventProcessingFinished();
204 * Callback for Internal::Scene KeyEventSignal signal
206 void OnKeyEvent( const Dali::KeyEvent& event );
209 * Callback for Internal::Scene TouchSignal signal
211 void OnTouchEvent( const Dali::TouchEvent& touch );
214 * Callback for Internal::Scene WheelEventSignal signal
216 void OnWheelEvent( const Dali::WheelEvent& event );
219 * Used by the EventProcessor to emit key event signals.
220 * @param[in] event The key event.
222 void EmitKeyEventSignal(const KeyEvent& event);
225 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
226 * @param[in] event The key event.
227 * @return The return is true if KeyEvent is consumed, otherwise false.
229 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
232 * Emits the event processing finished signal.
234 * @see Dali::Stage::SignalEventProcessingFinished()
236 void EmitEventProcessingFinishedSignal();
239 * Emits the touched signal.
240 * @param[in] touch The touch event details.
242 void EmitTouchedSignal( const Dali::TouchEvent& touch );
245 * Used by the EventProcessor to emit wheel event signals.
246 * @param[in] event The wheel event.
248 void EmitWheelEventSignal( const WheelEvent& event );
251 * Emits the scene created.
253 void EmitSceneCreatedSignal();
256 * @copydoc Dali::Stage::KeyEventSignal()
258 Dali::Stage::KeyEventSignalType& KeyEventSignal();
261 * @copydoc Dali::Stage::SignalEventProcessingFinished()
263 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
266 * @copydoc Dali::Stage::TouchSignal()
268 Dali::Stage::TouchSignalType& TouchSignal();
271 * @copydoc Dali::Stage::WheelEventSignal()
273 Dali::Stage::WheelEventSignalType& WheelEventSignal();
276 * @copydoc Dali::Stage::ContextLostSignal()
278 Dali::Stage::ContextStatusSignal& ContextLostSignal();
281 * @copydoc Dali::Stage::ContextRegainedSignal()
283 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
286 * @copydoc Dali::Stage::SceneCreatedSignal()
288 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
291 * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
293 Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
296 * @copydoc Dali::DevelStage::AddFrameCallback()
298 void AddFrameCallback( FrameCallbackInterface& frameCallback, Actor& rootActor );
301 * @copydoc Dali::DevelStage::RemoveFrameCallback()
303 void RemoveFrameCallback( FrameCallbackInterface& frameCallback );
306 * Connects a callback function with the object's signals.
307 * @param[in] object The object providing the signal.
308 * @param[in] tracker Used to disconnect the signal.
309 * @param[in] signalName The signal to connect to.
310 * @param[in] functor A newly allocated FunctorDelegate.
311 * @return True if the signal was connected.
312 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
314 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
316 private: // Implementation of ContextNotificationInterface:
319 * @copydoc Dali::Integration::NotifyContextLost();
321 virtual void NotifyContextLost();
324 * @copydoc Dali::Integration::NotifyContextRegained();
326 virtual void NotifyContextRegained();
331 * Protected constructor; see also Stage::New()
333 Stage( SceneGraph::UpdateManager& updateManager );
336 * A reference counted object may only be deleted by calling Unreference()
342 SceneGraph::UpdateManager& mUpdateManager;
344 IntrusivePtr<Scene> mScene;
346 // The key event signal
347 Dali::Stage::KeyEventSignalType mKeyEventSignal;
348 Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
350 // The event processing finished signal
351 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
353 // The touched signal
354 Dali::Stage::TouchSignalType mTouchSignal;
356 // The wheel event signal
357 Dali::Stage::WheelEventSignalType mWheelEventSignal;
359 Dali::Stage::ContextStatusSignal mContextLostSignal;
360 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
362 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
364 DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
367 } // namespace Internal
369 // Helpers for public-api forwarding methods
371 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
373 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
375 BaseObject& handle = stage.GetBaseObject();
377 return static_cast<Internal::Stage&>(handle);
380 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
382 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
384 const BaseObject& handle = stage.GetBaseObject();
386 return static_cast<const Internal::Stage&>(handle);
391 #endif // DALI_INTERNAL_STAGE_H