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 );
457 bool forceUpdate = false;
458 if( mWindowBase->IsEglWindowRotationSupported() )
463 SurfaceResized( forceUpdate );
465 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
467 Dali::Window handle( this );
468 mResizedSignal.Emit( newSize );
469 mResizeSignal.Emit( handle, newSize );
471 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
475 Dali::Window::WindowSize Window::GetSize() const
477 PositionSize positionSize = mSurface->GetPositionSize();
479 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
482 void Window::SetPosition( Dali::Window::WindowPosition position )
484 if( !mResizeEnabled )
486 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
487 mResizeEnabled = true;
490 PositionSize oldRect = mSurface->GetPositionSize();
492 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
495 Dali::Window::WindowPosition Window::GetPosition() const
497 PositionSize positionSize = mSurface->GetPositionSize();
499 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
502 void Window::SetPositionSize( PositionSize positionSize )
504 if( !mResizeEnabled )
506 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
507 mResizeEnabled = true;
510 PositionSize oldRect = mSurface->GetPositionSize();
512 mWindowSurface->MoveResize( positionSize );
514 PositionSize newRect = mSurface->GetPositionSize();
516 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
517 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
519 Uint16Pair newSize( newRect.width, newRect.height );
521 bool forceUpdate = false;
522 if( mWindowBase->IsEglWindowRotationSupported() )
527 SurfaceResized( forceUpdate );
529 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
531 Dali::Window handle( this );
532 mResizedSignal.Emit( newSize );
533 mResizeSignal.Emit( handle, newSize );
534 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
538 Dali::Layer Window::GetRootLayer() const
540 return mScene.GetRootLayer();
543 void Window::SetTransparency( bool transparent )
545 mWindowSurface->SetTransparency( transparent );
548 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
550 return mWindowBase->GrabKey( key, grabMode );
553 bool Window::UngrabKey( Dali::KEY key )
555 return mWindowBase->UngrabKey( key );
558 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
560 return mWindowBase->GrabKeyList( key, grabMode, result );
563 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
565 return mWindowBase->UngrabKeyList( key, result );
568 void Window::OnIconifyChanged( bool iconified )
576 WindowVisibilityObserver* observer( mAdaptor );
577 observer->OnWindowHidden();
580 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
588 WindowVisibilityObserver* observer( mAdaptor );
589 observer->OnWindowShown();
592 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
596 void Window::OnFocusChanged( bool focusIn )
598 Dali::Window handle( this );
599 mFocusChangedSignal.Emit( focusIn );
600 mFocusChangeSignal.Emit( handle, focusIn );
603 void Window::OnOutputTransformed()
605 bool forceUpdate = false;
606 if( mWindowBase->IsEglWindowRotationSupported() )
610 PositionSize positionSize = mSurface->GetPositionSize();
611 SurfaceResized( forceUpdate );
612 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
613 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
616 void Window::OnDeleteRequest()
618 mDeleteRequestSignal.Emit();
621 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
623 FeedTouchPoint( point, timeStamp );
626 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
628 FeedWheelEvent( wheelEvent );
631 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
633 FeedKeyEvent( keyEvent );
636 void Window::OnRotation( const RotationEvent& rotation )
638 mRotationAngle = rotation.angle;
639 mWindowWidth = rotation.width;
640 mWindowHeight = rotation.height;
642 // Notify that the orientation is changed
643 mOrientation->OnOrientationChange( rotation );
645 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
647 bool forceUpdate = false;
648 if( mWindowBase->IsEglWindowRotationSupported() )
653 SurfaceResized( forceUpdate );
655 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
658 Dali::Window handle( this );
659 mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
660 mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
662 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
665 void Window::OnPause()
669 mEventHandler->Pause();
673 void Window::OnResume()
677 mEventHandler->Resume();
681 void Window::RecalculateTouchPosition( Integration::Point& point )
683 Vector2 position = point.GetScreenPosition();
684 Vector2 convertedPosition;
686 switch( mRotationAngle )
690 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
691 convertedPosition.y = position.x;
696 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
697 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
702 convertedPosition.x = position.y;
703 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
708 convertedPosition = position;
713 point.SetScreenPosition( convertedPosition );
716 Dali::Window Window::Get( Dali::Actor actor )
718 Internal::Adaptor::Window* windowImpl = nullptr;
720 if ( Internal::Adaptor::Adaptor::IsAvailable() )
722 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
723 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
726 return Dali::Window( windowImpl );
729 void Window::SetParent( Dali::Window& parent )
731 if ( DALI_UNLIKELY( parent ) )
733 mParentWindow = parent;
734 Dali::Window grandParent = Dali::DevelWindow::GetParent( parent );
735 // check circular parent window setting
736 if ( DALI_UNLIKELY( grandParent ) && mWindowBase->IsMatchedWindow( grandParent.GetNativeHandle() ) )
738 Dali::DevelWindow::Unparent( parent );
740 mWindowBase->SetParent( parent.GetNativeHandle() );
744 void Window::Unparent()
747 mWindowBase->SetParent( parent );
750 Dali::Window Window::GetParent()
752 return mParentWindow;