[dali_1.0.43] Merge branch 'tizen'
[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) 2014 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/object/ref-object.h>
23 #include <dali/public-api/common/stage.h>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/integration-api/context-notifier.h>
26 #include <dali/internal/common/owner-pointer.h>
27 #include <dali/internal/event/actors/layer-impl.h>
28 #include <dali/internal/event/common/event-thread-services.h>
29 #include <dali/internal/event/common/object-registry-impl.h>
30 #include <dali/internal/event/common/stage-def.h>
31 #include <dali/internal/event/render-tasks/render-task-defaults.h>
32 #include <dali/internal/update/manager/update-manager.h>
33 #include <dali/public-api/common/view-mode.h>
34 #include <dali/public-api/math/vector2.h>
35 #include <dali/public-api/math/vector3.h>
36 #include <dali/public-api/math/vector4.h>
37 #include <dali/public-api/render-tasks/render-task.h>
38
39 namespace Dali
40 {
41
42 struct Vector2;
43
44 namespace Integration
45 {
46 class SystemOverlay;
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 SystemOverlay;
62 class CameraActor;
63 class RenderTaskList;
64
65 /**
66  * Implementation of Stage
67  */
68 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface, public EventThreadServices
69 {
70 public:
71
72   /**
73    * Create the stage
74    * @param[in] playlist for animations
75    * @param[in] propertyNotificationManager
76    * @param[in] updateManager
77    * @param[in] notificationManager
78    */
79   static StagePtr New( AnimationPlaylist& playlist,
80                        PropertyNotificationManager& propertyNotificationManager,
81                        SceneGraph::UpdateManager& updateManager,
82                        NotificationManager& notificationManager );
83
84   /**
85    * Initialize the stage.
86    */
87   void Initialize();
88
89   /**
90    * Uninitialize the stage.
91    */
92   void Uninitialize();
93
94   /**
95    * @copydoc Dali::Stage::GetCurrent()
96    * @note this version is for internal usage so it does not assert
97    */
98   static StagePtr GetCurrent();
99
100   /**
101    * @copydoc Dali::Stage::IsInstalled().
102    */
103   static bool IsInstalled();
104
105   /**
106    * @copydoc Dali::Stage::GetObjectRegistry()
107    */
108   ObjectRegistry& GetObjectRegistry();
109
110   /**
111    * Retrieve the root actor (not publically accessible).
112    * @return The root actor.
113    */
114   Layer& GetRootActor();
115
116   /**
117    * Returns the animation playlist.
118    * @return reference to the animation playlist.
119    */
120   AnimationPlaylist& GetAnimationPlaylist();
121
122   /**
123    * Returns the property notification manager.
124    * @return reference to the property notification manager.
125    */
126   PropertyNotificationManager& GetPropertyNotificationManager();
127
128   // Root actor accessors
129
130   /**
131    * @copydoc Dali::Stage::Add()
132    */
133   void Add( Actor& actor );
134
135   /**
136    * @copydoc Dali::Stage::Remove()
137    */
138   void Remove( Actor& actor );
139
140   /**
141    * Sets the size of the stage and indirectly, the root actor.
142    * @param [in] width  The new width.
143    * @param [in] height The new height.
144    */
145   void SetSize( float width, float height );
146
147   /**
148    * Returns the size of the Stage in pixels as a Vector.
149    * The x component will be the width of the Stage in pixels
150    * The y component will be the height of the Stage in pixels
151    * @return The size of the Stage as a Vector.
152    */
153   Vector2 GetSize() const;
154
155   /**
156    * @copydoc Dali::Stage::GetRenderTaskList()
157    */
158   RenderTaskList& GetRenderTaskList() const;
159
160   /**
161    * Create a default camera actor
162    */
163   void CreateDefaultCameraActor();
164
165   /**
166    * From RenderTaskDefaults; retrieve the default root actor.
167    * @return The default root actor.
168    */
169   virtual Actor& GetDefaultRootActor();
170
171   /**
172    * From RenderTaskDefaults; retrieve the default camera actor.
173    * @return The default camera actor.
174    */
175   virtual CameraActor& GetDefaultCameraActor();
176
177   // Layers
178
179   /**
180    * @copydoc Dali::Stage::GetLayerCount()
181    */
182   unsigned int GetLayerCount() const;
183
184   /**
185    * @copydoc Dali::Stage::GetLayer()
186    */
187   Dali::Layer GetLayer( unsigned int depth ) const;
188
189   /**
190    * @copydoc Dali::Stage::GetRootLayer()
191    */
192   Dali::Layer GetRootLayer() const;
193
194   /**
195    * Retrieve the ordered list of on-stage layers.
196    * @return The layer-list.
197    */
198   LayerList& GetLayerList();
199
200   // System-level overlay actors
201
202   /**
203    * @copydoc Dali::Integration::Core::GetSystemOverlay()
204    */
205   Integration::SystemOverlay& GetSystemOverlay();
206
207   /**
208    * Retrieve the internal implementation of the SystemOverlay.
209    * @return The implementation, or NULL if this has never been requested from Integration API.
210    */
211   SystemOverlay* GetSystemOverlayInternal();
212
213   // Stereoscopy
214
215   /**
216    * @copydoc Dali::Integration::Core::SetViewMode()
217    */
218   void SetViewMode( ViewMode viewMode );
219
220   /**
221    * @copydoc Dali::Integration::Core::GetViewMode()
222    */
223   ViewMode GetViewMode() const;
224
225   /**
226    * @copydoc Dali::Integration::Core::SetStereoBase()
227    */
228   void SetStereoBase( float stereoBase );
229
230   /**
231    * @copydoc Dali::Integration::Core::GetStereoBase()
232    */
233   float GetStereoBase() const;
234
235   // Keyboard stuff
236
237   /**
238    * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
239    * set to receive keyboard input.
240    * @param[in] actor to receive keyboard input
241    */
242   void SetKeyboardFocusActor( Actor* actor );
243
244   /**
245    * Get the actor that is currently set to receive keyboard inputs
246    * @return Pointer to the actor set to receive keyboard inputs.
247    */
248   Actor* GetKeyboardFocusActor() const;
249
250   /**
251    * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
252    * @param [in] actor which should be removed from focus.
253    */
254   void RemoveActorFromKeyFocus( Actor* actor );
255
256   // Misc
257
258   /**
259    * @copydoc Dali::Stage::SetBackgroundColor
260    */
261   void SetBackgroundColor(Vector4 color);
262
263   /**
264    * @copydoc Dali::Stage::GetBackgroundColor
265    */
266   Vector4 GetBackgroundColor() const;
267
268   /**
269    * @copydoc Dali::Stage::GetDpi
270    */
271   Vector2 GetDpi() const;
272
273   /**
274    * Sets horizontal and vertical pixels per inch value that is used by the display
275    * @param[in] dpi Horizontal and vertical dpi value
276    */
277   void SetDpi( Vector2 dpi );
278
279   NotificationManager& GetNotificationManager()
280   {
281     return mNotificationManager;
282   }
283
284   /**
285    * @copydoc Dali::Stage::KeepRendering()
286    */
287   void KeepRendering( float durationSeconds );
288
289   /**
290    * Used by the EventProcessor to emit key event signals.
291    * @param[in] event The key event.
292    */
293   void EmitKeyEventSignal(const KeyEvent& event);
294
295   /**
296    * Emits the event processing finished signal.
297    *
298    * @see Dali::Stage::SignalEventProcessingFinished()
299    */
300   void EmitEventProcessingFinishedSignal();
301
302   /**
303    * Emits the touched signal.
304    * @param[in] touch The touch event details.
305    */
306   void EmitTouchedSignal( const TouchEvent& touch );
307
308   /**
309    * Used by the EventProcessor to emit wheel event signals.
310    * @param[in] event The wheel event.
311    */
312   void EmitWheelEventSignal( const WheelEvent& event );
313
314   /**
315    * Emits the scene created.
316    */
317   void EmitSceneCreatedSignal();
318
319   /**
320    * @copydoc Dali::Stage::KeyEventSignal()
321    */
322   Dali::Stage::KeyEventSignalType& KeyEventSignal();
323
324   /**
325    * @copydoc Dali::Stage::SignalEventProcessingFinished()
326    */
327   Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
328
329   /**
330     * @copydoc Dali::Stage::TouchedSignal()
331     */
332   Dali::Stage::TouchedSignalType& TouchedSignal();
333
334   /**
335    * @copydoc Dali::Stage::WheelEventSignal()
336    */
337   Dali::Stage::WheelEventSignalType& WheelEventSignal();
338
339   /**
340    * @copydoc Dali::Stage::ContextLostSignal()
341    */
342   Dali::Stage::ContextStatusSignal& ContextLostSignal();
343
344   /**
345    * @copydoc Dali::Stage::ContextRegainedSignal()
346    */
347   Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
348
349   /**
350    * @copydoc Dali::Stage::SceneCreatedSignal()
351    */
352   Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
353
354   /**
355    * Connects a callback function with the object's signals.
356    * @param[in] object The object providing the signal.
357    * @param[in] tracker Used to disconnect the signal.
358    * @param[in] signalName The signal to connect to.
359    * @param[in] functor A newly allocated FunctorDelegate.
360    * @return True if the signal was connected.
361    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
362    */
363   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
364
365 private: // Implementation of ContextNotificationInterface:
366
367   /**
368    * @copydoc Dali::Integration::NotifyContextLost();
369    */
370   virtual void NotifyContextLost();
371
372   /**
373    * @copydoc Dali::Integration::NotifyContextRegained();
374    */
375   virtual void NotifyContextRegained();
376
377 public: // Implementation of EventThreadServices
378
379   /**
380    * @copydoc EventThreadServices::RegisterObject
381    */
382   virtual void RegisterObject( BaseObject* object);
383
384   /**
385    * @copydoc EventThreadServices::UnregisterObject
386    */
387   virtual void UnregisterObject( BaseObject* object);
388
389   /**
390    * @copydoc EventThreadServices::GetUpdateManager
391    */
392   virtual SceneGraph::UpdateManager& GetUpdateManager();
393
394   /**
395    * @copydoc EventThreadServices::ReserveMessageSlot
396    */
397   virtual unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene );
398
399   /**
400    * @copydoc EventThreadServices::GetEventBufferIndex
401    */
402   virtual BufferIndex GetEventBufferIndex() const;
403
404 private:
405
406   /**
407    * Protected constructor; see also Stage::New()
408    */
409   Stage( AnimationPlaylist& playlist,
410          PropertyNotificationManager& propertyNotificationManager,
411          SceneGraph::UpdateManager& updateManager,
412          NotificationManager& notificationManager );
413
414   /**
415    * A reference counted object may only be deleted by calling Unreference()
416    */
417   virtual ~Stage();
418
419 private:
420
421   // For 'Fire and forget' animation support
422   AnimationPlaylist& mAnimationPlaylist;
423
424   PropertyNotificationManager& mPropertyNotificationManager;
425
426   SceneGraph::UpdateManager& mUpdateManager;
427
428   NotificationManager& mNotificationManager;
429
430   // The Actual size of the stage.
431   Vector2 mSize;
432
433   // Cached for public GetBackgroundColor()
434   Vector4 mBackgroundColor;
435
436   LayerPtr mRootLayer;
437
438   // Ordered list of currently on-stage layers
439   OwnerPointer<LayerList> mLayerList;
440
441   IntrusivePtr<CameraActor> mDefaultCamera;
442
443   ViewMode mViewMode;
444   float mStereoBase;
445
446   Vector2 mDpi;
447
448   // The object registry
449   ObjectRegistryPtr mObjectRegistry;
450
451   // The list of render-tasks
452   IntrusivePtr<RenderTaskList> mRenderTaskList;
453
454   Dali::RenderTask mRightRenderTask;
455   IntrusivePtr<CameraActor> mRightCamera;
456   Dali::RenderTask mLeftRenderTask;
457   IntrusivePtr<CameraActor> mLeftCamera;
458
459   Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
460
461   // The key event signal
462   Dali::Stage::KeyEventSignalType                 mKeyEventSignal;
463
464   // The event processing finished signal
465   Dali::Stage::EventProcessingFinishedSignalType  mEventProcessingFinishedSignal;
466
467   // The touched signal
468   Dali::Stage::TouchedSignalType                  mTouchedSignal;
469
470   // The wheel event signal
471   Dali::Stage::WheelEventSignalType               mWheelEventSignal;
472
473   Dali::Stage::ContextStatusSignal mContextLostSignal;
474   Dali::Stage::ContextStatusSignal mContextRegainedSignal;
475
476   Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
477 };
478
479 } // namespace Internal
480
481 // Helpers for public-api forwarding methods
482
483 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
484 {
485   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
486
487   BaseObject& handle = stage.GetBaseObject();
488
489   return static_cast<Internal::Stage&>(handle);
490 }
491
492 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
493 {
494   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
495
496   const BaseObject& handle = stage.GetBaseObject();
497
498   return static_cast<const Internal::Stage&>(handle);
499 }
500
501 } // namespace Dali
502
503 #endif // __DALI_INTERNAL_STAGE_H__