Merge "Remove String::EMPTY" into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / common / stage-impl.h
1 #ifndef __DALI_INTERNAL_STAGE_H__
2 #define __DALI_INTERNAL_STAGE_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
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>
38
39 #ifdef DYNAMICS_SUPPORT
40 #include <dali/internal/event/dynamics/dynamics-declarations.h>
41 #include <dali/internal/event/dynamics/dynamics-notifier.h>
42 #endif
43
44 namespace Dali
45 {
46
47 struct Vector2;
48
49 namespace Integration
50 {
51 class SystemOverlay;
52 class DynamicsFactory;
53 }
54
55 namespace Internal
56 {
57
58 namespace SceneGraph
59 {
60 class UpdateManager;
61 }
62
63 class AnimationPlaylist;
64 class PropertyNotificationManager;
65 class Layer;
66 class LayerList;
67 class SystemOverlay;
68 class CameraActor;
69 class RenderTaskList;
70
71 /**
72  * Implementation of Stage
73  */
74 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public EventThreadServices
75 {
76 public:
77
78   /**
79    * Create the stage
80    * @param[in] playlist for animations
81    * @param[in] propertyNotificationManager
82    * @param[in] updateManager
83    * @param[in] notificationManager
84    */
85   static StagePtr New( AnimationPlaylist& playlist,
86                        PropertyNotificationManager& propertyNotificationManager,
87                        SceneGraph::UpdateManager& updateManager,
88                        NotificationManager& notificationManager );
89
90   /**
91    * Initialize the stage.
92    */
93   void Initialize();
94
95   /**
96    * Uninitialize the stage.
97    */
98   void Uninitialize();
99
100   /**
101    * @copydoc Dali::Stage::GetCurrent()
102    * @note this version is for internal usage so it does not assert
103    */
104   static StagePtr GetCurrent();
105
106   /**
107    * @copydoc Dali::Stage::IsInstalled().
108    */
109   static bool IsInstalled();
110
111   /**
112    * @copydoc Dali::Stage::GetObjectRegistry()
113    */
114   ObjectRegistry& GetObjectRegistry();
115
116   /**
117    * Retrieve the root actor (not publically accessible).
118    * @return The root actor.
119    */
120   Layer& GetRootActor();
121
122   /**
123    * Returns the animation playlist.
124    * @return reference to the animation playlist.
125    */
126   AnimationPlaylist& GetAnimationPlaylist();
127
128   /**
129    * Returns the property notification manager.
130    * @return reference to the property notification manager.
131    */
132   PropertyNotificationManager& GetPropertyNotificationManager();
133
134   // Root actor accessors
135
136   /**
137    * @copydoc Dali::Stage::Add()
138    */
139   void Add( Actor& actor );
140
141   /**
142    * @copydoc Dali::Stage::Remove()
143    */
144   void Remove( Actor& actor );
145
146   /**
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.
150    */
151   void SetSize( float width, float height );
152
153   /**
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.
158    */
159   Vector2 GetSize() const;
160
161   /**
162    * @copydoc Dali::Stage::GetRenderTaskList()
163    */
164   RenderTaskList& GetRenderTaskList() const;
165
166   /**
167    * Create a default camera actor
168    */
169   void CreateDefaultCameraActor();
170
171   /**
172    * From RenderTaskDefaults; retrieve the default root actor.
173    * @return The default root actor.
174    */
175   virtual Actor& GetDefaultRootActor();
176
177   /**
178    * From RenderTaskDefaults; retrieve the default camera actor.
179    * @return The default camera actor.
180    */
181   virtual CameraActor& GetDefaultCameraActor();
182
183   // Layers
184
185   /**
186    * @copydoc Dali::Stage::GetLayerCount()
187    */
188   unsigned int GetLayerCount() const;
189
190   /**
191    * @copydoc Dali::Stage::GetLayer()
192    */
193   Dali::Layer GetLayer( unsigned int depth ) const;
194
195   /**
196    * @copydoc Dali::Stage::GetRootLayer()
197    */
198   Dali::Layer GetRootLayer() const;
199
200   /**
201    * Retrieve the ordered list of on-stage layers.
202    * @return The layer-list.
203    */
204   LayerList& GetLayerList();
205
206   // System-level overlay actors
207
208   /**
209    * @copydoc Dali::Integration::Core::GetSystemOverlay()
210    */
211   Integration::SystemOverlay& GetSystemOverlay();
212
213   /**
214    * Retrieve the internal implementation of the SystemOverlay.
215    * @return The implementation, or NULL if this has never been requested from Integration API.
216    */
217   SystemOverlay* GetSystemOverlayInternal();
218
219   // Stereoscopy
220
221   /**
222    * @copydoc Dali::Integration::Core::SetViewMode()
223    */
224   void SetViewMode( ViewMode viewMode );
225
226   /**
227    * @copydoc Dali::Integration::Core::GetViewMode()
228    */
229   ViewMode GetViewMode() const;
230
231   /**
232    * @copydoc Dali::Integration::Core::SetStereoBase()
233    */
234   void SetStereoBase( float stereoBase );
235
236   /**
237    * @copydoc Dali::Integration::Core::GetStereoBase()
238    */
239   float GetStereoBase() const;
240
241   // Keyboard stuff
242
243   /**
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
247    */
248   void SetKeyboardFocusActor( Actor* actor );
249
250   /**
251    * Get the actor that is currently set to receive keyboard inputs
252    * @return Pointer to the actor set to receive keyboard inputs.
253    */
254   Actor* GetKeyboardFocusActor() const;
255
256   /**
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.
259    */
260   void RemoveActorFromKeyFocus( Actor* actor );
261
262   // Misc
263
264   /**
265    * @copydoc Dali::Stage::SetBackgroundColor
266    */
267   void SetBackgroundColor(Vector4 color);
268
269   /**
270    * @copydoc Dali::Stage::GetBackgroundColor
271    */
272   Vector4 GetBackgroundColor() const;
273
274   /**
275    * @copydoc Dali::Stage::GetDpi
276    */
277   Vector2 GetDpi() const;
278
279   /**
280    * Sets horizontal and vertical pixels per inch value that is used by the display
281    * @param[in] dpi Horizontal and vertical dpi value
282    */
283   void SetDpi( Vector2 dpi );
284
285 #ifdef DYNAMICS_SUPPORT
286
287   /**
288    * Return the Dynamics Simulation Notifier object
289    * @return The Dynamics Simulation Notifier object
290    */
291   DynamicsNotifier& GetDynamicsNotifier();
292
293   /**
294    * @copydoc Dali::Stage::InitializeDynamics
295    */
296   DynamicsWorldPtr InitializeDynamics(DynamicsWorldConfigPtr config);
297
298   /**
299    * @copydoc Dali::Stage::GetDynamicsWorld
300    */
301   DynamicsWorldPtr GetDynamicsWorld();
302
303   /**
304    * @copydoc Dali::Stage::TerminateDynamics
305    */
306   void TerminateDynamics();
307
308 #endif // DYNAMICS_SUPPORT
309
310   NotificationManager& GetNotificationManager()
311   {
312     return mNotificationManager;
313   }
314
315   /**
316    * @copydoc Dali::Stage::KeepRendering()
317    */
318   void KeepRendering( float durationSeconds );
319
320   /**
321    * Used by the EventProcessor to emit key event signals.
322    * @param[in] event The key event.
323    */
324   void EmitKeyEventSignal(const KeyEvent& event);
325
326   /**
327    * Emits the event processing finished signal.
328    *
329    * @see Dali::Stage::SignalEventProcessingFinished()
330    */
331   void EmitEventProcessingFinishedSignal();
332
333   /**
334    * Emits the touched signal.
335    * @param[in] touch The touch event details.
336    */
337   void EmitTouchedSignal( const TouchEvent& touch );
338
339   /**
340    * Used by the EventProcessor to emit wheel event signals.
341    * @param[in] event The wheel event.
342    */
343   void EmitWheelEventSignal( const WheelEvent& event );
344
345   /**
346    * Emits the scene created.
347    */
348   void EmitSceneCreatedSignal();
349
350   /**
351    * @copydoc Dali::Stage::KeyEventSignal()
352    */
353   Dali::Stage::KeyEventSignalType& KeyEventSignal();
354
355   /**
356    * @copydoc Dali::Stage::SignalEventProcessingFinished()
357    */
358   Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
359
360   /**
361     * @copydoc Dali::Stage::TouchedSignal()
362     */
363   Dali::Stage::TouchedSignalType& TouchedSignal();
364
365   /**
366    * @copydoc Dali::Stage::WheelEventSignal()
367    */
368   Dali::Stage::WheelEventSignalType& WheelEventSignal();
369
370   /**
371    * @copydoc Dali::Stage::ContextLostSignal()
372    */
373   Dali::Stage::ContextStatusSignal& ContextLostSignal();
374
375   /**
376    * @copydoc Dali::Stage::ContextRegainedSignal()
377    */
378   Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
379
380   /**
381    * @copydoc Dali::Stage::SceneCreatedSignal()
382    */
383   Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
384
385   /**
386    * Connects a callback function with the object's signals.
387    * @param[in] object The object providing the signal.
388    * @param[in] tracker Used to disconnect the signal.
389    * @param[in] signalName The signal to connect to.
390    * @param[in] functor A newly allocated FunctorDelegate.
391    * @return True if the signal was connected.
392    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
393    */
394   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
395
396 private: // Implementation of ContextNotificationInterface:
397
398   /**
399    * @copydoc Dali::Integration::NotifyContextLost();
400    */
401   virtual void NotifyContextLost();
402
403   /**
404    * @copydoc Dali::Integration::NotifyContextRegained();
405    */
406   virtual void NotifyContextRegained();
407
408 public: // Implementation of EventThreadServices
409
410   /**
411    * @copydoc EventThreadServices::RegisterObject
412    */
413   virtual void RegisterObject( BaseObject* object);
414
415   /**
416    * @copydoc EventThreadServices::UnregisterObject
417    */
418   virtual void UnregisterObject( BaseObject* object);
419
420   /**
421    * @copydoc EventThreadServices::GetUpdateManager
422    */
423   virtual SceneGraph::UpdateManager& GetUpdateManager();
424
425   /**
426    * @copydoc EventThreadServices::ReserveMessageSlot
427    */
428   virtual unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene );
429
430   /**
431    * @copydoc EventThreadServices::GetEventBufferIndex
432    */
433   virtual BufferIndex GetEventBufferIndex() const;
434
435 private:
436
437   /**
438    * Protected constructor; see also Stage::New()
439    */
440   Stage( AnimationPlaylist& playlist,
441          PropertyNotificationManager& propertyNotificationManager,
442          SceneGraph::UpdateManager& updateManager,
443          NotificationManager& notificationManager );
444
445   /**
446    * A reference counted object may only be deleted by calling Unreference()
447    */
448   virtual ~Stage();
449
450 private:
451
452   // For 'Fire and forget' animation support
453   AnimationPlaylist& mAnimationPlaylist;
454
455   PropertyNotificationManager& mPropertyNotificationManager;
456
457   SceneGraph::UpdateManager& mUpdateManager;
458
459   NotificationManager& mNotificationManager;
460
461   // The Actual size of the stage.
462   Vector2 mSize;
463
464   // Cached for public GetBackgroundColor()
465   Vector4 mBackgroundColor;
466
467   LayerPtr mRootLayer;
468
469   // Ordered list of currently on-stage layers
470   OwnerPointer<LayerList> mLayerList;
471
472   IntrusivePtr<CameraActor> mDefaultCamera;
473
474   ViewMode mViewMode;
475   float mStereoBase;
476
477   Vector2 mDpi;
478
479   // The object registry
480   ObjectRegistryPtr mObjectRegistry;
481
482 #ifdef DYNAMICS_SUPPORT
483
484   DynamicsNotifier mDynamicsNotifier;
485
486   // The Dynamics simulation world object
487   Integration::DynamicsFactory* mDynamicsFactory;   // Not owned pointer to DynamicsFactory (PlatformAbstraction will clean up)
488   DynamicsWorldPtr mDynamicsWorld;
489
490 #endif // DYNAMICS_SUPPORT
491
492   // The list of render-tasks
493   IntrusivePtr<RenderTaskList> mRenderTaskList;
494
495   Dali::RenderTask mRightRenderTask;
496   IntrusivePtr<CameraActor> mRightCamera;
497   Dali::RenderTask mLeftRenderTask;
498   IntrusivePtr<CameraActor> mLeftCamera;
499
500   Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
501
502   // The key event signal
503   Dali::Stage::KeyEventSignalType                 mKeyEventSignal;
504
505   // The event processing finished signal
506   Dali::Stage::EventProcessingFinishedSignalType  mEventProcessingFinishedSignal;
507
508   // The touched signal
509   Dali::Stage::TouchedSignalType                  mTouchedSignal;
510
511   // The wheel event signal
512   Dali::Stage::WheelEventSignalType               mWheelEventSignal;
513
514   Dali::Stage::ContextStatusSignal mContextLostSignal;
515   Dali::Stage::ContextStatusSignal mContextRegainedSignal;
516
517   Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
518 };
519
520 } // namespace Internal
521
522 // Helpers for public-api forwarding methods
523
524 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
525 {
526   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
527
528   BaseObject& handle = stage.GetBaseObject();
529
530   return static_cast<Internal::Stage&>(handle);
531 }
532
533 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
534 {
535   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
536
537   const BaseObject& handle = stage.GetBaseObject();
538
539   return static_cast<const Internal::Stage&>(handle);
540 }
541
542 } // namespace Dali
543
544 #endif // __DALI_INTERNAL_STAGE_H__