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