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.
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 * Used to calculate the size and orientation of the stage and indirectly, the root actor.
154 * @param [in] width The new surface width.
155 * @param [in] height The new surface height.
156 * @param [in] orientation The new surface orientation.
158 void SurfaceResized( float width, float height, int orientation );
161 * Sets the top margin size.
162 * Available stage size is reduced by this size.
163 * The stage is located below the size at the top of the display
164 * initial size is zero before it is assigned
165 * @param[in] margin margin size
167 void SetTopMargin( unsigned int margin );
170 * Returns the size of the Stage in pixels as a Vector.
171 * The x component will be the width of the Stage in pixels
172 * The y component will be the height of the Stage in pixels
173 * @return The size of the Stage as a Vector.
175 Vector2 GetSize() const;
178 * @copydoc Dali::Stage::GetRenderTaskList()
180 RenderTaskList& GetRenderTaskList() const;
183 * Create a default camera actor
185 void CreateDefaultCameraActor();
188 * Set position of default camera for current stage size
190 void SetDefaultCameraPosition();
193 * From RenderTaskDefaults; retrieve the default root actor.
194 * @return The default root actor.
196 virtual Actor& GetDefaultRootActor();
199 * From RenderTaskDefaults; retrieve the default camera actor.
200 * @return The default camera actor.
202 virtual CameraActor& GetDefaultCameraActor();
207 * @copydoc Dali::Stage::GetLayerCount()
209 unsigned int GetLayerCount() const;
212 * @copydoc Dali::Stage::GetLayer()
214 Dali::Layer GetLayer( unsigned int depth ) const;
217 * @copydoc Dali::Stage::GetRootLayer()
219 Dali::Layer GetRootLayer() const;
222 * Retrieve the ordered list of on-stage layers.
223 * @return The layer-list.
225 LayerList& GetLayerList();
227 // System-level overlay actors
230 * @copydoc Dali::Integration::Core::GetSystemOverlay()
232 Integration::SystemOverlay& GetSystemOverlay();
235 * Retrieve the internal implementation of the SystemOverlay.
236 * @return The implementation, or NULL if this has never been requested from Integration API.
238 SystemOverlay* GetSystemOverlayInternal();
243 * @copydoc Dali::Integration::Core::SetViewMode()
245 void SetViewMode( ViewMode viewMode );
248 * @copydoc Dali::Integration::Core::GetViewMode()
250 ViewMode GetViewMode() const;
253 * @copydoc Dali::Integration::Core::SetStereoBase()
255 void SetStereoBase( float stereoBase );
258 * @copydoc Dali::Integration::Core::GetStereoBase()
260 float GetStereoBase() const;
265 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
266 * set to receive keyboard input.
267 * @param[in] actor to receive keyboard input
269 void SetKeyboardFocusActor( Actor* actor );
272 * Get the actor that is currently set to receive keyboard inputs
273 * @return Pointer to the actor set to receive keyboard inputs.
275 Actor* GetKeyboardFocusActor() const;
278 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
279 * @param [in] actor which should be removed from focus.
281 void RemoveActorFromKeyFocus( Actor* actor );
286 * @copydoc Dali::Stage::SetBackgroundColor
288 void SetBackgroundColor(Vector4 color);
291 * @copydoc Dali::Stage::GetBackgroundColor
293 Vector4 GetBackgroundColor() const;
296 * @copydoc Dali::Stage::GetDpi
298 Vector2 GetDpi() const;
301 * Sets horizontal and vertical pixels per inch value that is used by the display
302 * @param[in] dpi Horizontal and vertical dpi value
304 void SetDpi( Vector2 dpi );
306 NotificationManager& GetNotificationManager()
308 return mNotificationManager;
312 * @copydoc Dali::Stage::KeepRendering()
314 void KeepRendering( float durationSeconds );
317 * Used by the EventProcessor to emit key event signals.
318 * @param[in] event The key event.
320 void EmitKeyEventSignal(const KeyEvent& event);
323 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
324 * @param[in] event The key event.
325 * @return The return is true if KeyEvent is consumed, otherwise false.
327 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
330 * Emits the event processing finished signal.
332 * @see Dali::Stage::SignalEventProcessingFinished()
334 void EmitEventProcessingFinishedSignal();
337 * Emits the touched signal.
338 * @param[in] touchEvent The touch event details (Old API).
339 * @param[in] touch The touch event details.
341 void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
344 * Used by the EventProcessor to emit wheel event signals.
345 * @param[in] event The wheel event.
347 void EmitWheelEventSignal( const WheelEvent& event );
350 * Emits the scene created.
352 void EmitSceneCreatedSignal();
355 * @copydoc Dali::Stage::KeyEventSignal()
357 Dali::Stage::KeyEventSignalType& KeyEventSignal();
360 * @copydoc Dali::Stage::SignalEventProcessingFinished()
362 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
365 * @copydoc Dali::Stage::TouchedSignal()
367 Dali::Stage::TouchedSignalType& TouchedSignal();
370 * @copydoc Dali::Stage::TouchSignal()
372 Dali::Stage::TouchSignalType& TouchSignal();
375 * @copydoc Dali::Stage::WheelEventSignal()
377 Dali::Stage::WheelEventSignalType& WheelEventSignal();
380 * @copydoc Dali::Stage::ContextLostSignal()
382 Dali::Stage::ContextStatusSignal& ContextLostSignal();
385 * @copydoc Dali::Stage::ContextRegainedSignal()
387 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
390 * @copydoc Dali::Stage::SceneCreatedSignal()
392 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
395 * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
397 Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
400 * Connects a callback function with the object's signals.
401 * @param[in] object The object providing the signal.
402 * @param[in] tracker Used to disconnect the signal.
403 * @param[in] signalName The signal to connect to.
404 * @param[in] functor A newly allocated FunctorDelegate.
405 * @return True if the signal was connected.
406 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
408 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
410 private: // Implementation of ContextNotificationInterface:
413 * @copydoc Dali::Integration::NotifyContextLost();
415 virtual void NotifyContextLost();
418 * @copydoc Dali::Integration::NotifyContextRegained();
420 virtual void NotifyContextRegained();
422 public: // Implementation of EventThreadServices
425 * @copydoc EventThreadServices::RegisterObject
427 virtual void RegisterObject( BaseObject* object);
430 * @copydoc EventThreadServices::UnregisterObject
432 virtual void UnregisterObject( BaseObject* object);
435 * @copydoc EventThreadServices::GetUpdateManager
437 virtual SceneGraph::UpdateManager& GetUpdateManager();
440 * @copydoc EventThreadServices::GetRenderController
442 virtual Integration::RenderController& GetRenderController();
445 * @copydoc EventThreadServices::ReserveMessageSlot
447 virtual unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene );
450 * @copydoc EventThreadServices::GetEventBufferIndex
452 virtual BufferIndex GetEventBufferIndex() const;
455 * @copydoc EventThreadServices::ForceNextUpdate
457 virtual void ForceNextUpdate();
460 * @copydoc EventThreadServices::IsNextUpdateForced
462 virtual bool IsNextUpdateForced();
465 * Request that the depth tree is rebuilt
467 void RequestRebuildDepthTree();
470 * Rebuilds the depth tree at the end of the event frame if
471 * it was requested this frame.
473 void RebuildDepthTree();
478 * Protected constructor; see also Stage::New()
480 Stage( AnimationPlaylist& playlist,
481 PropertyNotificationManager& propertyNotificationManager,
482 SceneGraph::UpdateManager& updateManager,
483 NotificationManager& notificationManager,
484 Integration::RenderController& renderController );
487 * A reference counted object may only be deleted by calling Unreference()
493 // For 'Fire and forget' animation support
494 AnimationPlaylist& mAnimationPlaylist;
496 PropertyNotificationManager& mPropertyNotificationManager;
498 SceneGraph::UpdateManager& mUpdateManager;
500 NotificationManager& mNotificationManager;
502 Integration::RenderController& mRenderController;
504 // The stage-size may be less than surface-size (reduced by top-margin)
506 Vector2 mSurfaceSize;
508 // Cached for public GetBackgroundColor()
509 Vector4 mBackgroundColor;
513 // Ordered list of currently on-stage layers
514 OwnerPointer<LayerList> mLayerList;
516 IntrusivePtr<CameraActor> mDefaultCamera;
521 unsigned int mTopMargin;
524 // The object registry
525 ObjectRegistryPtr mObjectRegistry;
527 // The list of render-tasks
528 IntrusivePtr<RenderTaskList> mRenderTaskList;
530 Dali::RenderTask mRightRenderTask;
531 IntrusivePtr<CameraActor> mRightCamera;
532 Dali::RenderTask mLeftRenderTask;
533 IntrusivePtr<CameraActor> mLeftCamera;
535 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
537 // The key event signal
538 Dali::Stage::KeyEventSignalType mKeyEventSignal;
539 Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
541 // The event processing finished signal
542 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
544 // The touched signals
545 Dali::Stage::TouchedSignalType mTouchedSignal;
546 Dali::Stage::TouchSignalType mTouchSignal;
548 // The wheel event signal
549 Dali::Stage::WheelEventSignalType mWheelEventSignal;
551 Dali::Stage::ContextStatusSignal mContextLostSignal;
552 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
554 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
556 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
557 bool mForceNextUpdate:1; ///< True if the next rendering is really required.
558 bool mRenderToFbo:1; ///< Whether to render to a Frame Buffer Object.
560 bool mNeedToRotation:1;
561 int mCurrentOrientation;
564 } // namespace Internal
566 // Helpers for public-api forwarding methods
568 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
570 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
572 BaseObject& handle = stage.GetBaseObject();
574 return static_cast<Internal::Stage&>(handle);
577 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
579 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
581 const BaseObject& handle = stage.GetBaseObject();
583 return static_cast<const Internal::Stage&>(handle);
588 #endif // DALI_INTERNAL_STAGE_H