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(),
91 mTransitionEffectEventSignal()
99 mEventHandler->RemoveObserver( *this );
103 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
105 // Create a window render surface
107 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
108 mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
109 mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
112 mWindowBase = mWindowSurface->GetWindowBase();
115 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
116 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
117 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
118 mWindowBase->TransitionEffectEventSignal().Connect( this, &Window::OnTransitionEffectEvent );
120 mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
122 if( !positionSize.IsEmpty() )
124 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
125 mResizeEnabled = true;
128 SetClass( name, className );
130 mWindowSurface->Map();
132 mOrientation = Orientation::New( this );
135 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
137 mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
138 mEventHandler->AddObserver( *this );
141 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
143 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
146 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
150 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
154 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
158 void Window::SetClass( std::string name, std::string className )
161 mClassName = className;
162 mWindowBase->SetClass( name, className );
165 std::string Window::GetClassName() const
172 mWindowBase->Raise();
173 DALI_LOG_RELEASE_INFO( "Window (%p) Raise() \n", this );
178 mWindowBase->Lower();
179 DALI_LOG_RELEASE_INFO( "Window (%p) Lower() \n", this );
182 void Window::Activate()
184 mWindowBase->Activate();
185 DALI_LOG_RELEASE_INFO( "Window (%p) Activate() \n", this );
188 uint32_t Window::GetLayerCount() const
190 return mScene.GetLayerCount();
193 Dali::Layer Window::GetLayer( uint32_t depth ) const
195 return mScene.GetLayer( depth );
198 Dali::RenderTaskList Window::GetRenderTaskList() const
200 return mScene.GetRenderTaskList();
203 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
207 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
209 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
211 if( mAvailableOrientations[i] == orientation )
220 mAvailableOrientations.push_back( orientation );
221 SetAvailableOrientations( mAvailableOrientations );
226 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
228 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
229 iter != mAvailableOrientations.end(); ++iter )
231 if( *iter == orientation )
233 mAvailableOrientations.erase( iter );
237 SetAvailableOrientations( mAvailableOrientations );
240 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
242 if( orientations.size() > 4 )
244 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
248 mAvailableOrientations = orientations;
250 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
253 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
255 return mAvailableOrientations;
258 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
260 mPreferredOrientation = orientation;
262 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
265 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
267 return mPreferredOrientation;
270 Dali::Any Window::GetNativeHandle() const
272 return mWindowSurface->GetNativeWindow();
275 void Window::SetAcceptFocus( bool accept )
277 mIsFocusAcceptable = accept;
279 mWindowBase->SetAcceptFocus( accept );
282 bool Window::IsFocusAcceptable() const
284 return mIsFocusAcceptable;
295 WindowVisibilityObserver* observer( mAdaptor );
296 observer->OnWindowShown();
298 Dali::Window handle( this );
299 mVisibilityChangedSignal.Emit( handle, true );
302 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
313 WindowVisibilityObserver* observer( mAdaptor );
314 observer->OnWindowHidden();
316 Dali::Window handle( this );
317 mVisibilityChangedSignal.Emit( handle, false );
320 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
323 bool Window::IsVisible() const
325 return mVisible && !mIconified;
328 unsigned int Window::GetSupportedAuxiliaryHintCount() const
330 return mWindowBase->GetSupportedAuxiliaryHintCount();
333 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
335 return mWindowBase->GetSupportedAuxiliaryHint( index );
338 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
340 return mWindowBase->AddAuxiliaryHint( hint, value );
343 bool Window::RemoveAuxiliaryHint( unsigned int id )
345 return mWindowBase->RemoveAuxiliaryHint( id );
348 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
350 return mWindowBase->SetAuxiliaryHintValue( id, value );
353 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
355 return mWindowBase->GetAuxiliaryHintValue( id );
358 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
360 return mWindowBase->GetAuxiliaryHintId( hint );
363 void Window::SetInputRegion( const Rect< int >& inputRegion )
365 mWindowBase->SetInputRegion( inputRegion );
367 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 );
370 void Window::SetType( Dali::Window::Type type )
374 mWindowBase->SetType( type );
380 Dali::Window::Type Window::GetType() const
385 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
387 if( mType != Dali::Window::NOTIFICATION )
389 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
393 return mWindowBase->SetNotificationLevel( level );
396 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
398 if( mType != Dali::Window::NOTIFICATION )
400 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
401 return Dali::Window::NotificationLevel::NONE;
404 return mWindowBase->GetNotificationLevel();
407 void Window::SetOpaqueState( bool opaque )
409 mOpaqueState = opaque;
411 mWindowBase->SetOpaqueState( opaque );
413 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
416 bool Window::IsOpaqueState() const
421 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
423 return mWindowBase->SetScreenOffMode( screenOffMode );
426 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
428 return mWindowBase->GetScreenOffMode();
431 bool Window::SetBrightness( int brightness )
433 if( brightness < 0 || brightness > 100 )
435 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
439 return mWindowBase->SetBrightness( brightness );
442 int Window::GetBrightness() const
444 return mWindowBase->GetBrightness();
447 void Window::SetSize( Dali::Window::WindowSize size )
449 if( !mResizeEnabled )
451 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
452 mResizeEnabled = true;
455 PositionSize oldRect = mSurface->GetPositionSize();
457 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
459 PositionSize newRect = mSurface->GetPositionSize();
461 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
462 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
464 Uint16Pair newSize( newRect.width, newRect.height );
466 bool forceUpdate = false;
467 if( mWindowBase->IsEglWindowRotationSupported() )
472 SurfaceResized( forceUpdate );
474 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
476 Dali::Window handle( this );
477 mResizedSignal.Emit( newSize );
478 mResizeSignal.Emit( handle, newSize );
480 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
484 Dali::Window::WindowSize Window::GetSize() const
486 PositionSize positionSize = mSurface->GetPositionSize();
488 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
491 void Window::SetPosition( Dali::Window::WindowPosition position )
493 if( !mResizeEnabled )
495 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
496 mResizeEnabled = true;
499 PositionSize oldRect = mSurface->GetPositionSize();
501 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
504 Dali::Window::WindowPosition Window::GetPosition() const
506 PositionSize positionSize = mSurface->GetPositionSize();
508 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
511 void Window::SetPositionSize( PositionSize positionSize )
513 if( !mResizeEnabled )
515 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
516 mResizeEnabled = true;
519 PositionSize oldRect = mSurface->GetPositionSize();
521 mWindowSurface->MoveResize( positionSize );
523 PositionSize newRect = mSurface->GetPositionSize();
525 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
526 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
528 Uint16Pair newSize( newRect.width, newRect.height );
530 bool forceUpdate = false;
531 if( mWindowBase->IsEglWindowRotationSupported() )
536 SurfaceResized( forceUpdate );
538 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
540 Dali::Window handle( this );
541 mResizedSignal.Emit( newSize );
542 mResizeSignal.Emit( handle, newSize );
543 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
547 Dali::Layer Window::GetRootLayer() const
549 return mScene.GetRootLayer();
552 void Window::SetTransparency( bool transparent )
554 mWindowSurface->SetTransparency( transparent );
557 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
559 return mWindowBase->GrabKey( key, grabMode );
562 bool Window::UngrabKey( Dali::KEY key )
564 return mWindowBase->UngrabKey( key );
567 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
569 return mWindowBase->GrabKeyList( key, grabMode, result );
572 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
574 return mWindowBase->UngrabKeyList( key, result );
577 void Window::OnIconifyChanged( bool iconified )
585 WindowVisibilityObserver* observer( mAdaptor );
586 observer->OnWindowHidden();
588 Dali::Window handle( this );
589 mVisibilityChangedSignal.Emit( handle, false );
592 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
600 WindowVisibilityObserver* observer( mAdaptor );
601 observer->OnWindowShown();
603 Dali::Window handle( this );
604 mVisibilityChangedSignal.Emit( handle, true );
607 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
611 void Window::OnFocusChanged( bool focusIn )
613 Dali::Window handle( this );
614 mFocusChangedSignal.Emit( focusIn );
615 mFocusChangeSignal.Emit( handle, focusIn );
618 void Window::OnOutputTransformed()
620 bool forceUpdate = false;
621 if( mWindowBase->IsEglWindowRotationSupported() )
625 PositionSize positionSize = mSurface->GetPositionSize();
626 SurfaceResized( forceUpdate );
627 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
628 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
631 void Window::OnDeleteRequest()
633 mDeleteRequestSignal.Emit();
636 void Window::OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type )
638 Dali::Window handle( this );
639 mTransitionEffectEventSignal.Emit( handle, state, type );
642 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
644 FeedTouchPoint( point, timeStamp );
647 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
649 FeedWheelEvent( wheelEvent );
652 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
654 FeedKeyEvent( keyEvent );
657 void Window::OnRotation( const RotationEvent& rotation )
659 mRotationAngle = rotation.angle;
660 mWindowWidth = rotation.width;
661 mWindowHeight = rotation.height;
663 // Notify that the orientation is changed
664 mOrientation->OnOrientationChange( rotation );
666 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
668 bool forceUpdate = false;
669 if( mWindowBase->IsEglWindowRotationSupported() )
674 SurfaceResized( forceUpdate );
676 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
679 Dali::Window handle( this );
680 mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
681 mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
683 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
686 void Window::OnPause()
690 mEventHandler->Pause();
694 void Window::OnResume()
698 mEventHandler->Resume();
702 void Window::RecalculateTouchPosition( Integration::Point& point )
704 Vector2 position = point.GetScreenPosition();
705 Vector2 convertedPosition;
707 switch( mRotationAngle )
711 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
712 convertedPosition.y = position.x;
717 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
718 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
723 convertedPosition.x = position.y;
724 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
729 convertedPosition = position;
734 point.SetScreenPosition( convertedPosition );
737 Dali::Window Window::Get( Dali::Actor actor )
739 Internal::Adaptor::Window* windowImpl = nullptr;
741 if ( Internal::Adaptor::Adaptor::IsAvailable() )
743 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
744 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
747 return Dali::Window( windowImpl );
750 void Window::SetParent( Dali::Window& parent )
752 if ( DALI_UNLIKELY( parent ) )
754 mParentWindow = parent;
755 Dali::Window self = Dali::Window( this );
756 // check circular parent window setting
757 if ( Dali::DevelWindow::GetParent( parent ) == self )
759 Dali::DevelWindow::Unparent( parent );
761 mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
765 void Window::Unparent()
767 mWindowBase->SetParent( nullptr );
768 mParentWindow.Reset();
771 Dali::Window Window::GetParent()
773 return mParentWindow;