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