[Tizen] Revert "Remove TypeRegistration from deprecated Image classes"
[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 SystemOverlay;
47 class RenderController;
48 }
49
50 namespace Internal
51 {
52
53 namespace SceneGraph
54 {
55 class UpdateManager;
56 }
57
58 class AnimationPlaylist;
59 class PropertyNotificationManager;
60 class Layer;
61 class LayerList;
62 class SystemOverlay;
63 class CameraActor;
64 class RenderTaskList;
65
66 /**
67  * Implementation of Stage
68  */
69 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public EventThreadServices
70 {
71 public:
72
73   /**
74    * Create the stage
75    * @param[in] playlist for animations
76    * @param[in] propertyNotificationManager
77    * @param[in] updateManager
78    * @param[in] notificationManager
79    * @param[in] renderController
80    */
81   static StagePtr New( AnimationPlaylist& playlist,
82                        PropertyNotificationManager& propertyNotificationManager,
83                        SceneGraph::UpdateManager& updateManager,
84                        NotificationManager& notificationManager,
85                        Integration::RenderController& renderController );
86
87   /**
88    * Initialize the stage.
89    * @param[in] renderToFbo Whether to render into a Frame Buffer Object.
90    */
91   void Initialize( bool renderToFbo );
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( uint32_t 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   uint32_t GetLayerCount() const;
201
202   /**
203    * @copydoc Dali::Stage::GetLayer()
204    */
205   Dali::Layer GetLayer( uint32_t 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   // Keyboard stuff
232
233   /**
234    * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
235    * set to receive keyboard input.
236    * @param[in] actor to receive keyboard input
237    */
238   void SetKeyboardFocusActor( Actor* actor );
239
240   /**
241    * Get the actor that is currently set to receive keyboard inputs
242    * @return Pointer to the actor set to receive keyboard inputs.
243    */
244   Actor* GetKeyboardFocusActor() const;
245
246   /**
247    * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
248    * @param [in] actor which should be removed from focus.
249    */
250   void RemoveActorFromKeyFocus( Actor* actor );
251
252   // Misc
253
254   /**
255    * @copydoc Dali::Stage::SetBackgroundColor
256    */
257   void SetBackgroundColor(Vector4 color);
258
259   /**
260    * @copydoc Dali::Stage::GetBackgroundColor
261    */
262   Vector4 GetBackgroundColor() const;
263
264   /**
265    * @copydoc Dali::Stage::GetDpi
266    */
267   Vector2 GetDpi() const;
268
269   /**
270    * Sets horizontal and vertical pixels per inch value that is used by the display
271    * @param[in] dpi Horizontal and vertical dpi value
272    */
273   void SetDpi( Vector2 dpi );
274
275   NotificationManager& GetNotificationManager()
276   {
277     return mNotificationManager;
278   }
279
280   /**
281    * @copydoc Dali::Stage::KeepRendering()
282    */
283   void KeepRendering( float durationSeconds );
284
285   /**
286    * @copydoc Dali::DevelStage::SetRenderingBehavior()
287    */
288   void SetRenderingBehavior( DevelStage::Rendering renderingBehavior );
289
290   /**
291    * @copydoc Dali::DevelStage::GetRenderingBehavior()
292    */
293   DevelStage::Rendering GetRenderingBehavior() const;
294
295   /**
296    * Used by the EventProcessor to emit key event signals.
297    * @param[in] event The key event.
298    */
299   void EmitKeyEventSignal(const KeyEvent& event);
300
301   /**
302    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
303    * @param[in] event The key event.
304    * @return The return is true if KeyEvent is consumed, otherwise false.
305    */
306   bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
307
308   /**
309    * Emits the event processing finished signal.
310    *
311    * @see Dali::Stage::SignalEventProcessingFinished()
312    */
313   void EmitEventProcessingFinishedSignal();
314
315   /**
316    * Emits the touched signal.
317    * @param[in] touchEvent The touch event details (Old API).
318    * @param[in] touch The touch event details.
319    */
320   void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
321
322   /**
323    * Used by the EventProcessor to emit wheel event signals.
324    * @param[in] event The wheel event.
325    */
326   void EmitWheelEventSignal( const WheelEvent& event );
327
328   /**
329    * Emits the scene created.
330    */
331   void EmitSceneCreatedSignal();
332
333   /**
334    * @copydoc Dali::Stage::KeyEventSignal()
335    */
336   Dali::Stage::KeyEventSignalType& KeyEventSignal();
337
338   /**
339    * @copydoc Dali::Stage::SignalEventProcessingFinished()
340    */
341   Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
342
343   /**
344     * @copydoc Dali::Stage::TouchedSignal()
345     */
346   Dali::Stage::TouchedSignalType& TouchedSignal();
347
348   /**
349     * @copydoc Dali::Stage::TouchSignal()
350     */
351   Dali::Stage::TouchSignalType& TouchSignal();
352
353   /**
354    * @copydoc Dali::Stage::WheelEventSignal()
355    */
356   Dali::Stage::WheelEventSignalType& WheelEventSignal();
357
358   /**
359    * @copydoc Dali::Stage::ContextLostSignal()
360    */
361   Dali::Stage::ContextStatusSignal& ContextLostSignal();
362
363   /**
364    * @copydoc Dali::Stage::ContextRegainedSignal()
365    */
366   Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
367
368   /**
369    * @copydoc Dali::Stage::SceneCreatedSignal()
370    */
371   Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
372
373   /**
374    * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
375    */
376   Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
377
378   /**
379    * @copydoc Dali::DevelStage::AddFrameCallback()
380    */
381   void AddFrameCallback( FrameCallbackInterface& frameCallback, Actor& rootActor );
382
383   /**
384    * @copydoc Dali::DevelStage::RemoveFrameCallback()
385    */
386   void RemoveFrameCallback( FrameCallbackInterface& frameCallback );
387
388   /**
389    * Connects a callback function with the object's signals.
390    * @param[in] object The object providing the signal.
391    * @param[in] tracker Used to disconnect the signal.
392    * @param[in] signalName The signal to connect to.
393    * @param[in] functor A newly allocated FunctorDelegate.
394    * @return True if the signal was connected.
395    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
396    */
397   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
398
399 private: // Implementation of ContextNotificationInterface:
400
401   /**
402    * @copydoc Dali::Integration::NotifyContextLost();
403    */
404   virtual void NotifyContextLost();
405
406   /**
407    * @copydoc Dali::Integration::NotifyContextRegained();
408    */
409   virtual void NotifyContextRegained();
410
411 public: // Implementation of EventThreadServices
412
413   /**
414    * @copydoc EventThreadServices::RegisterObject
415    */
416   virtual void RegisterObject( BaseObject* object);
417
418   /**
419    * @copydoc EventThreadServices::UnregisterObject
420    */
421   virtual void UnregisterObject( BaseObject* object);
422
423   /**
424    * @copydoc EventThreadServices::GetUpdateManager
425    */
426   virtual SceneGraph::UpdateManager& GetUpdateManager();
427
428   /**
429    * @copydoc EventThreadServices::GetRenderController
430    */
431   virtual Integration::RenderController& GetRenderController();
432
433   /**
434    * @copydoc EventThreadServices::ReserveMessageSlot
435    */
436   virtual uint32_t* ReserveMessageSlot( uint32_t size, bool updateScene );
437
438   /**
439    * @copydoc EventThreadServices::GetEventBufferIndex
440    */
441   virtual BufferIndex GetEventBufferIndex() const;
442
443   /**
444    * @copydoc EventThreadServices::ForceNextUpdate
445    */
446   virtual void ForceNextUpdate();
447
448   /**
449    * @copydoc EventThreadServices::IsNextUpdateForced
450    */
451   virtual bool IsNextUpdateForced();
452
453   /**
454    * Request that the depth tree is rebuilt
455    */
456   void RequestRebuildDepthTree();
457
458   /**
459    * Rebuilds the depth tree at the end of the event frame if
460    * it was requested this frame.
461    */
462   void RebuildDepthTree();
463
464 private:
465
466   /**
467    * Protected constructor; see also Stage::New()
468    */
469   Stage( AnimationPlaylist& playlist,
470          PropertyNotificationManager& propertyNotificationManager,
471          SceneGraph::UpdateManager& updateManager,
472          NotificationManager& notificationManager,
473          Integration::RenderController& renderController );
474
475   /**
476    * A reference counted object may only be deleted by calling Unreference()
477    */
478   virtual ~Stage();
479
480 private:
481
482   // For 'Fire and forget' animation support
483   AnimationPlaylist& mAnimationPlaylist;
484
485   PropertyNotificationManager& mPropertyNotificationManager;
486
487   SceneGraph::UpdateManager& mUpdateManager;
488
489   NotificationManager& mNotificationManager;
490
491   Integration::RenderController& mRenderController;
492
493   // The stage-size may be less than surface-size (reduced by top-margin)
494   Vector2 mSize;
495   Vector2 mSurfaceSize;
496
497   // Cached for public GetBackgroundColor()
498   Vector4 mBackgroundColor;
499
500   LayerPtr mRootLayer;
501
502   // Ordered list of currently on-stage layers
503   OwnerPointer<LayerList> mLayerList;
504
505   IntrusivePtr<CameraActor> mDefaultCamera;
506
507   uint32_t mTopMargin;
508   Vector2 mDpi;
509
510   // The object registry
511   ObjectRegistryPtr mObjectRegistry;
512
513   // The list of render-tasks
514   IntrusivePtr<RenderTaskList> mRenderTaskList;
515
516   Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
517
518   // The key event signal
519   Dali::Stage::KeyEventSignalType                 mKeyEventSignal;
520   Dali::DevelStage::KeyEventGeneratedSignalType   mKeyEventGeneratedSignal;
521
522   // The event processing finished signal
523   Dali::Stage::EventProcessingFinishedSignalType  mEventProcessingFinishedSignal;
524
525   // The touched signals
526   Dali::Stage::TouchedSignalType                  mTouchedSignal;
527   Dali::Stage::TouchSignalType                    mTouchSignal;
528
529   // The wheel event signal
530   Dali::Stage::WheelEventSignalType               mWheelEventSignal;
531
532   Dali::Stage::ContextStatusSignal mContextLostSignal;
533   Dali::Stage::ContextStatusSignal mContextRegainedSignal;
534
535   Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
536
537   DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
538
539   bool mDepthTreeDirty:1;  ///< True if the depth tree needs recalculating
540   bool mForceNextUpdate:1; ///< True if the next rendering is really required.
541   bool mRenderToFbo:1;     ///< Whether to render to a Frame Buffer Object.
542 };
543
544 } // namespace Internal
545
546 // Helpers for public-api forwarding methods
547
548 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
549 {
550   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
551
552   BaseObject& handle = stage.GetBaseObject();
553
554   return static_cast<Internal::Stage&>(handle);
555 }
556
557 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
558 {
559   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
560
561   const BaseObject& handle = stage.GetBaseObject();
562
563   return static_cast<const Internal::Stage&>(handle);
564 }
565
566 } // namespace Dali
567
568 #endif // DALI_INTERNAL_STAGE_H