2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/window-system/common/window-impl.h>
22 #include <dali/integration-api/core.h>
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/actors/camera-actor.h>
26 #include <dali/public-api/render-tasks/render-task.h>
27 #include <dali/public-api/render-tasks/render-task-list.h>
28 #include <dali/public-api/rendering/frame-buffer.h>
29 #include <dali/devel-api/adaptor-framework/orientation.h>
30 #include <dali/integration-api/events/touch-event-integ.h>
33 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
34 #include <dali/internal/window-system/common/event-handler.h>
35 #include <dali/internal/window-system/common/orientation-impl.h>
36 #include <dali/internal/window-system/common/render-surface-factory.h>
37 #include <dali/internal/window-system/common/window-factory.h>
38 #include <dali/internal/window-system/common/window-base.h>
39 #include <dali/internal/window-system/common/window-render-surface.h>
40 #include <dali/internal/window-system/common/window-visibility-observer.h>
52 #if defined(DEBUG_ENABLED)
53 Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW" );
56 } // unnamed namespace
58 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
60 Window* window = new Window();
61 window->mIsTransparent = isTransparent;
62 window->Initialize( positionSize, name, className );
67 : mWindowSurface( nullptr ),
69 mIsTransparent( false ),
70 mIsFocusAcceptable( true ),
72 mOpaqueState( false ),
73 mResizeEnabled( false ),
74 mType( Dali::Window::NORMAL ),
75 mParentWindow( NULL ),
76 mPreferredOrientation( Dali::Window::PORTRAIT ),
80 mFocusChangedSignal(),
82 mDeleteRequestSignal(),
85 mVisibilityChangedSignal(),
86 mTransitionEffectEventSignal()
94 mEventHandler->RemoveObserver( *this );
98 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
100 // Create a window render surface
102 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
103 mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
104 mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
107 mWindowBase = mWindowSurface->GetWindowBase();
110 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
111 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
112 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
113 mWindowBase->TransitionEffectEventSignal().Connect( this, &Window::OnTransitionEffectEvent );
115 mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
117 if( !positionSize.IsEmpty() )
119 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
120 mResizeEnabled = true;
123 SetClass( name, className );
125 mWindowSurface->Map();
127 mOrientation = Orientation::New( this );
130 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
132 mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
133 mEventHandler->AddObserver( *this );
136 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
138 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
141 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
145 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
149 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
153 void Window::SetClass( std::string name, std::string className )
156 mClassName = className;
157 mWindowBase->SetClass( name, className );
160 std::string Window::GetClassName() const
167 mWindowBase->Raise();
168 DALI_LOG_RELEASE_INFO( "Window (%p) Raise() \n", this );
173 mWindowBase->Lower();
174 DALI_LOG_RELEASE_INFO( "Window (%p) Lower() \n", this );
177 void Window::Activate()
179 mWindowBase->Activate();
180 DALI_LOG_RELEASE_INFO( "Window (%p) Activate() \n", this );
183 uint32_t Window::GetLayerCount() const
185 return mScene.GetLayerCount();
188 Dali::Layer Window::GetLayer( uint32_t depth ) const
190 return mScene.GetLayer( depth );
193 Dali::RenderTaskList Window::GetRenderTaskList() const
195 return mScene.GetRenderTaskList();
198 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
202 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
204 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
206 if( mAvailableOrientations[i] == orientation )
215 mAvailableOrientations.push_back( orientation );
216 SetAvailableOrientations( mAvailableOrientations );
221 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
223 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
224 iter != mAvailableOrientations.end(); ++iter )
226 if( *iter == orientation )
228 mAvailableOrientations.erase( iter );
232 SetAvailableOrientations( mAvailableOrientations );
235 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
237 if( orientations.size() > 4 )
239 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
243 mAvailableOrientations = orientations;
245 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
248 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
250 return mAvailableOrientations;
253 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
255 mPreferredOrientation = orientation;
257 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
260 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
262 return mPreferredOrientation;
265 Dali::Any Window::GetNativeHandle() const
267 return mWindowSurface->GetNativeWindow();
270 void Window::SetAcceptFocus( bool accept )
272 mIsFocusAcceptable = accept;
274 mWindowBase->SetAcceptFocus( accept );
277 bool Window::IsFocusAcceptable() const
279 return mIsFocusAcceptable;
290 WindowVisibilityObserver* observer( mAdaptor );
291 observer->OnWindowShown();
293 Dali::Window handle( this );
294 mVisibilityChangedSignal.Emit( handle, true );
297 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
308 WindowVisibilityObserver* observer( mAdaptor );
309 observer->OnWindowHidden();
311 Dali::Window handle( this );
312 mVisibilityChangedSignal.Emit( handle, false );
315 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
318 bool Window::IsVisible() const
320 return mVisible && !mIconified;
323 unsigned int Window::GetSupportedAuxiliaryHintCount() const
325 return mWindowBase->GetSupportedAuxiliaryHintCount();
328 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
330 return mWindowBase->GetSupportedAuxiliaryHint( index );
333 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
335 return mWindowBase->AddAuxiliaryHint( hint, value );
338 bool Window::RemoveAuxiliaryHint( unsigned int id )
340 return mWindowBase->RemoveAuxiliaryHint( id );
343 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
345 return mWindowBase->SetAuxiliaryHintValue( id, value );
348 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
350 return mWindowBase->GetAuxiliaryHintValue( id );
353 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
355 return mWindowBase->GetAuxiliaryHintId( hint );
358 void Window::SetInputRegion( const Rect< int >& inputRegion )
360 mWindowBase->SetInputRegion( inputRegion );
362 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 );
365 void Window::SetType( Dali::Window::Type type )
369 mWindowBase->SetType( type );
375 Dali::Window::Type Window::GetType() const
380 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
382 if( mType != Dali::Window::NOTIFICATION )
384 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
388 return mWindowBase->SetNotificationLevel( level );
391 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
393 if( mType != Dali::Window::NOTIFICATION )
395 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
396 return Dali::Window::NotificationLevel::NONE;
399 return mWindowBase->GetNotificationLevel();
402 void Window::SetOpaqueState( bool opaque )
404 mOpaqueState = opaque;
406 mWindowBase->SetOpaqueState( opaque );
408 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
411 bool Window::IsOpaqueState() const
416 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
418 return mWindowBase->SetScreenOffMode( screenOffMode );
421 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
423 return mWindowBase->GetScreenOffMode();
426 bool Window::SetBrightness( int brightness )
428 if( brightness < 0 || brightness > 100 )
430 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
434 return mWindowBase->SetBrightness( brightness );
437 int Window::GetBrightness() const
439 return mWindowBase->GetBrightness();
442 void Window::SetSize( Dali::Window::WindowSize size )
444 if( !mResizeEnabled )
446 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
447 mResizeEnabled = true;
450 PositionSize oldRect = mSurface->GetPositionSize();
452 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
454 PositionSize newRect = mSurface->GetPositionSize();
456 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
457 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
459 Uint16Pair newSize( newRect.width, newRect.height );
461 bool forceUpdate = false;
462 if( mWindowBase->IsEglWindowRotationSupported() )
467 SurfaceResized( forceUpdate );
469 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
471 Dali::Window handle( this );
472 mResizedSignal.Emit( newSize );
473 mResizeSignal.Emit( handle, newSize );
475 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
479 Dali::Window::WindowSize Window::GetSize() const
481 PositionSize positionSize = mSurface->GetPositionSize();
483 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
486 void Window::SetPosition( Dali::Window::WindowPosition position )
488 if( !mResizeEnabled )
490 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
491 mResizeEnabled = true;
494 PositionSize oldRect = mSurface->GetPositionSize();
496 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
499 Dali::Window::WindowPosition Window::GetPosition() const
501 PositionSize positionSize = mSurface->GetPositionSize();
503 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
506 void Window::SetPositionSize( PositionSize positionSize )
508 if( !mResizeEnabled )
510 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
511 mResizeEnabled = true;
514 PositionSize oldRect = mSurface->GetPositionSize();
516 mWindowSurface->MoveResize( positionSize );
518 PositionSize newRect = mSurface->GetPositionSize();
520 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
521 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
523 Uint16Pair newSize( newRect.width, newRect.height );
525 bool forceUpdate = false;
526 if( mWindowBase->IsEglWindowRotationSupported() )
531 SurfaceResized( forceUpdate );
533 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
535 Dali::Window handle( this );
536 mResizedSignal.Emit( newSize );
537 mResizeSignal.Emit( handle, newSize );
538 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
542 Dali::Layer Window::GetRootLayer() const
544 return mScene.GetRootLayer();
547 void Window::SetTransparency( bool transparent )
549 mWindowSurface->SetTransparency( transparent );
552 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
554 return mWindowBase->GrabKey( key, grabMode );
557 bool Window::UngrabKey( Dali::KEY key )
559 return mWindowBase->UngrabKey( key );
562 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
564 return mWindowBase->GrabKeyList( key, grabMode, result );
567 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
569 return mWindowBase->UngrabKeyList( key, result );
572 void Window::OnIconifyChanged( bool iconified )
580 WindowVisibilityObserver* observer( mAdaptor );
581 observer->OnWindowHidden();
583 Dali::Window handle( this );
584 mVisibilityChangedSignal.Emit( handle, false );
587 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
595 WindowVisibilityObserver* observer( mAdaptor );
596 observer->OnWindowShown();
598 Dali::Window handle( this );
599 mVisibilityChangedSignal.Emit( handle, true );
602 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
606 void Window::OnFocusChanged( bool focusIn )
608 Dali::Window handle( this );
609 mFocusChangedSignal.Emit( focusIn );
610 mFocusChangeSignal.Emit( handle, focusIn );
613 void Window::OnOutputTransformed()
615 bool forceUpdate = false;
616 if( mWindowBase->IsEglWindowRotationSupported() )
620 PositionSize positionSize = mSurface->GetPositionSize();
621 SurfaceResized( forceUpdate );
622 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
623 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
626 void Window::OnDeleteRequest()
628 mDeleteRequestSignal.Emit();
631 void Window::OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type )
633 Dali::Window handle( this );
634 mTransitionEffectEventSignal.Emit( handle, state, type );
637 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
639 FeedTouchPoint( point, timeStamp );
642 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
644 FeedWheelEvent( wheelEvent );
647 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
649 FeedKeyEvent( keyEvent );
652 void Window::OnRotation( const RotationEvent& rotation )
654 mRotationAngle = rotation.angle;
655 mWindowWidth = rotation.width;
656 mWindowHeight = rotation.height;
658 // Notify that the orientation is changed
659 mOrientation->OnOrientationChange( rotation );
661 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
663 bool forceUpdate = false;
664 if( mWindowBase->IsEglWindowRotationSupported() )
669 SurfaceResized( forceUpdate );
671 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
674 Dali::Window handle( this );
675 mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
676 mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
678 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
681 void Window::OnPause()
685 mEventHandler->Pause();
689 void Window::OnResume()
693 mEventHandler->Resume();
697 void Window::RecalculateTouchPosition( Integration::Point& point )
699 Vector2 position = point.GetScreenPosition();
700 Vector2 convertedPosition;
702 switch( mRotationAngle )
706 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
707 convertedPosition.y = position.x;
712 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
713 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
718 convertedPosition.x = position.y;
719 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
724 convertedPosition = position;
729 point.SetScreenPosition( convertedPosition );
732 Dali::Window Window::Get( Dali::Actor actor )
734 Internal::Adaptor::Window* windowImpl = nullptr;
736 if ( Internal::Adaptor::Adaptor::IsAvailable() )
738 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
739 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
742 return Dali::Window( windowImpl );
745 void Window::SetParent( Dali::Window& parent )
747 if ( DALI_UNLIKELY( parent ) )
749 mParentWindow = parent;
750 Dali::Window self = Dali::Window( this );
751 // check circular parent window setting
752 if ( Dali::DevelWindow::GetParent( parent ) == self )
754 Dali::DevelWindow::Unparent( parent );
756 mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
760 void Window::Unparent()
762 mWindowBase->SetParent( nullptr );
763 mParentWindow.Reset();
766 Dali::Window Window::GetParent()
768 return mParentWindow;