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/public-api/object/base-object.h>
25 #include <dali/integration-api/context-notifier.h>
26 #include <dali/internal/common/owner-pointer.h>
27 #include <dali/internal/event/actors/layer-impl.h>
28 #include <dali/internal/event/common/event-thread-services.h>
29 #include <dali/internal/event/common/object-registry-impl.h>
30 #include <dali/internal/event/common/stage-def.h>
31 #include <dali/internal/event/render-tasks/render-task-defaults.h>
32 #include <dali/internal/update/manager/update-manager.h>
33 #include <dali/public-api/common/view-mode.h>
34 #include <dali/public-api/math/vector2.h>
35 #include <dali/public-api/math/vector3.h>
36 #include <dali/public-api/math/vector4.h>
37 #include <dali/public-api/render-tasks/render-task.h>
39 #ifdef DYNAMICS_SUPPORT
40 #include <dali/internal/event/dynamics/dynamics-declarations.h>
41 #include <dali/internal/event/dynamics/dynamics-notifier.h>
52 class DynamicsFactory;
63 class AnimationPlaylist;
64 class PropertyNotificationManager;
72 * Implementation of Stage
74 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public EventThreadServices
80 * @param[in] playlist for animations
81 * @param[in] propertyNotificationManager
82 * @param[in] updateManager
83 * @param[in] notificationManager
85 static StagePtr New( AnimationPlaylist& playlist,
86 PropertyNotificationManager& propertyNotificationManager,
87 SceneGraph::UpdateManager& updateManager,
88 NotificationManager& notificationManager );
91 * Initialize the stage.
96 * Uninitialize the stage.
101 * @copydoc Dali::Stage::GetCurrent()
102 * @note this version is for internal usage so it does not assert
104 static StagePtr GetCurrent();
107 * @copydoc Dali::Stage::IsInstalled().
109 static bool IsInstalled();
112 * @copydoc Dali::Stage::GetObjectRegistry()
114 ObjectRegistry& GetObjectRegistry();
117 * Retrieve the root actor (not publically accessible).
118 * @return The root actor.
120 Layer& GetRootActor();
123 * Returns the animation playlist.
124 * @return reference to the animation playlist.
126 AnimationPlaylist& GetAnimationPlaylist();
129 * Returns the property notification manager.
130 * @return reference to the property notification manager.
132 PropertyNotificationManager& GetPropertyNotificationManager();
134 // Root actor accessors
137 * @copydoc Dali::Stage::Add()
139 void Add( Actor& actor );
142 * @copydoc Dali::Stage::Remove()
144 void Remove( Actor& actor );
147 * Sets the size of the stage and indirectly, the root actor.
148 * @param [in] width The new width.
149 * @param [in] height The new height.
151 void SetSize( float width, float height );
154 * Returns the size of the Stage in pixels as a Vector.
155 * The x component will be the width of the Stage in pixels
156 * The y component will be the height of the Stage in pixels
157 * @return The size of the Stage as a Vector.
159 Vector2 GetSize() const;
162 * @copydoc Dali::Stage::GetRenderTaskList()
164 RenderTaskList& GetRenderTaskList() const;
167 * Create a default camera actor
169 void CreateDefaultCameraActor();
172 * From RenderTaskDefaults; retrieve the default root actor.
173 * @return The default root actor.
175 virtual Actor& GetDefaultRootActor();
178 * From RenderTaskDefaults; retrieve the default camera actor.
179 * @return The default camera actor.
181 virtual CameraActor& GetDefaultCameraActor();
186 * @copydoc Dali::Stage::GetLayerCount()
188 unsigned int GetLayerCount() const;
191 * @copydoc Dali::Stage::GetLayer()
193 Dali::Layer GetLayer( unsigned int depth ) const;
196 * @copydoc Dali::Stage::GetRootLayer()
198 Dali::Layer GetRootLayer() const;
201 * Retrieve the ordered list of on-stage layers.
202 * @return The layer-list.
204 LayerList& GetLayerList();
206 // System-level overlay actors
209 * @copydoc Dali::Integration::Core::GetSystemOverlay()
211 Integration::SystemOverlay& GetSystemOverlay();
214 * Retrieve the internal implementation of the SystemOverlay.
215 * @return The implementation, or NULL if this has never been requested from Integration API.
217 SystemOverlay* GetSystemOverlayInternal();
222 * @copydoc Dali::Integration::Core::SetViewMode()
224 void SetViewMode( ViewMode viewMode );
227 * @copydoc Dali::Integration::Core::GetViewMode()
229 ViewMode GetViewMode() const;
232 * @copydoc Dali::Integration::Core::SetStereoBase()
234 void SetStereoBase( float stereoBase );
237 * @copydoc Dali::Integration::Core::GetStereoBase()
239 float GetStereoBase() const;
244 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
245 * set to receive keyboard input.
246 * @param[in] actor to receive keyboard input
248 void SetKeyboardFocusActor( Actor* actor );
251 * Get the actor that is currently set to receive keyboard inputs
252 * @return Pointer to the actor set to receive keyboard inputs.
254 Actor* GetKeyboardFocusActor() const;
257 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
258 * @param [in] actor which should be removed from focus.
260 void RemoveActorFromKeyFocus( Actor* actor );
265 * @copydoc Dali::Stage::SetBackgroundColor
267 void SetBackgroundColor(Vector4 color);
270 * @copydoc Dali::Stage::GetBackgroundColor
272 Vector4 GetBackgroundColor() const;
275 * @copydoc Dali::Stage::GetDpi
277 Vector2 GetDpi() const;
280 * Sets horizontal and vertical pixels per inch value that is used by the display
281 * @param[in] dpi Horizontal and vertical dpi value
283 void SetDpi( Vector2 dpi );
285 #ifdef DYNAMICS_SUPPORT
288 * Return the Dynamics Simulation Notifier object
289 * @return The Dynamics Simulation Notifier object
291 DynamicsNotifier& GetDynamicsNotifier();
294 * @copydoc Dali::Stage::InitializeDynamics
296 DynamicsWorldPtr InitializeDynamics(DynamicsWorldConfigPtr config);
299 * @copydoc Dali::Stage::GetDynamicsWorld
301 DynamicsWorldPtr GetDynamicsWorld();
304 * @copydoc Dali::Stage::TerminateDynamics
306 void TerminateDynamics();
308 #endif // DYNAMICS_SUPPORT
310 NotificationManager& GetNotificationManager()
312 return mNotificationManager;
316 * @copydoc Dali::Stage::KeepRendering()
318 void KeepRendering( float durationSeconds );
321 * Used by the EventProcessor to emit key event signals.
322 * @param[in] event The key event.
324 void EmitKeyEventSignal(const KeyEvent& event);
327 * Emits the event processing finished signal.
329 * @see Dali::Stage::SignalEventProcessingFinished()
331 void EmitEventProcessingFinishedSignal();
334 * Emits the touched signal.
335 * @param[in] touch The touch event details.
337 void EmitTouchedSignal( const TouchEvent& touch );
340 * Emits the scene created.
342 void EmitSceneCreatedSignal();
345 * @copydoc Dali::Stage::KeyEventSignal()
347 Dali::Stage::KeyEventSignalType& KeyEventSignal();
350 * @copydoc Dali::Stage::SignalEventProcessingFinished()
352 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
355 * @copydoc Dali::Stage::TouchedSignal()
357 Dali::Stage::TouchedSignalType& TouchedSignal();
360 * @copydoc Dali::Stage::ContextLostSignal()
362 Dali::Stage::ContextStatusSignal& ContextLostSignal();
365 * @copydoc Dali::Stage::ContextRegainedSignal()
367 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
370 * @copydoc Dali::Stage::SceneCreatedSignal()
372 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
375 * Connects a callback function with the object's signals.
376 * @param[in] object The object providing the signal.
377 * @param[in] tracker Used to disconnect the signal.
378 * @param[in] signalName The signal to connect to.
379 * @param[in] functor A newly allocated FunctorDelegate.
380 * @return True if the signal was connected.
381 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
383 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
385 private: // Implementation of ContextNotificationInterface:
388 * @copydoc Dali::Integration::NotifyContextLost();
390 virtual void NotifyContextLost();
393 * @copydoc Dali::Integration::NotifyContextRegained();
395 virtual void NotifyContextRegained();
397 public: // Implementation of EventThreadServices
400 * @copydoc EventThreadServices::RegisterObject
402 virtual void RegisterObject( BaseObject* object);
405 * @copydoc EventThreadServices::UnregisterObject
407 virtual void UnregisterObject( BaseObject* object);
410 * @copydoc EventThreadServices::GetUpdateManager
412 virtual SceneGraph::UpdateManager& GetUpdateManager();
415 * @copydoc EventThreadServices::ReserveMessageSlot
417 virtual unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene );
420 * @copydoc EventThreadServices::GetEventBufferIndex
422 virtual BufferIndex GetEventBufferIndex() const;
427 * Protected constructor; see also Stage::New()
429 Stage( AnimationPlaylist& playlist,
430 PropertyNotificationManager& propertyNotificationManager,
431 SceneGraph::UpdateManager& updateManager,
432 NotificationManager& notificationManager );
435 * A reference counted object may only be deleted by calling Unreference()
441 // For 'Fire and forget' animation support
442 AnimationPlaylist& mAnimationPlaylist;
444 PropertyNotificationManager& mPropertyNotificationManager;
446 SceneGraph::UpdateManager& mUpdateManager;
448 NotificationManager& mNotificationManager;
450 // The Actual size of the stage.
453 // Cached for public GetBackgroundColor()
454 Vector4 mBackgroundColor;
458 // Ordered list of currently on-stage layers
459 OwnerPointer<LayerList> mLayerList;
461 IntrusivePtr<CameraActor> mDefaultCamera;
468 // The object registry
469 ObjectRegistryPtr mObjectRegistry;
471 #ifdef DYNAMICS_SUPPORT
473 DynamicsNotifier mDynamicsNotifier;
475 // The Dynamics simulation world object
476 Integration::DynamicsFactory* mDynamicsFactory; // Not owned pointer to DynamicsFactory (PlatformAbstraction will clean up)
477 DynamicsWorldPtr mDynamicsWorld;
479 #endif // DYNAMICS_SUPPORT
481 // The list of render-tasks
482 IntrusivePtr<RenderTaskList> mRenderTaskList;
484 Dali::RenderTask mRightRenderTask;
485 IntrusivePtr<CameraActor> mRightCamera;
486 Dali::RenderTask mLeftRenderTask;
487 IntrusivePtr<CameraActor> mLeftCamera;
489 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
491 // The key event signal
492 Dali::Stage::KeyEventSignalType mKeyEventSignal;
494 // The event processing finished signal
495 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
497 // The touched signal
498 Dali::Stage::TouchedSignalType mTouchedSignal;
500 Dali::Stage::ContextStatusSignal mContextLostSignal;
501 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
503 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
506 } // namespace Internal
508 // Helpers for public-api forwarding methods
510 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
512 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
514 BaseObject& handle = stage.GetBaseObject();
516 return static_cast<Internal::Stage&>(handle);
519 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
521 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
523 const BaseObject& handle = stage.GetBaseObject();
525 return static_cast<const Internal::Stage&>(handle);
530 #endif // __DALI_INTERNAL_STAGE_H__