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>
57 class AnimationPlaylist;
58 class PropertyNotificationManager;
66 * Implementation of Stage
68 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public EventThreadServices
74 * @param[in] playlist for animations
75 * @param[in] propertyNotificationManager
76 * @param[in] updateManager
77 * @param[in] notificationManager
79 static StagePtr New( AnimationPlaylist& playlist,
80 PropertyNotificationManager& propertyNotificationManager,
81 SceneGraph::UpdateManager& updateManager,
82 NotificationManager& notificationManager );
85 * Initialize the stage.
90 * Uninitialize the stage.
95 * @copydoc Dali::Stage::GetCurrent()
96 * @note this version is for internal usage so it does not assert
98 static StagePtr GetCurrent();
101 * @copydoc Dali::Stage::IsInstalled().
103 static bool IsInstalled();
106 * @copydoc Dali::Stage::GetObjectRegistry()
108 ObjectRegistry& GetObjectRegistry();
111 * Retrieve the root actor (not publically accessible).
112 * @return The root actor.
114 Layer& GetRootActor();
117 * Returns the animation playlist.
118 * @return reference to the animation playlist.
120 AnimationPlaylist& GetAnimationPlaylist();
123 * Returns the property notification manager.
124 * @return reference to the property notification manager.
126 PropertyNotificationManager& GetPropertyNotificationManager();
128 // Root actor accessors
131 * @copydoc Dali::Stage::Add()
133 void Add( Actor& actor );
136 * @copydoc Dali::Stage::Remove()
138 void Remove( Actor& actor );
141 * Sets the size of the stage and indirectly, the root actor.
142 * @param [in] width The new width.
143 * @param [in] height The new height.
145 void SetSize( float width, float height );
148 * Returns the size of the Stage in pixels as a Vector.
149 * The x component will be the width of the Stage in pixels
150 * The y component will be the height of the Stage in pixels
151 * @return The size of the Stage as a Vector.
153 Vector2 GetSize() const;
156 * @copydoc Dali::Stage::GetRenderTaskList()
158 RenderTaskList& GetRenderTaskList() const;
161 * Create a default camera actor
163 void CreateDefaultCameraActor();
166 * From RenderTaskDefaults; retrieve the default root actor.
167 * @return The default root actor.
169 virtual Actor& GetDefaultRootActor();
172 * From RenderTaskDefaults; retrieve the default camera actor.
173 * @return The default camera actor.
175 virtual CameraActor& GetDefaultCameraActor();
180 * @copydoc Dali::Stage::GetLayerCount()
182 unsigned int GetLayerCount() const;
185 * @copydoc Dali::Stage::GetLayer()
187 Dali::Layer GetLayer( unsigned int depth ) const;
190 * @copydoc Dali::Stage::GetRootLayer()
192 Dali::Layer GetRootLayer() const;
195 * Retrieve the ordered list of on-stage layers.
196 * @return The layer-list.
198 LayerList& GetLayerList();
200 // System-level overlay actors
203 * @copydoc Dali::Integration::Core::GetSystemOverlay()
205 Integration::SystemOverlay& GetSystemOverlay();
208 * Retrieve the internal implementation of the SystemOverlay.
209 * @return The implementation, or NULL if this has never been requested from Integration API.
211 SystemOverlay* GetSystemOverlayInternal();
216 * @copydoc Dali::Integration::Core::SetViewMode()
218 void SetViewMode( ViewMode viewMode );
221 * @copydoc Dali::Integration::Core::GetViewMode()
223 ViewMode GetViewMode() const;
226 * @copydoc Dali::Integration::Core::SetStereoBase()
228 void SetStereoBase( float stereoBase );
231 * @copydoc Dali::Integration::Core::GetStereoBase()
233 float GetStereoBase() const;
238 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
239 * set to receive keyboard input.
240 * @param[in] actor to receive keyboard input
242 void SetKeyboardFocusActor( Actor* actor );
245 * Get the actor that is currently set to receive keyboard inputs
246 * @return Pointer to the actor set to receive keyboard inputs.
248 Actor* GetKeyboardFocusActor() const;
251 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
252 * @param [in] actor which should be removed from focus.
254 void RemoveActorFromKeyFocus( Actor* actor );
259 * @copydoc Dali::Stage::SetBackgroundColor
261 void SetBackgroundColor(Vector4 color);
264 * @copydoc Dali::Stage::GetBackgroundColor
266 Vector4 GetBackgroundColor() const;
269 * @copydoc Dali::Stage::GetDpi
271 Vector2 GetDpi() const;
274 * Sets horizontal and vertical pixels per inch value that is used by the display
275 * @param[in] dpi Horizontal and vertical dpi value
277 void SetDpi( Vector2 dpi );
279 NotificationManager& GetNotificationManager()
281 return mNotificationManager;
285 * @copydoc Dali::Stage::KeepRendering()
287 void KeepRendering( float durationSeconds );
290 * Used by the EventProcessor to emit key event signals.
291 * @param[in] event The key event.
293 void EmitKeyEventSignal(const KeyEvent& event);
296 * Emits the event processing finished signal.
298 * @see Dali::Stage::SignalEventProcessingFinished()
300 void EmitEventProcessingFinishedSignal();
303 * Emits the touched signal.
304 * @param[in] touchEvent The touch event details (Old API).
305 * @param[in] touch The touch event details.
307 void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
310 * Used by the EventProcessor to emit wheel event signals.
311 * @param[in] event The wheel event.
313 void EmitWheelEventSignal( const WheelEvent& event );
316 * Emits the scene created.
318 void EmitSceneCreatedSignal();
321 * @copydoc Dali::Stage::KeyEventSignal()
323 Dali::Stage::KeyEventSignalType& KeyEventSignal();
326 * @copydoc Dali::Stage::SignalEventProcessingFinished()
328 Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
331 * @copydoc Dali::Stage::TouchedSignal()
333 Dali::Stage::TouchedSignalType& TouchedSignal();
336 * @copydoc Dali::Stage::TouchSignal()
338 Dali::Stage::TouchSignalType& TouchSignal();
341 * @copydoc Dali::Stage::WheelEventSignal()
343 Dali::Stage::WheelEventSignalType& WheelEventSignal();
346 * @copydoc Dali::Stage::ContextLostSignal()
348 Dali::Stage::ContextStatusSignal& ContextLostSignal();
351 * @copydoc Dali::Stage::ContextRegainedSignal()
353 Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
356 * @copydoc Dali::Stage::SceneCreatedSignal()
358 Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
361 * Connects a callback function with the object's signals.
362 * @param[in] object The object providing the signal.
363 * @param[in] tracker Used to disconnect the signal.
364 * @param[in] signalName The signal to connect to.
365 * @param[in] functor A newly allocated FunctorDelegate.
366 * @return True if the signal was connected.
367 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
369 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
371 private: // Implementation of ContextNotificationInterface:
374 * @copydoc Dali::Integration::NotifyContextLost();
376 virtual void NotifyContextLost();
379 * @copydoc Dali::Integration::NotifyContextRegained();
381 virtual void NotifyContextRegained();
383 public: // Implementation of EventThreadServices
386 * @copydoc EventThreadServices::RegisterObject
388 virtual void RegisterObject( BaseObject* object);
391 * @copydoc EventThreadServices::UnregisterObject
393 virtual void UnregisterObject( BaseObject* object);
396 * @copydoc EventThreadServices::GetUpdateManager
398 virtual SceneGraph::UpdateManager& GetUpdateManager();
401 * @copydoc EventThreadServices::ReserveMessageSlot
403 virtual unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene );
406 * @copydoc EventThreadServices::GetEventBufferIndex
408 virtual BufferIndex GetEventBufferIndex() const;
413 * Protected constructor; see also Stage::New()
415 Stage( AnimationPlaylist& playlist,
416 PropertyNotificationManager& propertyNotificationManager,
417 SceneGraph::UpdateManager& updateManager,
418 NotificationManager& notificationManager );
421 * A reference counted object may only be deleted by calling Unreference()
427 // For 'Fire and forget' animation support
428 AnimationPlaylist& mAnimationPlaylist;
430 PropertyNotificationManager& mPropertyNotificationManager;
432 SceneGraph::UpdateManager& mUpdateManager;
434 NotificationManager& mNotificationManager;
436 // The Actual size of the stage.
439 // Cached for public GetBackgroundColor()
440 Vector4 mBackgroundColor;
444 // Ordered list of currently on-stage layers
445 OwnerPointer<LayerList> mLayerList;
447 IntrusivePtr<CameraActor> mDefaultCamera;
454 // The object registry
455 ObjectRegistryPtr mObjectRegistry;
457 // The list of render-tasks
458 IntrusivePtr<RenderTaskList> mRenderTaskList;
460 Dali::RenderTask mRightRenderTask;
461 IntrusivePtr<CameraActor> mRightCamera;
462 Dali::RenderTask mLeftRenderTask;
463 IntrusivePtr<CameraActor> mLeftCamera;
465 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
467 // The key event signal
468 Dali::Stage::KeyEventSignalType mKeyEventSignal;
470 // The event processing finished signal
471 Dali::Stage::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
473 // The touched signals
474 Dali::Stage::TouchedSignalType mTouchedSignal;
475 Dali::Stage::TouchSignalType mTouchSignal;
477 // The wheel event signal
478 Dali::Stage::WheelEventSignalType mWheelEventSignal;
480 Dali::Stage::ContextStatusSignal mContextLostSignal;
481 Dali::Stage::ContextStatusSignal mContextRegainedSignal;
483 Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
486 } // namespace Internal
488 // Helpers for public-api forwarding methods
490 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
492 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
494 BaseObject& handle = stage.GetBaseObject();
496 return static_cast<Internal::Stage&>(handle);
499 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
501 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
503 const BaseObject& handle = stage.GetBaseObject();
505 return static_cast<const Internal::Stage&>(handle);
510 #endif // __DALI_INTERNAL_STAGE_H__