1 #ifndef DALI_INTERNAL_STAGE_H
2 #define DALI_INTERNAL_STAGE_H
5 * Copyright (c) 2019 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/public-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 TouchedEventSignal signal
211 void OnTouchedEvent( const Dali::TouchEvent& touch );
214 * Callback for Internal::Scene TouchSignal signal
216 void OnTouchEvent( const Dali::TouchData& touch );
219 * Callback for Internal::Scene WheelEventSignal signal
221 void OnWheelEvent( const Dali::WheelEvent& event );
224 * Used by the EventProcessor to emit key event signals.
225 * @param[in] event The key event.
227 void EmitKeyEventSignal(const KeyEvent& event);
230 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
231 * @param[in] event The key event.
232 * @return The return is true if KeyEvent is consumed, otherwise false.
234 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
237 * Emits the event processing finished signal.
239 * @see Dali::Stage::SignalEventProcessingFinished()
241 void EmitEventProcessingFinishedSignal();
244 * Emits the touched signal.
245 * @param[in] touchEvent The touch event details (Old API).
246 * @param[in] touch The touch event details.
248 void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
251 * Used by the EventProcessor to emit wheel event signals.
252 * @param[in] event The wheel event.
254 void EmitWheelEventSignal( const WheelEvent& event );
257 * Emits the scene created.
259 void EmitSceneCreatedSignal();
262 * @copydoc Dali::Stage::KeyEventSignal()
264 Dali::Stage::KeyEventSignalType& KeyEventSignal();
267 * @copydoc Dali::Stage::SignalEventProcessingFinished()
269 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
272 * @copydoc Dali::Stage::TouchedSignal()
274 Dali::Stage::TouchedSignalType& TouchedSignal();
277 * @copydoc Dali::Stage::TouchSignal()
279 Dali::Stage::TouchSignalType& TouchSignal();
282 * @copydoc Dali::Stage::WheelEventSignal()
284 Dali::Stage::WheelEventSignalType& WheelEventSignal();
287 * @copydoc Dali::Stage::ContextLostSignal()
289 Dali::Stage::ContextStatusSignal& ContextLostSignal();
292 * @copydoc Dali::Stage::ContextRegainedSignal()
294 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
297 * @copydoc Dali::Stage::SceneCreatedSignal()
299 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
302 * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
304 Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
307 * @copydoc Dali::DevelStage::AddFrameCallback()
309 void AddFrameCallback( FrameCallbackInterface& frameCallback, Actor& rootActor );
312 * @copydoc Dali::DevelStage::RemoveFrameCallback()
314 void RemoveFrameCallback( FrameCallbackInterface& frameCallback );
317 * Connects a callback function with the object's signals.
318 * @param[in] object The object providing the signal.
319 * @param[in] tracker Used to disconnect the signal.
320 * @param[in] signalName The signal to connect to.
321 * @param[in] functor A newly allocated FunctorDelegate.
322 * @return True if the signal was connected.
323 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
325 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
327 private: // Implementation of ContextNotificationInterface:
330 * @copydoc Dali::Integration::NotifyContextLost();
332 virtual void NotifyContextLost();
335 * @copydoc Dali::Integration::NotifyContextRegained();
337 virtual void NotifyContextRegained();
342 * Protected constructor; see also Stage::New()
344 Stage( SceneGraph::UpdateManager& updateManager );
347 * A reference counted object may only be deleted by calling Unreference()
353 SceneGraph::UpdateManager& mUpdateManager;
355 IntrusivePtr<Scene> mScene;
357 // The key event signal
358 Dali::Stage::KeyEventSignalType mKeyEventSignal;
359 Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
361 // The event processing finished signal
362 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
364 // The touched signals
365 Dali::Stage::TouchedSignalType mTouchedSignal;
366 Dali::Stage::TouchSignalType mTouchSignal;
368 // The wheel event signal
369 Dali::Stage::WheelEventSignalType mWheelEventSignal;
371 Dali::Stage::ContextStatusSignal mContextLostSignal;
372 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
374 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
376 DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
379 } // namespace Internal
381 // Helpers for public-api forwarding methods
383 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
385 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
387 BaseObject& handle = stage.GetBaseObject();
389 return static_cast<Internal::Stage&>(handle);
392 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
394 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
396 const BaseObject& handle = stage.GetBaseObject();
398 return static_cast<const Internal::Stage&>(handle);
403 #endif // DALI_INTERNAL_STAGE_H