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 );
463 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
465 Dali::Window handle( this );
466 mResizedSignal.Emit( newSize );
467 mResizeSignal.Emit( handle, newSize );
469 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
473 Dali::Window::WindowSize Window::GetSize() const
475 PositionSize positionSize = mSurface->GetPositionSize();
477 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
480 void Window::SetPosition( Dali::Window::WindowPosition position )
482 if( !mResizeEnabled )
484 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
485 mResizeEnabled = true;
488 PositionSize oldRect = mSurface->GetPositionSize();
490 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
493 Dali::Window::WindowPosition Window::GetPosition() const
495 PositionSize positionSize = mSurface->GetPositionSize();
497 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
500 void Window::SetPositionSize( PositionSize positionSize )
502 if( !mResizeEnabled )
504 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
505 mResizeEnabled = true;
508 PositionSize oldRect = mSurface->GetPositionSize();
510 mWindowSurface->MoveResize( positionSize );
512 PositionSize newRect = mSurface->GetPositionSize();
514 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
515 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
517 Uint16Pair newSize( newRect.width, newRect.height );
521 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
523 Dali::Window handle( this );
524 mResizedSignal.Emit( newSize );
525 mResizeSignal.Emit( handle, newSize );
526 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
530 Dali::Layer Window::GetRootLayer() const
532 return mScene.GetRootLayer();
535 void Window::SetTransparency( bool transparent )
537 mWindowSurface->SetTransparency( transparent );
540 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
542 return mWindowBase->GrabKey( key, grabMode );
545 bool Window::UngrabKey( Dali::KEY key )
547 return mWindowBase->UngrabKey( key );
550 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
552 return mWindowBase->GrabKeyList( key, grabMode, result );
555 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
557 return mWindowBase->UngrabKeyList( key, result );
560 void Window::OnIconifyChanged( bool iconified )
568 WindowVisibilityObserver* observer( mAdaptor );
569 observer->OnWindowHidden();
571 Dali::Window handle( this );
572 mVisibilityChangedSignal.Emit( handle, false );
575 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
583 WindowVisibilityObserver* observer( mAdaptor );
584 observer->OnWindowShown();
586 Dali::Window handle( this );
587 mVisibilityChangedSignal.Emit( handle, true );
590 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
594 void Window::OnFocusChanged( bool focusIn )
596 Dali::Window handle( this );
597 mFocusChangedSignal.Emit( focusIn );
598 mFocusChangeSignal.Emit( handle, focusIn );
601 void Window::OnOutputTransformed()
603 PositionSize positionSize = mSurface->GetPositionSize();
605 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
606 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
609 void Window::OnDeleteRequest()
611 mDeleteRequestSignal.Emit();
614 void Window::OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type )
616 Dali::Window handle( this );
617 mTransitionEffectEventSignal.Emit( handle, state, type );
620 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
622 FeedTouchPoint( point, timeStamp );
625 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
627 FeedWheelEvent( wheelEvent );
630 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
632 FeedKeyEvent( keyEvent );
635 void Window::OnRotation( const RotationEvent& rotation )
637 mRotationAngle = rotation.angle;
638 mWindowWidth = rotation.width;
639 mWindowHeight = rotation.height;
641 // Notify that the orientation is changed
642 mOrientation->OnOrientationChange( rotation );
644 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
648 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
651 Dali::Window handle( this );
652 mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
653 mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
655 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
658 void Window::OnPause()
662 mEventHandler->Pause();
666 void Window::OnResume()
670 mEventHandler->Resume();
674 void Window::RecalculateTouchPosition( Integration::Point& point )
676 Vector2 position = point.GetScreenPosition();
677 Vector2 convertedPosition;
679 switch( mRotationAngle )
683 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
684 convertedPosition.y = position.x;
689 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
690 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
695 convertedPosition.x = position.y;
696 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
701 convertedPosition = position;
706 point.SetScreenPosition( convertedPosition );
709 Dali::Window Window::Get( Dali::Actor actor )
711 Internal::Adaptor::Window* windowImpl = nullptr;
713 if ( Internal::Adaptor::Adaptor::IsAvailable() )
715 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
716 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
719 return Dali::Window( windowImpl );
722 void Window::SetParent( Dali::Window& parent )
724 if ( DALI_UNLIKELY( parent ) )
726 mParentWindow = parent;
727 Dali::Window self = Dali::Window( this );
728 // check circular parent window setting
729 if ( Dali::DevelWindow::GetParent( parent ) == self )
731 Dali::DevelWindow::Unparent( parent );
733 mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
737 void Window::Unparent()
739 mWindowBase->SetParent( nullptr );
740 mParentWindow.Reset();
743 Dali::Window Window::GetParent()
745 return mParentWindow;