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