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