Changes to support stereoscopic 3D
[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 Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/object/ref-object.h>
22 #include <dali/public-api/common/stage.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/internal/common/owner-pointer.h>
25 #include <dali/internal/event/actors/layer-impl.h>
26 #include <dali/internal/event/common/object-registry-impl.h>
27 #include <dali/internal/event/common/stage-def.h>
28 #include <dali/internal/event/dynamics/dynamics-declarations.h>
29 #include <dali/internal/event/render-tasks/render-task-defaults.h>
30 #include <dali/internal/update/manager/update-manager.h>
31 #include <dali/public-api/common/view-mode.h>
32 #include <dali/public-api/math/vector2.h>
33 #include <dali/public-api/math/vector3.h>
34 #include <dali/public-api/math/vector4.h>
35 #include <dali/public-api/render-tasks/render-task.h>
36
37 namespace Dali
38 {
39
40 struct Vector2;
41
42 namespace Integration
43 {
44 class SystemOverlay;
45 class DynamicsFactory;
46 }
47
48 namespace Internal
49 {
50
51 namespace SceneGraph
52 {
53 class UpdateManager;
54 }
55
56 class AnimationPlaylist;
57 class PropertyNotificationManager;
58 class Layer;
59 class LayerList;
60 class SystemOverlay;
61 class CameraActor;
62 class RenderTaskList;
63
64 /**
65  * Implementation of Stage
66  */
67 class Stage : public BaseObject, public RenderTaskDefaults
68 {
69 public:
70
71   /**
72    * Create the stage
73    * @param playlist for animations
74    * @param dynamicsNotifier
75    * @param updateManager
76    * @param notificationManager
77    */
78   static StagePtr New( AnimationPlaylist& playlist,
79                        PropertyNotificationManager& propertyNotificationManager,
80                        DynamicsNotifier& dynamicsNotifier,
81                        SceneGraph::UpdateManager& updateManager,
82                        NotificationManager& notificationManager );
83
84   /**
85    * Initialize the stage.
86    */
87   void Initialize();
88
89   /**
90    * Uninitialize the stage.
91    */
92   void Uninitialize();
93
94   /**
95    * @copydoc Dali::Stage::GetCurrent()
96    */
97   static StagePtr GetCurrent();
98
99   /**
100    * @copydoc Dali::Stage::IsInstalled().
101    */
102   static bool IsInstalled();
103
104   /**
105    * @copydoc Dali::Stage::GetObjectRegistry()
106    */
107   ObjectRegistry& GetObjectRegistry();
108
109   /**
110    * Retrieve the root actor (not publically accessible).
111    * @return The root actor.
112    */
113   Layer& GetRootActor();
114
115   /**
116    * Retrieve the UpdateManager associated with this Stage
117    * @return The UpdateManager.
118    */
119   SceneGraph::UpdateManager& GetUpdateManager();
120
121   /**
122    * Helper for actors, to retrieve the current Event buffer index.
123    * @return The buffer index.
124    */
125   BufferIndex GetEventBufferIndex() const
126   {
127     // inlined as its called often from event thread
128     return mUpdateManager.GetEventBufferIndex();
129   }
130
131   /**
132    * Retrieve the interface for accessing update-thread data.
133    * @return The EventToUpdate interface.
134    */
135   EventToUpdate& GetUpdateInterface();
136
137   /**
138    * Returns the animation playlist.
139    * @return reference to the animation playlist.
140    */
141   AnimationPlaylist& GetAnimationPlaylist();
142
143   /**
144    * Returns the property notification manager.
145    * @return reference to the property notification manager.
146    */
147   PropertyNotificationManager& GetPropertyNotificationManager();
148
149   /**
150    * Return the Dynamics Simulation Notifier object
151    * @return The Dynamics Simulation Notifier object
152    */
153   DynamicsNotifier& GetDynamicsNotifier();
154
155   // Root actor accessors
156
157   /**
158    * @copydoc Dali::Stage::Add()
159    */
160   void Add( Actor& actor );
161
162   /**
163    * @copydoc Dali::Stage::Remove()
164    */
165   void Remove( Actor& actor );
166
167   /**
168    * Sets the size of the stage and indirectly, the root actor.
169    * @param [in] width  The new width.
170    * @param [in] height The new height.
171    */
172   void SetSize( float width, float height );
173
174   /**
175    * Returns the size of the Stage in pixels as a Vector.
176    * The x component will be the width of the Stage in pixels
177    * The y component will be the height of the Stage in pixels
178    * @return The size of the Stage as a Vector.
179    */
180   Vector2 GetSize() const;
181
182   /**
183    * @copydoc Dali::Stage::GetRenderTaskList()
184    */
185   RenderTaskList& GetRenderTaskList() const;
186
187   /**
188    * Create a default camera actor
189    */
190   void CreateDefaultCameraActor();
191
192   /**
193    * From RenderTaskDefaults; retrieve the default root actor.
194    * @return The default root actor.
195    */
196   virtual Actor& GetDefaultRootActor();
197
198   /**
199    * From RenderTaskDefaults; retrieve the default camera actor.
200    * @return The default camera actor.
201    */
202   virtual CameraActor& GetDefaultCameraActor();
203
204   // Layers
205
206   /**
207    * @copydoc Dali::Stage::GetLayerCount()
208    */
209   unsigned int GetLayerCount() const;
210
211   /**
212    * @copydoc Dali::Stage::GetLayer()
213    */
214   Dali::Layer GetLayer( unsigned int depth ) const;
215
216   /**
217    * @copydoc Dali::Stage::GetRootLayer()
218    */
219   Dali::Layer GetRootLayer() const;
220
221   /**
222    * Retrieve the ordered list of on-stage layers.
223    * @return The layer-list.
224    */
225   LayerList& GetLayerList();
226
227   // System-level overlay actors
228
229   /**
230    * @copydoc Dali::Integration::Core::GetSystemOverlay()
231    */
232   Integration::SystemOverlay& GetSystemOverlay();
233
234   /**
235    * Retrieve the internal implementation of the SystemOverlay.
236    * @return The implementation, or NULL if this has never been requested from Integration API.
237    */
238   SystemOverlay* GetSystemOverlayInternal();
239
240   // Stereoscopy
241
242   /**
243    * @copydoc Dali::Integration::Core::SetViewMode()
244    */
245   void SetViewMode( ViewMode viewMode );
246
247   /**
248    * @copydoc Dali::Integration::Core::GetViewMode()
249    */
250   ViewMode GetViewMode() const;
251
252   /**
253    * @copydoc Dali::Integration::Core::SetStereoBase()
254    */
255   void SetStereoBase( float stereoBase );
256
257   /**
258    * @copydoc Dali::Integration::Core::GetStereoBase()
259    */
260   float GetStereoBase() const;
261
262   // Keyboard stuff
263
264   /**
265    * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
266    * set to receive keyboard input.
267    * @param[in] actor to receive keyboard input
268    */
269   void SetKeyboardFocusActor( Actor* actor );
270
271   /**
272    * Get the actor that is currently set to receive keyboard inputs
273    * @return Pointer to the actor set to receive keyboard inputs.
274    */
275   Actor* GetKeyboardFocusActor() const;
276
277   /**
278    * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
279    * @param [in] actor which should be removed from focus.
280    */
281   void RemoveActorFromKeyFocus( Actor* actor );
282
283   // Misc
284
285   /**
286    * @copydoc Dali::Stage::SetBackgroundColor
287    */
288   void SetBackgroundColor(Vector4 color);
289
290   /**
291    * @copydoc Dali::Stage::GetBackgroundColor
292    */
293   Vector4 GetBackgroundColor() const;
294
295   /**
296    * @copydoc Dali::Stage::GetDpi
297    */
298   Vector2 GetDpi() const;
299
300   /**
301    * Sets horizontal and vertical pixels per inch value that is used by the display
302    * @param[in] dpi Horizontal and vertical dpi value
303    */
304   void SetDpi( Vector2 dpi );
305
306   /**
307    * @copydoc Dali::Stage::InitializeDynamics
308    */
309   DynamicsWorldPtr InitializeDynamics(DynamicsWorldConfigPtr config);
310
311   /**
312    * @copydoc Dali::Stage::GetDynamicsWorld
313    */
314   DynamicsWorldPtr GetDynamicsWorld();
315
316   /**
317    * @copydoc Dali::Stage::TerminateDynamics
318    */
319   void TerminateDynamics();
320
321   NotificationManager& GetNotificationManager()
322   {
323     return mNotificationManager;
324   }
325
326   /**
327    * @copydoc Dali::Stage::KeepRendering()
328    */
329   void KeepRendering( float durationSeconds );
330
331   /**
332    * Used by the EventProcessor to emit key event signals.
333    * @param[in] event The key event.
334    */
335   void EmitKeyEventSignal(const KeyEvent& event);
336
337   /**
338    * Emits the event processing finished signal.
339    *
340    * @see Dali::Stage::SignalEventProcessingFinished()
341    */
342   void EmitEventProcessingFinishedSignal();
343
344   /**
345    * Emits the touched signal.
346    * @param[in] touch The touch event details.
347    */
348   void EmitTouchedSignal( const TouchEvent& touch );
349
350   /**
351    * @copydoc Dali::Stage::KeyEventSignal()
352    */
353   Dali::Stage::KeyEventSignalV2& KeyEventSignal();
354
355   /**
356    * @copydoc Dali::Stage::SignalEventProcessingFinished()
357    */
358   Dali::Stage::EventProcessingFinishedSignalV2& EventProcessingFinishedSignal();
359
360   /**
361     * @copydoc Dali::Stage::TouchedSignal()
362     */
363   Dali::Stage::TouchedSignalV2& TouchedSignal();
364
365 private:
366
367   /**
368    * Protected constructor; see also Stage::New()
369    */
370   Stage( AnimationPlaylist& playlist,
371          PropertyNotificationManager& propertyNotificationManager,
372          DynamicsNotifier& dynamicsNotifier,
373          SceneGraph::UpdateManager& updateManager,
374          NotificationManager& notificationManager );
375
376   /**
377    * A reference counted object may only be deleted by calling Unreference()
378    */
379   virtual ~Stage();
380
381 private:
382
383   // For 'Fire and forget' animation support
384   AnimationPlaylist& mAnimationPlaylist;
385
386   PropertyNotificationManager& mPropertyNotificationManager;
387
388   DynamicsNotifier& mDynamicsNotifier;
389
390   SceneGraph::UpdateManager& mUpdateManager;
391
392   NotificationManager& mNotificationManager;
393
394   // The Actual size of the stage.
395   Vector2 mSize;
396
397   // Cached for public GetBackgroundColor()
398   Vector4 mBackgroundColor;
399
400   LayerPtr mRootLayer;
401
402   // Ordered list of currently on-stage layers
403   OwnerPointer<LayerList> mLayerList;
404
405   IntrusivePtr<CameraActor> mDefaultCamera;
406
407   ViewMode mViewMode;
408   float mStereoBase;
409
410   Vector2 mDpi;
411
412   // The object registry
413   ObjectRegistryPtr mObjectRegistry;
414
415   // The Dynamics simulation world object
416   Integration::DynamicsFactory* mDynamicsFactory;   // Not owned pointer to DynamicsFactory (PlatformAbstraction will clean up)
417   DynamicsWorldPtr mDynamicsWorld;
418
419   // The list of render-tasks
420   IntrusivePtr<RenderTaskList> mRenderTaskList;
421
422   Dali::RenderTask mRightRenderTask;
423   IntrusivePtr<CameraActor> mRightCamera;
424   Dali::RenderTask mLeftRenderTask;
425   IntrusivePtr<CameraActor> mLeftCamera;
426
427   Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
428
429   // The key event signal
430   Dali::Stage::KeyEventSignalV2                 mKeyEventSignalV2;
431
432   // The event processing finished signal
433   Dali::Stage::EventProcessingFinishedSignalV2  mEventProcessingFinishedSignalV2;
434
435   // The touched signal
436   Dali::Stage::TouchedSignalV2                  mTouchedSignalV2;
437 };
438
439 } // namespace Internal
440
441 // Helpers for public-api forwarding methods
442
443 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
444 {
445   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
446
447   BaseObject& handle = stage.GetBaseObject();
448
449   return static_cast<Internal::Stage&>(handle);
450 }
451
452 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
453 {
454   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
455
456   const BaseObject& handle = stage.GetBaseObject();
457
458   return static_cast<const Internal::Stage&>(handle);
459 }
460
461 } // namespace Dali
462
463 #endif // __DALI_INTERNAL_STAGE_H__