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 ),
77 mPreferredAngle( Dali::Window::NO_ORIENTATION_PREFERENCE ),
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 )
214 if( IsOrientationAvailable( orientation ) == false )
220 int convertedAngle = ConvertToAngle( orientation );
221 for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
223 if( mAvailableAngles[i] == convertedAngle )
232 mAvailableAngles.push_back( convertedAngle );
233 SetAvailableAnlges( mAvailableAngles );
237 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
239 if( IsOrientationAvailable( orientation ) == false )
244 int convertedAngle = ConvertToAngle( orientation );
245 for( std::vector< int >::iterator iter = mAvailableAngles.begin();
246 iter != mAvailableAngles.end(); ++iter )
248 if( *iter == convertedAngle )
250 mAvailableAngles.erase( iter );
255 SetAvailableAnlges( mAvailableAngles );
258 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
260 if( orientation < Dali::Window::NO_ORIENTATION_PREFERENCE || orientation > Dali::Window::LANDSCAPE_INVERSE )
264 mPreferredAngle = ConvertToAngle( orientation );
265 mWindowBase->SetPreferredAngle( mPreferredAngle );
268 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
270 Dali::Window::WindowOrientation preferredOrientation = ConvertToOrientation( mPreferredAngle );
271 return preferredOrientation;
274 void Window::SetAvailableAnlges( const std::vector< int >& angles )
276 if( angles.size() > 4 )
278 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size() );
282 mWindowBase->SetAvailableAnlges( angles );
285 int Window::ConvertToAngle( Dali::Window::WindowOrientation orientation )
287 int convertAngle = static_cast< int >( orientation );
288 if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
290 switch( orientation )
292 case Dali::Window::LANDSCAPE:
297 case Dali::Window::PORTRAIT:
302 case Dali::Window::LANDSCAPE_INVERSE:
307 case Dali::Window::PORTRAIT_INVERSE:
312 case Dali::Window::NO_ORIENTATION_PREFERENCE:
322 Dali::Window::WindowOrientation Window::ConvertToOrientation( int angle )
324 Dali::Window::WindowOrientation orientation = static_cast< Dali::Window::WindowOrientation >( angle );
325 if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
331 orientation = Dali::Window::LANDSCAPE;
336 orientation = Dali::Window::PORTRAIT;
341 orientation = Dali::Window::LANDSCAPE_INVERSE;
346 orientation = Dali::Window::PORTRAIT_INVERSE;
351 orientation = Dali::Window::NO_ORIENTATION_PREFERENCE;
359 bool Window::IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const
361 if( orientation <= Dali::Window::NO_ORIENTATION_PREFERENCE || orientation > Dali::Window::LANDSCAPE_INVERSE )
363 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation );
369 Dali::Any Window::GetNativeHandle() const
371 return mWindowSurface->GetNativeWindow();
374 void Window::SetAcceptFocus( bool accept )
376 mIsFocusAcceptable = accept;
378 mWindowBase->SetAcceptFocus( accept );
381 bool Window::IsFocusAcceptable() const
383 return mIsFocusAcceptable;
394 WindowVisibilityObserver* observer( mAdaptor );
395 observer->OnWindowShown();
397 Dali::Window handle( this );
398 mVisibilityChangedSignal.Emit( handle, true );
401 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
412 WindowVisibilityObserver* observer( mAdaptor );
413 observer->OnWindowHidden();
415 Dali::Window handle( this );
416 mVisibilityChangedSignal.Emit( handle, false );
419 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
422 bool Window::IsVisible() const
424 return mVisible && !mIconified;
427 unsigned int Window::GetSupportedAuxiliaryHintCount() const
429 return mWindowBase->GetSupportedAuxiliaryHintCount();
432 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
434 return mWindowBase->GetSupportedAuxiliaryHint( index );
437 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
439 return mWindowBase->AddAuxiliaryHint( hint, value );
442 bool Window::RemoveAuxiliaryHint( unsigned int id )
444 return mWindowBase->RemoveAuxiliaryHint( id );
447 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
449 return mWindowBase->SetAuxiliaryHintValue( id, value );
452 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
454 return mWindowBase->GetAuxiliaryHintValue( id );
457 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
459 return mWindowBase->GetAuxiliaryHintId( hint );
462 void Window::SetInputRegion( const Rect< int >& inputRegion )
464 mWindowBase->SetInputRegion( inputRegion );
466 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 );
469 void Window::SetType( Dali::Window::Type type )
473 mWindowBase->SetType( type );
479 Dali::Window::Type Window::GetType() const
484 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
486 if( mType != Dali::Window::NOTIFICATION )
488 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
492 return mWindowBase->SetNotificationLevel( level );
495 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
497 if( mType != Dali::Window::NOTIFICATION )
499 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
500 return Dali::Window::NotificationLevel::NONE;
503 return mWindowBase->GetNotificationLevel();
506 void Window::SetOpaqueState( bool opaque )
508 mOpaqueState = opaque;
510 mWindowBase->SetOpaqueState( opaque );
512 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
515 bool Window::IsOpaqueState() const
520 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
522 return mWindowBase->SetScreenOffMode( screenOffMode );
525 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
527 return mWindowBase->GetScreenOffMode();
530 bool Window::SetBrightness( int brightness )
532 if( brightness < 0 || brightness > 100 )
534 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
538 return mWindowBase->SetBrightness( brightness );
541 int Window::GetBrightness() const
543 return mWindowBase->GetBrightness();
546 void Window::SetSize( Dali::Window::WindowSize size )
548 if( !mResizeEnabled )
550 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
551 mResizeEnabled = true;
554 PositionSize oldRect = mSurface->GetPositionSize();
556 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
558 PositionSize newRect = mSurface->GetPositionSize();
560 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
561 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
563 Uint16Pair newSize( newRect.width, newRect.height );
567 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
569 Dali::Window handle( this );
570 mResizedSignal.Emit( newSize );
571 mResizeSignal.Emit( handle, newSize );
573 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
577 Dali::Window::WindowSize Window::GetSize() const
579 PositionSize positionSize = mSurface->GetPositionSize();
581 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
584 void Window::SetPosition( Dali::Window::WindowPosition position )
586 if( !mResizeEnabled )
588 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
589 mResizeEnabled = true;
592 PositionSize oldRect = mSurface->GetPositionSize();
594 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
597 Dali::Window::WindowPosition Window::GetPosition() const
599 PositionSize positionSize = mSurface->GetPositionSize();
601 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
604 void Window::SetPositionSize( PositionSize positionSize )
606 if( !mResizeEnabled )
608 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
609 mResizeEnabled = true;
612 PositionSize oldRect = mSurface->GetPositionSize();
614 mWindowSurface->MoveResize( positionSize );
616 PositionSize newRect = mSurface->GetPositionSize();
618 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
619 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
621 Uint16Pair newSize( newRect.width, newRect.height );
625 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
627 Dali::Window handle( this );
628 mResizedSignal.Emit( newSize );
629 mResizeSignal.Emit( handle, newSize );
630 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
634 Dali::Layer Window::GetRootLayer() const
636 return mScene.GetRootLayer();
639 void Window::SetTransparency( bool transparent )
641 mWindowSurface->SetTransparency( transparent );
644 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
646 return mWindowBase->GrabKey( key, grabMode );
649 bool Window::UngrabKey( Dali::KEY key )
651 return mWindowBase->UngrabKey( key );
654 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
656 return mWindowBase->GrabKeyList( key, grabMode, result );
659 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
661 return mWindowBase->UngrabKeyList( key, result );
664 void Window::OnIconifyChanged( bool iconified )
672 WindowVisibilityObserver* observer( mAdaptor );
673 observer->OnWindowHidden();
675 Dali::Window handle( this );
676 mVisibilityChangedSignal.Emit( handle, false );
679 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
687 WindowVisibilityObserver* observer( mAdaptor );
688 observer->OnWindowShown();
690 Dali::Window handle( this );
691 mVisibilityChangedSignal.Emit( handle, true );
694 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
698 void Window::OnFocusChanged( bool focusIn )
700 Dali::Window handle( this );
701 mFocusChangedSignal.Emit( focusIn );
702 mFocusChangeSignal.Emit( handle, focusIn );
705 void Window::OnOutputTransformed()
707 PositionSize positionSize = mSurface->GetPositionSize();
709 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
710 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
713 void Window::OnDeleteRequest()
715 mDeleteRequestSignal.Emit();
718 void Window::OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type )
720 Dali::Window handle( this );
721 mTransitionEffectEventSignal.Emit( handle, state, type );
724 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
726 FeedTouchPoint( point, timeStamp );
729 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
731 FeedWheelEvent( wheelEvent );
734 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
736 FeedKeyEvent( keyEvent );
739 void Window::OnRotation( const RotationEvent& rotation )
741 mRotationAngle = rotation.angle;
742 mWindowWidth = rotation.width;
743 mWindowHeight = rotation.height;
745 // Notify that the orientation is changed
746 mOrientation->OnOrientationChange( rotation );
748 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
752 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
755 Dali::Window handle( this );
756 mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
757 mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
759 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
762 void Window::OnPause()
766 mEventHandler->Pause();
770 void Window::OnResume()
774 mEventHandler->Resume();
778 void Window::RecalculateTouchPosition( Integration::Point& point )
780 Vector2 position = point.GetScreenPosition();
781 Vector2 convertedPosition;
783 switch( mRotationAngle )
787 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
788 convertedPosition.y = position.x;
793 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
794 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
799 convertedPosition.x = position.y;
800 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
805 convertedPosition = position;
810 point.SetScreenPosition( convertedPosition );
813 Dali::Window Window::Get( Dali::Actor actor )
815 Internal::Adaptor::Window* windowImpl = nullptr;
817 if ( Internal::Adaptor::Adaptor::IsAvailable() )
819 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
820 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
823 return Dali::Window( windowImpl );
826 void Window::SetParent( Dali::Window& parent )
828 if ( DALI_UNLIKELY( parent ) )
830 mParentWindow = parent;
831 Dali::Window self = Dali::Window( this );
832 // check circular parent window setting
833 if ( Dali::DevelWindow::GetParent( parent ) == self )
835 Dali::DevelWindow::Unparent( parent );
837 mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
841 void Window::Unparent()
843 mWindowBase->SetParent( nullptr );
844 mParentWindow.Reset();
847 Dali::Window Window::GetParent()
849 return mParentWindow;