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-system.h>
40 #include <dali/internal/window-system/common/window-render-surface.h>
41 #include <dali/internal/window-system/common/window-visibility-observer.h>
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW" );
57 } // unnamed namespace
59 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
61 Window* window = new Window();
62 window->mIsTransparent = isTransparent;
63 window->Initialize( positionSize, name, className );
68 : mWindowSurface( nullptr ),
70 mIsTransparent( false ),
71 mIsFocusAcceptable( true ),
73 mOpaqueState( false ),
74 mResizeEnabled( false ),
75 mType( Dali::Window::NORMAL ),
76 mParentWindow( NULL ),
81 mOrientationMode( Internal::Adaptor::Window::OrientationMode::PORTRAIT ),
82 mFocusChangedSignal(),
84 mDeleteRequestSignal(),
87 mVisibilityChangedSignal(),
88 mTransitionEffectEventSignal()
96 mEventHandler->RemoveObserver( *this );
100 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
102 // Create a window render surface
104 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
105 mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
106 mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
109 mWindowBase = mWindowSurface->GetWindowBase();
112 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
113 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
114 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
115 mWindowBase->TransitionEffectEventSignal().Connect( this, &Window::OnTransitionEffectEvent );
117 mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
119 if( !positionSize.IsEmpty() )
121 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
122 mResizeEnabled = true;
125 SetClass( name, className );
127 mWindowSurface->Map();
129 mOrientation = Orientation::New( this );
131 // Get OrientationMode
132 int screenWidth, screenHeight;
133 WindowSystem::GetScreenSize( screenWidth, screenHeight );
134 if( screenWidth > screenHeight )
136 mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
140 mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
144 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
146 mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
147 mEventHandler->AddObserver( *this );
150 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
152 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
155 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
159 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
163 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
167 void Window::SetClass( std::string name, std::string className )
170 mClassName = className;
171 mWindowBase->SetClass( name, className );
174 std::string Window::GetClassName() const
181 mWindowBase->Raise();
182 DALI_LOG_RELEASE_INFO( "Window (%p) Raise() \n", this );
187 mWindowBase->Lower();
188 DALI_LOG_RELEASE_INFO( "Window (%p) Lower() \n", this );
191 void Window::Activate()
193 mWindowBase->Activate();
194 DALI_LOG_RELEASE_INFO( "Window (%p) Activate() \n", this );
197 uint32_t Window::GetLayerCount() const
199 return mScene.GetLayerCount();
202 Dali::Layer Window::GetLayer( uint32_t depth ) const
204 return mScene.GetLayer( depth );
207 Dali::RenderTaskList Window::GetRenderTaskList() const
209 return mScene.GetRenderTaskList();
212 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
215 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
217 int convertedAngle = ConvertToAngle( orientation );
218 for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
220 if( mAvailableAngles[i] == convertedAngle )
229 mAvailableAngles.push_back( convertedAngle );
230 SetAvailableAnlges( mAvailableAngles );
235 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
237 int convertedAngle = ConvertToAngle( orientation );
238 for( std::vector< int >::iterator iter = mAvailableAngles.begin();
239 iter != mAvailableAngles.end(); ++iter )
241 if( *iter == convertedAngle )
243 mAvailableAngles.erase( iter );
248 SetAvailableAnlges( mAvailableAngles );
251 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
253 mPreferredAngle = ConvertToAngle( orientation );
254 mWindowBase->SetPreferredAngle( mPreferredAngle );
257 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
259 Dali::Window::WindowOrientation preferredOrientation = ConvertToOrientation( mPreferredAngle );
260 return preferredOrientation;
263 void Window::SetAvailableAnlges( const std::vector< int >& angles )
265 if( angles.size() > 4 )
267 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size() );
271 mWindowBase->SetAvailableAnlges( angles );
274 int Window::ConvertToAngle( Dali::Window::WindowOrientation orientation )
276 int convertAngle = static_cast< int >( orientation );
277 if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
279 switch( orientation )
281 case Dali::Window::LANDSCAPE:
286 case Dali::Window::PORTRAIT:
291 case Dali::Window::LANDSCAPE_INVERSE:
296 case Dali::Window::PORTRAIT_INVERSE:
306 Dali::Window::WindowOrientation Window::ConvertToOrientation( int angle )
308 Dali::Window::WindowOrientation orientation = static_cast< Dali::Window::WindowOrientation >( angle );
309 if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
315 orientation = Dali::Window::LANDSCAPE;
320 orientation = Dali::Window::PORTRAIT;
325 orientation = Dali::Window::LANDSCAPE_INVERSE;
330 orientation = Dali::Window::PORTRAIT_INVERSE;
338 Dali::Any Window::GetNativeHandle() const
340 return mWindowSurface->GetNativeWindow();
343 void Window::SetAcceptFocus( bool accept )
345 mIsFocusAcceptable = accept;
347 mWindowBase->SetAcceptFocus( accept );
350 bool Window::IsFocusAcceptable() const
352 return mIsFocusAcceptable;
363 WindowVisibilityObserver* observer( mAdaptor );
364 observer->OnWindowShown();
366 Dali::Window handle( this );
367 mVisibilityChangedSignal.Emit( handle, true );
370 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
381 WindowVisibilityObserver* observer( mAdaptor );
382 observer->OnWindowHidden();
384 Dali::Window handle( this );
385 mVisibilityChangedSignal.Emit( handle, false );
388 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
391 bool Window::IsVisible() const
393 return mVisible && !mIconified;
396 unsigned int Window::GetSupportedAuxiliaryHintCount() const
398 return mWindowBase->GetSupportedAuxiliaryHintCount();
401 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
403 return mWindowBase->GetSupportedAuxiliaryHint( index );
406 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
408 return mWindowBase->AddAuxiliaryHint( hint, value );
411 bool Window::RemoveAuxiliaryHint( unsigned int id )
413 return mWindowBase->RemoveAuxiliaryHint( id );
416 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
418 return mWindowBase->SetAuxiliaryHintValue( id, value );
421 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
423 return mWindowBase->GetAuxiliaryHintValue( id );
426 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
428 return mWindowBase->GetAuxiliaryHintId( hint );
431 void Window::SetInputRegion( const Rect< int >& inputRegion )
433 mWindowBase->SetInputRegion( inputRegion );
435 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 );
438 void Window::SetType( Dali::Window::Type type )
442 mWindowBase->SetType( type );
448 Dali::Window::Type Window::GetType() const
453 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
455 if( mType != Dali::Window::NOTIFICATION )
457 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
461 return mWindowBase->SetNotificationLevel( level );
464 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
466 if( mType != Dali::Window::NOTIFICATION )
468 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
469 return Dali::Window::NotificationLevel::NONE;
472 return mWindowBase->GetNotificationLevel();
475 void Window::SetOpaqueState( bool opaque )
477 mOpaqueState = opaque;
479 mWindowBase->SetOpaqueState( opaque );
481 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
484 bool Window::IsOpaqueState() const
489 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
491 return mWindowBase->SetScreenOffMode( screenOffMode );
494 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
496 return mWindowBase->GetScreenOffMode();
499 bool Window::SetBrightness( int brightness )
501 if( brightness < 0 || brightness > 100 )
503 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
507 return mWindowBase->SetBrightness( brightness );
510 int Window::GetBrightness() const
512 return mWindowBase->GetBrightness();
515 void Window::SetSize( Dali::Window::WindowSize size )
517 if( !mResizeEnabled )
519 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
520 mResizeEnabled = true;
523 PositionSize oldRect = mSurface->GetPositionSize();
525 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
527 PositionSize newRect = mSurface->GetPositionSize();
529 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
530 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
532 Uint16Pair newSize( newRect.width, newRect.height );
534 bool forceUpdate = false;
535 if( mWindowBase->IsEglWindowRotationSupported() )
540 SurfaceResized( forceUpdate );
542 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
544 Dali::Window handle( this );
545 mResizedSignal.Emit( newSize );
546 mResizeSignal.Emit( handle, newSize );
548 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
552 Dali::Window::WindowSize Window::GetSize() const
554 PositionSize positionSize = mSurface->GetPositionSize();
556 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
559 void Window::SetPosition( Dali::Window::WindowPosition position )
561 if( !mResizeEnabled )
563 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
564 mResizeEnabled = true;
567 PositionSize oldRect = mSurface->GetPositionSize();
569 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
572 Dali::Window::WindowPosition Window::GetPosition() const
574 PositionSize positionSize = mSurface->GetPositionSize();
576 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
579 void Window::SetPositionSize( PositionSize positionSize )
581 if( !mResizeEnabled )
583 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
584 mResizeEnabled = true;
587 PositionSize oldRect = mSurface->GetPositionSize();
589 mWindowSurface->MoveResize( positionSize );
591 PositionSize newRect = mSurface->GetPositionSize();
593 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
594 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
596 Uint16Pair newSize( newRect.width, newRect.height );
598 bool forceUpdate = false;
599 if( mWindowBase->IsEglWindowRotationSupported() )
604 SurfaceResized( forceUpdate );
606 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
608 Dali::Window handle( this );
609 mResizedSignal.Emit( newSize );
610 mResizeSignal.Emit( handle, newSize );
611 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
615 Dali::Layer Window::GetRootLayer() const
617 return mScene.GetRootLayer();
620 void Window::SetTransparency( bool transparent )
622 mWindowSurface->SetTransparency( transparent );
625 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
627 return mWindowBase->GrabKey( key, grabMode );
630 bool Window::UngrabKey( Dali::KEY key )
632 return mWindowBase->UngrabKey( key );
635 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
637 return mWindowBase->GrabKeyList( key, grabMode, result );
640 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
642 return mWindowBase->UngrabKeyList( key, result );
645 void Window::OnIconifyChanged( bool iconified )
653 WindowVisibilityObserver* observer( mAdaptor );
654 observer->OnWindowHidden();
656 Dali::Window handle( this );
657 mVisibilityChangedSignal.Emit( handle, false );
660 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
668 WindowVisibilityObserver* observer( mAdaptor );
669 observer->OnWindowShown();
671 Dali::Window handle( this );
672 mVisibilityChangedSignal.Emit( handle, true );
675 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
679 void Window::OnFocusChanged( bool focusIn )
681 Dali::Window handle( this );
682 mFocusChangedSignal.Emit( focusIn );
683 mFocusChangeSignal.Emit( handle, focusIn );
686 void Window::OnOutputTransformed()
688 bool forceUpdate = false;
689 if( mWindowBase->IsEglWindowRotationSupported() )
693 PositionSize positionSize = mSurface->GetPositionSize();
694 SurfaceResized( forceUpdate );
695 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
696 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
699 void Window::OnDeleteRequest()
701 mDeleteRequestSignal.Emit();
704 void Window::OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type )
706 Dali::Window handle( this );
707 mTransitionEffectEventSignal.Emit( handle, state, type );
710 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
712 FeedTouchPoint( point, timeStamp );
715 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
717 FeedWheelEvent( wheelEvent );
720 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
722 FeedKeyEvent( keyEvent );
725 void Window::OnRotation( const RotationEvent& rotation )
727 mRotationAngle = rotation.angle;
728 mWindowWidth = rotation.width;
729 mWindowHeight = rotation.height;
731 // Notify that the orientation is changed
732 mOrientation->OnOrientationChange( rotation );
734 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
736 bool forceUpdate = false;
737 if( mWindowBase->IsEglWindowRotationSupported() )
742 SurfaceResized( forceUpdate );
744 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
747 Dali::Window handle( this );
748 mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
749 mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
751 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
754 void Window::OnPause()
758 mEventHandler->Pause();
762 void Window::OnResume()
766 mEventHandler->Resume();
770 void Window::RecalculateTouchPosition( Integration::Point& point )
772 Vector2 position = point.GetScreenPosition();
773 Vector2 convertedPosition;
775 switch( mRotationAngle )
779 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
780 convertedPosition.y = position.x;
785 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
786 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
791 convertedPosition.x = position.y;
792 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
797 convertedPosition = position;
802 point.SetScreenPosition( convertedPosition );
805 Dali::Window Window::Get( Dali::Actor actor )
807 Internal::Adaptor::Window* windowImpl = nullptr;
809 if ( Internal::Adaptor::Adaptor::IsAvailable() )
811 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
812 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
815 return Dali::Window( windowImpl );
818 void Window::SetParent( Dali::Window& parent )
820 if ( DALI_UNLIKELY( parent ) )
822 mParentWindow = parent;
823 Dali::Window self = Dali::Window( this );
824 // check circular parent window setting
825 if ( Dali::DevelWindow::GetParent( parent ) == self )
827 Dali::DevelWindow::Unparent( parent );
829 mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
833 void Window::Unparent()
835 mWindowBase->SetParent( nullptr );
836 mParentWindow.Reset();
839 Dali::Window Window::GetParent()
841 return mParentWindow;