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