Do nothing if the same size is set to the stage.
[platform/core/uifw/dali-core.git] / dali / internal / event / common / stage-impl.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/common/stage-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <algorithm>
23 #include <cmath>
24 #include <cstring> // for strcmp
25
26 // INTERNAL INCLUDES
27 #include <dali/integration-api/system-overlay.h>
28 #include <dali/internal/event/actors/layer-impl.h>
29 #include <dali/internal/event/actors/layer-list.h>
30 #include <dali/internal/event/actors/camera-actor-impl.h>
31 #include <dali/internal/event/common/system-overlay-impl.h>
32 #include <dali/internal/event/common/thread-local-storage.h>
33 #include <dali/internal/event/common/property-notification-manager.h>
34 #include <dali/internal/event/render-tasks/render-task-list-impl.h>
35 #include <dali/internal/update/nodes/node.h>
36 #include <dali/internal/event/common/object-registry-impl.h>
37 #include <dali/integration-api/platform-abstraction.h>
38 #include <dali/public-api/common/constants.h>
39 #include <dali/public-api/events/touch-data.h>
40 #include <dali/public-api/object/type-registry.h>
41 #include <dali/public-api/render-tasks/render-task-list.h>
42
43 using Dali::Internal::SceneGraph::Node;
44
45 namespace
46 {
47 #if defined(DEBUG_ENABLED)
48 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_DEPTH_TIMER" );
49 #endif
50 }
51
52 namespace Dali
53 {
54
55 namespace Internal
56 {
57
58 namespace
59 {
60
61 const float DEFAULT_STEREO_BASE( 65.0f );
62
63 // Signals
64
65 const char* const SIGNAL_KEY_EVENT =                 "keyEvent";
66 const char* const SIGNAL_KEY_EVENT_GENERATED =       "keyEventGenerated";
67 const char* const SIGNAL_EVENT_PROCESSING_FINISHED = "eventProcessingFinished";
68 const char* const SIGNAL_TOUCHED =                   "touched";
69 const char* const SIGNAL_TOUCH =                     "touch";
70 const char* const SIGNAL_WHEEL_EVENT =               "wheelEvent";
71 const char* const SIGNAL_CONTEXT_LOST =              "contextLost";
72 const char* const SIGNAL_CONTEXT_REGAINED =          "contextRegained";
73 const char* const SIGNAL_SCENE_CREATED =             "sceneCreated";
74
75 TypeRegistration mType( typeid(Dali::Stage), typeid(Dali::BaseHandle), NULL );
76
77 SignalConnectorType signalConnector1( mType, SIGNAL_KEY_EVENT,                 &Stage::DoConnectSignal );
78 SignalConnectorType signalConnector2( mType, SIGNAL_EVENT_PROCESSING_FINISHED, &Stage::DoConnectSignal );
79 SignalConnectorType signalConnector3( mType, SIGNAL_TOUCHED,                   &Stage::DoConnectSignal );
80 SignalConnectorType signalConnector4( mType, SIGNAL_WHEEL_EVENT,               &Stage::DoConnectSignal );
81 SignalConnectorType signalConnector5( mType, SIGNAL_CONTEXT_LOST,              &Stage::DoConnectSignal );
82 SignalConnectorType signalConnector6( mType, SIGNAL_CONTEXT_REGAINED,          &Stage::DoConnectSignal );
83 SignalConnectorType signalConnector7( mType, SIGNAL_SCENE_CREATED,             &Stage::DoConnectSignal );
84 SignalConnectorType signalConnector8( mType, SIGNAL_KEY_EVENT_GENERATED,       &Stage::DoConnectSignal );
85 SignalConnectorType signalConnector9( mType, SIGNAL_TOUCH,                     &Stage::DoConnectSignal );
86
87 } // unnamed namespace
88
89 StagePtr Stage::New( AnimationPlaylist& playlist,
90                      PropertyNotificationManager& propertyNotificationManager,
91                      SceneGraph::UpdateManager& updateManager,
92                      NotificationManager& notificationManager )
93 {
94   return StagePtr( new Stage( playlist, propertyNotificationManager, updateManager, notificationManager ) );
95 }
96
97 void Stage::Initialize()
98 {
99   mObjectRegistry = ObjectRegistry::New();
100
101   // Create the ordered list of layers
102   mLayerList = LayerList::New( mUpdateManager, false/*not system-level*/ );
103
104   // The stage owns the default layer
105   mRootLayer = Layer::NewRoot( *mLayerList, mUpdateManager, false/*not system-level*/ );
106   mRootLayer->SetName("RootLayer");
107   // The root layer needs to have a fixed resize policy (as opposed to the default USE_NATURAL_SIZE).
108   // This stops actors parented to the stage having their relayout requests propagating
109   // up to the root layer, and down through other children unnecessarily.
110   mRootLayer->SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
111
112   // Create the default camera actor first; this is needed by the RenderTaskList
113   CreateDefaultCameraActor();
114
115   // Create the list of render-tasks
116   mRenderTaskList = RenderTaskList::New( *this, *this, false/*not system-level*/ );
117
118   // Create the default render-task
119   Dali::RenderTask defaultRenderTask = mRenderTaskList->CreateTask();
120 }
121
122 void Stage::Uninitialize()
123 {
124   // Remove actors added to SystemOverlay
125   delete mSystemOverlay;
126   mSystemOverlay = NULL;
127
128   if( mDefaultCamera )
129   {
130     // its enough to release the handle so the object is released
131     // don't need to remove it from root actor as root actor will delete the object
132     mDefaultCamera.Reset();
133   }
134
135   if( mRootLayer )
136   {
137     // we are closing down so just delete the root, no point emit disconnect
138     // signals or send messages to update
139     mRootLayer.Reset();
140   }
141 }
142
143 StagePtr Stage::GetCurrent()
144 {
145   StagePtr stage( NULL );
146   // no checking in this version
147   ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
148   if( tls )
149   {
150     stage = tls->GetCurrentStage();
151   }
152   return stage;
153 }
154
155 bool Stage::IsInstalled()
156 {
157   return ThreadLocalStorage::Created();
158 }
159
160 ObjectRegistry& Stage::GetObjectRegistry()
161 {
162   return *mObjectRegistry;
163 }
164
165 void Stage::RegisterObject( Dali::BaseObject* object )
166 {
167   mObjectRegistry->RegisterObject( object );
168 }
169
170 void Stage::UnregisterObject( Dali::BaseObject* object )
171 {
172   mObjectRegistry->UnregisterObject( object );
173 }
174
175 Layer& Stage::GetRootActor()
176 {
177   return *mRootLayer;
178 }
179
180 AnimationPlaylist& Stage::GetAnimationPlaylist()
181 {
182   return mAnimationPlaylist;
183 }
184
185 PropertyNotificationManager& Stage::GetPropertyNotificationManager()
186 {
187   return mPropertyNotificationManager;
188 }
189
190 void Stage::Add( Actor& actor )
191 {
192   mRootLayer->Add( actor );
193 }
194
195 void Stage::Remove( Actor& actor )
196 {
197   mRootLayer->Remove( actor );
198 }
199
200 void Stage::SurfaceResized( float width, float height )
201 {
202   if( ( fabs( width - mSurfaceSize.width ) > Math::MACHINE_EPSILON_1000 ) || ( fabs( height - mSurfaceSize.height ) > Math::MACHINE_EPSILON_1000 ) )
203   {
204     mSurfaceSize.width = width;
205     mSurfaceSize.height = height;
206
207     // Internally we want to report the actual size of the stage.
208     mSize.width = width;
209     mSize.height = height - mTopMargin;
210
211     // Calculates the aspect ratio, near and far clipping planes, field of view and camera Z position.
212     mDefaultCamera->SetPerspectiveProjection( mSurfaceSize );
213
214     // Adjust the camera height to allow for top-margin
215     SetDefaultCameraPosition();
216
217     mRootLayer->SetSize( mSize.width, mSize.height );
218
219     // Repeat for SystemOverlay actors
220     if( mSystemOverlay )
221     {
222       // Note that the SystemOverlay has a separate camera, configured for the full surface-size.
223       // This will remain unaffected by changes in SetDefaultCameraPosition()
224       mSystemOverlay->GetImpl()->SetSize( width, height );
225     }
226
227     SetDefaultSurfaceRectMessage( mUpdateManager, Rect<int>( 0, 0, width, height ) );
228
229     // if single render task to screen then set its viewport parameters
230     if( 1 == mRenderTaskList->GetTaskCount() )
231     {
232       Dali::RenderTask mDefaultRenderTask = mRenderTaskList->GetTask( 0u );
233
234       if(!mDefaultRenderTask.GetTargetFrameBuffer())
235       {
236         mDefaultRenderTask.SetViewport( Viewport(0, 0, width, height) );
237       }
238     }
239   }
240 }
241
242 Vector2 Stage::GetSize() const
243 {
244   return mSize;
245 }
246
247 void Stage::SetTopMargin( unsigned int margin )
248 {
249   if (mTopMargin == margin)
250   {
251     return;
252   }
253   mTopMargin = margin;
254
255   mSize.width = mSurfaceSize.width;
256   mSize.height = mSurfaceSize.height - mTopMargin;
257
258   // Adjust the camera height to allow for top-margin
259   SetDefaultCameraPosition();
260
261   mRootLayer->SetSize( mSize.width, mSize.height );
262 }
263
264 RenderTaskList& Stage::GetRenderTaskList() const
265 {
266   return *mRenderTaskList;
267 }
268
269 void Stage::CreateDefaultCameraActor()
270 {
271   // The default camera attributes and position is such that
272   // children of the default layer, can be positioned at (0,0) and
273   // be at the top-left of the viewport.
274   mDefaultCamera = CameraActor::New( Size::ZERO );
275   mDefaultCamera->SetParentOrigin(ParentOrigin::CENTER);
276   Add(*(mDefaultCamera.Get()));
277 }
278
279 void Stage::SetDefaultCameraPosition()
280 {
281   mDefaultCamera->SetY( -(static_cast<float>(mTopMargin) * 0.5f) );
282 }
283
284 Actor& Stage::GetDefaultRootActor()
285 {
286   return *mRootLayer;
287 }
288
289 CameraActor& Stage::GetDefaultCameraActor()
290 {
291   return *mDefaultCamera;
292 }
293
294 unsigned int Stage::GetLayerCount() const
295 {
296   return mLayerList->GetLayerCount();
297 }
298
299 Dali::Layer Stage::GetLayer( unsigned int depth ) const
300 {
301   return Dali::Layer(mLayerList->GetLayer( depth ));
302 }
303
304 Dali::Layer Stage::GetRootLayer() const
305 {
306   return Dali::Layer( mRootLayer.Get() );
307 }
308
309 LayerList& Stage::GetLayerList()
310 {
311   return *mLayerList;
312 }
313
314 Integration::SystemOverlay& Stage::GetSystemOverlay()
315 {
316   // Lazily create system-level if requested
317   if( !mSystemOverlay )
318   {
319     mSystemOverlay = new Integration::SystemOverlay( SystemOverlay::New( *this ) );
320     DALI_ASSERT_ALWAYS( NULL != mSystemOverlay && "Failed to create system overlay" );
321
322     mSystemOverlay->GetImpl()->SetSize( mSize.width, mSize.height );
323   }
324
325   return *mSystemOverlay;
326 }
327
328 SystemOverlay* Stage::GetSystemOverlayInternal()
329 {
330   SystemOverlay* overlay( NULL );
331
332   if( mSystemOverlay )
333   {
334     overlay = mSystemOverlay->GetImpl();
335   }
336
337   return overlay;
338 }
339
340 void Stage::SetViewMode( ViewMode viewMode )
341 {
342   if( mViewMode != viewMode )
343   {
344     DALI_LOG_INFO( Debug::Filter::gActor, Debug::Concise, "View mode changed from %d to %d\n", mViewMode, viewMode);
345
346     if( mViewMode == MONO )
347     {
348       mDefaultCamera->SetOrientation( Dali::ANGLE_180, Vector3::YAXIS );
349       mRenderTaskList->GetTask(0).SetSourceActor( Dali::Actor() );
350
351       //Create camera and RenderTask for left eye
352       mLeftCamera = CameraActor::New( Size::ZERO );
353       mLeftCamera->SetParentOrigin( ParentOrigin::CENTER );
354       mDefaultCamera->Add( *mLeftCamera.Get() );
355       mLeftRenderTask = mRenderTaskList->CreateTask();
356       mLeftRenderTask.SetCameraActor( Dali::CameraActor( mLeftCamera.Get() ) );
357       mLeftCamera->SetType( Dali::Camera::FREE_LOOK );
358
359       //Create camera and RenderTask for right eye
360       mRightCamera = CameraActor::New( Size::ZERO );
361       mRightCamera->SetParentOrigin( ParentOrigin::CENTER );
362       mDefaultCamera->Add( *mRightCamera.Get() );
363       mRightRenderTask = mRenderTaskList->CreateTask();
364       mRightRenderTask.SetClearColor( Vector4( 1.0f,0.0f,0.0f,1.0f));
365
366       mRightRenderTask.SetCameraActor( Dali::CameraActor( mRightCamera.Get() ) );
367       mRightCamera->SetType( Dali::Camera::FREE_LOOK );
368     }
369
370     // save new mode
371     mViewMode = viewMode;
372
373     switch( viewMode )
374     {
375       case MONO:
376       {
377         // delete extra stereoscopic render tasks and cameras
378         mRenderTaskList->RemoveTask( mLeftRenderTask );
379         mDefaultCamera->Remove( *mLeftCamera.Get() );
380         mLeftRenderTask.Reset();
381         mLeftCamera.Reset();
382         mRenderTaskList->RemoveTask( mRightRenderTask );
383         mDefaultCamera->Remove( *mRightCamera.Get() );
384         mRightRenderTask.Reset();
385         mRightCamera.Reset();
386         mDefaultCamera->SetOrientation( Dali::ANGLE_0, Vector3::YAXIS );
387         mDefaultCamera->SetType( Dali::Camera::LOOK_AT_TARGET );
388         mRenderTaskList->GetTask(0).SetSourceActor( Dali::Layer(mRootLayer.Get()) );
389
390         break;
391       }
392       case STEREO_HORIZONTAL:
393       {
394         //Stereo mode with horizontal split is for landscape mode. That's the reason for the cameras being rotated
395         //Top camera renders the scene as seen from the right eye and bottom camera as seen from left.
396
397         //Calculate separation in pixels along vertical axis ( mStereoBase is defined in millimetres )
398         const float stereoBase( ( (mStereoBase / 25.4f) * GetDpi().y ) * 0.5f );
399
400         //Calculate aspect ratio
401         float aspect = mSize.width / (mSize.height * 0.5f);
402
403         mLeftCamera->SetPerspectiveProjection( mSize, Vector2( 0.0f,stereoBase) );
404         mLeftCamera->SetAspectRatio( aspect );
405
406         mLeftCamera->SetOrientation( -Dali::ANGLE_90, Vector3::ZAXIS );
407         mLeftCamera->SetPosition( Vector3( stereoBase, 0.0f, 0.0f ) );
408         mLeftRenderTask.SetViewport( Viewport(0, mSize.height * 0.5f, mSize.width, mSize.height * 0.5f) );
409
410         mRightCamera->SetPerspectiveProjection( mSize, Vector2( 0.0,  -stereoBase) );
411         mRightCamera->SetAspectRatio( aspect );
412         mRightCamera->SetOrientation( -Dali::ANGLE_90, Vector3::ZAXIS );
413         mRightCamera->SetPosition( Vector3(-stereoBase, 0.0f, 0.0f ) );
414         mRightRenderTask.SetViewport( Viewport(0, 0, mSize.width, mSize.height * 0.5f ) );
415
416         break;
417       }
418       case STEREO_VERTICAL:
419       {
420         //Calculate separation in pixels along horizontal axis
421         const float stereoBase( ( (mStereoBase / 25.4f) * GetDpi().x ) * 0.5f );
422
423         //Recalculate fov based on viewport size
424         const float fov = 2.0f * std::atan(  mSize.y / (2.0f * std::max( mSize.x*0.5f, mSize.y )) );
425
426         mLeftCamera->SetPerspectiveProjection( Size( mSize.x * 0.5f, mSize.y ), Vector2(stereoBase,0.0f) );
427         mLeftCamera->SetFieldOfView( fov );
428         mLeftCamera->SetOrientation( Dali::ANGLE_0, Vector3::ZAXIS );
429         mLeftCamera->SetPosition( Vector3( stereoBase, 0.0f, 0.0f ) );
430         mLeftRenderTask.SetViewport( Viewport(0, 0, mSize.width * 0.5f, mSize.height ) );
431
432         mRightCamera->SetPerspectiveProjection( Size( mSize.x * 0.5f, mSize.y ), Vector2(-stereoBase,0.0f) );
433         mRightCamera->SetFieldOfView( fov );
434         mRightCamera->SetOrientation( Dali::ANGLE_0, Vector3::ZAXIS );
435         mRightCamera->SetPosition( Vector3( -stereoBase, 0.0f, 0.0f ) );
436         mRightRenderTask.SetViewport( Viewport(mSize.width * 0.5f, 0, mSize.width * 0.5f, mSize.height ) );
437
438         break;
439       }
440       case STEREO_INTERLACED:
441       {
442         break;
443       }
444     }
445   }
446 }
447
448 ViewMode Stage::GetViewMode() const
449 {
450   return mViewMode;
451 }
452
453 void Stage::SetStereoBase( float stereoBase )
454 {
455   if( ! Equals( mStereoBase, stereoBase ) )
456   {
457     DALI_LOG_INFO( Debug::Filter::gActor, Debug::Concise, "old( %.2f) new(%.2f)\n", mStereoBase, stereoBase );
458     mStereoBase = stereoBase;
459
460     switch( mViewMode  )
461     {
462       case STEREO_HORIZONTAL:
463       {
464         stereoBase = mStereoBase / 25.4f * GetDpi().y * 0.5f;
465         float aspect = mSize.width / (mSize.height * 0.5f);
466
467         mLeftCamera->SetPerspectiveProjection( mSize, Vector2( 0.0, stereoBase) );
468         mLeftCamera->SetAspectRatio( aspect );
469         mLeftCamera->SetPosition( Vector3( stereoBase, 0.0f, 0.0f ) );
470
471         mRightCamera->SetPerspectiveProjection( mSize, Vector2( 0.0, -stereoBase) );
472         mRightCamera->SetAspectRatio( aspect );
473         mRightCamera->SetPosition( Vector3(-stereoBase, 0.0f, 0.0f ) );
474
475         break;
476       }
477       case STEREO_VERTICAL:
478       {
479         stereoBase = mStereoBase / 25.4f * GetDpi().x * 0.5f;
480         const float fov = 2.0f * std::atan(  mSize.y / (2.0f * std::max( mSize.x*0.5f, mSize.y )) );
481
482         mLeftCamera->SetPerspectiveProjection( Size( mSize.x * 0.5f, mSize.y ), Vector2(stereoBase,0.0f) );
483         mLeftCamera->SetFieldOfView( fov );
484         mLeftCamera->SetPosition( Vector3( stereoBase, 0.0f, 0.0f ) );
485
486         mRightCamera->SetPerspectiveProjection( Size( mSize.x * 0.5f, mSize.y ), Vector2(-stereoBase,0.0f) );
487         mRightCamera->SetFieldOfView( fov );
488         mRightCamera->SetPosition( Vector3(-stereoBase, 0.0f, 0.0f ) );
489
490         break;
491       }
492       default:
493         break;
494     }
495   }
496 }
497
498 float Stage::GetStereoBase() const
499 {
500   return mStereoBase;
501 }
502
503 void Stage::SetBackgroundColor(Vector4 color)
504 {
505   // Cache for public GetBackgroundColor()
506   mBackgroundColor = color;
507
508   // Send message to change color in next frame
509   SetBackgroundColorMessage( mUpdateManager, color );
510 }
511
512 Vector4 Stage::GetBackgroundColor() const
513 {
514   return mBackgroundColor;
515 }
516
517 Vector2 Stage::GetDpi() const
518 {
519   return mDpi;
520 }
521
522 void Stage::SetDpi(Vector2 dpi)
523 {
524   mDpi = dpi;
525 }
526
527 void Stage::KeepRendering( float durationSeconds )
528 {
529   // Send message to keep rendering
530   KeepRenderingMessage( mUpdateManager, durationSeconds );
531 }
532
533 bool Stage::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
534 {
535   bool connected( true );
536   Stage* stage = static_cast< Stage* >(object); // TypeRegistry guarantees that this is the correct type.
537
538   if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
539   {
540     stage->KeyEventSignal().Connect( tracker, functor );
541   }
542   else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT_GENERATED ) )
543   {
544     stage->KeyEventGeneratedSignal().Connect( tracker, functor );
545   }
546   else if( 0 == strcmp( signalName.c_str(), SIGNAL_EVENT_PROCESSING_FINISHED ) )
547   {
548     stage->EventProcessingFinishedSignal().Connect( tracker, functor );
549   }
550   else if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED ) )
551   {
552     stage->TouchedSignal().Connect( tracker, functor );
553   }
554   else if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCH ) )
555   {
556     stage->TouchSignal().Connect( tracker, functor );
557   }
558   else if( 0 == strcmp( signalName.c_str(), SIGNAL_WHEEL_EVENT ) )
559   {
560     stage->WheelEventSignal().Connect( tracker, functor );
561   }
562   else if( 0 == strcmp( signalName.c_str(), SIGNAL_CONTEXT_LOST ) )
563   {
564     stage->ContextLostSignal().Connect( tracker, functor );
565   }
566   else if( 0 == strcmp( signalName.c_str(), SIGNAL_CONTEXT_REGAINED ) )
567   {
568     stage->ContextRegainedSignal().Connect( tracker, functor );
569   }
570   else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCENE_CREATED ) )
571   {
572     stage->SceneCreatedSignal().Connect( tracker, functor );
573   }
574   else
575   {
576     // signalName does not match any signal
577     connected = false;
578   }
579
580   return connected;
581 }
582
583 void Stage::EmitKeyEventSignal(const KeyEvent& event)
584 {
585   // Emit the key event signal when no actor in the stage has gained the key input focus
586
587   mKeyEventSignal.Emit( event );
588 }
589
590 bool Stage::EmitKeyEventGeneratedSignal(const KeyEvent& event)
591 {
592   // Emit the KeyEventGenerated signal when KeyEvent is generated
593
594   return mKeyEventGeneratedSignal.Emit( event );
595 }
596
597 void Stage::EmitEventProcessingFinishedSignal()
598 {
599    mEventProcessingFinishedSignal.Emit();
600 }
601
602 void Stage::EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch )
603 {
604   mTouchedSignal.Emit( touchEvent );
605   mTouchSignal.Emit( touch );
606 }
607
608 void Stage::EmitWheelEventSignal(const WheelEvent& event)
609 {
610   // Emit the wheel event signal when no actor in the stage has gained the wheel input focus
611
612   mWheelEventSignal.Emit( event );
613 }
614
615 void Stage::EmitSceneCreatedSignal()
616 {
617   mSceneCreatedSignal.Emit();
618 }
619
620 Dali::Stage::KeyEventSignalType& Stage::KeyEventSignal()
621 {
622   return mKeyEventSignal;
623 }
624
625 Dali::DevelStage::KeyEventGeneratedSignalType& Stage::KeyEventGeneratedSignal()
626 {
627   return mKeyEventGeneratedSignal;
628 }
629
630 Dali::Stage::EventProcessingFinishedSignalType& Stage::EventProcessingFinishedSignal()
631 {
632   return mEventProcessingFinishedSignal;
633 }
634
635 Dali::Stage::TouchedSignalType& Stage::TouchedSignal()
636 {
637   DALI_LOG_WARNING( "Deprecated. Use TouchSignal() instead.\n" );
638   return mTouchedSignal;
639 }
640
641 Dali::Stage::TouchSignalType& Stage::TouchSignal()
642 {
643   return mTouchSignal;
644 }
645
646 Dali::Stage::WheelEventSignalType& Stage::WheelEventSignal()
647 {
648   return mWheelEventSignal;
649 }
650
651 Dali::Stage::ContextStatusSignal& Stage::ContextLostSignal()
652 {
653   return mContextLostSignal;
654 }
655
656 Dali::Stage::ContextStatusSignal& Stage::ContextRegainedSignal()
657 {
658   return mContextRegainedSignal;
659 }
660
661 Dali::Stage::SceneCreatedSignalType& Stage::SceneCreatedSignal()
662 {
663   return mSceneCreatedSignal;
664 }
665
666 void Stage::NotifyContextLost()
667 {
668   mContextLostSignal.Emit();
669 }
670
671 void Stage::NotifyContextRegained()
672 {
673   mContextRegainedSignal.Emit();
674 }
675
676
677 void Stage::RequestRebuildDepthTree()
678 {
679   DALI_LOG_INFO(gLogFilter, Debug::General, "RequestRebuildDepthTree()\n");
680   mDepthTreeDirty = true;
681 }
682
683 void Stage::RebuildDepthTree()
684 {
685   // If the depth tree needs rebuilding, do it in this frame only.
686   if( mDepthTreeDirty )
687   {
688     DALI_LOG_INFO(gLogFilter, Debug::Concise, "RebuildDepthTree() dirty:T\n");
689
690     ActorPtr actor( mRootLayer.Get() );
691     actor->RebuildDepthTree();
692     mDepthTreeDirty = false;
693   }
694 }
695
696
697 Stage::Stage( AnimationPlaylist& playlist,
698               PropertyNotificationManager& propertyNotificationManager,
699               SceneGraph::UpdateManager& updateManager,
700               NotificationManager& notificationManager )
701 : mAnimationPlaylist( playlist ),
702   mPropertyNotificationManager(propertyNotificationManager),
703   mUpdateManager(updateManager),
704   mNotificationManager(notificationManager),
705   mSize(Vector2::ZERO),
706   mBackgroundColor(Dali::Stage::DEFAULT_BACKGROUND_COLOR),
707   mViewMode( MONO ),
708   mStereoBase( DEFAULT_STEREO_BASE ),
709   mTopMargin( 0 ),
710   mSystemOverlay(NULL),
711   mDepthTreeDirty( false )
712 {
713 }
714
715 SceneGraph::UpdateManager& Stage::GetUpdateManager()
716 {
717   return mUpdateManager;
718 }
719
720 unsigned int* Stage::ReserveMessageSlot( std::size_t size, bool updateScene )
721 {
722   return mUpdateManager.ReserveMessageSlot( size, updateScene );
723 }
724
725 BufferIndex Stage::GetEventBufferIndex() const
726 {
727   return mUpdateManager.GetEventBufferIndex();
728 }
729
730 Stage::~Stage()
731 {
732   delete mSystemOverlay;
733
734   mObjectRegistry.Reset();
735 }
736
737 } // namespace Internal
738
739 } // namespace Dali