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>
46 #include <dali/devel-api/adaptor-framework/accessibility.h>
58 #if defined(DEBUG_ENABLED)
59 Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW" );
62 } // unnamed namespace
64 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
66 Window* window = new Window();
67 window->mIsTransparent = isTransparent;
68 window->Initialize( positionSize, name, className );
73 : mWindowSurface( nullptr ),
75 mIsTransparent( false ),
76 mIsFocusAcceptable( true ),
78 mOpaqueState( false ),
79 mResizeEnabled( false ),
80 mType( Dali::Window::NORMAL ),
81 mParentWindow( NULL ),
82 mPreferredOrientation( Dali::Window::PORTRAIT ),
86 mFocusChangedSignal(),
88 mDeleteRequestSignal(),
98 auto bridge = Accessibility::Bridge::GetCurrentBridge();
99 auto accessible2 = mScene.GetRootLayer();
100 auto accessible = Accessibility::Accessible::Get( accessible2 );
101 bridge->RemoveTopLevelWindow( accessible );
103 mAdaptor->RemoveWindow( this );
109 mEventHandler->RemoveObserver( *this );
113 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
115 // Create a window render surface
117 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
118 mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
119 mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
122 mWindowBase = mWindowSurface->GetWindowBase();
125 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
126 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
127 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
129 mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
131 if( !positionSize.IsEmpty() )
133 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
134 mResizeEnabled = true;
137 SetClass( name, className );
139 mWindowSurface->Map();
141 mOrientation = Orientation::New( this );
144 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
146 mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
147 mEventHandler->AddObserver( *this );
149 auto bridge = Accessibility::Bridge::GetCurrentBridge();
150 auto v = mScene.GetRootLayer();
151 auto accessible = Accessibility::Accessible::Get( v, true );
152 bridge->AddTopLevelWindow( accessible );
154 //FIXME: line below is temporary solution for missing "activate" signal and should be removed
158 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
160 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
163 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
167 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
171 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
175 void Window::SetClass( std::string name, std::string className )
178 mClassName = className;
179 mWindowBase->SetClass( name, className );
182 std::string Window::GetClassName() const
189 mWindowBase->Raise();
190 DALI_LOG_RELEASE_INFO( "Window (%p) Raise() \n", this );
195 mWindowBase->Lower();
196 DALI_LOG_RELEASE_INFO( "Window (%p) Lower() \n", this );
199 void Window::Activate()
201 mWindowBase->Activate();
202 DALI_LOG_RELEASE_INFO( "Window (%p) Activate() \n", this );
205 uint32_t Window::GetLayerCount() const
207 return mScene.GetLayerCount();
210 Dali::Layer Window::GetLayer( uint32_t depth ) const
212 return mScene.GetLayer( depth );
215 Dali::RenderTaskList Window::GetRenderTaskList() const
217 return mScene.GetRenderTaskList();
220 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
224 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
226 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
228 if( mAvailableOrientations[i] == orientation )
237 mAvailableOrientations.push_back( orientation );
238 SetAvailableOrientations( mAvailableOrientations );
243 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
245 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
246 iter != mAvailableOrientations.end(); ++iter )
248 if( *iter == orientation )
250 mAvailableOrientations.erase( iter );
254 SetAvailableOrientations( mAvailableOrientations );
257 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
259 if( orientations.size() > 4 )
261 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
265 mAvailableOrientations = orientations;
267 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
270 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
272 return mAvailableOrientations;
275 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
277 mPreferredOrientation = orientation;
279 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
282 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
284 return mPreferredOrientation;
287 Dali::Any Window::GetNativeHandle() const
289 return mWindowSurface->GetNativeWindow();
292 void Window::SetAcceptFocus( bool accept )
294 mIsFocusAcceptable = accept;
296 mWindowBase->SetAcceptFocus( accept );
299 bool Window::IsFocusAcceptable() const
301 return mIsFocusAcceptable;
312 WindowVisibilityObserver* observer( mAdaptor );
313 observer->OnWindowShown();
316 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
327 WindowVisibilityObserver* observer( mAdaptor );
328 observer->OnWindowHidden();
331 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
334 bool Window::IsVisible() const
336 return mVisible && !mIconified;
339 unsigned int Window::GetSupportedAuxiliaryHintCount() const
341 return mWindowBase->GetSupportedAuxiliaryHintCount();
344 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
346 return mWindowBase->GetSupportedAuxiliaryHint( index );
349 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
351 return mWindowBase->AddAuxiliaryHint( hint, value );
354 bool Window::RemoveAuxiliaryHint( unsigned int id )
356 return mWindowBase->RemoveAuxiliaryHint( id );
359 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
361 return mWindowBase->SetAuxiliaryHintValue( id, value );
364 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
366 return mWindowBase->GetAuxiliaryHintValue( id );
369 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
371 return mWindowBase->GetAuxiliaryHintId( hint );
374 void Window::SetInputRegion( const Rect< int >& inputRegion )
376 mWindowBase->SetInputRegion( inputRegion );
378 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 );
381 void Window::SetType( Dali::Window::Type type )
385 mWindowBase->SetType( type );
391 Dali::Window::Type Window::GetType() const
396 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
398 if( mType != Dali::Window::NOTIFICATION )
400 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
404 return mWindowBase->SetNotificationLevel( level );
407 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
409 if( mType != Dali::Window::NOTIFICATION )
411 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
412 return Dali::Window::NotificationLevel::NONE;
415 return mWindowBase->GetNotificationLevel();
418 void Window::SetOpaqueState( bool opaque )
420 mOpaqueState = opaque;
422 mWindowBase->SetOpaqueState( opaque );
424 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
427 bool Window::IsOpaqueState() const
432 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
434 return mWindowBase->SetScreenOffMode( screenOffMode );
437 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
439 return mWindowBase->GetScreenOffMode();
442 bool Window::SetBrightness( int brightness )
444 if( brightness < 0 || brightness > 100 )
446 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
450 return mWindowBase->SetBrightness( brightness );
453 int Window::GetBrightness() const
455 return mWindowBase->GetBrightness();
458 void Window::SetSize( Dali::Window::WindowSize size )
460 if( !mResizeEnabled )
462 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
463 mResizeEnabled = true;
466 PositionSize oldRect = mSurface->GetPositionSize();
468 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
470 PositionSize newRect = mSurface->GetPositionSize();
472 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
473 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
475 Uint16Pair newSize( newRect.width, newRect.height );
477 bool forceUpdate = false;
478 if( mWindowBase->IsEglWindowRotationSupported() )
483 SurfaceResized( forceUpdate );
485 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
487 Dali::Window handle( this );
488 mResizedSignal.Emit( newSize );
489 mResizeSignal.Emit( handle, newSize );
491 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
495 Dali::Window::WindowSize Window::GetSize() const
497 PositionSize positionSize = mSurface->GetPositionSize();
499 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
502 void Window::SetPosition( Dali::Window::WindowPosition position )
504 if( !mResizeEnabled )
506 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
507 mResizeEnabled = true;
510 PositionSize oldRect = mSurface->GetPositionSize();
512 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
515 Dali::Window::WindowPosition Window::GetPosition() const
517 PositionSize positionSize = mSurface->GetPositionSize();
519 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
522 void Window::SetPositionSize( PositionSize positionSize )
524 if( !mResizeEnabled )
526 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
527 mResizeEnabled = true;
530 PositionSize oldRect = mSurface->GetPositionSize();
532 mWindowSurface->MoveResize( positionSize );
534 PositionSize newRect = mSurface->GetPositionSize();
536 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
537 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
539 Uint16Pair newSize( newRect.width, newRect.height );
541 bool forceUpdate = false;
542 if( mWindowBase->IsEglWindowRotationSupported() )
547 SurfaceResized( forceUpdate );
549 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
551 Dali::Window handle( this );
552 mResizedSignal.Emit( newSize );
553 mResizeSignal.Emit( handle, newSize );
554 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
558 Dali::Layer Window::GetRootLayer() const
560 return mScene.GetRootLayer();
563 void Window::SetTransparency( bool transparent )
565 mWindowSurface->SetTransparency( transparent );
568 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
570 return mWindowBase->GrabKey( key, grabMode );
573 bool Window::UngrabKey( Dali::KEY key )
575 return mWindowBase->UngrabKey( key );
578 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
580 return mWindowBase->GrabKeyList( key, grabMode, result );
583 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
585 return mWindowBase->UngrabKeyList( key, result );
588 void Window::OnIconifyChanged( bool iconified )
596 WindowVisibilityObserver* observer( mAdaptor );
597 observer->OnWindowHidden();
600 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
608 WindowVisibilityObserver* observer( mAdaptor );
609 observer->OnWindowShown();
612 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
616 void Window::OnFocusChanged( bool focusIn )
618 Dali::Window handle( this );
619 mFocusChangedSignal.Emit( focusIn );
620 mFocusChangeSignal.Emit( handle, focusIn );
622 if (auto b = Dali::Accessibility::Bridge::GetCurrentBridge())
626 b->ApplicationShown();
630 b->ApplicationHidden();
635 void Window::OnOutputTransformed()
637 bool forceUpdate = false;
638 if( mWindowBase->IsEglWindowRotationSupported() )
642 PositionSize positionSize = mSurface->GetPositionSize();
643 SurfaceResized( forceUpdate );
644 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
645 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
648 void Window::OnDeleteRequest()
650 mDeleteRequestSignal.Emit();
653 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
655 FeedTouchPoint( point, timeStamp );
658 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
660 FeedWheelEvent( wheelEvent );
663 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
665 FeedKeyEvent( keyEvent );
668 void Window::OnRotation( const RotationEvent& rotation )
670 mRotationAngle = rotation.angle;
671 mWindowWidth = rotation.width;
672 mWindowHeight = rotation.height;
674 // Notify that the orientation is changed
675 mOrientation->OnOrientationChange( rotation );
677 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
679 bool forceUpdate = false;
680 if( mWindowBase->IsEglWindowRotationSupported() )
685 SurfaceResized( forceUpdate );
687 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
690 Dali::Window handle( this );
691 mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
692 mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
694 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
697 void Window::OnPause()
701 mEventHandler->Pause();
705 void Window::OnResume()
709 mEventHandler->Resume();
713 void Window::RecalculateTouchPosition( Integration::Point& point )
715 Vector2 position = point.GetScreenPosition();
716 Vector2 convertedPosition;
718 switch( mRotationAngle )
722 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
723 convertedPosition.y = position.x;
728 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
729 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
734 convertedPosition.x = position.y;
735 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
740 convertedPosition = position;
745 point.SetScreenPosition( convertedPosition );
748 Dali::Window Window::Get( Dali::Actor actor )
750 Internal::Adaptor::Window* windowImpl = nullptr;
752 if ( Internal::Adaptor::Adaptor::IsAvailable() )
754 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
755 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
758 return Dali::Window( windowImpl );
761 void Window::SetParent( Dali::Window& parent )
763 if ( DALI_UNLIKELY( parent ) )
765 mParentWindow = parent;
766 Dali::Window grandParent = Dali::DevelWindow::GetParent( parent );
767 // check circular parent window setting
768 if ( DALI_UNLIKELY( grandParent ) && mWindowBase->IsMatchedWindow( grandParent.GetNativeHandle() ) )
770 Dali::DevelWindow::Unparent( parent );
772 mWindowBase->SetParent( parent.GetNativeHandle() );
776 void Window::Unparent()
779 mWindowBase->SetParent( parent );
782 Dali::Window Window::GetParent()
784 return mParentWindow;