4ce80b02f66a38ba0f2f92d1636ac743e41be21b
[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) 2020 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/devel-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 class Scene;
64
65 /**
66  * Implementation of Stage
67  */
68 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public ConnectionTracker
69 {
70 public:
71
72   /**
73    * Create the stage
74    * @param[in] updateManager
75    */
76   static StagePtr New( SceneGraph::UpdateManager& updateManager );
77
78   /**
79    * Initialize the stage.
80    * @param[in] scene The default scene (for main window).
81    */
82   void Initialize( Scene& scene );
83
84   /**
85    * @copydoc Dali::Stage::GetCurrent()
86    * @note this version is for internal usage so it does not assert
87    */
88   static StagePtr GetCurrent();
89
90   /**
91    * @copydoc Dali::Stage::IsInstalled().
92    */
93   static bool IsInstalled();
94
95   /**
96    * @copydoc Dali::Stage::GetObjectRegistry()
97    */
98   ObjectRegistry& GetObjectRegistry();
99
100   /**
101    * Retrieve the root actor (not publically accessible).
102    * @return The root actor.
103    */
104   Layer& GetRootActor();
105
106   // Root actor accessors
107
108   /**
109    * @copydoc Dali::Stage::Add()
110    */
111   void Add( Actor& actor );
112
113   /**
114    * @copydoc Dali::Stage::Remove()
115    */
116   void Remove( Actor& actor );
117
118   /**
119    * Returns the size of the Stage in pixels as a Vector.
120    * The x component will be the width of the Stage in pixels
121    * The y component will be the height of the Stage in pixels
122    * @return The size of the Stage as a Vector.
123    */
124   Vector2 GetSize() const;
125
126   /**
127    * @copydoc Dali::Stage::GetRenderTaskList()
128    */
129   RenderTaskList& GetRenderTaskList() const;
130
131   /**
132    * From RenderTaskDefaults; retrieve the default root actor.
133    * @return The default root actor.
134    */
135   virtual Actor& GetDefaultRootActor();
136
137   /**
138    * From RenderTaskDefaults; retrieve the default camera actor.
139    * @return The default camera actor.
140    */
141   virtual CameraActor& GetDefaultCameraActor();
142
143   // Layers
144
145   /**
146    * @copydoc Dali::Stage::GetLayerCount()
147    */
148   uint32_t GetLayerCount() const;
149
150   /**
151    * @copydoc Dali::Stage::GetLayer()
152    */
153   Dali::Layer GetLayer( uint32_t depth ) const;
154
155   /**
156    * @copydoc Dali::Stage::GetRootLayer()
157    */
158   Dali::Layer GetRootLayer() const;
159
160   /**
161    * Retrieve the ordered list of on-stage layers.
162    * @return The layer-list.
163    */
164   LayerList& GetLayerList();
165
166   // Misc
167
168   /**
169    * @copydoc Dali::Stage::SetBackgroundColor
170    */
171   void SetBackgroundColor(Vector4 color);
172
173   /**
174    * @copydoc Dali::Stage::GetBackgroundColor
175    */
176   Vector4 GetBackgroundColor() const;
177
178   /**
179    * @copydoc Dali::Stage::GetDpi
180    */
181   Vector2 GetDpi() const;
182
183   /**
184    * @copydoc Dali::Stage::KeepRendering()
185    */
186   void KeepRendering( float durationSeconds );
187
188   /**
189    * @copydoc Dali::DevelStage::SetRenderingBehavior()
190    */
191   void SetRenderingBehavior( DevelStage::Rendering renderingBehavior );
192
193   /**
194    * @copydoc Dali::DevelStage::GetRenderingBehavior()
195    */
196   DevelStage::Rendering GetRenderingBehavior() const;
197
198   /**
199    * Callback for Internal::Scene EventProcessingFinished signal
200    */
201   void OnEventProcessingFinished();
202
203   /**
204    * Callback for Internal::Scene KeyEventSignal signal
205    */
206   void OnKeyEvent( const Dali::KeyEvent& event );
207
208   /**
209    * Callback for Internal::Scene TouchSignal signal
210    */
211   void OnTouchEvent( const Dali::TouchEvent& touch );
212
213   /**
214    * Callback for Internal::Scene WheelEventSignal signal
215    */
216   void OnWheelEvent( const Dali::WheelEvent& event );
217
218   /**
219    * Used by the EventProcessor to emit key event signals.
220    * @param[in] event The key event.
221    */
222   void EmitKeyEventSignal(const KeyEvent& event);
223
224   /**
225    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
226    * @param[in] event The key event.
227    * @return The return is true if KeyEvent is consumed, otherwise false.
228    */
229   bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
230
231   /**
232    * Emits the event processing finished signal.
233    *
234    * @see Dali::Stage::SignalEventProcessingFinished()
235    */
236   void EmitEventProcessingFinishedSignal();
237
238   /**
239    * Emits the touched signal.
240    * @param[in] touch The touch event details.
241    */
242   void EmitTouchedSignal( const Dali::TouchEvent& touch );
243
244   /**
245    * Used by the EventProcessor to emit wheel event signals.
246    * @param[in] event The wheel event.
247    */
248   void EmitWheelEventSignal( const WheelEvent& event );
249
250   /**
251    * Emits the scene created.
252    */
253   void EmitSceneCreatedSignal();
254
255   /**
256    * @copydoc Dali::Stage::KeyEventSignal()
257    */
258   Dali::Stage::KeyEventSignalType& KeyEventSignal();
259
260   /**
261    * @copydoc Dali::Stage::SignalEventProcessingFinished()
262    */
263   Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
264
265   /**
266     * @copydoc Dali::Stage::TouchSignal()
267     */
268   Dali::Stage::TouchSignalType& TouchSignal();
269
270   /**
271    * @copydoc Dali::Stage::WheelEventSignal()
272    */
273   Dali::Stage::WheelEventSignalType& WheelEventSignal();
274
275   /**
276    * @copydoc Dali::Stage::ContextLostSignal()
277    */
278   Dali::Stage::ContextStatusSignal& ContextLostSignal();
279
280   /**
281    * @copydoc Dali::Stage::ContextRegainedSignal()
282    */
283   Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
284
285   /**
286    * @copydoc Dali::Stage::SceneCreatedSignal()
287    */
288   Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
289
290   /**
291    * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
292    */
293   Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
294
295   /**
296    * @copydoc Dali::DevelStage::AddFrameCallback()
297    */
298   void AddFrameCallback( FrameCallbackInterface& frameCallback, Actor& rootActor );
299
300   /**
301    * @copydoc Dali::DevelStage::RemoveFrameCallback()
302    */
303   void RemoveFrameCallback( FrameCallbackInterface& frameCallback );
304
305   /**
306    * Connects a callback function with the object's signals.
307    * @param[in] object The object providing the signal.
308    * @param[in] tracker Used to disconnect the signal.
309    * @param[in] signalName The signal to connect to.
310    * @param[in] functor A newly allocated FunctorDelegate.
311    * @return True if the signal was connected.
312    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
313    */
314   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
315
316 private: // Implementation of ContextNotificationInterface:
317
318   /**
319    * @copydoc Dali::Integration::NotifyContextLost();
320    */
321   virtual void NotifyContextLost();
322
323   /**
324    * @copydoc Dali::Integration::NotifyContextRegained();
325    */
326   virtual void NotifyContextRegained();
327
328 private:
329
330   /**
331    * Protected constructor; see also Stage::New()
332    */
333   Stage( SceneGraph::UpdateManager& updateManager );
334
335   /**
336    * A reference counted object may only be deleted by calling Unreference()
337    */
338   virtual ~Stage();
339
340 private:
341
342   SceneGraph::UpdateManager& mUpdateManager;
343
344   IntrusivePtr<Scene> mScene;
345
346   // The key event signal
347   Dali::Stage::KeyEventSignalType                 mKeyEventSignal;
348   Dali::DevelStage::KeyEventGeneratedSignalType   mKeyEventGeneratedSignal;
349
350   // The event processing finished signal
351   Dali::Stage::EventProcessingFinishedSignalType  mEventProcessingFinishedSignal;
352
353   // The touched signal
354   Dali::Stage::TouchSignalType                    mTouchSignal;
355
356   // The wheel event signal
357   Dali::Stage::WheelEventSignalType               mWheelEventSignal;
358
359   Dali::Stage::ContextStatusSignal mContextLostSignal;
360   Dali::Stage::ContextStatusSignal mContextRegainedSignal;
361
362   Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
363
364   DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
365 };
366
367 } // namespace Internal
368
369 // Helpers for public-api forwarding methods
370
371 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
372 {
373   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
374
375   BaseObject& handle = stage.GetBaseObject();
376
377   return static_cast<Internal::Stage&>(handle);
378 }
379
380 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
381 {
382   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
383
384   const BaseObject& handle = stage.GetBaseObject();
385
386   return static_cast<const Internal::Stage&>(handle);
387 }
388
389 } // namespace Dali
390
391 #endif // DALI_INTERNAL_STAGE_H