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