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