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>
46 class RenderController;
57 class AnimationPlaylist;
58 class PropertyNotificationManager;
65 * Implementation of Stage
67 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public EventThreadServices
73 * @param[in] playlist for animations
74 * @param[in] propertyNotificationManager
75 * @param[in] updateManager
76 * @param[in] notificationManager
77 * @param[in] renderController
79 static StagePtr New( AnimationPlaylist& playlist,
80 PropertyNotificationManager& propertyNotificationManager,
81 SceneGraph::UpdateManager& updateManager,
82 NotificationManager& notificationManager,
83 Integration::RenderController& renderController );
86 * Initialize the stage.
87 * @param[in] renderToFbo Whether to render into a Frame Buffer Object.
89 void Initialize( bool renderToFbo );
92 * Uninitialize the stage.
97 * @copydoc Dali::Stage::GetCurrent()
98 * @note this version is for internal usage so it does not assert
100 static StagePtr GetCurrent();
103 * @copydoc Dali::Stage::IsInstalled().
105 static bool IsInstalled();
108 * @copydoc Dali::Stage::GetObjectRegistry()
110 ObjectRegistry& GetObjectRegistry();
113 * Retrieve the root actor (not publically accessible).
114 * @return The root actor.
116 Layer& GetRootActor();
119 * Returns the animation playlist.
120 * @return reference to the animation playlist.
122 AnimationPlaylist& GetAnimationPlaylist();
125 * Returns the property notification manager.
126 * @return reference to the property notification manager.
128 PropertyNotificationManager& GetPropertyNotificationManager();
130 // Root actor accessors
133 * @copydoc Dali::Stage::Add()
135 void Add( Actor& actor );
138 * @copydoc Dali::Stage::Remove()
140 void Remove( Actor& actor );
143 * Used to calculate the size of the stage and indirectly, the root actor.
144 * @param [in] width The new surface width.
145 * @param [in] height The new surface height.
147 void SurfaceResized( float width, float height );
150 * Sets the top margin size.
151 * Available stage size is reduced by this size.
152 * The stage is located below the size at the top of the display
153 * initial size is zero before it is assigned
154 * @param[in] margin margin size
156 void SetTopMargin( uint32_t margin );
159 * Returns the size of the Stage in pixels as a Vector.
160 * The x component will be the width of the Stage in pixels
161 * The y component will be the height of the Stage in pixels
162 * @return The size of the Stage as a Vector.
164 Vector2 GetSize() const;
167 * @copydoc Dali::Stage::GetRenderTaskList()
169 RenderTaskList& GetRenderTaskList() const;
172 * Create a default camera actor
174 void CreateDefaultCameraActor();
177 * Set position of default camera for current stage size
179 void SetDefaultCameraPosition();
182 * From RenderTaskDefaults; retrieve the default root actor.
183 * @return The default root actor.
185 virtual Actor& GetDefaultRootActor();
188 * From RenderTaskDefaults; retrieve the default camera actor.
189 * @return The default camera actor.
191 virtual CameraActor& GetDefaultCameraActor();
196 * @copydoc Dali::Stage::GetLayerCount()
198 uint32_t GetLayerCount() const;
201 * @copydoc Dali::Stage::GetLayer()
203 Dali::Layer GetLayer( uint32_t depth ) const;
206 * @copydoc Dali::Stage::GetRootLayer()
208 Dali::Layer GetRootLayer() const;
211 * Retrieve the ordered list of on-stage layers.
212 * @return The layer-list.
214 LayerList& GetLayerList();
219 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
220 * set to receive keyboard input.
221 * @param[in] actor to receive keyboard input
223 void SetKeyboardFocusActor( Actor* actor );
226 * Get the actor that is currently set to receive keyboard inputs
227 * @return Pointer to the actor set to receive keyboard inputs.
229 Actor* GetKeyboardFocusActor() const;
232 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
233 * @param [in] actor which should be removed from focus.
235 void RemoveActorFromKeyFocus( Actor* actor );
240 * @copydoc Dali::Stage::SetBackgroundColor
242 void SetBackgroundColor(Vector4 color);
245 * @copydoc Dali::Stage::GetBackgroundColor
247 Vector4 GetBackgroundColor() const;
250 * @copydoc Dali::Stage::GetDpi
252 Vector2 GetDpi() const;
255 * Sets horizontal and vertical pixels per inch value that is used by the display
256 * @param[in] dpi Horizontal and vertical dpi value
258 void SetDpi( Vector2 dpi );
260 NotificationManager& GetNotificationManager()
262 return mNotificationManager;
266 * @copydoc Dali::Stage::KeepRendering()
268 void KeepRendering( float durationSeconds );
271 * @copydoc Dali::DevelStage::SetRenderingBehavior()
273 void SetRenderingBehavior( DevelStage::Rendering renderingBehavior );
276 * @copydoc Dali::DevelStage::GetRenderingBehavior()
278 DevelStage::Rendering GetRenderingBehavior() const;
281 * Used by the EventProcessor to emit key event signals.
282 * @param[in] event The key event.
284 void EmitKeyEventSignal(const KeyEvent& event);
287 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
288 * @param[in] event The key event.
289 * @return The return is true if KeyEvent is consumed, otherwise false.
291 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
294 * Emits the event processing finished signal.
296 * @see Dali::Stage::SignalEventProcessingFinished()
298 void EmitEventProcessingFinishedSignal();
301 * Emits the touched signal.
302 * @param[in] touchEvent The touch event details (Old API).
303 * @param[in] touch The touch event details.
305 void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
308 * Used by the EventProcessor to emit wheel event signals.
309 * @param[in] event The wheel event.
311 void EmitWheelEventSignal( const WheelEvent& event );
314 * Emits the scene created.
316 void EmitSceneCreatedSignal();
319 * @copydoc Dali::Stage::KeyEventSignal()
321 Dali::Stage::KeyEventSignalType& KeyEventSignal();
324 * @copydoc Dali::Stage::SignalEventProcessingFinished()
326 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
329 * @copydoc Dali::Stage::TouchedSignal()
331 Dali::Stage::TouchedSignalType& TouchedSignal();
334 * @copydoc Dali::Stage::TouchSignal()
336 Dali::Stage::TouchSignalType& TouchSignal();
339 * @copydoc Dali::Stage::WheelEventSignal()
341 Dali::Stage::WheelEventSignalType& WheelEventSignal();
344 * @copydoc Dali::Stage::ContextLostSignal()
346 Dali::Stage::ContextStatusSignal& ContextLostSignal();
349 * @copydoc Dali::Stage::ContextRegainedSignal()
351 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
354 * @copydoc Dali::Stage::SceneCreatedSignal()
356 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
359 * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
361 Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
364 * @copydoc Dali::DevelStage::AddFrameCallback()
366 void AddFrameCallback( FrameCallbackInterface& frameCallback, Actor& rootActor );
369 * @copydoc Dali::DevelStage::RemoveFrameCallback()
371 void RemoveFrameCallback( FrameCallbackInterface& frameCallback );
374 * Connects a callback function with the object's signals.
375 * @param[in] object The object providing the signal.
376 * @param[in] tracker Used to disconnect the signal.
377 * @param[in] signalName The signal to connect to.
378 * @param[in] functor A newly allocated FunctorDelegate.
379 * @return True if the signal was connected.
380 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
382 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
384 private: // Implementation of ContextNotificationInterface:
387 * @copydoc Dali::Integration::NotifyContextLost();
389 virtual void NotifyContextLost();
392 * @copydoc Dali::Integration::NotifyContextRegained();
394 virtual void NotifyContextRegained();
396 public: // Implementation of EventThreadServices
399 * @copydoc EventThreadServices::RegisterObject
401 virtual void RegisterObject( BaseObject* object);
404 * @copydoc EventThreadServices::UnregisterObject
406 virtual void UnregisterObject( BaseObject* object);
409 * @copydoc EventThreadServices::GetUpdateManager
411 virtual SceneGraph::UpdateManager& GetUpdateManager();
414 * @copydoc EventThreadServices::GetRenderController
416 virtual Integration::RenderController& GetRenderController();
419 * @copydoc EventThreadServices::ReserveMessageSlot
421 virtual uint32_t* ReserveMessageSlot( uint32_t size, bool updateScene );
424 * @copydoc EventThreadServices::GetEventBufferIndex
426 virtual BufferIndex GetEventBufferIndex() const;
429 * @copydoc EventThreadServices::ForceNextUpdate
431 virtual void ForceNextUpdate();
434 * @copydoc EventThreadServices::IsNextUpdateForced
436 virtual bool IsNextUpdateForced();
439 * Request that the depth tree is rebuilt
441 void RequestRebuildDepthTree();
444 * Rebuilds the depth tree at the end of the event frame if
445 * it was requested this frame.
447 void RebuildDepthTree();
452 * Protected constructor; see also Stage::New()
454 Stage( AnimationPlaylist& playlist,
455 PropertyNotificationManager& propertyNotificationManager,
456 SceneGraph::UpdateManager& updateManager,
457 NotificationManager& notificationManager,
458 Integration::RenderController& renderController );
461 * A reference counted object may only be deleted by calling Unreference()
467 // For 'Fire and forget' animation support
468 AnimationPlaylist& mAnimationPlaylist;
470 PropertyNotificationManager& mPropertyNotificationManager;
472 SceneGraph::UpdateManager& mUpdateManager;
474 NotificationManager& mNotificationManager;
476 Integration::RenderController& mRenderController;
478 // The stage-size may be less than surface-size (reduced by top-margin)
480 Vector2 mSurfaceSize;
482 // Cached for public GetBackgroundColor()
483 Vector4 mBackgroundColor;
487 // Ordered list of currently on-stage layers
488 OwnerPointer<LayerList> mLayerList;
490 IntrusivePtr<CameraActor> mDefaultCamera;
495 // The object registry
496 ObjectRegistryPtr mObjectRegistry;
498 // The list of render-tasks
499 IntrusivePtr<RenderTaskList> mRenderTaskList;
501 // The key event signal
502 Dali::Stage::KeyEventSignalType mKeyEventSignal;
503 Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
505 // The event processing finished signal
506 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
508 // The touched signals
509 Dali::Stage::TouchedSignalType mTouchedSignal;
510 Dali::Stage::TouchSignalType mTouchSignal;
512 // The wheel event signal
513 Dali::Stage::WheelEventSignalType mWheelEventSignal;
515 Dali::Stage::ContextStatusSignal mContextLostSignal;
516 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
518 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
520 DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
522 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
523 bool mForceNextUpdate:1; ///< True if the next rendering is really required.
524 bool mRenderToFbo:1; ///< Whether to render to a Frame Buffer Object.
527 } // namespace Internal
529 // Helpers for public-api forwarding methods
531 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
533 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
535 BaseObject& handle = stage.GetBaseObject();
537 return static_cast<Internal::Stage&>(handle);
540 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
542 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
544 const BaseObject& handle = stage.GetBaseObject();
546 return static_cast<const Internal::Stage&>(handle);
551 #endif // DALI_INTERNAL_STAGE_H