1 #ifndef __DALI_INTERNAL_STAGE_H__
2 #define __DALI_INTERNAL_STAGE_H__
5 * Copyright (c) 2017 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/object/ref-object.h>
23 #include <dali/public-api/common/stage.h>
24 #include <dali/devel-api/common/stage-devel.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/integration-api/context-notifier.h>
27 #include <dali/internal/common/owner-pointer.h>
28 #include <dali/internal/event/actors/layer-impl.h>
29 #include <dali/internal/event/common/event-thread-services.h>
30 #include <dali/internal/event/common/object-registry-impl.h>
31 #include <dali/internal/event/common/stage-def.h>
32 #include <dali/internal/event/render-tasks/render-task-defaults.h>
33 #include <dali/internal/update/manager/update-manager.h>
34 #include <dali/public-api/common/view-mode.h>
35 #include <dali/public-api/math/vector2.h>
36 #include <dali/public-api/math/vector3.h>
37 #include <dali/public-api/math/vector4.h>
38 #include <dali/public-api/render-tasks/render-task.h>
48 class RenderController;
59 class AnimationPlaylist;
60 class PropertyNotificationManager;
68 * Implementation of Stage
70 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public EventThreadServices
76 * @param[in] playlist for animations
77 * @param[in] propertyNotificationManager
78 * @param[in] updateManager
79 * @param[in] notificationManager
80 * @param[in] renderController
82 static StagePtr New( AnimationPlaylist& playlist,
83 PropertyNotificationManager& propertyNotificationManager,
84 SceneGraph::UpdateManager& updateManager,
85 NotificationManager& notificationManager,
86 Integration::RenderController& renderController );
89 * Initialize the stage.
94 * Uninitialize the stage.
99 * @copydoc Dali::Stage::GetCurrent()
100 * @note this version is for internal usage so it does not assert
102 static StagePtr GetCurrent();
105 * @copydoc Dali::Stage::IsInstalled().
107 static bool IsInstalled();
110 * @copydoc Dali::Stage::GetObjectRegistry()
112 ObjectRegistry& GetObjectRegistry();
115 * Retrieve the root actor (not publically accessible).
116 * @return The root actor.
118 Layer& GetRootActor();
121 * Returns the animation playlist.
122 * @return reference to the animation playlist.
124 AnimationPlaylist& GetAnimationPlaylist();
127 * Returns the property notification manager.
128 * @return reference to the property notification manager.
130 PropertyNotificationManager& GetPropertyNotificationManager();
132 // Root actor accessors
135 * @copydoc Dali::Stage::Add()
137 void Add( Actor& actor );
140 * @copydoc Dali::Stage::Remove()
142 void Remove( Actor& actor );
145 * Used to calculate the size of the stage and indirectly, the root actor.
146 * @param [in] width The new surface width.
147 * @param [in] height The new surface height.
149 void SurfaceResized( float width, float height );
152 * Sets the top margin size.
153 * Available stage size is reduced by this size.
154 * The stage is located below the size at the top of the display
155 * initial size is zero before it is assigned
156 * @param[in] margin margin size
158 void SetTopMargin( unsigned int margin );
161 * Returns the size of the Stage in pixels as a Vector.
162 * The x component will be the width of the Stage in pixels
163 * The y component will be the height of the Stage in pixels
164 * @return The size of the Stage as a Vector.
166 Vector2 GetSize() const;
169 * @copydoc Dali::Stage::GetRenderTaskList()
171 RenderTaskList& GetRenderTaskList() const;
174 * Create a default camera actor
176 void CreateDefaultCameraActor();
179 * Set position of default camera for current stage size
181 void SetDefaultCameraPosition();
184 * From RenderTaskDefaults; retrieve the default root actor.
185 * @return The default root actor.
187 virtual Actor& GetDefaultRootActor();
190 * From RenderTaskDefaults; retrieve the default camera actor.
191 * @return The default camera actor.
193 virtual CameraActor& GetDefaultCameraActor();
198 * @copydoc Dali::Stage::GetLayerCount()
200 unsigned int GetLayerCount() const;
203 * @copydoc Dali::Stage::GetLayer()
205 Dali::Layer GetLayer( unsigned int depth ) const;
208 * @copydoc Dali::Stage::GetRootLayer()
210 Dali::Layer GetRootLayer() const;
213 * Retrieve the ordered list of on-stage layers.
214 * @return The layer-list.
216 LayerList& GetLayerList();
218 // System-level overlay actors
221 * @copydoc Dali::Integration::Core::GetSystemOverlay()
223 Integration::SystemOverlay& GetSystemOverlay();
226 * Retrieve the internal implementation of the SystemOverlay.
227 * @return The implementation, or NULL if this has never been requested from Integration API.
229 SystemOverlay* GetSystemOverlayInternal();
234 * @copydoc Dali::Integration::Core::SetViewMode()
236 void SetViewMode( ViewMode viewMode );
239 * @copydoc Dali::Integration::Core::GetViewMode()
241 ViewMode GetViewMode() const;
244 * @copydoc Dali::Integration::Core::SetStereoBase()
246 void SetStereoBase( float stereoBase );
249 * @copydoc Dali::Integration::Core::GetStereoBase()
251 float GetStereoBase() const;
256 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
257 * set to receive keyboard input.
258 * @param[in] actor to receive keyboard input
260 void SetKeyboardFocusActor( Actor* actor );
263 * Get the actor that is currently set to receive keyboard inputs
264 * @return Pointer to the actor set to receive keyboard inputs.
266 Actor* GetKeyboardFocusActor() const;
269 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
270 * @param [in] actor which should be removed from focus.
272 void RemoveActorFromKeyFocus( Actor* actor );
277 * @copydoc Dali::Stage::SetBackgroundColor
279 void SetBackgroundColor(Vector4 color);
282 * @copydoc Dali::Stage::GetBackgroundColor
284 Vector4 GetBackgroundColor() const;
287 * @copydoc Dali::Stage::GetDpi
289 Vector2 GetDpi() const;
292 * Sets horizontal and vertical pixels per inch value that is used by the display
293 * @param[in] dpi Horizontal and vertical dpi value
295 void SetDpi( Vector2 dpi );
297 NotificationManager& GetNotificationManager()
299 return mNotificationManager;
303 * @copydoc Dali::Stage::KeepRendering()
305 void KeepRendering( float durationSeconds );
308 * Used by the EventProcessor to emit key event signals.
309 * @param[in] event The key event.
311 void EmitKeyEventSignal(const KeyEvent& event);
314 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
315 * @param[in] event The key event.
316 * @return The return is true if KeyEvent is consumed, otherwise false.
318 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
321 * Emits the event processing finished signal.
323 * @see Dali::Stage::SignalEventProcessingFinished()
325 void EmitEventProcessingFinishedSignal();
328 * Emits the touched signal.
329 * @param[in] touchEvent The touch event details (Old API).
330 * @param[in] touch The touch event details.
332 void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
335 * Used by the EventProcessor to emit wheel event signals.
336 * @param[in] event The wheel event.
338 void EmitWheelEventSignal( const WheelEvent& event );
341 * Emits the scene created.
343 void EmitSceneCreatedSignal();
346 * @copydoc Dali::Stage::KeyEventSignal()
348 Dali::Stage::KeyEventSignalType& KeyEventSignal();
351 * @copydoc Dali::Stage::SignalEventProcessingFinished()
353 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
356 * @copydoc Dali::Stage::TouchedSignal()
358 Dali::Stage::TouchedSignalType& TouchedSignal();
361 * @copydoc Dali::Stage::TouchSignal()
363 Dali::Stage::TouchSignalType& TouchSignal();
366 * @copydoc Dali::Stage::WheelEventSignal()
368 Dali::Stage::WheelEventSignalType& WheelEventSignal();
371 * @copydoc Dali::Stage::ContextLostSignal()
373 Dali::Stage::ContextStatusSignal& ContextLostSignal();
376 * @copydoc Dali::Stage::ContextRegainedSignal()
378 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
381 * @copydoc Dali::Stage::SceneCreatedSignal()
383 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
386 * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
388 Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
391 * Connects a callback function with the object's signals.
392 * @param[in] object The object providing the signal.
393 * @param[in] tracker Used to disconnect the signal.
394 * @param[in] signalName The signal to connect to.
395 * @param[in] functor A newly allocated FunctorDelegate.
396 * @return True if the signal was connected.
397 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
399 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
401 private: // Implementation of ContextNotificationInterface:
404 * @copydoc Dali::Integration::NotifyContextLost();
406 virtual void NotifyContextLost();
409 * @copydoc Dali::Integration::NotifyContextRegained();
411 virtual void NotifyContextRegained();
413 public: // Implementation of EventThreadServices
416 * @copydoc EventThreadServices::RegisterObject
418 virtual void RegisterObject( BaseObject* object);
421 * @copydoc EventThreadServices::UnregisterObject
423 virtual void UnregisterObject( BaseObject* object);
426 * @copydoc EventThreadServices::GetUpdateManager
428 virtual SceneGraph::UpdateManager& GetUpdateManager();
431 * @copydoc EventThreadServices::GetRenderController
433 virtual Integration::RenderController& GetRenderController();
436 * @copydoc EventThreadServices::ReserveMessageSlot
438 virtual unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene );
441 * @copydoc EventThreadServices::GetEventBufferIndex
443 virtual BufferIndex GetEventBufferIndex() const;
446 * @copydoc EventThreadServices::ForceNextUpdate
448 virtual void ForceNextUpdate();
451 * @copydoc EventThreadServices::IsNextUpdateForced
453 virtual bool IsNextUpdateForced();
456 * Request that the depth tree is rebuilt
458 void RequestRebuildDepthTree();
461 * Rebuilds the depth tree at the end of the event frame if
462 * it was requested this frame.
464 void RebuildDepthTree();
469 * Protected constructor; see also Stage::New()
471 Stage( AnimationPlaylist& playlist,
472 PropertyNotificationManager& propertyNotificationManager,
473 SceneGraph::UpdateManager& updateManager,
474 NotificationManager& notificationManager,
475 Integration::RenderController& renderController );
478 * A reference counted object may only be deleted by calling Unreference()
484 // For 'Fire and forget' animation support
485 AnimationPlaylist& mAnimationPlaylist;
487 PropertyNotificationManager& mPropertyNotificationManager;
489 SceneGraph::UpdateManager& mUpdateManager;
491 NotificationManager& mNotificationManager;
493 Integration::RenderController& mRenderController;
495 // The stage-size may be less than surface-size (reduced by top-margin)
497 Vector2 mSurfaceSize;
499 // Cached for public GetBackgroundColor()
500 Vector4 mBackgroundColor;
504 // Ordered list of currently on-stage layers
505 OwnerPointer<LayerList> mLayerList;
507 IntrusivePtr<CameraActor> mDefaultCamera;
512 unsigned int mTopMargin;
515 // The object registry
516 ObjectRegistryPtr mObjectRegistry;
518 // The list of render-tasks
519 IntrusivePtr<RenderTaskList> mRenderTaskList;
521 Dali::RenderTask mRightRenderTask;
522 IntrusivePtr<CameraActor> mRightCamera;
523 Dali::RenderTask mLeftRenderTask;
524 IntrusivePtr<CameraActor> mLeftCamera;
526 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
528 bool mDepthTreeDirty; ///< True if the depth tree needs recalculating
529 bool mForceNextUpdate; ///< True if the next rendering is really required.
531 // The key event signal
532 Dali::Stage::KeyEventSignalType mKeyEventSignal;
533 Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
535 // The event processing finished signal
536 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
538 // The touched signals
539 Dali::Stage::TouchedSignalType mTouchedSignal;
540 Dali::Stage::TouchSignalType mTouchSignal;
542 // The wheel event signal
543 Dali::Stage::WheelEventSignalType mWheelEventSignal;
545 Dali::Stage::ContextStatusSignal mContextLostSignal;
546 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
548 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
551 } // namespace Internal
553 // Helpers for public-api forwarding methods
555 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
557 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
559 BaseObject& handle = stage.GetBaseObject();
561 return static_cast<Internal::Stage&>(handle);
564 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
566 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
568 const BaseObject& handle = stage.GetBaseObject();
570 return static_cast<const Internal::Stage&>(handle);
575 #endif // __DALI_INTERNAL_STAGE_H__