1f524318b064850a86994c01c39a80ab61292a43
[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) 2019 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 class Scene;
64
65 /**
66  * Implementation of Stage
67  */
68 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface
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    * Used by the EventProcessor to emit key event signals.
200    * @param[in] event The key event.
201    */
202   void EmitKeyEventSignal(const KeyEvent& event);
203
204   /**
205    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
206    * @param[in] event The key event.
207    * @return The return is true if KeyEvent is consumed, otherwise false.
208    */
209   bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
210
211   /**
212    * Emits the event processing finished signal.
213    *
214    * @see Dali::Stage::SignalEventProcessingFinished()
215    */
216   void EmitEventProcessingFinishedSignal();
217
218   /**
219    * Emits the touched signal.
220    * @param[in] touchEvent The touch event details (Old API).
221    * @param[in] touch The touch event details.
222    */
223   void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
224
225   /**
226    * Used by the EventProcessor to emit wheel event signals.
227    * @param[in] event The wheel event.
228    */
229   void EmitWheelEventSignal( const WheelEvent& event );
230
231   /**
232    * Emits the scene created.
233    */
234   void EmitSceneCreatedSignal();
235
236   /**
237    * @copydoc Dali::Stage::KeyEventSignal()
238    */
239   Dali::Stage::KeyEventSignalType& KeyEventSignal();
240
241   /**
242    * @copydoc Dali::Stage::SignalEventProcessingFinished()
243    */
244   Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
245
246   /**
247     * @copydoc Dali::Stage::TouchedSignal()
248     */
249   Dali::Stage::TouchedSignalType& TouchedSignal();
250
251   /**
252     * @copydoc Dali::Stage::TouchSignal()
253     */
254   Dali::Stage::TouchSignalType& TouchSignal();
255
256   /**
257    * @copydoc Dali::Stage::WheelEventSignal()
258    */
259   Dali::Stage::WheelEventSignalType& WheelEventSignal();
260
261   /**
262    * @copydoc Dali::Stage::ContextLostSignal()
263    */
264   Dali::Stage::ContextStatusSignal& ContextLostSignal();
265
266   /**
267    * @copydoc Dali::Stage::ContextRegainedSignal()
268    */
269   Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
270
271   /**
272    * @copydoc Dali::Stage::SceneCreatedSignal()
273    */
274   Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
275
276   /**
277    * @copydoc Dali::DevelStage::KeyEventGeneratedSignal()
278    */
279   Dali::DevelStage::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
280
281   /**
282    * @copydoc Dali::DevelStage::AddFrameCallback()
283    */
284   void AddFrameCallback( FrameCallbackInterface& frameCallback, Actor& rootActor );
285
286   /**
287    * @copydoc Dali::DevelStage::RemoveFrameCallback()
288    */
289   void RemoveFrameCallback( FrameCallbackInterface& frameCallback );
290
291   /**
292    * Connects a callback function with the object's signals.
293    * @param[in] object The object providing the signal.
294    * @param[in] tracker Used to disconnect the signal.
295    * @param[in] signalName The signal to connect to.
296    * @param[in] functor A newly allocated FunctorDelegate.
297    * @return True if the signal was connected.
298    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
299    */
300   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
301
302 private: // Implementation of ContextNotificationInterface:
303
304   /**
305    * @copydoc Dali::Integration::NotifyContextLost();
306    */
307   virtual void NotifyContextLost();
308
309   /**
310    * @copydoc Dali::Integration::NotifyContextRegained();
311    */
312   virtual void NotifyContextRegained();
313
314 private:
315
316   /**
317    * Protected constructor; see also Stage::New()
318    */
319   Stage( SceneGraph::UpdateManager& updateManager );
320
321   /**
322    * A reference counted object may only be deleted by calling Unreference()
323    */
324   virtual ~Stage();
325
326 private:
327
328   SceneGraph::UpdateManager& mUpdateManager;
329
330   IntrusivePtr<Scene> mScene;
331
332   // The key event signal
333   Dali::Stage::KeyEventSignalType                 mKeyEventSignal;
334   Dali::DevelStage::KeyEventGeneratedSignalType   mKeyEventGeneratedSignal;
335
336   // The event processing finished signal
337   Dali::Stage::EventProcessingFinishedSignalType  mEventProcessingFinishedSignal;
338
339   // The touched signals
340   Dali::Stage::TouchedSignalType                  mTouchedSignal;
341   Dali::Stage::TouchSignalType                    mTouchSignal;
342
343   // The wheel event signal
344   Dali::Stage::WheelEventSignalType               mWheelEventSignal;
345
346   Dali::Stage::ContextStatusSignal mContextLostSignal;
347   Dali::Stage::ContextStatusSignal mContextRegainedSignal;
348
349   Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
350
351   DevelStage::Rendering mRenderingBehavior; ///< The rendering behavior
352 };
353
354 } // namespace Internal
355
356 // Helpers for public-api forwarding methods
357
358 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
359 {
360   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
361
362   BaseObject& handle = stage.GetBaseObject();
363
364   return static_cast<Internal::Stage&>(handle);
365 }
366
367 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
368 {
369   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
370
371   const BaseObject& handle = stage.GetBaseObject();
372
373   return static_cast<const Internal::Stage&>(handle);
374 }
375
376 } // namespace Dali
377
378 #endif // DALI_INTERNAL_STAGE_H