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