Add NO_ORIENTATION_PREFERENCE type to unset the preferred orientation
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
1 /*
2  * Copyright (c) 2019 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/window-system/common/window-impl.h>
20
21 // EXTERNAL HEADERS
22 #include <dali/integration-api/core.h>
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/actors/camera-actor.h>
26 #include <dali/public-api/render-tasks/render-task.h>
27 #include <dali/public-api/render-tasks/render-task-list.h>
28 #include <dali/public-api/rendering/frame-buffer.h>
29 #include <dali/devel-api/adaptor-framework/orientation.h>
30 #include <dali/integration-api/events/touch-event-integ.h>
31
32 // INTERNAL HEADERS
33 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
34 #include <dali/internal/window-system/common/event-handler.h>
35 #include <dali/internal/window-system/common/orientation-impl.h>
36 #include <dali/internal/window-system/common/render-surface-factory.h>
37 #include <dali/internal/window-system/common/window-factory.h>
38 #include <dali/internal/window-system/common/window-base.h>
39 #include <dali/internal/window-system/common/window-system.h>
40 #include <dali/internal/window-system/common/window-render-surface.h>
41 #include <dali/internal/window-system/common/window-visibility-observer.h>
42
43 namespace Dali
44 {
45 namespace Internal
46 {
47 namespace Adaptor
48 {
49
50 namespace
51 {
52
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW" );
55 #endif
56
57 } // unnamed namespace
58
59 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
60 {
61   Window* window = new Window();
62   window->mIsTransparent = isTransparent;
63   window->Initialize( positionSize, name, className );
64   return window;
65 }
66
67 Window::Window()
68 : mWindowSurface( nullptr ),
69   mWindowBase(),
70   mIsTransparent( false ),
71   mIsFocusAcceptable( true ),
72   mIconified( false ),
73   mOpaqueState( false ),
74   mResizeEnabled( false ),
75   mType( Dali::Window::NORMAL ),
76   mParentWindow( NULL ),
77   mPreferredAngle( Dali::Window::NO_ORIENTATION_PREFERENCE ),
78   mRotationAngle( 0 ),
79   mWindowWidth( 0 ),
80   mWindowHeight( 0 ),
81   mOrientationMode( Internal::Adaptor::Window::OrientationMode::PORTRAIT ),
82   mFocusChangedSignal(),
83   mResizedSignal(),
84   mDeleteRequestSignal(),
85   mFocusChangeSignal(),
86   mResizeSignal(),
87   mVisibilityChangedSignal(),
88   mTransitionEffectEventSignal()
89 {
90 }
91
92 Window::~Window()
93 {
94   if ( mEventHandler )
95   {
96     mEventHandler->RemoveObserver( *this );
97   }
98 }
99
100 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
101 {
102   // Create a window render surface
103   Any surface;
104   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
105   mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
106   mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
107
108   // Get a window base
109   mWindowBase = mWindowSurface->GetWindowBase();
110
111   // Connect signals
112   mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
113   mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
114   mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
115   mWindowBase->TransitionEffectEventSignal().Connect( this, &Window::OnTransitionEffectEvent );
116
117   mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
118
119   if( !positionSize.IsEmpty() )
120   {
121     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
122     mResizeEnabled = true;
123   }
124
125   SetClass( name, className );
126
127   mWindowSurface->Map();
128
129   mOrientation = Orientation::New( this );
130
131   // Get OrientationMode
132   int screenWidth, screenHeight;
133   WindowSystem::GetScreenSize( screenWidth, screenHeight );
134   if( screenWidth > screenHeight )
135   {
136     mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
137   }
138   else
139   {
140     mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
141   }
142 }
143
144 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
145 {
146   mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
147   mEventHandler->AddObserver( *this );
148 }
149
150 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
151 {
152   mWindowSurface = static_cast<WindowRenderSurface*>( surface );
153 }
154
155 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
156 {
157 }
158
159 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
160 {
161 }
162
163 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
164 {
165 }
166
167 void Window::SetClass( std::string name, std::string className )
168 {
169   mName = name;
170   mClassName = className;
171   mWindowBase->SetClass( name, className );
172 }
173
174 std::string Window::GetClassName() const
175 {
176   return mClassName;
177 }
178
179 void Window::Raise()
180 {
181   mWindowBase->Raise();
182   DALI_LOG_RELEASE_INFO( "Window (%p) Raise() \n", this );
183 }
184
185 void Window::Lower()
186 {
187   mWindowBase->Lower();
188   DALI_LOG_RELEASE_INFO( "Window (%p) Lower() \n", this );
189 }
190
191 void Window::Activate()
192 {
193   mWindowBase->Activate();
194   DALI_LOG_RELEASE_INFO( "Window (%p) Activate() \n", this );
195 }
196
197 uint32_t Window::GetLayerCount() const
198 {
199   return mScene.GetLayerCount();
200 }
201
202 Dali::Layer Window::GetLayer( uint32_t depth ) const
203 {
204   return mScene.GetLayer( depth );
205 }
206
207 Dali::RenderTaskList Window::GetRenderTaskList() const
208 {
209   return mScene.GetRenderTaskList();
210 }
211
212 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
213 {
214   if( IsOrientationAvailable( orientation ) == false )
215   {
216     return;
217   }
218
219   bool found = false;
220   int convertedAngle = ConvertToAngle( orientation );
221   for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
222   {
223     if( mAvailableAngles[i] == convertedAngle )
224     {
225       found = true;
226       break;
227     }
228   }
229
230   if( !found )
231   {
232     mAvailableAngles.push_back( convertedAngle );
233     SetAvailableAnlges( mAvailableAngles );
234   }
235 }
236
237 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
238 {
239   if( IsOrientationAvailable( orientation ) == false )
240   {
241     return;
242   }
243
244   int convertedAngle = ConvertToAngle( orientation );
245   for( std::vector< int >::iterator iter = mAvailableAngles.begin();
246        iter != mAvailableAngles.end(); ++iter )
247   {
248     if( *iter == convertedAngle )
249     {
250       mAvailableAngles.erase( iter );
251       break;
252     }
253   }
254
255   SetAvailableAnlges( mAvailableAngles );
256 }
257
258 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
259 {
260   if( orientation < Dali::Window::NO_ORIENTATION_PREFERENCE || orientation > Dali::Window::LANDSCAPE_INVERSE )
261   {
262     return;
263   }
264   mPreferredAngle = ConvertToAngle( orientation );
265   mWindowBase->SetPreferredAngle( mPreferredAngle );
266 }
267
268 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
269 {
270   Dali::Window::WindowOrientation preferredOrientation = ConvertToOrientation( mPreferredAngle );
271   return preferredOrientation;
272 }
273
274 void Window::SetAvailableAnlges( const std::vector< int >& angles )
275 {
276   if( angles.size() > 4 )
277   {
278     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size() );
279     return;
280   }
281
282   mWindowBase->SetAvailableAnlges( angles );
283 }
284
285 int Window::ConvertToAngle( Dali::Window::WindowOrientation orientation )
286 {
287   int convertAngle = static_cast< int >( orientation );
288   if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
289   {
290     switch( orientation )
291     {
292       case Dali::Window::LANDSCAPE:
293       {
294         convertAngle = 0;
295         break;
296       }
297       case Dali::Window::PORTRAIT:
298       {
299         convertAngle = 90;
300         break;
301       }
302       case Dali::Window::LANDSCAPE_INVERSE:
303       {
304         convertAngle = 180;
305         break;
306       }
307       case Dali::Window::PORTRAIT_INVERSE:
308       {
309         convertAngle = 270;
310         break;
311       }
312       case Dali::Window::NO_ORIENTATION_PREFERENCE:
313       {
314         convertAngle = -1;
315         break;
316       }
317     }
318   }
319   return convertAngle;
320 }
321
322 Dali::Window::WindowOrientation Window::ConvertToOrientation( int angle )
323 {
324   Dali::Window::WindowOrientation orientation = static_cast< Dali::Window::WindowOrientation >( angle );
325   if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
326   {
327     switch( angle )
328     {
329       case 0:
330       {
331         orientation = Dali::Window::LANDSCAPE;
332         break;
333       }
334       case 90:
335       {
336         orientation = Dali::Window::PORTRAIT;
337         break;
338       }
339       case 180:
340       {
341         orientation = Dali::Window::LANDSCAPE_INVERSE;
342         break;
343       }
344       case 270:
345       {
346         orientation = Dali::Window::PORTRAIT_INVERSE;
347         break;
348       }
349       case -1:
350       {
351         orientation = Dali::Window::NO_ORIENTATION_PREFERENCE;
352         break;
353       }
354     }
355   }
356   return orientation;
357 }
358
359 bool Window::IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const
360 {
361   if( orientation <= Dali::Window::NO_ORIENTATION_PREFERENCE || orientation > Dali::Window::LANDSCAPE_INVERSE )
362   {
363     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation );
364     return false;
365   }
366   return true;
367 }
368
369 Dali::Any Window::GetNativeHandle() const
370 {
371   return mWindowSurface->GetNativeWindow();
372 }
373
374 void Window::SetAcceptFocus( bool accept )
375 {
376   mIsFocusAcceptable = accept;
377
378   mWindowBase->SetAcceptFocus( accept );
379 }
380
381 bool Window::IsFocusAcceptable() const
382 {
383   return mIsFocusAcceptable;
384 }
385
386 void Window::Show()
387 {
388   mVisible = true;
389
390   mWindowBase->Show();
391
392   if( !mIconified )
393   {
394     WindowVisibilityObserver* observer( mAdaptor );
395     observer->OnWindowShown();
396
397     Dali::Window handle( this );
398     mVisibilityChangedSignal.Emit( handle, true );
399   }
400
401   DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
402 }
403
404 void Window::Hide()
405 {
406   mVisible = false;
407
408   mWindowBase->Hide();
409
410   if( !mIconified )
411   {
412     WindowVisibilityObserver* observer( mAdaptor );
413     observer->OnWindowHidden();
414
415     Dali::Window handle( this );
416     mVisibilityChangedSignal.Emit( handle, false );
417   }
418
419   DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
420 }
421
422 bool Window::IsVisible() const
423 {
424   return mVisible && !mIconified;
425 }
426
427 unsigned int Window::GetSupportedAuxiliaryHintCount() const
428 {
429   return mWindowBase->GetSupportedAuxiliaryHintCount();
430 }
431
432 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
433 {
434   return mWindowBase->GetSupportedAuxiliaryHint( index );
435 }
436
437 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
438 {
439   return mWindowBase->AddAuxiliaryHint( hint, value );
440 }
441
442 bool Window::RemoveAuxiliaryHint( unsigned int id )
443 {
444   return mWindowBase->RemoveAuxiliaryHint( id );
445 }
446
447 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
448 {
449   return mWindowBase->SetAuxiliaryHintValue( id, value );
450 }
451
452 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
453 {
454   return mWindowBase->GetAuxiliaryHintValue( id );
455 }
456
457 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
458 {
459   return mWindowBase->GetAuxiliaryHintId( hint );
460 }
461
462 void Window::SetInputRegion( const Rect< int >& inputRegion )
463 {
464   mWindowBase->SetInputRegion( inputRegion );
465
466   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetInputRegion: x = %d, y = %d, w = %d, h = %d\n", inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
467 }
468
469 void Window::SetType( Dali::Window::Type type )
470 {
471   if( type != mType )
472   {
473     mWindowBase->SetType( type );
474
475     mType = type;
476   }
477 }
478
479 Dali::Window::Type Window::GetType() const
480 {
481   return mType;
482 }
483
484 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
485 {
486   if( mType != Dali::Window::NOTIFICATION )
487   {
488     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
489     return false;
490   }
491
492   return mWindowBase->SetNotificationLevel( level );
493 }
494
495 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
496 {
497   if( mType != Dali::Window::NOTIFICATION )
498   {
499     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
500     return Dali::Window::NotificationLevel::NONE;
501   }
502
503   return mWindowBase->GetNotificationLevel();
504 }
505
506 void Window::SetOpaqueState( bool opaque )
507 {
508   mOpaqueState = opaque;
509
510   mWindowBase->SetOpaqueState( opaque );
511
512   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
513 }
514
515 bool Window::IsOpaqueState() const
516 {
517   return mOpaqueState;
518 }
519
520 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
521 {
522   return mWindowBase->SetScreenOffMode( screenOffMode );
523 }
524
525 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
526 {
527   return mWindowBase->GetScreenOffMode();
528 }
529
530 bool Window::SetBrightness( int brightness )
531 {
532   if( brightness < 0 || brightness > 100 )
533   {
534     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
535     return false;
536   }
537
538   return mWindowBase->SetBrightness( brightness );
539 }
540
541 int Window::GetBrightness() const
542 {
543   return mWindowBase->GetBrightness();
544 }
545
546 void Window::SetSize( Dali::Window::WindowSize size )
547 {
548   if( !mResizeEnabled )
549   {
550     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
551     mResizeEnabled = true;
552   }
553
554   PositionSize oldRect = mSurface->GetPositionSize();
555
556   mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
557
558   PositionSize newRect = mSurface->GetPositionSize();
559
560   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
561   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
562   {
563     Uint16Pair newSize( newRect.width, newRect.height );
564
565     SurfaceResized();
566
567     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
568
569     Dali::Window handle( this );
570     mResizedSignal.Emit( newSize );
571     mResizeSignal.Emit( handle, newSize );
572
573     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
574   }
575 }
576
577 Dali::Window::WindowSize Window::GetSize() const
578 {
579   PositionSize positionSize = mSurface->GetPositionSize();
580
581   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
582 }
583
584 void Window::SetPosition( Dali::Window::WindowPosition position )
585 {
586   if( !mResizeEnabled )
587   {
588     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
589     mResizeEnabled = true;
590   }
591
592   PositionSize oldRect = mSurface->GetPositionSize();
593
594   mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
595 }
596
597 Dali::Window::WindowPosition Window::GetPosition() const
598 {
599   PositionSize positionSize = mSurface->GetPositionSize();
600
601   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
602 }
603
604 void Window::SetPositionSize( PositionSize positionSize )
605 {
606   if( !mResizeEnabled )
607   {
608     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
609     mResizeEnabled = true;
610   }
611
612   PositionSize oldRect = mSurface->GetPositionSize();
613
614   mWindowSurface->MoveResize( positionSize );
615
616   PositionSize newRect = mSurface->GetPositionSize();
617
618   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
619   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
620   {
621     Uint16Pair newSize( newRect.width, newRect.height );
622
623     SurfaceResized();
624
625     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
626
627     Dali::Window handle( this );
628     mResizedSignal.Emit( newSize );
629     mResizeSignal.Emit( handle, newSize );
630     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
631   }
632 }
633
634 Dali::Layer Window::GetRootLayer() const
635 {
636   return mScene.GetRootLayer();
637 }
638
639 void Window::SetTransparency( bool transparent )
640 {
641   mWindowSurface->SetTransparency( transparent );
642 }
643
644 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
645 {
646   return mWindowBase->GrabKey( key, grabMode );
647 }
648
649 bool Window::UngrabKey( Dali::KEY key )
650 {
651   return mWindowBase->UngrabKey( key );
652 }
653
654 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
655 {
656   return mWindowBase->GrabKeyList( key, grabMode, result );
657 }
658
659 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
660 {
661   return mWindowBase->UngrabKeyList( key, result );
662 }
663
664 void Window::OnIconifyChanged( bool iconified )
665 {
666   if( iconified )
667   {
668     mIconified = true;
669
670     if( mVisible )
671     {
672       WindowVisibilityObserver* observer( mAdaptor );
673       observer->OnWindowHidden();
674
675       Dali::Window handle( this );
676       mVisibilityChangedSignal.Emit( handle, false );
677     }
678
679     DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
680   }
681   else
682   {
683     mIconified = false;
684
685     if( mVisible )
686     {
687       WindowVisibilityObserver* observer( mAdaptor );
688       observer->OnWindowShown();
689
690       Dali::Window handle( this );
691       mVisibilityChangedSignal.Emit( handle, true );
692     }
693
694     DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
695   }
696 }
697
698 void Window::OnFocusChanged( bool focusIn )
699 {
700   Dali::Window handle( this );
701   mFocusChangedSignal.Emit( focusIn );
702   mFocusChangeSignal.Emit( handle, focusIn );
703 }
704
705 void Window::OnOutputTransformed()
706 {
707   PositionSize positionSize = mSurface->GetPositionSize();
708   SurfaceResized();
709   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
710   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
711 }
712
713 void Window::OnDeleteRequest()
714 {
715   mDeleteRequestSignal.Emit();
716 }
717
718 void Window::OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type )
719 {
720   Dali::Window handle( this );
721   mTransitionEffectEventSignal.Emit( handle, state, type );
722 }
723
724 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
725 {
726   FeedTouchPoint( point, timeStamp );
727 }
728
729 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
730 {
731   FeedWheelEvent( wheelEvent );
732 }
733
734 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
735 {
736   FeedKeyEvent( keyEvent );
737 }
738
739 void Window::OnRotation( const RotationEvent& rotation )
740 {
741   mRotationAngle = rotation.angle;
742   mWindowWidth = rotation.width;
743   mWindowHeight = rotation.height;
744
745   // Notify that the orientation is changed
746   mOrientation->OnOrientationChange( rotation );
747
748   mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
749
750   SurfaceResized();
751
752   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
753
754   // Emit signal
755   Dali::Window handle( this );
756   mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
757   mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
758
759   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
760 }
761
762 void Window::OnPause()
763 {
764   if( mEventHandler )
765   {
766     mEventHandler->Pause();
767   }
768 }
769
770 void Window::OnResume()
771 {
772   if( mEventHandler )
773   {
774     mEventHandler->Resume();
775   }
776 }
777
778 void Window::RecalculateTouchPosition( Integration::Point& point )
779 {
780   Vector2 position = point.GetScreenPosition();
781   Vector2 convertedPosition;
782
783   switch( mRotationAngle )
784   {
785     case 90:
786     {
787       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
788       convertedPosition.y = position.x;
789       break;
790     }
791     case 180:
792     {
793       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
794       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
795       break;
796     }
797     case 270:
798     {
799       convertedPosition.x = position.y;
800       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
801       break;
802     }
803     default:
804     {
805       convertedPosition = position;
806       break;
807     }
808   }
809
810   point.SetScreenPosition( convertedPosition );
811 }
812
813 Dali::Window Window::Get( Dali::Actor actor )
814 {
815   Internal::Adaptor::Window* windowImpl = nullptr;
816
817   if ( Internal::Adaptor::Adaptor::IsAvailable() )
818   {
819     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
820     windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
821   }
822
823   return Dali::Window( windowImpl );
824 }
825
826 void Window::SetParent( Dali::Window& parent )
827 {
828   if ( DALI_UNLIKELY( parent ) )
829   {
830     mParentWindow = parent;
831     Dali::Window self = Dali::Window( this );
832     // check circular parent window setting
833     if ( Dali::DevelWindow::GetParent( parent ) == self )
834     {
835       Dali::DevelWindow::Unparent( parent );
836     }
837     mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
838   }
839 }
840
841 void Window::Unparent()
842 {
843   mWindowBase->SetParent( nullptr );
844   mParentWindow.Reset();
845 }
846
847 Dali::Window Window::GetParent()
848 {
849   return mParentWindow;
850 }
851
852 } // Adaptor
853
854 } // Internal
855
856 } // Dali