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