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()
93 mEventHandler->RemoveObserver( *this );
97 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
99 // Create a window render surface
101 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
102 mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
103 mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
106 mWindowBase = mWindowSurface->GetWindowBase();
109 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
110 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
111 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
113 mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
115 if( !positionSize.IsEmpty() )
117 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
118 mResizeEnabled = true;
121 SetClass( name, className );
123 mWindowSurface->Map();
125 mOrientation = Orientation::New( this );
128 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
130 mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
131 mEventHandler->AddObserver( *this );
134 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
136 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
139 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
143 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
147 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
151 void Window::SetClass( std::string name, std::string className )
154 mClassName = className;
155 mWindowBase->SetClass( name, className );
158 std::string Window::GetClassName() const
165 mWindowBase->Raise();
166 DALI_LOG_RELEASE_INFO( "Window (%p) Raise() \n", this );
171 mWindowBase->Lower();
172 DALI_LOG_RELEASE_INFO( "Window (%p) Lower() \n", this );
175 void Window::Activate()
177 mWindowBase->Activate();
178 DALI_LOG_RELEASE_INFO( "Window (%p) Activate() \n", this );
181 uint32_t Window::GetLayerCount() const
183 return mScene.GetLayerCount();
186 Dali::Layer Window::GetLayer( uint32_t depth ) const
188 return mScene.GetLayer( depth );
191 Dali::RenderTaskList Window::GetRenderTaskList() const
193 return mScene.GetRenderTaskList();
196 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
200 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
202 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
204 if( mAvailableOrientations[i] == orientation )
213 mAvailableOrientations.push_back( orientation );
214 SetAvailableOrientations( mAvailableOrientations );
219 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
221 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
222 iter != mAvailableOrientations.end(); ++iter )
224 if( *iter == orientation )
226 mAvailableOrientations.erase( iter );
230 SetAvailableOrientations( mAvailableOrientations );
233 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
235 if( orientations.size() > 4 )
237 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
241 mAvailableOrientations = orientations;
243 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
246 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
248 return mAvailableOrientations;
251 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
253 mPreferredOrientation = orientation;
255 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
258 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
260 return mPreferredOrientation;
263 Dali::Any Window::GetNativeHandle() const
265 return mWindowSurface->GetNativeWindow();
268 void Window::SetAcceptFocus( bool accept )
270 mIsFocusAcceptable = accept;
272 mWindowBase->SetAcceptFocus( accept );
275 bool Window::IsFocusAcceptable() const
277 return mIsFocusAcceptable;
288 WindowVisibilityObserver* observer( mAdaptor );
289 observer->OnWindowShown();
291 Dali::Window handle( this );
292 mVisibilityChangedSignal.Emit( handle, true );
295 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
306 WindowVisibilityObserver* observer( mAdaptor );
307 observer->OnWindowHidden();
309 Dali::Window handle( this );
310 mVisibilityChangedSignal.Emit( handle, false );
313 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
316 bool Window::IsVisible() const
318 return mVisible && !mIconified;
321 unsigned int Window::GetSupportedAuxiliaryHintCount() const
323 return mWindowBase->GetSupportedAuxiliaryHintCount();
326 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
328 return mWindowBase->GetSupportedAuxiliaryHint( index );
331 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
333 return mWindowBase->AddAuxiliaryHint( hint, value );
336 bool Window::RemoveAuxiliaryHint( unsigned int id )
338 return mWindowBase->RemoveAuxiliaryHint( id );
341 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
343 return mWindowBase->SetAuxiliaryHintValue( id, value );
346 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
348 return mWindowBase->GetAuxiliaryHintValue( id );
351 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
353 return mWindowBase->GetAuxiliaryHintId( hint );
356 void Window::SetInputRegion( const Rect< int >& inputRegion )
358 mWindowBase->SetInputRegion( inputRegion );
360 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 );
363 void Window::SetType( Dali::Window::Type type )
367 mWindowBase->SetType( type );
373 Dali::Window::Type Window::GetType() const
378 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
380 if( mType != Dali::Window::NOTIFICATION )
382 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
386 return mWindowBase->SetNotificationLevel( level );
389 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
391 if( mType != Dali::Window::NOTIFICATION )
393 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
394 return Dali::Window::NotificationLevel::NONE;
397 return mWindowBase->GetNotificationLevel();
400 void Window::SetOpaqueState( bool opaque )
402 mOpaqueState = opaque;
404 mWindowBase->SetOpaqueState( opaque );
406 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
409 bool Window::IsOpaqueState() const
414 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
416 return mWindowBase->SetScreenOffMode( screenOffMode );
419 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
421 return mWindowBase->GetScreenOffMode();
424 bool Window::SetBrightness( int brightness )
426 if( brightness < 0 || brightness > 100 )
428 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
432 return mWindowBase->SetBrightness( brightness );
435 int Window::GetBrightness() const
437 return mWindowBase->GetBrightness();
440 void Window::SetSize( Dali::Window::WindowSize size )
442 if( !mResizeEnabled )
444 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
445 mResizeEnabled = true;
448 PositionSize oldRect = mSurface->GetPositionSize();
450 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
452 PositionSize newRect = mSurface->GetPositionSize();
454 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
455 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
457 Uint16Pair newSize( newRect.width, newRect.height );
461 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
463 Dali::Window handle( this );
464 mResizedSignal.Emit( newSize );
465 mResizeSignal.Emit( handle, newSize );
467 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
471 Dali::Window::WindowSize Window::GetSize() const
473 PositionSize positionSize = mSurface->GetPositionSize();
475 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
478 void Window::SetPosition( Dali::Window::WindowPosition position )
480 if( !mResizeEnabled )
482 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
483 mResizeEnabled = true;
486 PositionSize oldRect = mSurface->GetPositionSize();
488 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
491 Dali::Window::WindowPosition Window::GetPosition() const
493 PositionSize positionSize = mSurface->GetPositionSize();
495 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
498 void Window::SetPositionSize( PositionSize positionSize )
500 if( !mResizeEnabled )
502 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
503 mResizeEnabled = true;
506 PositionSize oldRect = mSurface->GetPositionSize();
508 mWindowSurface->MoveResize( positionSize );
510 PositionSize newRect = mSurface->GetPositionSize();
512 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
513 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
515 Uint16Pair newSize( newRect.width, newRect.height );
519 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
521 Dali::Window handle( this );
522 mResizedSignal.Emit( newSize );
523 mResizeSignal.Emit( handle, newSize );
524 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
528 Dali::Layer Window::GetRootLayer() const
530 return mScene.GetRootLayer();
533 void Window::SetTransparency( bool transparent )
535 mWindowSurface->SetTransparency( transparent );
538 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
540 return mWindowBase->GrabKey( key, grabMode );
543 bool Window::UngrabKey( Dali::KEY key )
545 return mWindowBase->UngrabKey( key );
548 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
550 return mWindowBase->GrabKeyList( key, grabMode, result );
553 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
555 return mWindowBase->UngrabKeyList( key, result );
558 void Window::OnIconifyChanged( bool iconified )
566 WindowVisibilityObserver* observer( mAdaptor );
567 observer->OnWindowHidden();
569 Dali::Window handle( this );
570 mVisibilityChangedSignal.Emit( handle, false );
573 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
581 WindowVisibilityObserver* observer( mAdaptor );
582 observer->OnWindowShown();
584 Dali::Window handle( this );
585 mVisibilityChangedSignal.Emit( handle, true );
588 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
592 void Window::OnFocusChanged( bool focusIn )
594 Dali::Window handle( this );
595 mFocusChangedSignal.Emit( focusIn );
596 mFocusChangeSignal.Emit( handle, focusIn );
599 void Window::OnOutputTransformed()
601 PositionSize positionSize = mSurface->GetPositionSize();
603 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
604 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
607 void Window::OnDeleteRequest()
609 mDeleteRequestSignal.Emit();
612 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
614 FeedTouchPoint( point, timeStamp );
617 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
619 FeedWheelEvent( wheelEvent );
622 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
624 FeedKeyEvent( keyEvent );
627 void Window::OnRotation( const RotationEvent& rotation )
629 mRotationAngle = rotation.angle;
630 mWindowWidth = rotation.width;
631 mWindowHeight = rotation.height;
633 // Notify that the orientation is changed
634 mOrientation->OnOrientationChange( rotation );
636 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
640 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
643 Dali::Window handle( this );
644 mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
645 mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
647 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
650 void Window::OnPause()
654 mEventHandler->Pause();
658 void Window::OnResume()
662 mEventHandler->Resume();
666 void Window::RecalculateTouchPosition( Integration::Point& point )
668 Vector2 position = point.GetScreenPosition();
669 Vector2 convertedPosition;
671 switch( mRotationAngle )
675 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
676 convertedPosition.y = position.x;
681 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
682 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
687 convertedPosition.x = position.y;
688 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
693 convertedPosition = position;
698 point.SetScreenPosition( convertedPosition );
701 Dali::Window Window::Get( Dali::Actor actor )
703 Internal::Adaptor::Window* windowImpl = nullptr;
705 if ( Internal::Adaptor::Adaptor::IsAvailable() )
707 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
708 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
711 return Dali::Window( windowImpl );
714 void Window::SetParent( Dali::Window& parent )
716 if ( DALI_UNLIKELY( parent ) )
718 mParentWindow = parent;
719 Dali::Window self = Dali::Window( this );
720 // check circular parent window setting
721 if ( Dali::DevelWindow::GetParent( parent ) == self )
723 Dali::DevelWindow::Unparent( parent );
725 mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
729 void Window::Unparent()
731 mWindowBase->SetParent( nullptr );
732 mParentWindow.Reset();
735 Dali::Window Window::GetParent()
737 return mParentWindow;