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>
32 #ifdef DALI_ADAPTOR_COMPILATION
33 #include <dali/integration-api/render-surface-interface.h>
35 #include <dali/integration-api/adaptors/render-surface-interface.h>
39 #include <dali/internal/window-system/common/event-handler.h>
40 #include <dali/internal/window-system/common/orientation-impl.h>
41 #include <dali/internal/window-system/common/render-surface-factory.h>
42 #include <dali/internal/window-system/common/window-factory.h>
43 #include <dali/internal/window-system/common/window-base.h>
44 #include <dali/internal/window-system/common/window-render-surface.h>
45 #include <dali/internal/window-system/common/window-visibility-observer.h>
57 #if defined(DEBUG_ENABLED)
58 Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW" );
61 } // unnamed namespace
63 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
65 Window* window = new Window();
66 window->mIsTransparent = isTransparent;
67 window->Initialize( positionSize, name, className );
72 : mWindowSurface( nullptr ),
74 mIsTransparent( false ),
75 mIsFocusAcceptable( true ),
77 mOpaqueState( false ),
78 mResizeEnabled( false ),
79 mType( Dali::Window::NORMAL ),
80 mParentWindow( NULL ),
81 mPreferredOrientation( Dali::Window::PORTRAIT ),
85 mFocusChangedSignal(),
87 mDeleteRequestSignal(),
97 mEventHandler->RemoveObserver( *this );
101 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
103 // Create a window render surface
105 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
106 mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
107 mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
110 mWindowBase = mWindowSurface->GetWindowBase();
113 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
114 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
115 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
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 );
132 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
134 mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
135 mEventHandler->AddObserver( *this );
138 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
140 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
143 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
147 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
151 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
155 void Window::SetClass( std::string name, std::string className )
158 mClassName = className;
159 mWindowBase->SetClass( name, className );
162 std::string Window::GetClassName() const
169 mWindowBase->Raise();
170 DALI_LOG_RELEASE_INFO( "Window (%p) Raise() \n", this );
175 mWindowBase->Lower();
176 DALI_LOG_RELEASE_INFO( "Window (%p) Lower() \n", this );
179 void Window::Activate()
181 mWindowBase->Activate();
182 DALI_LOG_RELEASE_INFO( "Window (%p) Activate() \n", this );
185 uint32_t Window::GetLayerCount() const
187 return mScene.GetLayerCount();
190 Dali::Layer Window::GetLayer( uint32_t depth ) const
192 return mScene.GetLayer( depth );
195 Dali::RenderTaskList Window::GetRenderTaskList() const
197 return mScene.GetRenderTaskList();
200 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
204 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
206 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
208 if( mAvailableOrientations[i] == orientation )
217 mAvailableOrientations.push_back( orientation );
218 SetAvailableOrientations( mAvailableOrientations );
223 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
225 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
226 iter != mAvailableOrientations.end(); ++iter )
228 if( *iter == orientation )
230 mAvailableOrientations.erase( iter );
234 SetAvailableOrientations( mAvailableOrientations );
237 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
239 if( orientations.size() > 4 )
241 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
245 mAvailableOrientations = orientations;
247 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
250 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
252 return mAvailableOrientations;
255 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
257 mPreferredOrientation = orientation;
259 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
262 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
264 return mPreferredOrientation;
267 Dali::Any Window::GetNativeHandle() const
269 return mWindowSurface->GetNativeWindow();
272 void Window::SetAcceptFocus( bool accept )
274 mIsFocusAcceptable = accept;
276 mWindowBase->SetAcceptFocus( accept );
279 bool Window::IsFocusAcceptable() const
281 return mIsFocusAcceptable;
292 WindowVisibilityObserver* observer( mAdaptor );
293 observer->OnWindowShown();
296 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
307 WindowVisibilityObserver* observer( mAdaptor );
308 observer->OnWindowHidden();
311 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
314 bool Window::IsVisible() const
316 return mVisible && !mIconified;
319 unsigned int Window::GetSupportedAuxiliaryHintCount() const
321 return mWindowBase->GetSupportedAuxiliaryHintCount();
324 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
326 return mWindowBase->GetSupportedAuxiliaryHint( index );
329 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
331 return mWindowBase->AddAuxiliaryHint( hint, value );
334 bool Window::RemoveAuxiliaryHint( unsigned int id )
336 return mWindowBase->RemoveAuxiliaryHint( id );
339 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
341 return mWindowBase->SetAuxiliaryHintValue( id, value );
344 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
346 return mWindowBase->GetAuxiliaryHintValue( id );
349 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
351 return mWindowBase->GetAuxiliaryHintId( hint );
354 void Window::SetInputRegion( const Rect< int >& inputRegion )
356 mWindowBase->SetInputRegion( inputRegion );
358 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 );
361 void Window::SetType( Dali::Window::Type type )
365 mWindowBase->SetType( type );
371 Dali::Window::Type Window::GetType() const
376 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
378 if( mType != Dali::Window::NOTIFICATION )
380 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
384 return mWindowBase->SetNotificationLevel( level );
387 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
389 if( mType != Dali::Window::NOTIFICATION )
391 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
392 return Dali::Window::NotificationLevel::NONE;
395 return mWindowBase->GetNotificationLevel();
398 void Window::SetOpaqueState( bool opaque )
400 mOpaqueState = opaque;
402 mWindowBase->SetOpaqueState( opaque );
404 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
407 bool Window::IsOpaqueState() const
412 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
414 return mWindowBase->SetScreenOffMode( screenOffMode );
417 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
419 return mWindowBase->GetScreenOffMode();
422 bool Window::SetBrightness( int brightness )
424 if( brightness < 0 || brightness > 100 )
426 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
430 return mWindowBase->SetBrightness( brightness );
433 int Window::GetBrightness() const
435 return mWindowBase->GetBrightness();
438 void Window::SetSize( Dali::Window::WindowSize size )
440 if( !mResizeEnabled )
442 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
443 mResizeEnabled = true;
446 PositionSize oldRect = mSurface->GetPositionSize();
448 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
450 PositionSize newRect = mSurface->GetPositionSize();
452 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
453 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
455 Uint16Pair newSize( newRect.width, newRect.height );
459 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
461 Dali::Window handle( this );
462 mResizedSignal.Emit( newSize );
463 mResizeSignal.Emit( handle, newSize );
465 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
469 Dali::Window::WindowSize Window::GetSize() const
471 PositionSize positionSize = mSurface->GetPositionSize();
473 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
476 void Window::SetPosition( Dali::Window::WindowPosition position )
478 if( !mResizeEnabled )
480 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
481 mResizeEnabled = true;
484 PositionSize oldRect = mSurface->GetPositionSize();
486 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
489 Dali::Window::WindowPosition Window::GetPosition() const
491 PositionSize positionSize = mSurface->GetPositionSize();
493 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
496 void Window::SetPositionSize( PositionSize positionSize )
498 if( !mResizeEnabled )
500 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
501 mResizeEnabled = true;
504 PositionSize oldRect = mSurface->GetPositionSize();
506 mWindowSurface->MoveResize( positionSize );
508 PositionSize newRect = mSurface->GetPositionSize();
510 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
511 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
513 Uint16Pair newSize( newRect.width, newRect.height );
517 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
519 Dali::Window handle( this );
520 mResizedSignal.Emit( newSize );
521 mResizeSignal.Emit( handle, newSize );
522 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
526 Dali::Layer Window::GetRootLayer() const
528 return mScene.GetRootLayer();
531 void Window::SetTransparency( bool transparent )
533 mWindowSurface->SetTransparency( transparent );
536 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
538 return mWindowBase->GrabKey( key, grabMode );
541 bool Window::UngrabKey( Dali::KEY key )
543 return mWindowBase->UngrabKey( key );
546 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
548 return mWindowBase->GrabKeyList( key, grabMode, result );
551 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
553 return mWindowBase->UngrabKeyList( key, result );
556 void Window::OnIconifyChanged( bool iconified )
564 WindowVisibilityObserver* observer( mAdaptor );
565 observer->OnWindowHidden();
568 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
576 WindowVisibilityObserver* observer( mAdaptor );
577 observer->OnWindowShown();
580 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
584 void Window::OnFocusChanged( bool focusIn )
586 Dali::Window handle( this );
587 mFocusChangedSignal.Emit( focusIn );
588 mFocusChangeSignal.Emit( handle, focusIn );
591 void Window::OnOutputTransformed()
593 PositionSize positionSize = mSurface->GetPositionSize();
595 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
596 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
599 void Window::OnDeleteRequest()
601 mDeleteRequestSignal.Emit();
604 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
606 FeedTouchPoint( point, timeStamp );
609 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
611 FeedWheelEvent( wheelEvent );
614 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
616 FeedKeyEvent( keyEvent );
619 void Window::OnRotation( const RotationEvent& rotation )
621 mRotationAngle = rotation.angle;
622 mWindowWidth = rotation.width;
623 mWindowHeight = rotation.height;
625 // Notify that the orientation is changed
626 mOrientation->OnOrientationChange( rotation );
628 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
632 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
635 Dali::Window handle( this );
636 mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
637 mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
639 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
642 void Window::OnPause()
646 mEventHandler->Pause();
650 void Window::OnResume()
654 mEventHandler->Resume();
658 void Window::RecalculateTouchPosition( Integration::Point& point )
660 Vector2 position = point.GetScreenPosition();
661 Vector2 convertedPosition;
663 switch( mRotationAngle )
667 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
668 convertedPosition.y = position.x;
673 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
674 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
679 convertedPosition.x = position.y;
680 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
685 convertedPosition = position;
690 point.SetScreenPosition( convertedPosition );
693 Dali::Window Window::Get( Dali::Actor actor )
695 Internal::Adaptor::Window* windowImpl = nullptr;
697 if ( Internal::Adaptor::Adaptor::IsAvailable() )
699 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
700 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
703 return Dali::Window( windowImpl );
706 void Window::SetParent( Dali::Window& parent )
708 if ( DALI_UNLIKELY( parent ) )
710 mParentWindow = parent;
711 Dali::Window self = Dali::Window( this );
712 // check circular parent window setting
713 if ( Dali::DevelWindow::GetParent( parent ) == self )
715 Dali::DevelWindow::Unparent( parent );
717 mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
721 void Window::Unparent()
723 mWindowBase->SetParent( nullptr );
724 mParentWindow.Reset();
727 Dali::Window Window::GetParent()
729 return mParentWindow;