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