1 #ifndef __DALI_INTERNAL_STAGE_H__
2 #define __DALI_INTERNAL_STAGE_H__
5 * Copyright (c) 2014 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>
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
80 static StagePtr New( AnimationPlaylist& playlist,
81 PropertyNotificationManager& propertyNotificationManager,
82 SceneGraph::UpdateManager& updateManager,
83 NotificationManager& notificationManager );
86 * Initialize the stage.
91 * Uninitialize the stage.
96 * @copydoc Dali::Stage::GetCurrent()
97 * @note this version is for internal usage so it does not assert
99 static StagePtr GetCurrent();
102 * @copydoc Dali::Stage::IsInstalled().
104 static bool IsInstalled();
107 * @copydoc Dali::Stage::GetObjectRegistry()
109 ObjectRegistry& GetObjectRegistry();
112 * Retrieve the root actor (not publically accessible).
113 * @return The root actor.
115 Layer& GetRootActor();
118 * Returns the animation playlist.
119 * @return reference to the animation playlist.
121 AnimationPlaylist& GetAnimationPlaylist();
124 * Returns the property notification manager.
125 * @return reference to the property notification manager.
127 PropertyNotificationManager& GetPropertyNotificationManager();
129 // Root actor accessors
132 * @copydoc Dali::Stage::Add()
134 void Add( Actor& actor );
137 * @copydoc Dali::Stage::Remove()
139 void Remove( Actor& actor );
142 * Used to calculate the size of the stage and indirectly, the root actor.
143 * @param [in] width The new surface width.
144 * @param [in] height The new surface height.
146 void SurfaceResized( float width, float height );
149 * Sets the top margin size.
150 * Available stage size is reduced by this size.
151 * The stage is located below the size at the top of the display
152 * initial size is zero before it is assigned
153 * @param[in] margin margin size
155 void SetTopMargin( unsigned int margin );
158 * Returns the size of the Stage in pixels as a Vector.
159 * The x component will be the width of the Stage in pixels
160 * The y component will be the height of the Stage in pixels
161 * @return The size of the Stage as a Vector.
163 Vector2 GetSize() const;
166 * @copydoc Dali::Stage::GetRenderTaskList()
168 RenderTaskList& GetRenderTaskList() const;
171 * Create a default camera actor
173 void CreateDefaultCameraActor();
176 * Set position of default camera for current stage size
178 void SetDefaultCameraPosition();
181 * From RenderTaskDefaults; retrieve the default root actor.
182 * @return The default root actor.
184 virtual Actor& GetDefaultRootActor();
187 * From RenderTaskDefaults; retrieve the default camera actor.
188 * @return The default camera actor.
190 virtual CameraActor& GetDefaultCameraActor();
195 * @copydoc Dali::Stage::GetLayerCount()
197 unsigned int GetLayerCount() const;
200 * @copydoc Dali::Stage::GetLayer()
202 Dali::Layer GetLayer( unsigned int depth ) const;
205 * @copydoc Dali::Stage::GetRootLayer()
207 Dali::Layer GetRootLayer() const;
210 * Retrieve the ordered list of on-stage layers.
211 * @return The layer-list.
213 LayerList& GetLayerList();
215 // System-level overlay actors
218 * @copydoc Dali::Integration::Core::GetSystemOverlay()
220 Integration::SystemOverlay& GetSystemOverlay();
223 * Retrieve the internal implementation of the SystemOverlay.
224 * @return The implementation, or NULL if this has never been requested from Integration API.
226 SystemOverlay* GetSystemOverlayInternal();
231 * @copydoc Dali::Integration::Core::SetViewMode()
233 void SetViewMode( ViewMode viewMode );
236 * @copydoc Dali::Integration::Core::GetViewMode()
238 ViewMode GetViewMode() const;
241 * @copydoc Dali::Integration::Core::SetStereoBase()
243 void SetStereoBase( float stereoBase );
246 * @copydoc Dali::Integration::Core::GetStereoBase()
248 float GetStereoBase() const;
253 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
254 * set to receive keyboard input.
255 * @param[in] actor to receive keyboard input
257 void SetKeyboardFocusActor( Actor* actor );
260 * Get the actor that is currently set to receive keyboard inputs
261 * @return Pointer to the actor set to receive keyboard inputs.
263 Actor* GetKeyboardFocusActor() const;
266 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
267 * @param [in] actor which should be removed from focus.
269 void RemoveActorFromKeyFocus( Actor* actor );
274 * @copydoc Dali::Stage::SetBackgroundColor
276 void SetBackgroundColor(Vector4 color);
279 * @copydoc Dali::Stage::GetBackgroundColor
281 Vector4 GetBackgroundColor() const;
284 * @copydoc Dali::Stage::GetDpi
286 Vector2 GetDpi() const;
289 * Sets horizontal and vertical pixels per inch value that is used by the display
290 * @param[in] dpi Horizontal and vertical dpi value
292 void SetDpi( Vector2 dpi );
294 NotificationManager& GetNotificationManager()
296 return mNotificationManager;
300 * @copydoc Dali::Stage::KeepRendering()
302 void KeepRendering( float durationSeconds );
305 * Used by the EventProcessor to emit key event signals.
306 * @param[in] event The key event.
308 void EmitKeyEventSignal(const KeyEvent& event);
311 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
312 * @param[in] event The key event.
313 * @return The return is true if KeyEvent is consumed, otherwise false.
315 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
318 * Emits the event processing finished signal.
320 * @see Dali::Stage::SignalEventProcessingFinished()
322 void EmitEventProcessingFinishedSignal();
325 * Emits the touched signal.
326 * @param[in] touchEvent The touch event details (Old API).
327 * @param[in] touch The touch event details.
329 void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
332 * Used by the EventProcessor to emit wheel event signals.
333 * @param[in] event The wheel event.
335 void EmitWheelEventSignal( const WheelEvent& event );
338 * Emits the scene created.
340 void EmitSceneCreatedSignal();
343 * @copydoc Dali::Stage::KeyEventSignal()
345 Dali::Stage::KeyEventSignalType& KeyEventSignal();
348 * @copydoc Dali::Stage::SignalEventProcessingFinished()
350 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
353 * @copydoc Dali::Stage::TouchedSignal()
355 Dali::Stage::TouchedSignalType& TouchedSignal();
358 * @copydoc Dali::Stage::TouchSignal()
360 Dali::Stage::TouchSignalType& TouchSignal();
363 * @copydoc Dali::Stage::WheelEventSignal()
365 Dali::Stage::WheelEventSignalType& WheelEventSignal();
368 * @copydoc Dali::Stage::ContextLostSignal()
370 Dali::Stage::ContextStatusSignal& ContextLostSignal();
373 * @copydoc Dali::Stage::ContextRegainedSignal()
375 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
378 * @copydoc Dali::Stage::SceneCreatedSignal()
380 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
383 * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
385 Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
388 * Connects a callback function with the object's signals.
389 * @param[in] object The object providing the signal.
390 * @param[in] tracker Used to disconnect the signal.
391 * @param[in] signalName The signal to connect to.
392 * @param[in] functor A newly allocated FunctorDelegate.
393 * @return True if the signal was connected.
394 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
396 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
398 private: // Implementation of ContextNotificationInterface:
401 * @copydoc Dali::Integration::NotifyContextLost();
403 virtual void NotifyContextLost();
406 * @copydoc Dali::Integration::NotifyContextRegained();
408 virtual void NotifyContextRegained();
410 public: // Implementation of EventThreadServices
413 * @copydoc EventThreadServices::RegisterObject
415 virtual void RegisterObject( BaseObject* object);
418 * @copydoc EventThreadServices::UnregisterObject
420 virtual void UnregisterObject( BaseObject* object);
423 * @copydoc EventThreadServices::GetUpdateManager
425 virtual SceneGraph::UpdateManager& GetUpdateManager();
428 * @copydoc EventThreadServices::ReserveMessageSlot
430 virtual unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene );
433 * @copydoc EventThreadServices::GetEventBufferIndex
435 virtual BufferIndex GetEventBufferIndex() const;
438 * Request that the depth tree is rebuilt
440 void RequestRebuildDepthTree();
443 * Rebuilds the depth tree at the end of the event frame if
444 * it was requested this frame.
446 void RebuildDepthTree();
451 * Protected constructor; see also Stage::New()
453 Stage( AnimationPlaylist& playlist,
454 PropertyNotificationManager& propertyNotificationManager,
455 SceneGraph::UpdateManager& updateManager,
456 NotificationManager& notificationManager );
459 * A reference counted object may only be deleted by calling Unreference()
465 // For 'Fire and forget' animation support
466 AnimationPlaylist& mAnimationPlaylist;
468 PropertyNotificationManager& mPropertyNotificationManager;
470 SceneGraph::UpdateManager& mUpdateManager;
472 NotificationManager& mNotificationManager;
474 // The stage-size may be less than surface-size (reduced by top-margin)
476 Vector2 mSurfaceSize;
478 // Cached for public GetBackgroundColor()
479 Vector4 mBackgroundColor;
483 // Ordered list of currently on-stage layers
484 OwnerPointer<LayerList> mLayerList;
486 IntrusivePtr<CameraActor> mDefaultCamera;
491 unsigned int mTopMargin;
494 // The object registry
495 ObjectRegistryPtr mObjectRegistry;
497 // The list of render-tasks
498 IntrusivePtr<RenderTaskList> mRenderTaskList;
500 Dali::RenderTask mRightRenderTask;
501 IntrusivePtr<CameraActor> mRightCamera;
502 Dali::RenderTask mLeftRenderTask;
503 IntrusivePtr<CameraActor> mLeftCamera;
505 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
507 // The key event signal
508 Dali::Stage::KeyEventSignalType mKeyEventSignal;
509 Dali::DevelStage::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
511 // The event processing finished signal
512 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
514 // The touched signals
515 Dali::Stage::TouchedSignalType mTouchedSignal;
516 Dali::Stage::TouchSignalType mTouchSignal;
517 bool mDepthTreeDirty; ///< True if the depth tree needs recalculating
519 // The wheel event signal
520 Dali::Stage::WheelEventSignalType mWheelEventSignal;
522 Dali::Stage::ContextStatusSignal mContextLostSignal;
523 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
525 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
528 } // namespace Internal
530 // Helpers for public-api forwarding methods
532 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
534 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
536 BaseObject& handle = stage.GetBaseObject();
538 return static_cast<Internal::Stage&>(handle);
541 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
543 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
545 const BaseObject& handle = stage.GetBaseObject();
547 return static_cast<const Internal::Stage&>(handle);
552 #endif // __DALI_INTERNAL_STAGE_H__