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