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(),
90 mVisibilityChangedSignal()
98 mEventHandler->RemoveObserver( *this );
102 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
104 // Create a window render surface
106 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
107 mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
108 mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
111 mWindowBase = mWindowSurface->GetWindowBase();
114 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
115 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
116 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
118 mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
120 if( !positionSize.IsEmpty() )
122 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
123 mResizeEnabled = true;
126 SetClass( name, className );
128 mWindowSurface->Map();
130 mOrientation = Orientation::New( this );
133 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
135 mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
136 mEventHandler->AddObserver( *this );
139 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
141 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
144 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
148 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
152 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
156 void Window::SetClass( std::string name, std::string className )
159 mClassName = className;
160 mWindowBase->SetClass( name, className );
163 std::string Window::GetClassName() const
170 mWindowBase->Raise();
171 DALI_LOG_RELEASE_INFO( "Window (%p) Raise() \n", this );
176 mWindowBase->Lower();
177 DALI_LOG_RELEASE_INFO( "Window (%p) Lower() \n", this );
180 void Window::Activate()
182 mWindowBase->Activate();
183 DALI_LOG_RELEASE_INFO( "Window (%p) Activate() \n", this );
186 uint32_t Window::GetLayerCount() const
188 return mScene.GetLayerCount();
191 Dali::Layer Window::GetLayer( uint32_t depth ) const
193 return mScene.GetLayer( depth );
196 Dali::RenderTaskList Window::GetRenderTaskList() const
198 return mScene.GetRenderTaskList();
201 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
205 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
207 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
209 if( mAvailableOrientations[i] == orientation )
218 mAvailableOrientations.push_back( orientation );
219 SetAvailableOrientations( mAvailableOrientations );
224 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
226 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
227 iter != mAvailableOrientations.end(); ++iter )
229 if( *iter == orientation )
231 mAvailableOrientations.erase( iter );
235 SetAvailableOrientations( mAvailableOrientations );
238 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
240 if( orientations.size() > 4 )
242 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
246 mAvailableOrientations = orientations;
248 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
251 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
253 return mAvailableOrientations;
256 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
258 mPreferredOrientation = orientation;
260 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
263 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
265 return mPreferredOrientation;
268 Dali::Any Window::GetNativeHandle() const
270 return mWindowSurface->GetNativeWindow();
273 void Window::SetAcceptFocus( bool accept )
275 mIsFocusAcceptable = accept;
277 mWindowBase->SetAcceptFocus( accept );
280 bool Window::IsFocusAcceptable() const
282 return mIsFocusAcceptable;
293 WindowVisibilityObserver* observer( mAdaptor );
294 observer->OnWindowShown();
296 Dali::Window handle( this );
297 mVisibilityChangedSignal.Emit( handle, true );
300 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
311 WindowVisibilityObserver* observer( mAdaptor );
312 observer->OnWindowHidden();
314 Dali::Window handle( this );
315 mVisibilityChangedSignal.Emit( handle, false );
318 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
321 bool Window::IsVisible() const
323 return mVisible && !mIconified;
326 unsigned int Window::GetSupportedAuxiliaryHintCount() const
328 return mWindowBase->GetSupportedAuxiliaryHintCount();
331 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
333 return mWindowBase->GetSupportedAuxiliaryHint( index );
336 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
338 return mWindowBase->AddAuxiliaryHint( hint, value );
341 bool Window::RemoveAuxiliaryHint( unsigned int id )
343 return mWindowBase->RemoveAuxiliaryHint( id );
346 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
348 return mWindowBase->SetAuxiliaryHintValue( id, value );
351 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
353 return mWindowBase->GetAuxiliaryHintValue( id );
356 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
358 return mWindowBase->GetAuxiliaryHintId( hint );
361 void Window::SetInputRegion( const Rect< int >& inputRegion )
363 mWindowBase->SetInputRegion( inputRegion );
365 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 );
368 void Window::SetType( Dali::Window::Type type )
372 mWindowBase->SetType( type );
378 Dali::Window::Type Window::GetType() const
383 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
385 if( mType != Dali::Window::NOTIFICATION )
387 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
391 return mWindowBase->SetNotificationLevel( level );
394 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
396 if( mType != Dali::Window::NOTIFICATION )
398 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
399 return Dali::Window::NotificationLevel::NONE;
402 return mWindowBase->GetNotificationLevel();
405 void Window::SetOpaqueState( bool opaque )
407 mOpaqueState = opaque;
409 mWindowBase->SetOpaqueState( opaque );
411 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
414 bool Window::IsOpaqueState() const
419 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
421 return mWindowBase->SetScreenOffMode( screenOffMode );
424 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
426 return mWindowBase->GetScreenOffMode();
429 bool Window::SetBrightness( int brightness )
431 if( brightness < 0 || brightness > 100 )
433 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
437 return mWindowBase->SetBrightness( brightness );
440 int Window::GetBrightness() const
442 return mWindowBase->GetBrightness();
445 void Window::SetSize( Dali::Window::WindowSize size )
447 if( !mResizeEnabled )
449 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
450 mResizeEnabled = true;
453 PositionSize oldRect = mSurface->GetPositionSize();
455 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
457 PositionSize newRect = mSurface->GetPositionSize();
459 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
460 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
462 Uint16Pair newSize( newRect.width, newRect.height );
466 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
468 Dali::Window handle( this );
469 mResizedSignal.Emit( newSize );
470 mResizeSignal.Emit( handle, newSize );
472 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
476 Dali::Window::WindowSize Window::GetSize() const
478 PositionSize positionSize = mSurface->GetPositionSize();
480 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
483 void Window::SetPosition( Dali::Window::WindowPosition position )
485 if( !mResizeEnabled )
487 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
488 mResizeEnabled = true;
491 PositionSize oldRect = mSurface->GetPositionSize();
493 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
496 Dali::Window::WindowPosition Window::GetPosition() const
498 PositionSize positionSize = mSurface->GetPositionSize();
500 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
503 void Window::SetPositionSize( PositionSize positionSize )
505 if( !mResizeEnabled )
507 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
508 mResizeEnabled = true;
511 PositionSize oldRect = mSurface->GetPositionSize();
513 mWindowSurface->MoveResize( positionSize );
515 PositionSize newRect = mSurface->GetPositionSize();
517 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
518 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
520 Uint16Pair newSize( newRect.width, newRect.height );
524 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
526 Dali::Window handle( this );
527 mResizedSignal.Emit( newSize );
528 mResizeSignal.Emit( handle, newSize );
529 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
533 Dali::Layer Window::GetRootLayer() const
535 return mScene.GetRootLayer();
538 void Window::SetTransparency( bool transparent )
540 mWindowSurface->SetTransparency( transparent );
543 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
545 return mWindowBase->GrabKey( key, grabMode );
548 bool Window::UngrabKey( Dali::KEY key )
550 return mWindowBase->UngrabKey( key );
553 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
555 return mWindowBase->GrabKeyList( key, grabMode, result );
558 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
560 return mWindowBase->UngrabKeyList( key, result );
563 void Window::OnIconifyChanged( bool iconified )
571 WindowVisibilityObserver* observer( mAdaptor );
572 observer->OnWindowHidden();
574 Dali::Window handle( this );
575 mVisibilityChangedSignal.Emit( handle, false );
578 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
586 WindowVisibilityObserver* observer( mAdaptor );
587 observer->OnWindowShown();
589 Dali::Window handle( this );
590 mVisibilityChangedSignal.Emit( handle, true );
593 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
597 void Window::OnFocusChanged( bool focusIn )
599 Dali::Window handle( this );
600 mFocusChangedSignal.Emit( focusIn );
601 mFocusChangeSignal.Emit( handle, focusIn );
604 void Window::OnOutputTransformed()
606 PositionSize positionSize = mSurface->GetPositionSize();
608 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
609 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
612 void Window::OnDeleteRequest()
614 mDeleteRequestSignal.Emit();
617 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
619 FeedTouchPoint( point, timeStamp );
622 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
624 FeedWheelEvent( wheelEvent );
627 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
629 FeedKeyEvent( keyEvent );
632 void Window::OnRotation( const RotationEvent& rotation )
634 mRotationAngle = rotation.angle;
635 mWindowWidth = rotation.width;
636 mWindowHeight = rotation.height;
638 // Notify that the orientation is changed
639 mOrientation->OnOrientationChange( rotation );
641 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
645 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
648 Dali::Window handle( this );
649 mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
650 mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
652 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
655 void Window::OnPause()
659 mEventHandler->Pause();
663 void Window::OnResume()
667 mEventHandler->Resume();
671 void Window::RecalculateTouchPosition( Integration::Point& point )
673 Vector2 position = point.GetScreenPosition();
674 Vector2 convertedPosition;
676 switch( mRotationAngle )
680 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
681 convertedPosition.y = position.x;
686 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
687 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
692 convertedPosition.x = position.y;
693 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
698 convertedPosition = position;
703 point.SetScreenPosition( convertedPosition );
706 Dali::Window Window::Get( Dali::Actor actor )
708 Internal::Adaptor::Window* windowImpl = nullptr;
710 if ( Internal::Adaptor::Adaptor::IsAvailable() )
712 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
713 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
716 return Dali::Window( windowImpl );
719 void Window::SetParent( Dali::Window& parent )
721 if ( DALI_UNLIKELY( parent ) )
723 mParentWindow = parent;
724 Dali::Window self = Dali::Window( this );
725 // check circular parent window setting
726 if ( Dali::DevelWindow::GetParent( parent ) == self )
728 Dali::DevelWindow::Unparent( parent );
730 mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
734 void Window::Unparent()
736 mWindowBase->SetParent( nullptr );
737 mParentWindow.Reset();
740 Dali::Window Window::GetParent()
742 return mParentWindow;