Revert "Remove EGL surface in the update thread"
[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     SurfaceResized();
588
589     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
590
591     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
592
593     Dali::Window handle( this );
594     mResizedSignal.Emit( newSize );
595     mResizeSignal.Emit( handle, newSize );
596
597     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
598   }
599 }
600
601 Dali::Window::WindowSize Window::GetSize() const
602 {
603   PositionSize positionSize = mSurface->GetPositionSize();
604
605   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
606 }
607
608 void Window::SetPosition( Dali::Window::WindowPosition position )
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( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
619 }
620
621 Dali::Window::WindowPosition Window::GetPosition() const
622 {
623   PositionSize positionSize = mSurface->GetPositionSize();
624
625   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
626 }
627
628 void Window::SetPositionSize( PositionSize positionSize )
629 {
630   if( !mResizeEnabled )
631   {
632     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
633     mResizeEnabled = true;
634   }
635
636   PositionSize oldRect = mSurface->GetPositionSize();
637
638   mWindowSurface->MoveResize( positionSize );
639
640   PositionSize newRect = mSurface->GetPositionSize();
641
642   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
643   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
644   {
645     Uint16Pair newSize( newRect.width, newRect.height );
646
647     SurfaceResized();
648
649     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
650
651     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
652     Dali::Window handle( this );
653     mResizedSignal.Emit( newSize );
654     mResizeSignal.Emit( handle, newSize );
655     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
656   }
657 }
658
659 Dali::Layer Window::GetRootLayer() const
660 {
661   return mScene.GetRootLayer();
662 }
663
664 void Window::SetTransparency( bool transparent )
665 {
666   mWindowSurface->SetTransparency( transparent );
667 }
668
669 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
670 {
671   return mWindowBase->GrabKey( key, grabMode );
672 }
673
674 bool Window::UngrabKey( Dali::KEY key )
675 {
676   return mWindowBase->UngrabKey( key );
677 }
678
679 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
680 {
681   return mWindowBase->GrabKeyList( key, grabMode, result );
682 }
683
684 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
685 {
686   return mWindowBase->UngrabKeyList( key, result );
687 }
688
689 void Window::OnIconifyChanged( bool iconified )
690 {
691   if( iconified )
692   {
693     mIconified = true;
694
695     if( mVisible )
696     {
697       WindowVisibilityObserver* observer( mAdaptor );
698       observer->OnWindowHidden();
699
700       Dali::Window handle( this );
701       mVisibilityChangedSignal.Emit( handle, false );
702     }
703
704     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible );
705   }
706   else
707   {
708     mIconified = false;
709
710     if( mVisible )
711     {
712       WindowVisibilityObserver* observer( mAdaptor );
713       observer->OnWindowShown();
714
715       Dali::Window handle( this );
716       mVisibilityChangedSignal.Emit( handle, true );
717     }
718
719     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible );
720   }
721 }
722
723 void Window::OnFocusChanged( bool focusIn )
724 {
725   Dali::Window handle( this );
726   mFocusChangedSignal.Emit( focusIn );
727   mFocusChangeSignal.Emit( handle, focusIn );
728 }
729
730 void Window::OnOutputTransformed()
731 {
732   PositionSize positionSize = mSurface->GetPositionSize();
733   SurfaceResized();
734   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
735   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
736 }
737
738 void Window::OnDeleteRequest()
739 {
740   mDeleteRequestSignal.Emit();
741 }
742
743 void Window::OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type )
744 {
745   Dali::Window handle( this );
746   mTransitionEffectEventSignal.Emit( handle, state, type );
747 }
748
749 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
750 {
751   FeedTouchPoint( point, timeStamp );
752 }
753
754 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
755 {
756   FeedWheelEvent( wheelEvent );
757 }
758
759 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
760 {
761   FeedKeyEvent( keyEvent );
762 }
763
764 void Window::OnRotation( const RotationEvent& rotation )
765 {
766   mRotationAngle = rotation.angle;
767   mWindowWidth = rotation.width;
768   mWindowHeight = rotation.height;
769
770   // Notify that the orientation is changed
771   mOrientation->OnOrientationChange( rotation );
772
773   mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
774
775   SurfaceResized();
776
777   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
778
779   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight );
780   // Emit signal
781   Dali::Window handle( this );
782   mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
783   mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
784
785   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
786 }
787
788 void Window::OnPause()
789 {
790   if( mEventHandler )
791   {
792     mEventHandler->Pause();
793   }
794 }
795
796 void Window::OnResume()
797 {
798   if( mEventHandler )
799   {
800     mEventHandler->Resume();
801   }
802 }
803
804 void Window::RecalculateTouchPosition( Integration::Point& point )
805 {
806   Vector2 position = point.GetScreenPosition();
807   Vector2 convertedPosition;
808
809   switch( mRotationAngle )
810   {
811     case 90:
812     {
813       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
814       convertedPosition.y = position.x;
815       break;
816     }
817     case 180:
818     {
819       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
820       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
821       break;
822     }
823     case 270:
824     {
825       convertedPosition.x = position.y;
826       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
827       break;
828     }
829     default:
830     {
831       convertedPosition = position;
832       break;
833     }
834   }
835
836   point.SetScreenPosition( convertedPosition );
837 }
838
839 Dali::Window Window::Get( Dali::Actor actor )
840 {
841   Internal::Adaptor::Window* windowImpl = nullptr;
842
843   if ( Internal::Adaptor::Adaptor::IsAvailable() )
844   {
845     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
846     windowImpl = dynamic_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
847     if( windowImpl )
848     {
849       return Dali::Window( windowImpl );
850     }
851   }
852
853   return Dali::Window();
854 }
855
856 void Window::SetParent( Dali::Window& parent )
857 {
858   if ( DALI_UNLIKELY( parent ) )
859   {
860     mParentWindow = parent;
861     Dali::Window self = Dali::Window( this );
862     // check circular parent window setting
863     if ( Dali::DevelWindow::GetParent( parent ) == self )
864     {
865       Dali::DevelWindow::Unparent( parent );
866     }
867     mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
868   }
869 }
870
871 void Window::Unparent()
872 {
873   mWindowBase->SetParent( nullptr );
874   mParentWindow.Reset();
875 }
876
877 Dali::Window Window::GetParent()
878 {
879   return mParentWindow;
880 }
881
882 Dali::Window::WindowOrientation Window::GetCurrentOrientation() const
883 {
884   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle );
885   return ConvertToOrientation( mRotationAngle );
886 }
887
888 void Window::SetAvailableOrientations( const Dali::Vector<Dali::Window::WindowOrientation>& orientations )
889 {
890   Dali::Vector<float>::SizeType count = orientations.Count();
891   for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
892   {
893     if( IsOrientationAvailable( orientations[index] ) == false )
894     {
895       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
896       continue;
897     }
898
899     bool found = false;
900     int convertedAngle = ConvertToAngle( orientations[index] );
901
902     for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
903     {
904       if( mAvailableAngles[i] == convertedAngle )
905       {
906         found = true;
907         break;
908       }
909     }
910
911     if( !found )
912     {
913       DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle );
914       mAvailableAngles.push_back( convertedAngle );
915     }
916   }
917   SetAvailableAnlges( mAvailableAngles );
918 }
919
920 } // Adaptor
921
922 } // Internal
923
924 } // Dali