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/object-registry-impl.h>
29 #include <dali/internal/event/common/stage-def.h>
30 #include <dali/internal/event/render-tasks/render-task-defaults.h>
31 #include <dali/internal/update/manager/update-manager.h>
32 #include <dali/public-api/common/view-mode.h>
33 #include <dali/public-api/math/vector2.h>
34 #include <dali/public-api/math/vector3.h>
35 #include <dali/public-api/math/vector4.h>
36 #include <dali/public-api/render-tasks/render-task.h>
38 #ifdef DYNAMICS_SUPPORT
39 #include <dali/internal/event/dynamics/dynamics-declarations.h>
40 #include <dali/internal/event/dynamics/dynamics-notifier.h>
51 class DynamicsFactory;
62 class AnimationPlaylist;
63 class PropertyNotificationManager;
71 * Implementation of Stage
73 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface
79 * @param[in] playlist for animations
80 * @param[in] propertyNotificationManager
81 * @param[in] updateManager
82 * @param[in] notificationManager
84 static StagePtr New( AnimationPlaylist& playlist,
85 PropertyNotificationManager& propertyNotificationManager,
86 SceneGraph::UpdateManager& updateManager,
87 NotificationManager& notificationManager );
90 * Initialize the stage.
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 * @copydoc Dali::Internal::ObjectRegistry::RegisterObject
118 void RegisterObject( Dali::BaseObject* object );
121 * @copydoc Dali::Internal::ObjectRegistry::UnregisterObject
123 void UnregisterObject( Dali::BaseObject* object );
126 * Retrieve the root actor (not publically accessible).
127 * @return The root actor.
129 Layer& GetRootActor();
132 * Retrieve the UpdateManager associated with this Stage
133 * @return The UpdateManager.
135 SceneGraph::UpdateManager& GetUpdateManager();
138 * Helper for actors, to retrieve the current Event buffer index.
139 * @return The buffer index.
141 BufferIndex GetEventBufferIndex() const
143 // inlined as its called often from event thread
144 return mUpdateManager.GetEventBufferIndex();
148 * Retrieve the interface for accessing update-thread data.
149 * @return The EventToUpdate interface.
151 EventToUpdate& GetUpdateInterface();
154 * Returns the animation playlist.
155 * @return reference to the animation playlist.
157 AnimationPlaylist& GetAnimationPlaylist();
160 * Returns the property notification manager.
161 * @return reference to the property notification manager.
163 PropertyNotificationManager& GetPropertyNotificationManager();
165 // Root actor accessors
168 * @copydoc Dali::Stage::Add()
170 void Add( Actor& actor );
173 * @copydoc Dali::Stage::Remove()
175 void Remove( Actor& actor );
178 * Sets the size of the stage and indirectly, the root actor.
179 * @param [in] width The new width.
180 * @param [in] height The new height.
182 void SetSize( float width, float height );
185 * Returns the size of the Stage in pixels as a Vector.
186 * The x component will be the width of the Stage in pixels
187 * The y component will be the height of the Stage in pixels
188 * @return The size of the Stage as a Vector.
190 Vector2 GetSize() const;
193 * @copydoc Dali::Stage::GetRenderTaskList()
195 RenderTaskList& GetRenderTaskList() const;
198 * Create a default camera actor
200 void CreateDefaultCameraActor();
203 * From RenderTaskDefaults; retrieve the default root actor.
204 * @return The default root actor.
206 virtual Actor& GetDefaultRootActor();
209 * From RenderTaskDefaults; retrieve the default camera actor.
210 * @return The default camera actor.
212 virtual CameraActor& GetDefaultCameraActor();
217 * @copydoc Dali::Stage::GetLayerCount()
219 unsigned int GetLayerCount() const;
222 * @copydoc Dali::Stage::GetLayer()
224 Dali::Layer GetLayer( unsigned int depth ) const;
227 * @copydoc Dali::Stage::GetRootLayer()
229 Dali::Layer GetRootLayer() const;
232 * Retrieve the ordered list of on-stage layers.
233 * @return The layer-list.
235 LayerList& GetLayerList();
237 // System-level overlay actors
240 * @copydoc Dali::Integration::Core::GetSystemOverlay()
242 Integration::SystemOverlay& GetSystemOverlay();
245 * Retrieve the internal implementation of the SystemOverlay.
246 * @return The implementation, or NULL if this has never been requested from Integration API.
248 SystemOverlay* GetSystemOverlayInternal();
253 * @copydoc Dali::Integration::Core::SetViewMode()
255 void SetViewMode( ViewMode viewMode );
258 * @copydoc Dali::Integration::Core::GetViewMode()
260 ViewMode GetViewMode() const;
263 * @copydoc Dali::Integration::Core::SetStereoBase()
265 void SetStereoBase( float stereoBase );
268 * @copydoc Dali::Integration::Core::GetStereoBase()
270 float GetStereoBase() const;
275 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
276 * set to receive keyboard input.
277 * @param[in] actor to receive keyboard input
279 void SetKeyboardFocusActor( Actor* actor );
282 * Get the actor that is currently set to receive keyboard inputs
283 * @return Pointer to the actor set to receive keyboard inputs.
285 Actor* GetKeyboardFocusActor() const;
288 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
289 * @param [in] actor which should be removed from focus.
291 void RemoveActorFromKeyFocus( Actor* actor );
296 * @copydoc Dali::Stage::SetBackgroundColor
298 void SetBackgroundColor(Vector4 color);
301 * @copydoc Dali::Stage::GetBackgroundColor
303 Vector4 GetBackgroundColor() const;
306 * @copydoc Dali::Stage::GetDpi
308 Vector2 GetDpi() const;
311 * Sets horizontal and vertical pixels per inch value that is used by the display
312 * @param[in] dpi Horizontal and vertical dpi value
314 void SetDpi( Vector2 dpi );
316 #ifdef DYNAMICS_SUPPORT
319 * Return the Dynamics Simulation Notifier object
320 * @return The Dynamics Simulation Notifier object
322 DynamicsNotifier& GetDynamicsNotifier();
325 * @copydoc Dali::Stage::InitializeDynamics
327 DynamicsWorldPtr InitializeDynamics(DynamicsWorldConfigPtr config);
330 * @copydoc Dali::Stage::GetDynamicsWorld
332 DynamicsWorldPtr GetDynamicsWorld();
335 * @copydoc Dali::Stage::TerminateDynamics
337 void TerminateDynamics();
339 #endif // DYNAMICS_SUPPORT
341 NotificationManager& GetNotificationManager()
343 return mNotificationManager;
348 * @copydoc Dali::Stage::KeepRendering()
350 void KeepRendering( float durationSeconds );
353 * Used by the EventProcessor to emit key event signals.
354 * @param[in] event The key event.
356 void EmitKeyEventSignal(const KeyEvent& event);
359 * Emits the event processing finished signal.
361 * @see Dali::Stage::SignalEventProcessingFinished()
363 void EmitEventProcessingFinishedSignal();
366 * Emits the touched signal.
367 * @param[in] touch The touch event details.
369 void EmitTouchedSignal( const TouchEvent& touch );
372 * Emits the scene created.
374 void EmitSceneCreatedSignal();
377 * @copydoc Dali::Stage::KeyEventSignal()
379 Dali::Stage::KeyEventSignalType& KeyEventSignal();
382 * @copydoc Dali::Stage::SignalEventProcessingFinished()
384 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
387 * @copydoc Dali::Stage::TouchedSignal()
389 Dali::Stage::TouchedSignalType& TouchedSignal();
392 * @copydoc Dali::Stage::ContextLostSignal()
394 Dali::Stage::ContextStatusSignal& ContextLostSignal();
397 * @copydoc Dali::Stage::ContextRegainedSignal()
399 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
402 * @copydoc Dali::Stage::SceneCreatedSignal()
404 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
406 private: // Implementation of ContextNotificationInterface:
409 * @copydoc Dali::Integration::NotifyContextLost();
411 virtual void NotifyContextLost();
414 * @copydoc Dali::Integration::NotifyContextRegained();
416 virtual void NotifyContextRegained();
421 * Protected constructor; see also Stage::New()
423 Stage( AnimationPlaylist& playlist,
424 PropertyNotificationManager& propertyNotificationManager,
425 SceneGraph::UpdateManager& updateManager,
426 NotificationManager& notificationManager );
429 * A reference counted object may only be deleted by calling Unreference()
435 // For 'Fire and forget' animation support
436 AnimationPlaylist& mAnimationPlaylist;
438 PropertyNotificationManager& mPropertyNotificationManager;
440 SceneGraph::UpdateManager& mUpdateManager;
442 NotificationManager& mNotificationManager;
444 // The Actual size of the stage.
447 // Cached for public GetBackgroundColor()
448 Vector4 mBackgroundColor;
452 // Ordered list of currently on-stage layers
453 OwnerPointer<LayerList> mLayerList;
455 IntrusivePtr<CameraActor> mDefaultCamera;
462 // The object registry
463 ObjectRegistryPtr mObjectRegistry;
465 #ifdef DYNAMICS_SUPPORT
467 DynamicsNotifier mDynamicsNotifier;
469 // The Dynamics simulation world object
470 Integration::DynamicsFactory* mDynamicsFactory; // Not owned pointer to DynamicsFactory (PlatformAbstraction will clean up)
471 DynamicsWorldPtr mDynamicsWorld;
473 #endif // DYNAMICS_SUPPORT
475 // The list of render-tasks
476 IntrusivePtr<RenderTaskList> mRenderTaskList;
478 Dali::RenderTask mRightRenderTask;
479 IntrusivePtr<CameraActor> mRightCamera;
480 Dali::RenderTask mLeftRenderTask;
481 IntrusivePtr<CameraActor> mLeftCamera;
483 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
485 // The key event signal
486 Dali::Stage::KeyEventSignalType mKeyEventSignal;
488 // The event processing finished signal
489 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
491 // The touched signal
492 Dali::Stage::TouchedSignalType mTouchedSignal;
494 Dali::Stage::ContextStatusSignal mContextLostSignal;
495 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
497 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
500 } // namespace Internal
502 // Helpers for public-api forwarding methods
504 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
506 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
508 BaseObject& handle = stage.GetBaseObject();
510 return static_cast<Internal::Stage&>(handle);
513 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
515 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
517 const BaseObject& handle = stage.GetBaseObject();
519 return static_cast<const Internal::Stage&>(handle);
524 #endif // __DALI_INTERNAL_STAGE_H__