5321782f6b2d3d80470d6ddc24e64029ca8b7f41
[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   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
124   mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
125
126   if( !positionSize.IsEmpty() )
127   {
128     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
129     mResizeEnabled = true;
130   }
131
132   SetClass( name, className );
133
134   mWindowSurface->Map();
135
136   mOrientation = Orientation::New( this );
137
138   // Get OrientationMode
139   int screenWidth, screenHeight;
140   WindowSystem::GetScreenSize( screenWidth, screenHeight );
141   if( screenWidth > screenHeight )
142   {
143     mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
144   }
145   else
146   {
147     mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
148   }
149   // For Debugging
150   mNativeWindowId = mWindowBase->GetNativeWindowId();
151 }
152
153 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
154 {
155   mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
156   mEventHandler->AddObserver( *this );
157 }
158
159 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
160 {
161   mWindowSurface = static_cast<WindowRenderSurface*>( surface );
162 }
163
164 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
165 {
166 }
167
168 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
169 {
170 }
171
172 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
173 {
174 }
175
176 void Window::SetClass( std::string name, std::string className )
177 {
178   mName = name;
179   mClassName = className;
180   mWindowBase->SetClass( name, className );
181 }
182
183 std::string Window::GetClassName() const
184 {
185   return mClassName;
186 }
187
188 void Window::Raise()
189 {
190   mWindowBase->Raise();
191   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId );
192 }
193
194 void Window::Lower()
195 {
196   mWindowBase->Lower();
197   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId );
198 }
199
200 void Window::Activate()
201 {
202   mWindowBase->Activate();
203   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId );
204 }
205
206 uint32_t Window::GetLayerCount() const
207 {
208   return mScene.GetLayerCount();
209 }
210
211 Dali::Layer Window::GetLayer( uint32_t depth ) const
212 {
213   return mScene.GetLayer( depth );
214 }
215
216 Dali::RenderTaskList Window::GetRenderTaskList() const
217 {
218   return mScene.GetRenderTaskList();
219 }
220
221 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
222 {
223   if( IsOrientationAvailable( orientation ) == false )
224   {
225     return;
226   }
227
228   bool found = false;
229   int convertedAngle = ConvertToAngle( orientation );
230   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle );
231   for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
232   {
233     if( mAvailableAngles[i] == convertedAngle )
234     {
235       found = true;
236       break;
237     }
238   }
239
240   if( !found )
241   {
242     mAvailableAngles.push_back( convertedAngle );
243     SetAvailableAnlges( mAvailableAngles );
244   }
245 }
246
247 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
248 {
249   if( IsOrientationAvailable( orientation ) == false )
250   {
251     return;
252   }
253
254   int convertedAngle = ConvertToAngle( orientation );
255   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle );
256   for( std::vector< int >::iterator iter = mAvailableAngles.begin();
257        iter != mAvailableAngles.end(); ++iter )
258   {
259     if( *iter == convertedAngle )
260     {
261       mAvailableAngles.erase( iter );
262       break;
263     }
264   }
265
266   SetAvailableAnlges( mAvailableAngles );
267 }
268
269 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
270 {
271   if( orientation < Dali::Window::NO_ORIENTATION_PREFERENCE || orientation > Dali::Window::LANDSCAPE_INVERSE )
272   {
273     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation );
274     return;
275   }
276   mPreferredAngle = ConvertToAngle( orientation );
277   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle );
278   mWindowBase->SetPreferredAngle( mPreferredAngle );
279 }
280
281 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
282 {
283   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle );
284   Dali::Window::WindowOrientation preferredOrientation = ConvertToOrientation( mPreferredAngle );
285   return preferredOrientation;
286 }
287
288 void Window::SetAvailableAnlges( const std::vector< int >& angles )
289 {
290   if( angles.size() > 4 )
291   {
292     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size() );
293     return;
294   }
295
296   mWindowBase->SetAvailableAnlges( angles );
297 }
298
299 int Window::ConvertToAngle( Dali::Window::WindowOrientation orientation )
300 {
301   int convertAngle = static_cast< int >( orientation );
302   if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
303   {
304     switch( orientation )
305     {
306       case Dali::Window::LANDSCAPE:
307       {
308         convertAngle = 0;
309         break;
310       }
311       case Dali::Window::PORTRAIT:
312       {
313         convertAngle = 90;
314         break;
315       }
316       case Dali::Window::LANDSCAPE_INVERSE:
317       {
318         convertAngle = 180;
319         break;
320       }
321       case Dali::Window::PORTRAIT_INVERSE:
322       {
323         convertAngle = 270;
324         break;
325       }
326       case Dali::Window::NO_ORIENTATION_PREFERENCE:
327       {
328         convertAngle = -1;
329         break;
330       }
331     }
332   }
333   return convertAngle;
334 }
335
336 Dali::Window::WindowOrientation Window::ConvertToOrientation( int angle ) const
337 {
338   Dali::Window::WindowOrientation orientation = static_cast< Dali::Window::WindowOrientation >( angle );
339   if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
340   {
341     switch( angle )
342     {
343       case 0:
344       {
345         orientation = Dali::Window::LANDSCAPE;
346         break;
347       }
348       case 90:
349       {
350         orientation = Dali::Window::PORTRAIT;
351         break;
352       }
353       case 180:
354       {
355         orientation = Dali::Window::LANDSCAPE_INVERSE;
356         break;
357       }
358       case 270:
359       {
360         orientation = Dali::Window::PORTRAIT_INVERSE;
361         break;
362       }
363       case -1:
364       {
365         orientation = Dali::Window::NO_ORIENTATION_PREFERENCE;
366         break;
367       }
368     }
369   }
370   return orientation;
371 }
372
373 bool Window::IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const
374 {
375   if( orientation <= Dali::Window::NO_ORIENTATION_PREFERENCE || orientation > Dali::Window::LANDSCAPE_INVERSE )
376   {
377     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation );
378     return false;
379   }
380   return true;
381 }
382
383 Dali::Any Window::GetNativeHandle() const
384 {
385   return mWindowSurface->GetNativeWindow();
386 }
387
388 void Window::SetAcceptFocus( bool accept )
389 {
390   mIsFocusAcceptable = accept;
391
392   mWindowBase->SetAcceptFocus( accept );
393 }
394
395 bool Window::IsFocusAcceptable() const
396 {
397   return mIsFocusAcceptable;
398 }
399
400 void Window::Show()
401 {
402   mVisible = true;
403
404   mWindowBase->Show();
405
406   if( !mIconified )
407   {
408     WindowVisibilityObserver* observer( mAdaptor );
409     observer->OnWindowShown();
410
411     Dali::Window handle( this );
412     mVisibilityChangedSignal.Emit( handle, true );
413   }
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     mResizedSignal.Emit( newSize );
588     mResizeSignal.Emit( handle, newSize );
589
590     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
591   }
592 }
593
594 Dali::Window::WindowSize Window::GetSize() const
595 {
596   PositionSize positionSize = mSurface->GetPositionSize();
597
598   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
599 }
600
601 void Window::SetPosition( Dali::Window::WindowPosition position )
602 {
603   if( !mResizeEnabled )
604   {
605     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
606     mResizeEnabled = true;
607   }
608
609   PositionSize oldRect = mSurface->GetPositionSize();
610
611   mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
612 }
613
614 Dali::Window::WindowPosition Window::GetPosition() const
615 {
616   PositionSize positionSize = mSurface->GetPositionSize();
617
618   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
619 }
620
621 void Window::SetPositionSize( PositionSize positionSize )
622 {
623   if( !mResizeEnabled )
624   {
625     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
626     mResizeEnabled = true;
627   }
628
629   PositionSize oldRect = mSurface->GetPositionSize();
630
631   mWindowSurface->MoveResize( positionSize );
632
633   PositionSize newRect = mSurface->GetPositionSize();
634
635   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
636   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
637   {
638     Uint16Pair newSize( newRect.width, newRect.height );
639
640     SurfaceResized();
641
642     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
643
644     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
645     Dali::Window handle( this );
646     mResizedSignal.Emit( newSize );
647     mResizeSignal.Emit( handle, newSize );
648     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
649   }
650 }
651
652 Dali::Layer Window::GetRootLayer() const
653 {
654   return mScene.GetRootLayer();
655 }
656
657 void Window::SetTransparency( bool transparent )
658 {
659   mWindowSurface->SetTransparency( transparent );
660 }
661
662 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
663 {
664   return mWindowBase->GrabKey( key, grabMode );
665 }
666
667 bool Window::UngrabKey( Dali::KEY key )
668 {
669   return mWindowBase->UngrabKey( key );
670 }
671
672 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
673 {
674   return mWindowBase->GrabKeyList( key, grabMode, result );
675 }
676
677 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
678 {
679   return mWindowBase->UngrabKeyList( key, result );
680 }
681
682 void Window::OnIconifyChanged( bool iconified )
683 {
684   if( iconified )
685   {
686     mIconified = true;
687
688     if( mVisible )
689     {
690       WindowVisibilityObserver* observer( mAdaptor );
691       observer->OnWindowHidden();
692
693       Dali::Window handle( this );
694       mVisibilityChangedSignal.Emit( handle, false );
695     }
696
697     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible );
698   }
699   else
700   {
701     mIconified = false;
702
703     if( mVisible )
704     {
705       WindowVisibilityObserver* observer( mAdaptor );
706       observer->OnWindowShown();
707
708       Dali::Window handle( this );
709       mVisibilityChangedSignal.Emit( handle, true );
710     }
711
712     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible );
713   }
714 }
715
716 void Window::OnFocusChanged( bool focusIn )
717 {
718   Dali::Window handle( this );
719   mFocusChangedSignal.Emit( focusIn );
720   mFocusChangeSignal.Emit( handle, focusIn );
721 }
722
723 void Window::OnOutputTransformed()
724 {
725   PositionSize positionSize = mSurface->GetPositionSize();
726   SurfaceResized();
727   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
728   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
729 }
730
731 void Window::OnDeleteRequest()
732 {
733   mDeleteRequestSignal.Emit();
734 }
735
736 void Window::OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type )
737 {
738   Dali::Window handle( this );
739   mTransitionEffectEventSignal.Emit( handle, state, type );
740 }
741
742 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
743 {
744   FeedTouchPoint( point, timeStamp );
745 }
746
747 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
748 {
749   FeedWheelEvent( wheelEvent );
750 }
751
752 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
753 {
754   FeedKeyEvent( keyEvent );
755 }
756
757 void Window::OnRotation( const RotationEvent& rotation )
758 {
759   mRotationAngle = rotation.angle;
760   mWindowWidth = rotation.width;
761   mWindowHeight = rotation.height;
762
763   // Notify that the orientation is changed
764   mOrientation->OnOrientationChange( rotation );
765
766   mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
767
768   SurfaceResized();
769
770   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
771
772   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight );
773   // Emit signal
774   Dali::Window handle( this );
775   mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
776   mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
777
778   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
779 }
780
781 void Window::OnPause()
782 {
783   if( mEventHandler )
784   {
785     mEventHandler->Pause();
786   }
787 }
788
789 void Window::OnResume()
790 {
791   if( mEventHandler )
792   {
793     mEventHandler->Resume();
794   }
795 }
796
797 void Window::RecalculateTouchPosition( Integration::Point& point )
798 {
799   Vector2 position = point.GetScreenPosition();
800   Vector2 convertedPosition;
801
802   switch( mRotationAngle )
803   {
804     case 90:
805     {
806       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
807       convertedPosition.y = position.x;
808       break;
809     }
810     case 180:
811     {
812       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
813       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
814       break;
815     }
816     case 270:
817     {
818       convertedPosition.x = position.y;
819       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
820       break;
821     }
822     default:
823     {
824       convertedPosition = position;
825       break;
826     }
827   }
828
829   point.SetScreenPosition( convertedPosition );
830 }
831
832 Dali::Window Window::Get( Dali::Actor actor )
833 {
834   Internal::Adaptor::Window* windowImpl = nullptr;
835
836   if ( Internal::Adaptor::Adaptor::IsAvailable() )
837   {
838     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
839     windowImpl = dynamic_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
840     if( windowImpl )
841     {
842       return Dali::Window( windowImpl );
843     }
844   }
845
846   return Dali::Window();
847 }
848
849 void Window::SetParent( Dali::Window& parent )
850 {
851   if ( DALI_UNLIKELY( parent ) )
852   {
853     mParentWindow = parent;
854     Dali::Window self = Dali::Window( this );
855     // check circular parent window setting
856     if ( Dali::DevelWindow::GetParent( parent ) == self )
857     {
858       Dali::DevelWindow::Unparent( parent );
859     }
860     mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
861   }
862 }
863
864 void Window::Unparent()
865 {
866   mWindowBase->SetParent( nullptr );
867   mParentWindow.Reset();
868 }
869
870 Dali::Window Window::GetParent()
871 {
872   return mParentWindow;
873 }
874
875 Dali::Window::WindowOrientation Window::GetCurrentOrientation() const
876 {
877   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle );
878   return ConvertToOrientation( mRotationAngle );
879 }
880
881 void Window::SetAvailableOrientations( const Dali::Vector<Dali::Window::WindowOrientation>& orientations )
882 {
883   Dali::Vector<float>::SizeType count = orientations.Count();
884   for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
885   {
886     if( IsOrientationAvailable( orientations[index] ) == false )
887     {
888       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
889       continue;
890     }
891
892     bool found = false;
893     int convertedAngle = ConvertToAngle( orientations[index] );
894
895     for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
896     {
897       if( mAvailableAngles[i] == convertedAngle )
898       {
899         found = true;
900         break;
901       }
902     }
903
904     if( !found )
905     {
906       DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle );
907       mAvailableAngles.push_back( convertedAngle );
908     }
909   }
910   SetAvailableAnlges( mAvailableAngles );
911 }
912
913 } // Adaptor
914
915 } // Internal
916
917 } // Dali