Merge "Change to process events when the application is paused" into devel/master
[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) 2017 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/devel-api/common/stage-devel.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/integration-api/context-notifier.h>
27 #include <dali/internal/common/owner-pointer.h>
28 #include <dali/internal/event/actors/layer-impl.h>
29 #include <dali/internal/event/common/event-thread-services.h>
30 #include <dali/internal/event/common/object-registry-impl.h>
31 #include <dali/internal/event/common/stage-def.h>
32 #include <dali/internal/event/render-tasks/render-task-defaults.h>
33 #include <dali/internal/update/manager/update-manager.h>
34 #include <dali/public-api/common/view-mode.h>
35 #include <dali/public-api/math/vector2.h>
36 #include <dali/public-api/math/vector3.h>
37 #include <dali/public-api/math/vector4.h>
38 #include <dali/public-api/render-tasks/render-task.h>
39
40 namespace Dali
41 {
42
43 struct Vector2;
44
45 namespace Integration
46 {
47 class SystemOverlay;
48 class RenderController;
49 }
50
51 namespace Internal
52 {
53
54 namespace SceneGraph
55 {
56 class UpdateManager;
57 }
58
59 class AnimationPlaylist;
60 class PropertyNotificationManager;
61 class Layer;
62 class LayerList;
63 class SystemOverlay;
64 class CameraActor;
65 class RenderTaskList;
66
67 /**
68  * Implementation of Stage
69  */
70 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public EventThreadServices
71 {
72 public:
73
74   /**
75    * Create the stage
76    * @param[in] playlist for animations
77    * @param[in] propertyNotificationManager
78    * @param[in] updateManager
79    * @param[in] notificationManager
80    * @param[in] renderController
81    */
82   static StagePtr New( AnimationPlaylist& playlist,
83                        PropertyNotificationManager& propertyNotificationManager,
84                        SceneGraph::UpdateManager& updateManager,
85                        NotificationManager& notificationManager,
86                        Integration::RenderController& renderController );
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    * @note this version is for internal usage so it does not assert
101    */
102   static StagePtr GetCurrent();
103
104   /**
105    * @copydoc Dali::Stage::IsInstalled().
106    */
107   static bool IsInstalled();
108
109   /**
110    * @copydoc Dali::Stage::GetObjectRegistry()
111    */
112   ObjectRegistry& GetObjectRegistry();
113
114   /**
115    * Retrieve the root actor (not publically accessible).
116    * @return The root actor.
117    */
118   Layer& GetRootActor();
119
120   /**
121    * Returns the animation playlist.
122    * @return reference to the animation playlist.
123    */
124   AnimationPlaylist& GetAnimationPlaylist();
125
126   /**
127    * Returns the property notification manager.
128    * @return reference to the property notification manager.
129    */
130   PropertyNotificationManager& GetPropertyNotificationManager();
131
132   // Root actor accessors
133
134   /**
135    * @copydoc Dali::Stage::Add()
136    */
137   void Add( Actor& actor );
138
139   /**
140    * @copydoc Dali::Stage::Remove()
141    */
142   void Remove( Actor& actor );
143
144   /**
145    * Used to calculate the size of the stage and indirectly, the root actor.
146    * @param [in] width  The new surface width.
147    * @param [in] height The new surface height.
148    */
149   void SurfaceResized( float width, float height );
150
151   /**
152    * Sets the top margin size.
153    * Available stage size is reduced by this size.
154    * The stage is located below the size at the top of the display
155    * initial size is zero before it is assigned
156    * @param[in] margin margin size
157    */
158   void SetTopMargin( unsigned int margin );
159
160   /**
161    * Returns the size of the Stage in pixels as a Vector.
162    * The x component will be the width of the Stage in pixels
163    * The y component will be the height of the Stage in pixels
164    * @return The size of the Stage as a Vector.
165    */
166   Vector2 GetSize() const;
167
168   /**
169    * @copydoc Dali::Stage::GetRenderTaskList()
170    */
171   RenderTaskList& GetRenderTaskList() const;
172
173   /**
174    * Create a default camera actor
175    */
176   void CreateDefaultCameraActor();
177
178   /**
179    * Set position of default camera for current stage size
180    */
181   void SetDefaultCameraPosition();
182
183   /**
184    * From RenderTaskDefaults; retrieve the default root actor.
185    * @return The default root actor.
186    */
187   virtual Actor& GetDefaultRootActor();
188
189   /**
190    * From RenderTaskDefaults; retrieve the default camera actor.
191    * @return The default camera actor.
192    */
193   virtual CameraActor& GetDefaultCameraActor();
194
195   // Layers
196
197   /**
198    * @copydoc Dali::Stage::GetLayerCount()
199    */
200   unsigned int GetLayerCount() const;
201
202   /**
203    * @copydoc Dali::Stage::GetLayer()
204    */
205   Dali::Layer GetLayer( unsigned int depth ) const;
206
207   /**
208    * @copydoc Dali::Stage::GetRootLayer()
209    */
210   Dali::Layer GetRootLayer() const;
211
212   /**
213    * Retrieve the ordered list of on-stage layers.
214    * @return The layer-list.
215    */
216   LayerList& GetLayerList();
217
218   // System-level overlay actors
219
220   /**
221    * @copydoc Dali::Integration::Core::GetSystemOverlay()
222    */
223   Integration::SystemOverlay& GetSystemOverlay();
224
225   /**
226    * Retrieve the internal implementation of the SystemOverlay.
227    * @return The implementation, or NULL if this has never been requested from Integration API.
228    */
229   SystemOverlay* GetSystemOverlayInternal();
230
231   // Stereoscopy
232
233   /**
234    * @copydoc Dali::Integration::Core::SetViewMode()
235    */
236   void SetViewMode( ViewMode viewMode );
237
238   /**
239    * @copydoc Dali::Integration::Core::GetViewMode()
240    */
241   ViewMode GetViewMode() const;
242
243   /**
244    * @copydoc Dali::Integration::Core::SetStereoBase()
245    */
246   void SetStereoBase( float stereoBase );
247
248   /**
249    * @copydoc Dali::Integration::Core::GetStereoBase()
250    */
251   float GetStereoBase() const;
252
253   // Keyboard stuff
254
255   /**
256    * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
257    * set to receive keyboard input.
258    * @param[in] actor to receive keyboard input
259    */
260   void SetKeyboardFocusActor( Actor* actor );
261
262   /**
263    * Get the actor that is currently set to receive keyboard inputs
264    * @return Pointer to the actor set to receive keyboard inputs.
265    */
266   Actor* GetKeyboardFocusActor() const;
267
268   /**
269    * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
270    * @param [in] actor which should be removed from focus.
271    */
272   void RemoveActorFromKeyFocus( Actor* actor );
273
274   // Misc
275
276   /**
277    * @copydoc Dali::Stage::SetBackgroundColor
278    */
279   void SetBackgroundColor(Vector4 color);
280
281   /**
282    * @copydoc Dali::Stage::GetBackgroundColor
283    */
284   Vector4 GetBackgroundColor() const;
285
286   /**
287    * @copydoc Dali::Stage::GetDpi
288    */
289   Vector2 GetDpi() const;
290
291   /**
292    * Sets horizontal and vertical pixels per inch value that is used by the display
293    * @param[in] dpi Horizontal and vertical dpi value
294    */
295   void SetDpi( Vector2 dpi );
296
297   NotificationManager& GetNotificationManager()
298   {
299     return mNotificationManager;
300   }
301
302   /**
303    * @copydoc Dali::Stage::KeepRendering()
304    */
305   void KeepRendering( float durationSeconds );
306
307   /**
308    * Used by the EventProcessor to emit key event signals.
309    * @param[in] event The key event.
310    */
311   void EmitKeyEventSignal(const KeyEvent& event);
312
313   /**
314    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
315    * @param[in] event The key event.
316    * @return The return is true if KeyEvent is consumed, otherwise false.
317    */
318   bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
319
320   /**
321    * Emits the event processing finished signal.
322    *
323    * @see Dali::Stage::SignalEventProcessingFinished()
324    */
325   void EmitEventProcessingFinishedSignal();
326
327   /**
328    * Emits the touched signal.
329    * @param[in] touchEvent The touch event details (Old API).
330    * @param[in] touch The touch event details.
331    */
332   void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
333
334   /**
335    * Used by the EventProcessor to emit wheel event signals.
336    * @param[in] event The wheel event.
337    */
338   void EmitWheelEventSignal( const WheelEvent& event );
339
340   /**
341    * Emits the scene created.
342    */
343   void EmitSceneCreatedSignal();
344
345   /**
346    * @copydoc Dali::Stage::KeyEventSignal()
347    */
348   Dali::Stage::KeyEventSignalType& KeyEventSignal();
349
350   /**
351    * @copydoc Dali::Stage::SignalEventProcessingFinished()
352    */
353   Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
354
355   /**
356     * @copydoc Dali::Stage::TouchedSignal()
357     */
358   Dali::Stage::TouchedSignalType& TouchedSignal();
359
360   /**
361     * @copydoc Dali::Stage::TouchSignal()
362     */
363   Dali::Stage::TouchSignalType& TouchSignal();
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    * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
387    */
388   Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
389
390   /**
391    * Connects a callback function with the object's signals.
392    * @param[in] object The object providing the signal.
393    * @param[in] tracker Used to disconnect the signal.
394    * @param[in] signalName The signal to connect to.
395    * @param[in] functor A newly allocated FunctorDelegate.
396    * @return True if the signal was connected.
397    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
398    */
399   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
400
401 private: // Implementation of ContextNotificationInterface:
402
403   /**
404    * @copydoc Dali::Integration::NotifyContextLost();
405    */
406   virtual void NotifyContextLost();
407
408   /**
409    * @copydoc Dali::Integration::NotifyContextRegained();
410    */
411   virtual void NotifyContextRegained();
412
413 public: // Implementation of EventThreadServices
414
415   /**
416    * @copydoc EventThreadServices::RegisterObject
417    */
418   virtual void RegisterObject( BaseObject* object);
419
420   /**
421    * @copydoc EventThreadServices::UnregisterObject
422    */
423   virtual void UnregisterObject( BaseObject* object);
424
425   /**
426    * @copydoc EventThreadServices::GetUpdateManager
427    */
428   virtual SceneGraph::UpdateManager& GetUpdateManager();
429
430   /**
431    * @copydoc EventThreadServices::GetRenderController
432    */
433   virtual Integration::RenderController& GetRenderController();
434
435   /**
436    * @copydoc EventThreadServices::ReserveMessageSlot
437    */
438   virtual unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene );
439
440   /**
441    * @copydoc EventThreadServices::GetEventBufferIndex
442    */
443   virtual BufferIndex GetEventBufferIndex() const;
444
445   /**
446    * @copydoc EventThreadServices::ForceNextUpdate
447    */
448   virtual void ForceNextUpdate();
449
450   /**
451    * @copydoc EventThreadServices::IsNextUpdateForced
452    */
453   virtual bool IsNextUpdateForced();
454
455   /**
456    * Request that the depth tree is rebuilt
457    */
458   void RequestRebuildDepthTree();
459
460   /**
461    * Rebuilds the depth tree at the end of the event frame if
462    * it was requested this frame.
463    */
464   void RebuildDepthTree();
465
466 private:
467
468   /**
469    * Protected constructor; see also Stage::New()
470    */
471   Stage( AnimationPlaylist& playlist,
472          PropertyNotificationManager& propertyNotificationManager,
473          SceneGraph::UpdateManager& updateManager,
474          NotificationManager& notificationManager,
475          Integration::RenderController& renderController );
476
477   /**
478    * A reference counted object may only be deleted by calling Unreference()
479    */
480   virtual ~Stage();
481
482 private:
483
484   // For 'Fire and forget' animation support
485   AnimationPlaylist& mAnimationPlaylist;
486
487   PropertyNotificationManager& mPropertyNotificationManager;
488
489   SceneGraph::UpdateManager& mUpdateManager;
490
491   NotificationManager& mNotificationManager;
492
493   Integration::RenderController& mRenderController;
494
495   // The stage-size may be less than surface-size (reduced by top-margin)
496   Vector2 mSize;
497   Vector2 mSurfaceSize;
498
499   // Cached for public GetBackgroundColor()
500   Vector4 mBackgroundColor;
501
502   LayerPtr mRootLayer;
503
504   // Ordered list of currently on-stage layers
505   OwnerPointer<LayerList> mLayerList;
506
507   IntrusivePtr<CameraActor> mDefaultCamera;
508
509   ViewMode mViewMode;
510   float mStereoBase;
511
512   unsigned int mTopMargin;
513   Vector2 mDpi;
514
515   // The object registry
516   ObjectRegistryPtr mObjectRegistry;
517
518   // The list of render-tasks
519   IntrusivePtr<RenderTaskList> mRenderTaskList;
520
521   Dali::RenderTask mRightRenderTask;
522   IntrusivePtr<CameraActor> mRightCamera;
523   Dali::RenderTask mLeftRenderTask;
524   IntrusivePtr<CameraActor> mLeftCamera;
525
526   Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
527
528   bool mDepthTreeDirty; ///< True if the depth tree needs recalculating
529   bool mForceNextUpdate; ///< True if the next rendering is really required.
530
531   // The key event signal
532   Dali::Stage::KeyEventSignalType                 mKeyEventSignal;
533   Dali::DevelStage::KeyEventGeneratedSignalType   mKeyEventGeneratedSignal;
534
535   // The event processing finished signal
536   Dali::Stage::EventProcessingFinishedSignalType  mEventProcessingFinishedSignal;
537
538   // The touched signals
539   Dali::Stage::TouchedSignalType                  mTouchedSignal;
540   Dali::Stage::TouchSignalType                    mTouchSignal;
541
542   // The wheel event signal
543   Dali::Stage::WheelEventSignalType               mWheelEventSignal;
544
545   Dali::Stage::ContextStatusSignal mContextLostSignal;
546   Dali::Stage::ContextStatusSignal mContextRegainedSignal;
547
548   Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
549 };
550
551 } // namespace Internal
552
553 // Helpers for public-api forwarding methods
554
555 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
556 {
557   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
558
559   BaseObject& handle = stage.GetBaseObject();
560
561   return static_cast<Internal::Stage&>(handle);
562 }
563
564 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
565 {
566   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
567
568   const BaseObject& handle = stage.GetBaseObject();
569
570   return static_cast<const Internal::Stage&>(handle);
571 }
572
573 } // namespace Dali
574
575 #endif // __DALI_INTERNAL_STAGE_H__