39c6653e0cef1b3ccf574ecea6f4cabe7589d585
[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     bool forceUpdate = false;
616     if( mWindowBase->IsEglWindowRotationSupported() )
617     {
618       forceUpdate = true;
619     }
620
621     SurfaceResized( forceUpdate );
622
623     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
624
625     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
626
627     Dali::Window handle( this );
628     mResizeSignal.Emit( handle, newSize );
629
630     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
631   }
632
633   GraphicsInterface& graphics = mAdaptor->GetGraphicsInterface();
634   EglGraphics* eglGraphics = static_cast<EglGraphics*>(&graphics);
635   if (eglGraphics)
636   {
637     eglGraphics->SetFullSwapNextFrame();
638   }
639 }
640
641 Dali::Window::WindowSize Window::GetSize() const
642 {
643   PositionSize positionSize = mSurface->GetPositionSize();
644
645   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
646 }
647
648 void Window::SetPosition( Dali::Window::WindowPosition position )
649 {
650   if( !mResizeEnabled )
651   {
652     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
653     mResizeEnabled = true;
654   }
655
656   PositionSize oldRect = mSurface->GetPositionSize();
657
658   mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
659
660   GraphicsInterface& graphics = mAdaptor->GetGraphicsInterface();
661   EglGraphics* eglGraphics = static_cast<EglGraphics*>(&graphics);
662   if (eglGraphics)
663   {
664     eglGraphics->SetFullSwapNextFrame();
665   }
666 }
667
668 Dali::Window::WindowPosition Window::GetPosition() const
669 {
670   PositionSize positionSize = mSurface->GetPositionSize();
671
672   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
673 }
674
675 void Window::SetPositionSize( PositionSize positionSize )
676 {
677   if( !mResizeEnabled )
678   {
679     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
680     mResizeEnabled = true;
681   }
682
683   PositionSize oldRect = mSurface->GetPositionSize();
684
685   mWindowSurface->MoveResize( positionSize );
686
687   PositionSize newRect = mSurface->GetPositionSize();
688
689   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
690   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
691   {
692     Uint16Pair newSize( newRect.width, newRect.height );
693
694     bool forceUpdate = false;
695     if( mWindowBase->IsEglWindowRotationSupported() )
696     {
697       forceUpdate = true;
698     }
699
700     SurfaceResized( forceUpdate );
701
702     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
703
704     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
705     Dali::Window handle( this );
706     mResizeSignal.Emit( handle, newSize );
707     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
708   }
709
710   GraphicsInterface& graphics = mAdaptor->GetGraphicsInterface();
711   EglGraphics* eglGraphics = static_cast<EglGraphics*>(&graphics);
712   if (eglGraphics)
713   {
714     eglGraphics->SetFullSwapNextFrame();
715   }
716 }
717
718 Dali::Layer Window::GetRootLayer() const
719 {
720   return mScene.GetRootLayer();
721 }
722
723 void Window::SetTransparency( bool transparent )
724 {
725   mWindowSurface->SetTransparency( transparent );
726 }
727
728 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
729 {
730   return mWindowBase->GrabKey( key, grabMode );
731 }
732
733 bool Window::UngrabKey( Dali::KEY key )
734 {
735   return mWindowBase->UngrabKey( key );
736 }
737
738 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
739 {
740   return mWindowBase->GrabKeyList( key, grabMode, result );
741 }
742
743 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
744 {
745   return mWindowBase->UngrabKeyList( key, result );
746 }
747
748 void Window::OnIconifyChanged( bool iconified )
749 {
750   if( iconified )
751   {
752     mIconified = true;
753
754     if( mVisible )
755     {
756       WindowVisibilityObserver* observer( mAdaptor );
757       observer->OnWindowHidden();
758
759       Dali::Window handle( this );
760       mVisibilityChangedSignal.Emit( handle, false );
761     }
762
763     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible );
764   }
765   else
766   {
767     mIconified = false;
768
769     if( mVisible )
770     {
771       WindowVisibilityObserver* observer( mAdaptor );
772       observer->OnWindowShown();
773
774       Dali::Window handle( this );
775       mVisibilityChangedSignal.Emit( handle, true );
776     }
777
778     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible );
779   }
780
781   GraphicsInterface& graphics = mAdaptor->GetGraphicsInterface();
782   EglGraphics* eglGraphics = static_cast<EglGraphics*>(&graphics);
783   if (eglGraphics)
784   {
785     eglGraphics->SetFullSwapNextFrame();
786   }
787 }
788
789 void Window::OnFocusChanged( bool focusIn )
790 {
791   Dali::Window handle( this );
792   mFocusChangeSignal.Emit( handle, focusIn );
793
794   GraphicsInterface& graphics = mAdaptor->GetGraphicsInterface();
795   EglGraphics* eglGraphics = static_cast<EglGraphics*>(&graphics);
796   if (eglGraphics)
797   {
798     eglGraphics->SetFullSwapNextFrame();
799   }
800 }
801
802 void Window::OnOutputTransformed()
803 {
804   bool forceUpdate = false;
805   if( mWindowBase->IsEglWindowRotationSupported() )
806   {
807     forceUpdate = true;
808   }
809   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), OnOutputTransformed()\n", this, mNativeWindowId );
810   SurfaceResized( forceUpdate );
811
812   PositionSize positionSize = mSurface->GetPositionSize();
813   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
814   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
815 }
816
817 void Window::OnDeleteRequest()
818 {
819   mDeleteRequestSignal.Emit();
820 }
821
822 void Window::OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type )
823 {
824   Dali::Window handle( this );
825   mTransitionEffectEventSignal.Emit( handle, state, type );
826 }
827
828 void Window::OnKeyboardRepeatSettingsChanged()
829 {
830   Dali::Window handle( this );
831   mKeyboardRepeatSettingsChangedSignal.Emit();
832 }
833
834 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
835 {
836   FeedTouchPoint( point, timeStamp );
837 }
838
839 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
840 {
841   FeedWheelEvent( wheelEvent );
842 }
843
844 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
845 {
846   FeedKeyEvent( keyEvent );
847 }
848
849 void Window::OnRotation( const RotationEvent& rotation )
850 {
851   mRotationAngle = rotation.angle;
852   mWindowWidth = rotation.width;
853   mWindowHeight = rotation.height;
854
855   // Notify that the orientation is changed
856   mOrientation->OnOrientationChange( rotation );
857
858   mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
859
860   bool forceUpdate = false;
861   if( mWindowBase->IsEglWindowRotationSupported() )
862   {
863     forceUpdate = true;
864   }
865
866   SurfaceResized( forceUpdate );
867
868   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
869
870   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight );
871   // Emit signal
872   Dali::Window handle( this );
873   mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
874
875   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
876 }
877
878 void Window::OnPause()
879 {
880   if( mEventHandler )
881   {
882     mEventHandler->Pause();
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::OnResume()
894 {
895   if( mEventHandler )
896   {
897     mEventHandler->Resume();
898   }
899
900   GraphicsInterface& graphics = mAdaptor->GetGraphicsInterface();
901   EglGraphics* eglGraphics = static_cast<EglGraphics*>(&graphics);
902   if (eglGraphics)
903   {
904     eglGraphics->SetFullSwapNextFrame();
905   }
906 }
907
908 void Window::RecalculateTouchPosition( Integration::Point& point )
909 {
910   Vector2 position = point.GetScreenPosition();
911   Vector2 convertedPosition;
912
913   switch( mRotationAngle )
914   {
915     case 90:
916     {
917       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
918       convertedPosition.y = position.x;
919       break;
920     }
921     case 180:
922     {
923       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
924       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
925       break;
926     }
927     case 270:
928     {
929       convertedPosition.x = position.y;
930       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
931       break;
932     }
933     default:
934     {
935       convertedPosition = position;
936       break;
937     }
938   }
939
940   point.SetScreenPosition( convertedPosition );
941 }
942
943 Dali::Window Window::Get( Dali::Actor actor )
944 {
945   Internal::Adaptor::Window* windowImpl = nullptr;
946
947   if ( Internal::Adaptor::Adaptor::IsAvailable() )
948   {
949     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
950     windowImpl = dynamic_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
951     if( windowImpl )
952     {
953       return Dali::Window( windowImpl );
954     }
955   }
956
957   return Dali::Window();
958 }
959
960 void Window::SetParent( Dali::Window& parent )
961 {
962   if ( DALI_UNLIKELY( parent ) )
963   {
964     mParentWindow = parent;
965     Dali::Window self = Dali::Window( this );
966     // check circular parent window setting
967     if ( Dali::DevelWindow::GetParent( parent ) == self )
968     {
969       Dali::DevelWindow::Unparent( parent );
970     }
971     mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
972   }
973 }
974
975 void Window::Unparent()
976 {
977   mWindowBase->SetParent( nullptr );
978   mParentWindow.Reset();
979 }
980
981 Dali::Window Window::GetParent()
982 {
983   return mParentWindow;
984 }
985
986 Dali::Window::WindowOrientation Window::GetCurrentOrientation() const
987 {
988   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle );
989   return ConvertToOrientation( mRotationAngle );
990 }
991
992 void Window::SetAvailableOrientations( const Dali::Vector<Dali::Window::WindowOrientation>& orientations )
993 {
994   Dali::Vector<float>::SizeType count = orientations.Count();
995   for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
996   {
997     if( IsOrientationAvailable( orientations[index] ) == false )
998     {
999       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1000       continue;
1001     }
1002
1003     bool found = false;
1004     int convertedAngle = ConvertToAngle( orientations[index] );
1005
1006     for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
1007     {
1008       if( mAvailableAngles[i] == convertedAngle )
1009       {
1010         found = true;
1011         break;
1012       }
1013     }
1014
1015     if( !found )
1016     {
1017       DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle );
1018       mAvailableAngles.push_back( convertedAngle );
1019     }
1020   }
1021   SetAvailableAnlges( mAvailableAngles );
1022 }
1023
1024 int32_t Window::GetNativeId() const
1025 {
1026   return mWindowBase->GetNativeWindowId();
1027 }
1028
1029 void Window::SetDamagedAreas(std::vector<Dali::Rect<int>>& areas)
1030 {
1031   GraphicsInterface& graphics = mAdaptor->GetGraphicsInterface();
1032   EglGraphics* eglGraphics = static_cast<EglGraphics*>(&graphics);
1033   if (eglGraphics)
1034   {
1035     eglGraphics->SetDamagedAreas(areas);
1036   }
1037 }
1038
1039 } // Adaptor
1040
1041 } // Internal
1042
1043 } // Dali