1 #ifndef DALI_INTERNAL_STAGE_H
2 #define DALI_INTERNAL_STAGE_H
5 * Copyright (c) 2018 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.
90 * @param[in] renderToFbo Whether to render into a Frame Buffer Object.
92 void Initialize( bool renderToFbo );
95 * Uninitialize the stage.
100 * @copydoc Dali::Stage::GetCurrent()
101 * @note this version is for internal usage so it does not assert
103 static StagePtr GetCurrent();
106 * @copydoc Dali::Stage::IsInstalled().
108 static bool IsInstalled();
111 * @copydoc Dali::Stage::GetObjectRegistry()
113 ObjectRegistry& GetObjectRegistry();
116 * Retrieve the root actor (not publically accessible).
117 * @return The root actor.
119 Layer& GetRootActor();
122 * Returns the animation playlist.
123 * @return reference to the animation playlist.
125 AnimationPlaylist& GetAnimationPlaylist();
128 * Returns the property notification manager.
129 * @return reference to the property notification manager.
131 PropertyNotificationManager& GetPropertyNotificationManager();
133 // Root actor accessors
136 * @copydoc Dali::Stage::Add()
138 void Add( Actor& actor );
141 * @copydoc Dali::Stage::Remove()
143 void Remove( Actor& actor );
146 * Used to calculate the size of the stage and indirectly, the root actor.
147 * @param [in] width The new surface width.
148 * @param [in] height The new surface height.
150 void SurfaceResized( float width, float height );
153 * Sets the top margin size.
154 * Available stage size is reduced by this size.
155 * The stage is located below the size at the top of the display
156 * initial size is zero before it is assigned
157 * @param[in] margin margin size
159 void SetTopMargin( uint32_t margin );
162 * Returns the size of the Stage in pixels as a Vector.
163 * The x component will be the width of the Stage in pixels
164 * The y component will be the height of the Stage in pixels
165 * @return The size of the Stage as a Vector.
167 Vector2 GetSize() const;
170 * @copydoc Dali::Stage::GetRenderTaskList()
172 RenderTaskList& GetRenderTaskList() const;
175 * Create a default camera actor
177 void CreateDefaultCameraActor();
180 * Set position of default camera for current stage size
182 void SetDefaultCameraPosition();
185 * From RenderTaskDefaults; retrieve the default root actor.
186 * @return The default root actor.
188 virtual Actor& GetDefaultRootActor();
191 * From RenderTaskDefaults; retrieve the default camera actor.
192 * @return The default camera actor.
194 virtual CameraActor& GetDefaultCameraActor();
199 * @copydoc Dali::Stage::GetLayerCount()
201 uint32_t GetLayerCount() const;
204 * @copydoc Dali::Stage::GetLayer()
206 Dali::Layer GetLayer( uint32_t depth ) const;
209 * @copydoc Dali::Stage::GetRootLayer()
211 Dali::Layer GetRootLayer() const;
214 * Retrieve the ordered list of on-stage layers.
215 * @return The layer-list.
217 LayerList& GetLayerList();
219 // System-level overlay actors
222 * @copydoc Dali::Integration::Core::GetSystemOverlay()
224 Integration::SystemOverlay& GetSystemOverlay();
227 * Retrieve the internal implementation of the SystemOverlay.
228 * @return The implementation, or NULL if this has never been requested from Integration API.
230 SystemOverlay* GetSystemOverlayInternal();
235 * @copydoc Dali::Integration::Core::SetViewMode()
237 void SetViewMode( ViewMode viewMode );
240 * @copydoc Dali::Integration::Core::GetViewMode()
242 ViewMode GetViewMode() const;
245 * @copydoc Dali::Integration::Core::SetStereoBase()
247 void SetStereoBase( float stereoBase );
250 * @copydoc Dali::Integration::Core::GetStereoBase()
252 float GetStereoBase() const;
257 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
258 * set to receive keyboard input.
259 * @param[in] actor to receive keyboard input
261 void SetKeyboardFocusActor( Actor* actor );
264 * Get the actor that is currently set to receive keyboard inputs
265 * @return Pointer to the actor set to receive keyboard inputs.
267 Actor* GetKeyboardFocusActor() const;
270 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
271 * @param [in] actor which should be removed from focus.
273 void RemoveActorFromKeyFocus( Actor* actor );
278 * @copydoc Dali::Stage::SetBackgroundColor
280 void SetBackgroundColor(Vector4 color);
283 * @copydoc Dali::Stage::GetBackgroundColor
285 Vector4 GetBackgroundColor() const;
288 * @copydoc Dali::Stage::GetDpi
290 Vector2 GetDpi() const;
293 * Sets horizontal and vertical pixels per inch value that is used by the display
294 * @param[in] dpi Horizontal and vertical dpi value
296 void SetDpi( Vector2 dpi );
298 NotificationManager& GetNotificationManager()
300 return mNotificationManager;
304 * @copydoc Dali::Stage::KeepRendering()
306 void KeepRendering( float durationSeconds );
309 * @copydoc Dali::DevelStage::SetRenderingBehavior()
311 void SetRenderingBehavior( DevelStage::Rendering renderingBehavior );
314 * @copydoc Dali::DevelStage::GetRenderingBehavior()
316 DevelStage::Rendering GetRenderingBehavior() const;
319 * Used by the EventProcessor to emit key event signals.
320 * @param[in] event The key event.
322 void EmitKeyEventSignal(const KeyEvent& event);
325 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
326 * @param[in] event The key event.
327 * @return The return is true if KeyEvent is consumed, otherwise false.
329 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
332 * Emits the event processing finished signal.
334 * @see Dali::Stage::SignalEventProcessingFinished()
336 void EmitEventProcessingFinishedSignal();
339 * Emits the touched signal.
340 * @param[in] touchEvent The touch event details (Old API).
341 * @param[in] touch The touch event details.
343 void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
346 * Used by the EventProcessor to emit wheel event signals.
347 * @param[in] event The wheel event.
349 void EmitWheelEventSignal( const WheelEvent& event );
352 * Emits the scene created.
354 void EmitSceneCreatedSignal();
357 * @copydoc Dali::Stage::KeyEventSignal()
359 Dali::Stage::KeyEventSignalType& KeyEventSignal();
362 * @copydoc Dali::Stage::SignalEventProcessingFinished()
364 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
367 * @copydoc Dali::Stage::TouchedSignal()
369 Dali::Stage::TouchedSignalType& TouchedSignal();
372 * @copydoc Dali::Stage::TouchSignal()
374 Dali::Stage::TouchSignalType& TouchSignal();
377 * @copydoc Dali::Stage::WheelEventSignal()
379 Dali::Stage::WheelEventSignalType& WheelEventSignal();
382 * @copydoc Dali::Stage::ContextLostSignal()
384 Dali::Stage::ContextStatusSignal& ContextLostSignal();
387 * @copydoc Dali::Stage::ContextRegainedSignal()
389 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
392 * @copydoc Dali::Stage::SceneCreatedSignal()
394 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
397 * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
399 Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
402 * @copydoc Dali::DevelStage::AddFrameCallback()
404 void AddFrameCallback( FrameCallbackInterface& frameCallback, Actor& rootActor );
407 * @copydoc Dali::DevelStage::RemoveFrameCallback()
409 void RemoveFrameCallback( FrameCallbackInterface& frameCallback );
412 * Connects a callback function with the object's signals.
413 * @param[in] object The object providing the signal.
414 * @param[in] tracker Used to disconnect the signal.
415 * @param[in] signalName The signal to connect to.
416 * @param[in] functor A newly allocated FunctorDelegate.
417 * @return True if the signal was connected.
418 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
420 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
422 private: // Implementation of ContextNotificationInterface:
425 * @copydoc Dali::Integration::NotifyContextLost();
427 virtual void NotifyContextLost();
430 * @copydoc Dali::Integration::NotifyContextRegained();
432 virtual void NotifyContextRegained();
434 public: // Implementation of EventThreadServices
437 * @copydoc EventThreadServices::RegisterObject
439 virtual void RegisterObject( BaseObject* object);
442 * @copydoc EventThreadServices::UnregisterObject
444 virtual void UnregisterObject( BaseObject* object);
447 * @copydoc EventThreadServices::GetUpdateManager
449 virtual SceneGraph::UpdateManager& GetUpdateManager();
452 * @copydoc EventThreadServices::GetRenderController
454 virtual Integration::RenderController& GetRenderController();
457 * @copydoc EventThreadServices::ReserveMessageSlot
459 virtual uint32_t* ReserveMessageSlot( uint32_t size, bool updateScene );
462 * @copydoc EventThreadServices::GetEventBufferIndex
464 virtual BufferIndex GetEventBufferIndex() const;
467 * @copydoc EventThreadServices::ForceNextUpdate
469 virtual void ForceNextUpdate();
472 * @copydoc EventThreadServices::IsNextUpdateForced
474 virtual bool IsNextUpdateForced();
477 * Request that the depth tree is rebuilt
479 void RequestRebuildDepthTree();
482 * Rebuilds the depth tree at the end of the event frame if
483 * it was requested this frame.
485 void RebuildDepthTree();
490 * Protected constructor; see also Stage::New()
492 Stage( AnimationPlaylist& playlist,
493 PropertyNotificationManager& propertyNotificationManager,
494 SceneGraph::UpdateManager& updateManager,
495 NotificationManager& notificationManager,
496 Integration::RenderController& renderController );
499 * A reference counted object may only be deleted by calling Unreference()
505 // For 'Fire and forget' animation support
506 AnimationPlaylist& mAnimationPlaylist;
508 PropertyNotificationManager& mPropertyNotificationManager;
510 SceneGraph::UpdateManager& mUpdateManager;
512 NotificationManager& mNotificationManager;
514 Integration::RenderController& mRenderController;
516 // The stage-size may be less than surface-size (reduced by top-margin)
518 Vector2 mSurfaceSize;
520 // Cached for public GetBackgroundColor()
521 Vector4 mBackgroundColor;
525 // Ordered list of currently on-stage layers
526 OwnerPointer<LayerList> mLayerList;
528 IntrusivePtr<CameraActor> mDefaultCamera;
536 // The object registry
537 ObjectRegistryPtr mObjectRegistry;
539 // The list of render-tasks
540 IntrusivePtr<RenderTaskList> mRenderTaskList;
542 Dali::RenderTask mRightRenderTask;
543 IntrusivePtr<CameraActor> mRightCamera;
544 Dali::RenderTask mLeftRenderTask;
545 IntrusivePtr<CameraActor> mLeftCamera;
547 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
549 // The key event signal
550 Dali::Stage::KeyEventSignalType mKeyEventSignal;
551 Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
553 // The event processing finished signal
554 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
556 // The touched signals
557 Dali::Stage::TouchedSignalType mTouchedSignal;
558 Dali::Stage::TouchSignalType mTouchSignal;
560 // The wheel event signal
561 Dali::Stage::WheelEventSignalType mWheelEventSignal;
563 Dali::Stage::ContextStatusSignal mContextLostSignal;
564 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
566 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
568 DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
570 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
571 bool mForceNextUpdate:1; ///< True if the next rendering is really required.
572 bool mRenderToFbo:1; ///< Whether to render to a Frame Buffer Object.
575 } // namespace Internal
577 // Helpers for public-api forwarding methods
579 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
581 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
583 BaseObject& handle = stage.GetBaseObject();
585 return static_cast<Internal::Stage&>(handle);
588 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
590 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
592 const BaseObject& handle = stage.GetBaseObject();
594 return static_cast<const Internal::Stage&>(handle);
599 #endif // DALI_INTERNAL_STAGE_H