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