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