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/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>
47 class RenderController;
58 class AnimationPlaylist;
59 class PropertyNotificationManager;
67 * Implementation of Stage
69 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public EventThreadServices
75 * @param[in] playlist for animations
76 * @param[in] propertyNotificationManager
77 * @param[in] updateManager
78 * @param[in] notificationManager
79 * @param[in] renderController
81 static StagePtr New( AnimationPlaylist& playlist,
82 PropertyNotificationManager& propertyNotificationManager,
83 SceneGraph::UpdateManager& updateManager,
84 NotificationManager& notificationManager,
85 Integration::RenderController& renderController );
88 * Initialize the stage.
89 * @param[in] renderToFbo Whether to render into a Frame Buffer Object.
91 void Initialize( bool renderToFbo );
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( uint32_t 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 uint32_t GetLayerCount() const;
203 * @copydoc Dali::Stage::GetLayer()
205 Dali::Layer GetLayer( uint32_t 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 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
235 * set to receive keyboard input.
236 * @param[in] actor to receive keyboard input
238 void SetKeyboardFocusActor( Actor* actor );
241 * Get the actor that is currently set to receive keyboard inputs
242 * @return Pointer to the actor set to receive keyboard inputs.
244 Actor* GetKeyboardFocusActor() const;
247 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
248 * @param [in] actor which should be removed from focus.
250 void RemoveActorFromKeyFocus( Actor* actor );
255 * @copydoc Dali::Stage::SetBackgroundColor
257 void SetBackgroundColor(Vector4 color);
260 * @copydoc Dali::Stage::GetBackgroundColor
262 Vector4 GetBackgroundColor() const;
265 * @copydoc Dali::Stage::GetDpi
267 Vector2 GetDpi() const;
270 * Sets horizontal and vertical pixels per inch value that is used by the display
271 * @param[in] dpi Horizontal and vertical dpi value
273 void SetDpi( Vector2 dpi );
275 NotificationManager& GetNotificationManager()
277 return mNotificationManager;
281 * @copydoc Dali::Stage::KeepRendering()
283 void KeepRendering( float durationSeconds );
286 * @copydoc Dali::DevelStage::SetRenderingBehavior()
288 void SetRenderingBehavior( DevelStage::Rendering renderingBehavior );
291 * @copydoc Dali::DevelStage::GetRenderingBehavior()
293 DevelStage::Rendering GetRenderingBehavior() const;
296 * Used by the EventProcessor to emit key event signals.
297 * @param[in] event The key event.
299 void EmitKeyEventSignal(const KeyEvent& event);
302 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
303 * @param[in] event The key event.
304 * @return The return is true if KeyEvent is consumed, otherwise false.
306 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
309 * Emits the event processing finished signal.
311 * @see Dali::Stage::SignalEventProcessingFinished()
313 void EmitEventProcessingFinishedSignal();
316 * Emits the touched signal.
317 * @param[in] touchEvent The touch event details (Old API).
318 * @param[in] touch The touch event details.
320 void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
323 * Used by the EventProcessor to emit wheel event signals.
324 * @param[in] event The wheel event.
326 void EmitWheelEventSignal( const WheelEvent& event );
329 * Emits the scene created.
331 void EmitSceneCreatedSignal();
334 * @copydoc Dali::Stage::KeyEventSignal()
336 Dali::Stage::KeyEventSignalType& KeyEventSignal();
339 * @copydoc Dali::Stage::SignalEventProcessingFinished()
341 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
344 * @copydoc Dali::Stage::TouchedSignal()
346 Dali::Stage::TouchedSignalType& TouchedSignal();
349 * @copydoc Dali::Stage::TouchSignal()
351 Dali::Stage::TouchSignalType& TouchSignal();
354 * @copydoc Dali::Stage::WheelEventSignal()
356 Dali::Stage::WheelEventSignalType& WheelEventSignal();
359 * @copydoc Dali::Stage::ContextLostSignal()
361 Dali::Stage::ContextStatusSignal& ContextLostSignal();
364 * @copydoc Dali::Stage::ContextRegainedSignal()
366 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
369 * @copydoc Dali::Stage::SceneCreatedSignal()
371 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
374 * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
376 Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
379 * @copydoc Dali::DevelStage::AddFrameCallback()
381 void AddFrameCallback( FrameCallbackInterface& frameCallback, Actor& rootActor );
384 * @copydoc Dali::DevelStage::RemoveFrameCallback()
386 void RemoveFrameCallback( FrameCallbackInterface& frameCallback );
389 * Connects a callback function with the object's signals.
390 * @param[in] object The object providing the signal.
391 * @param[in] tracker Used to disconnect the signal.
392 * @param[in] signalName The signal to connect to.
393 * @param[in] functor A newly allocated FunctorDelegate.
394 * @return True if the signal was connected.
395 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
397 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
399 private: // Implementation of ContextNotificationInterface:
402 * @copydoc Dali::Integration::NotifyContextLost();
404 virtual void NotifyContextLost();
407 * @copydoc Dali::Integration::NotifyContextRegained();
409 virtual void NotifyContextRegained();
411 public: // Implementation of EventThreadServices
414 * @copydoc EventThreadServices::RegisterObject
416 virtual void RegisterObject( BaseObject* object);
419 * @copydoc EventThreadServices::UnregisterObject
421 virtual void UnregisterObject( BaseObject* object);
424 * @copydoc EventThreadServices::GetUpdateManager
426 virtual SceneGraph::UpdateManager& GetUpdateManager();
429 * @copydoc EventThreadServices::GetRenderController
431 virtual Integration::RenderController& GetRenderController();
434 * @copydoc EventThreadServices::ReserveMessageSlot
436 virtual uint32_t* ReserveMessageSlot( uint32_t size, bool updateScene );
439 * @copydoc EventThreadServices::GetEventBufferIndex
441 virtual BufferIndex GetEventBufferIndex() const;
444 * @copydoc EventThreadServices::ForceNextUpdate
446 virtual void ForceNextUpdate();
449 * @copydoc EventThreadServices::IsNextUpdateForced
451 virtual bool IsNextUpdateForced();
454 * Request that the depth tree is rebuilt
456 void RequestRebuildDepthTree();
459 * Rebuilds the depth tree at the end of the event frame if
460 * it was requested this frame.
462 void RebuildDepthTree();
467 * Protected constructor; see also Stage::New()
469 Stage( AnimationPlaylist& playlist,
470 PropertyNotificationManager& propertyNotificationManager,
471 SceneGraph::UpdateManager& updateManager,
472 NotificationManager& notificationManager,
473 Integration::RenderController& renderController );
476 * A reference counted object may only be deleted by calling Unreference()
482 // For 'Fire and forget' animation support
483 AnimationPlaylist& mAnimationPlaylist;
485 PropertyNotificationManager& mPropertyNotificationManager;
487 SceneGraph::UpdateManager& mUpdateManager;
489 NotificationManager& mNotificationManager;
491 Integration::RenderController& mRenderController;
493 // The stage-size may be less than surface-size (reduced by top-margin)
495 Vector2 mSurfaceSize;
497 // Cached for public GetBackgroundColor()
498 Vector4 mBackgroundColor;
502 // Ordered list of currently on-stage layers
503 OwnerPointer<LayerList> mLayerList;
505 IntrusivePtr<CameraActor> mDefaultCamera;
510 // The object registry
511 ObjectRegistryPtr mObjectRegistry;
513 // The list of render-tasks
514 IntrusivePtr<RenderTaskList> mRenderTaskList;
516 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
518 // The key event signal
519 Dali::Stage::KeyEventSignalType mKeyEventSignal;
520 Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
522 // The event processing finished signal
523 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
525 // The touched signals
526 Dali::Stage::TouchedSignalType mTouchedSignal;
527 Dali::Stage::TouchSignalType mTouchSignal;
529 // The wheel event signal
530 Dali::Stage::WheelEventSignalType mWheelEventSignal;
532 Dali::Stage::ContextStatusSignal mContextLostSignal;
533 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
535 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
537 DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
539 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
540 bool mForceNextUpdate:1; ///< True if the next rendering is really required.
541 bool mRenderToFbo:1; ///< Whether to render to a Frame Buffer Object.
544 } // namespace Internal
546 // Helpers for public-api forwarding methods
548 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
550 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
552 BaseObject& handle = stage.GetBaseObject();
554 return static_cast<Internal::Stage&>(handle);
557 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
559 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
561 const BaseObject& handle = stage.GetBaseObject();
563 return static_cast<const Internal::Stage&>(handle);
568 #endif // DALI_INTERNAL_STAGE_H