Revert "[Tizen] Initialize 'mDepthTreeDirty' member in stage-impl.cpp"
[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   mSurfaceSize.width = width;
203   mSurfaceSize.height = height;
204
205   // Internally we want to report the actual size of the stage.
206   mSize.width = width;
207   mSize.height = height - mTopMargin;
208
209   // Calculates the aspect ratio, near and far clipping planes, field of view and camera Z position.
210   mDefaultCamera->SetPerspectiveProjection( mSurfaceSize );
211
212   // Adjust the camera height to allow for top-margin
213   SetDefaultCameraPosition();
214
215   mRootLayer->SetSize( mSize.width, mSize.height );
216
217   // Repeat for SystemOverlay actors
218   if( mSystemOverlay )
219   {
220     // Note that the SystemOverlay has a separate camera, configured for the full surface-size.
221     // This will remain unaffected by changes in SetDefaultCameraPosition()
222     mSystemOverlay->GetImpl()->SetSize( width, height );
223   }
224
225   SetDefaultSurfaceRectMessage( mUpdateManager, Rect<int>( 0, 0, width, height ) );
226
227   // if single render task to screen then set its viewport parameters
228   if( 1 == mRenderTaskList->GetTaskCount() )
229   {
230     Dali::RenderTask mDefaultRenderTask = mRenderTaskList->GetTask(0);
231
232     if(!mDefaultRenderTask.GetTargetFrameBuffer())
233     {
234       mDefaultRenderTask.SetViewport( Viewport(0, 0, width, height) );
235     }
236   }
237
238 }
239
240 Vector2 Stage::GetSize() const
241 {
242   return mSize;
243 }
244
245 void Stage::SetTopMargin( unsigned int margin )
246 {
247   if (mTopMargin == margin)
248   {
249     return;
250   }
251   mTopMargin = margin;
252
253   mSize.width = mSurfaceSize.width;
254   mSize.height = mSurfaceSize.height - mTopMargin;
255
256   // Adjust the camera height to allow for top-margin
257   SetDefaultCameraPosition();
258
259   mRootLayer->SetSize( mSize.width, mSize.height );
260 }
261
262 RenderTaskList& Stage::GetRenderTaskList() const
263 {
264   return *mRenderTaskList;
265 }
266
267 void Stage::CreateDefaultCameraActor()
268 {
269   // The default camera attributes and position is such that
270   // children of the default layer, can be positioned at (0,0) and
271   // be at the top-left of the viewport.
272   mDefaultCamera = CameraActor::New( Size::ZERO );
273   mDefaultCamera->SetParentOrigin(ParentOrigin::CENTER);
274   Add(*(mDefaultCamera.Get()));
275 }
276
277 void Stage::SetDefaultCameraPosition()
278 {
279   mDefaultCamera->SetY( -(static_cast<float>(mTopMargin) * 0.5f) );
280 }
281
282 Actor& Stage::GetDefaultRootActor()
283 {
284   return *mRootLayer;
285 }
286
287 CameraActor& Stage::GetDefaultCameraActor()
288 {
289   return *mDefaultCamera;
290 }
291
292 unsigned int Stage::GetLayerCount() const
293 {
294   return mLayerList->GetLayerCount();
295 }
296
297 Dali::Layer Stage::GetLayer( unsigned int depth ) const
298 {
299   return Dali::Layer(mLayerList->GetLayer( depth ));
300 }
301
302 Dali::Layer Stage::GetRootLayer() const
303 {
304   return Dali::Layer( mRootLayer.Get() );
305 }
306
307 LayerList& Stage::GetLayerList()
308 {
309   return *mLayerList;
310 }
311
312 Integration::SystemOverlay& Stage::GetSystemOverlay()
313 {
314   // Lazily create system-level if requested
315   if( !mSystemOverlay )
316   {
317     mSystemOverlay = new Integration::SystemOverlay( SystemOverlay::New( *this ) );
318     DALI_ASSERT_ALWAYS( NULL != mSystemOverlay && "Failed to create system overlay" );
319
320     mSystemOverlay->GetImpl()->SetSize( mSize.width, mSize.height );
321   }
322
323   return *mSystemOverlay;
324 }
325
326 SystemOverlay* Stage::GetSystemOverlayInternal()
327 {
328   SystemOverlay* overlay( NULL );
329
330   if( mSystemOverlay )
331   {
332     overlay = mSystemOverlay->GetImpl();
333   }
334
335   return overlay;
336 }
337
338 void Stage::SetViewMode( ViewMode viewMode )
339 {
340   if( mViewMode != viewMode )
341   {
342     DALI_LOG_INFO( Debug::Filter::gActor, Debug::Concise, "View mode changed from %d to %d\n", mViewMode, viewMode);
343
344     if( mViewMode == MONO )
345     {
346       mDefaultCamera->SetOrientation( Dali::ANGLE_180, Vector3::YAXIS );
347       mRenderTaskList->GetTask(0).SetSourceActor( Dali::Actor() );
348
349       //Create camera and RenderTask for left eye
350       mLeftCamera = CameraActor::New( Size::ZERO );
351       mLeftCamera->SetParentOrigin( ParentOrigin::CENTER );
352       mDefaultCamera->Add( *mLeftCamera.Get() );
353       mLeftRenderTask = mRenderTaskList->CreateTask();
354       mLeftRenderTask.SetCameraActor( Dali::CameraActor( mLeftCamera.Get() ) );
355       mLeftCamera->SetType( Dali::Camera::FREE_LOOK );
356
357       //Create camera and RenderTask for right eye
358       mRightCamera = CameraActor::New( Size::ZERO );
359       mRightCamera->SetParentOrigin( ParentOrigin::CENTER );
360       mDefaultCamera->Add( *mRightCamera.Get() );
361       mRightRenderTask = mRenderTaskList->CreateTask();
362       mRightRenderTask.SetClearColor( Vector4( 1.0f,0.0f,0.0f,1.0f));
363
364       mRightRenderTask.SetCameraActor( Dali::CameraActor( mRightCamera.Get() ) );
365       mRightCamera->SetType( Dali::Camera::FREE_LOOK );
366     }
367
368     // save new mode
369     mViewMode = viewMode;
370
371     switch( viewMode )
372     {
373       case MONO:
374       {
375         // delete extra stereoscopic render tasks and cameras
376         mRenderTaskList->RemoveTask( mLeftRenderTask );
377         mDefaultCamera->Remove( *mLeftCamera.Get() );
378         mLeftRenderTask.Reset();
379         mLeftCamera.Reset();
380         mRenderTaskList->RemoveTask( mRightRenderTask );
381         mDefaultCamera->Remove( *mRightCamera.Get() );
382         mRightRenderTask.Reset();
383         mRightCamera.Reset();
384         mDefaultCamera->SetOrientation( Dali::ANGLE_0, Vector3::YAXIS );
385         mDefaultCamera->SetType( Dali::Camera::LOOK_AT_TARGET );
386         mRenderTaskList->GetTask(0).SetSourceActor( Dali::Layer(mRootLayer.Get()) );
387
388         break;
389       }
390       case STEREO_HORIZONTAL:
391       {
392         //Stereo mode with horizontal split is for landscape mode. That's the reason for the cameras being rotated
393         //Top camera renders the scene as seen from the right eye and bottom camera as seen from left.
394
395         //Calculate separation in pixels along vertical axis ( mStereoBase is defined in millimetres )
396         const float stereoBase( ( (mStereoBase / 25.4f) * GetDpi().y ) * 0.5f );
397
398         //Calculate aspect ratio
399         float aspect = mSize.width / (mSize.height * 0.5f);
400
401         mLeftCamera->SetPerspectiveProjection( mSize, Vector2( 0.0f,stereoBase) );
402         mLeftCamera->SetAspectRatio( aspect );
403
404         mLeftCamera->SetOrientation( -Dali::ANGLE_90, Vector3::ZAXIS );
405         mLeftCamera->SetPosition( Vector3( stereoBase, 0.0f, 0.0f ) );
406         mLeftRenderTask.SetViewport( Viewport(0, mSize.height * 0.5f, mSize.width, mSize.height * 0.5f) );
407
408         mRightCamera->SetPerspectiveProjection( mSize, Vector2( 0.0,  -stereoBase) );
409         mRightCamera->SetAspectRatio( aspect );
410         mRightCamera->SetOrientation( -Dali::ANGLE_90, Vector3::ZAXIS );
411         mRightCamera->SetPosition( Vector3(-stereoBase, 0.0f, 0.0f ) );
412         mRightRenderTask.SetViewport( Viewport(0, 0, mSize.width, mSize.height * 0.5f ) );
413
414         break;
415       }
416       case STEREO_VERTICAL:
417       {
418         //Calculate separation in pixels along horizontal axis
419         const float stereoBase( ( (mStereoBase / 25.4f) * GetDpi().x ) * 0.5f );
420
421         //Recalculate fov based on viewport size
422         const float fov = 2.0f * std::atan(  mSize.y / (2.0f * std::max( mSize.x*0.5f, mSize.y )) );
423
424         mLeftCamera->SetPerspectiveProjection( Size( mSize.x * 0.5f, mSize.y ), Vector2(stereoBase,0.0f) );
425         mLeftCamera->SetFieldOfView( fov );
426         mLeftCamera->SetOrientation( Dali::ANGLE_0, Vector3::ZAXIS );
427         mLeftCamera->SetPosition( Vector3( stereoBase, 0.0f, 0.0f ) );
428         mLeftRenderTask.SetViewport( Viewport(0, 0, mSize.width * 0.5f, mSize.height ) );
429
430         mRightCamera->SetPerspectiveProjection( Size( mSize.x * 0.5f, mSize.y ), Vector2(-stereoBase,0.0f) );
431         mRightCamera->SetFieldOfView( fov );
432         mRightCamera->SetOrientation( Dali::ANGLE_0, Vector3::ZAXIS );
433         mRightCamera->SetPosition( Vector3( -stereoBase, 0.0f, 0.0f ) );
434         mRightRenderTask.SetViewport( Viewport(mSize.width * 0.5f, 0, mSize.width * 0.5f, mSize.height ) );
435
436         break;
437       }
438       case STEREO_INTERLACED:
439       {
440         break;
441       }
442     }
443   }
444 }
445
446 ViewMode Stage::GetViewMode() const
447 {
448   return mViewMode;
449 }
450
451 void Stage::SetStereoBase( float stereoBase )
452 {
453   if( ! Equals( mStereoBase, stereoBase ) )
454   {
455     DALI_LOG_INFO( Debug::Filter::gActor, Debug::Concise, "old( %.2f) new(%.2f)\n", mStereoBase, stereoBase );
456     mStereoBase = stereoBase;
457
458     switch( mViewMode  )
459     {
460       case STEREO_HORIZONTAL:
461       {
462         stereoBase = mStereoBase / 25.4f * GetDpi().y * 0.5f;
463         float aspect = mSize.width / (mSize.height * 0.5f);
464
465         mLeftCamera->SetPerspectiveProjection( mSize, Vector2( 0.0, stereoBase) );
466         mLeftCamera->SetAspectRatio( aspect );
467         mLeftCamera->SetPosition( Vector3( stereoBase, 0.0f, 0.0f ) );
468
469         mRightCamera->SetPerspectiveProjection( mSize, Vector2( 0.0, -stereoBase) );
470         mRightCamera->SetAspectRatio( aspect );
471         mRightCamera->SetPosition( Vector3(-stereoBase, 0.0f, 0.0f ) );
472
473         break;
474       }
475       case STEREO_VERTICAL:
476       {
477         stereoBase = mStereoBase / 25.4f * GetDpi().x * 0.5f;
478         const float fov = 2.0f * std::atan(  mSize.y / (2.0f * std::max( mSize.x*0.5f, mSize.y )) );
479
480         mLeftCamera->SetPerspectiveProjection( Size( mSize.x * 0.5f, mSize.y ), Vector2(stereoBase,0.0f) );
481         mLeftCamera->SetFieldOfView( fov );
482         mLeftCamera->SetPosition( Vector3( stereoBase, 0.0f, 0.0f ) );
483
484         mRightCamera->SetPerspectiveProjection( Size( mSize.x * 0.5f, mSize.y ), Vector2(-stereoBase,0.0f) );
485         mRightCamera->SetFieldOfView( fov );
486         mRightCamera->SetPosition( Vector3(-stereoBase, 0.0f, 0.0f ) );
487
488         break;
489       }
490       default:
491         break;
492     }
493   }
494 }
495
496 float Stage::GetStereoBase() const
497 {
498   return mStereoBase;
499 }
500
501 void Stage::SetBackgroundColor(Vector4 color)
502 {
503   // Cache for public GetBackgroundColor()
504   mBackgroundColor = color;
505
506   // Send message to change color in next frame
507   SetBackgroundColorMessage( mUpdateManager, color );
508 }
509
510 Vector4 Stage::GetBackgroundColor() const
511 {
512   return mBackgroundColor;
513 }
514
515 Vector2 Stage::GetDpi() const
516 {
517   return mDpi;
518 }
519
520 void Stage::SetDpi(Vector2 dpi)
521 {
522   mDpi = dpi;
523 }
524
525 void Stage::KeepRendering( float durationSeconds )
526 {
527   // Send message to keep rendering
528   KeepRenderingMessage( mUpdateManager, durationSeconds );
529 }
530
531 bool Stage::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
532 {
533   bool connected( true );
534   Stage* stage = static_cast< Stage* >(object); // TypeRegistry guarantees that this is the correct type.
535
536   if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
537   {
538     stage->KeyEventSignal().Connect( tracker, functor );
539   }
540   else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT_GENERATED ) )
541   {
542     stage->KeyEventGeneratedSignal().Connect( tracker, functor );
543   }
544   else if( 0 == strcmp( signalName.c_str(), SIGNAL_EVENT_PROCESSING_FINISHED ) )
545   {
546     stage->EventProcessingFinishedSignal().Connect( tracker, functor );
547   }
548   else if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED ) )
549   {
550     stage->TouchedSignal().Connect( tracker, functor );
551   }
552   else if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCH ) )
553   {
554     stage->TouchSignal().Connect( tracker, functor );
555   }
556   else if( 0 == strcmp( signalName.c_str(), SIGNAL_WHEEL_EVENT ) )
557   {
558     stage->WheelEventSignal().Connect( tracker, functor );
559   }
560   else if( 0 == strcmp( signalName.c_str(), SIGNAL_CONTEXT_LOST ) )
561   {
562     stage->ContextLostSignal().Connect( tracker, functor );
563   }
564   else if( 0 == strcmp( signalName.c_str(), SIGNAL_CONTEXT_REGAINED ) )
565   {
566     stage->ContextRegainedSignal().Connect( tracker, functor );
567   }
568   else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCENE_CREATED ) )
569   {
570     stage->SceneCreatedSignal().Connect( tracker, functor );
571   }
572   else
573   {
574     // signalName does not match any signal
575     connected = false;
576   }
577
578   return connected;
579 }
580
581 void Stage::EmitKeyEventSignal(const KeyEvent& event)
582 {
583   // Emit the key event signal when no actor in the stage has gained the key input focus
584
585   mKeyEventSignal.Emit( event );
586 }
587
588 bool Stage::EmitKeyEventGeneratedSignal(const KeyEvent& event)
589 {
590   // Emit the KeyEventGenerated signal when KeyEvent is generated
591
592   return mKeyEventGeneratedSignal.Emit( event );
593 }
594
595 void Stage::EmitEventProcessingFinishedSignal()
596 {
597    mEventProcessingFinishedSignal.Emit();
598 }
599
600 void Stage::EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch )
601 {
602   mTouchedSignal.Emit( touchEvent );
603   mTouchSignal.Emit( touch );
604 }
605
606 void Stage::EmitWheelEventSignal(const WheelEvent& event)
607 {
608   // Emit the wheel event signal when no actor in the stage has gained the wheel input focus
609
610   mWheelEventSignal.Emit( event );
611 }
612
613 void Stage::EmitSceneCreatedSignal()
614 {
615   mSceneCreatedSignal.Emit();
616 }
617
618 Dali::Stage::KeyEventSignalType& Stage::KeyEventSignal()
619 {
620   return mKeyEventSignal;
621 }
622
623 Dali::DevelStage::KeyEventGeneratedSignalType& Stage::KeyEventGeneratedSignal()
624 {
625   return mKeyEventGeneratedSignal;
626 }
627
628 Dali::Stage::EventProcessingFinishedSignalType& Stage::EventProcessingFinishedSignal()
629 {
630   return mEventProcessingFinishedSignal;
631 }
632
633 Dali::Stage::TouchedSignalType& Stage::TouchedSignal()
634 {
635   DALI_LOG_WARNING( "Deprecated. Use TouchSignal() instead.\n" );
636   return mTouchedSignal;
637 }
638
639 Dali::Stage::TouchSignalType& Stage::TouchSignal()
640 {
641   return mTouchSignal;
642 }
643
644 Dali::Stage::WheelEventSignalType& Stage::WheelEventSignal()
645 {
646   return mWheelEventSignal;
647 }
648
649 Dali::Stage::ContextStatusSignal& Stage::ContextLostSignal()
650 {
651   return mContextLostSignal;
652 }
653
654 Dali::Stage::ContextStatusSignal& Stage::ContextRegainedSignal()
655 {
656   return mContextRegainedSignal;
657 }
658
659 Dali::Stage::SceneCreatedSignalType& Stage::SceneCreatedSignal()
660 {
661   return mSceneCreatedSignal;
662 }
663
664 void Stage::NotifyContextLost()
665 {
666   mContextLostSignal.Emit();
667 }
668
669 void Stage::NotifyContextRegained()
670 {
671   mContextRegainedSignal.Emit();
672 }
673
674
675 void Stage::RequestRebuildDepthTree()
676 {
677   DALI_LOG_INFO(gLogFilter, Debug::General, "RequestRebuildDepthTree()\n");
678   mDepthTreeDirty = true;
679 }
680
681 void Stage::RebuildDepthTree()
682 {
683   // If the depth tree needs rebuilding, do it in this frame only.
684   if( mDepthTreeDirty )
685   {
686     DALI_LOG_INFO(gLogFilter, Debug::Concise, "RebuildDepthTree() dirty:T\n");
687
688     ActorPtr actor( mRootLayer.Get() );
689     actor->RebuildDepthTree();
690     mDepthTreeDirty = false;
691   }
692 }
693
694
695 Stage::Stage( AnimationPlaylist& playlist,
696               PropertyNotificationManager& propertyNotificationManager,
697               SceneGraph::UpdateManager& updateManager,
698               NotificationManager& notificationManager )
699 : mAnimationPlaylist( playlist ),
700   mPropertyNotificationManager(propertyNotificationManager),
701   mUpdateManager(updateManager),
702   mNotificationManager(notificationManager),
703   mSize(Vector2::ZERO),
704   mBackgroundColor(Dali::Stage::DEFAULT_BACKGROUND_COLOR),
705   mViewMode( MONO ),
706   mStereoBase( DEFAULT_STEREO_BASE ),
707   mTopMargin( 0 ),
708   mSystemOverlay(NULL)
709 {
710 }
711
712 SceneGraph::UpdateManager& Stage::GetUpdateManager()
713 {
714   return mUpdateManager;
715 }
716
717 unsigned int* Stage::ReserveMessageSlot( std::size_t size, bool updateScene )
718 {
719   return mUpdateManager.ReserveMessageSlot( size, updateScene );
720 }
721
722 BufferIndex Stage::GetEventBufferIndex() const
723 {
724   return mUpdateManager.GetEventBufferIndex();
725 }
726
727 Stage::~Stage()
728 {
729   delete mSystemOverlay;
730
731   mObjectRegistry.Reset();
732 }
733
734 } // namespace Internal
735
736 } // namespace Dali