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