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