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()
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 * Retrieve the UpdateManager associated with this Stage
122 * @return The UpdateManager.
124 SceneGraph::UpdateManager& GetUpdateManager();
127 * Helper for actors, to retrieve the current Event buffer index.
128 * @return The buffer index.
130 BufferIndex GetEventBufferIndex() const
132 // inlined as its called often from event thread
133 return mUpdateManager.GetEventBufferIndex();
137 * Retrieve the interface for accessing update-thread data.
138 * @return The EventToUpdate interface.
140 EventToUpdate& GetUpdateInterface();
143 * Returns the animation playlist.
144 * @return reference to the animation playlist.
146 AnimationPlaylist& GetAnimationPlaylist();
149 * Returns the property notification manager.
150 * @return reference to the property notification manager.
152 PropertyNotificationManager& GetPropertyNotificationManager();
154 // Root actor accessors
157 * @copydoc Dali::Stage::Add()
159 void Add( Actor& actor );
162 * @copydoc Dali::Stage::Remove()
164 void Remove( Actor& actor );
167 * Sets the size of the stage and indirectly, the root actor.
168 * @param [in] width The new width.
169 * @param [in] height The new height.
171 void SetSize( float width, float height );
174 * Returns the size of the Stage in pixels as a Vector.
175 * The x component will be the width of the Stage in pixels
176 * The y component will be the height of the Stage in pixels
177 * @return The size of the Stage as a Vector.
179 Vector2 GetSize() const;
182 * @copydoc Dali::Stage::GetRenderTaskList()
184 RenderTaskList& GetRenderTaskList() const;
187 * Create a default camera actor
189 void CreateDefaultCameraActor();
192 * From RenderTaskDefaults; retrieve the default root actor.
193 * @return The default root actor.
195 virtual Actor& GetDefaultRootActor();
198 * From RenderTaskDefaults; retrieve the default camera actor.
199 * @return The default camera actor.
201 virtual CameraActor& GetDefaultCameraActor();
206 * @copydoc Dali::Stage::GetLayerCount()
208 unsigned int GetLayerCount() const;
211 * @copydoc Dali::Stage::GetLayer()
213 Dali::Layer GetLayer( unsigned int depth ) const;
216 * @copydoc Dali::Stage::GetRootLayer()
218 Dali::Layer GetRootLayer() const;
221 * Retrieve the ordered list of on-stage layers.
222 * @return The layer-list.
224 LayerList& GetLayerList();
226 // System-level overlay actors
229 * @copydoc Dali::Integration::Core::GetSystemOverlay()
231 Integration::SystemOverlay& GetSystemOverlay();
234 * Retrieve the internal implementation of the SystemOverlay.
235 * @return The implementation, or NULL if this has never been requested from Integration API.
237 SystemOverlay* GetSystemOverlayInternal();
242 * @copydoc Dali::Integration::Core::SetViewMode()
244 void SetViewMode( ViewMode viewMode );
247 * @copydoc Dali::Integration::Core::GetViewMode()
249 ViewMode GetViewMode() const;
252 * @copydoc Dali::Integration::Core::SetStereoBase()
254 void SetStereoBase( float stereoBase );
257 * @copydoc Dali::Integration::Core::GetStereoBase()
259 float GetStereoBase() const;
264 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
265 * set to receive keyboard input.
266 * @param[in] actor to receive keyboard input
268 void SetKeyboardFocusActor( Actor* actor );
271 * Get the actor that is currently set to receive keyboard inputs
272 * @return Pointer to the actor set to receive keyboard inputs.
274 Actor* GetKeyboardFocusActor() const;
277 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
278 * @param [in] actor which should be removed from focus.
280 void RemoveActorFromKeyFocus( Actor* actor );
285 * @copydoc Dali::Stage::SetBackgroundColor
287 void SetBackgroundColor(Vector4 color);
290 * @copydoc Dali::Stage::GetBackgroundColor
292 Vector4 GetBackgroundColor() const;
295 * @copydoc Dali::Stage::GetDpi
297 Vector2 GetDpi() const;
300 * Sets horizontal and vertical pixels per inch value that is used by the display
301 * @param[in] dpi Horizontal and vertical dpi value
303 void SetDpi( Vector2 dpi );
305 #ifdef DYNAMICS_SUPPORT
308 * Return the Dynamics Simulation Notifier object
309 * @return The Dynamics Simulation Notifier object
311 DynamicsNotifier& GetDynamicsNotifier();
314 * @copydoc Dali::Stage::InitializeDynamics
316 DynamicsWorldPtr InitializeDynamics(DynamicsWorldConfigPtr config);
319 * @copydoc Dali::Stage::GetDynamicsWorld
321 DynamicsWorldPtr GetDynamicsWorld();
324 * @copydoc Dali::Stage::TerminateDynamics
326 void TerminateDynamics();
328 #endif // DYNAMICS_SUPPORT
330 NotificationManager& GetNotificationManager()
332 return mNotificationManager;
337 * @copydoc Dali::Stage::KeepRendering()
339 void KeepRendering( float durationSeconds );
342 * Used by the EventProcessor to emit key event signals.
343 * @param[in] event The key event.
345 void EmitKeyEventSignal(const KeyEvent& event);
348 * Emits the event processing finished signal.
350 * @see Dali::Stage::SignalEventProcessingFinished()
352 void EmitEventProcessingFinishedSignal();
355 * Emits the touched signal.
356 * @param[in] touch The touch event details.
358 void EmitTouchedSignal( const TouchEvent& touch );
361 * @copydoc Dali::Stage::KeyEventSignal()
363 Dali::Stage::KeyEventSignalV2& KeyEventSignal();
366 * @copydoc Dali::Stage::SignalEventProcessingFinished()
368 Dali::Stage::EventProcessingFinishedSignalV2& EventProcessingFinishedSignal();
371 * @copydoc Dali::Stage::TouchedSignal()
373 Dali::Stage::TouchedSignalV2& TouchedSignal();
376 * @copydoc Dali::Stage::ContextLostSignal()
378 Dali::Stage::ContextStatusSignal& ContextLostSignal();
381 * @copydoc Dali::Stage::ContextRegainedSignal()
383 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
385 private: // Implementation of ContextNotificationInterface:
388 * @copydoc Dali::Integration::NotifyContextLost();
390 virtual void NotifyContextLost();
393 * @copydoc Dali::Integration::NotifyContextRegained();
395 virtual void NotifyContextRegained();
400 * Protected constructor; see also Stage::New()
402 Stage( AnimationPlaylist& playlist,
403 PropertyNotificationManager& propertyNotificationManager,
404 SceneGraph::UpdateManager& updateManager,
405 NotificationManager& notificationManager );
408 * A reference counted object may only be deleted by calling Unreference()
414 // For 'Fire and forget' animation support
415 AnimationPlaylist& mAnimationPlaylist;
417 PropertyNotificationManager& mPropertyNotificationManager;
419 SceneGraph::UpdateManager& mUpdateManager;
421 NotificationManager& mNotificationManager;
423 // The Actual size of the stage.
426 // Cached for public GetBackgroundColor()
427 Vector4 mBackgroundColor;
431 // Ordered list of currently on-stage layers
432 OwnerPointer<LayerList> mLayerList;
434 IntrusivePtr<CameraActor> mDefaultCamera;
441 // The object registry
442 ObjectRegistryPtr mObjectRegistry;
444 #ifdef DYNAMICS_SUPPORT
446 DynamicsNotifier mDynamicsNotifier;
448 // The Dynamics simulation world object
449 Integration::DynamicsFactory* mDynamicsFactory; // Not owned pointer to DynamicsFactory (PlatformAbstraction will clean up)
450 DynamicsWorldPtr mDynamicsWorld;
452 #endif // DYNAMICS_SUPPORT
454 // The list of render-tasks
455 IntrusivePtr<RenderTaskList> mRenderTaskList;
457 Dali::RenderTask mRightRenderTask;
458 IntrusivePtr<CameraActor> mRightCamera;
459 Dali::RenderTask mLeftRenderTask;
460 IntrusivePtr<CameraActor> mLeftCamera;
462 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
464 // The key event signal
465 Dali::Stage::KeyEventSignalV2 mKeyEventSignalV2;
467 // The event processing finished signal
468 Dali::Stage::EventProcessingFinishedSignalV2 mEventProcessingFinishedSignalV2;
470 // The touched signal
471 Dali::Stage::TouchedSignalV2 mTouchedSignalV2;
473 Dali::Stage::ContextStatusSignal mContextLostSignal;
474 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
477 } // namespace Internal
479 // Helpers for public-api forwarding methods
481 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
483 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
485 BaseObject& handle = stage.GetBaseObject();
487 return static_cast<Internal::Stage&>(handle);
490 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
492 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
494 const BaseObject& handle = stage.GetBaseObject();
496 return static_cast<const Internal::Stage&>(handle);
501 #endif // __DALI_INTERNAL_STAGE_H__