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()
95 mEventHandler->RemoveObserver( *this );
99 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
101 // Create a window render surface
103 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
104 mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
105 mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
108 mWindowBase = mWindowSurface->GetWindowBase();
111 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
112 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
113 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
115 mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
117 if( !positionSize.IsEmpty() )
119 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
120 mResizeEnabled = true;
123 SetClass( name, className );
125 mWindowSurface->Map();
127 mOrientation = Orientation::New( this );
130 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
132 mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
133 mEventHandler->AddObserver( *this );
136 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
138 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
141 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
145 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
149 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
153 void Window::SetClass( std::string name, std::string className )
156 mClassName = className;
157 mWindowBase->SetClass( name, className );
160 std::string Window::GetClassName() const
167 mWindowBase->Raise();
168 DALI_LOG_RELEASE_INFO( "Window (%p) Raise() \n", this );
173 mWindowBase->Lower();
174 DALI_LOG_RELEASE_INFO( "Window (%p) Lower() \n", this );
177 void Window::Activate()
179 mWindowBase->Activate();
180 DALI_LOG_RELEASE_INFO( "Window (%p) Activate() \n", this );
183 uint32_t Window::GetLayerCount() const
185 return mScene.GetLayerCount();
188 Dali::Layer Window::GetLayer( uint32_t depth ) const
190 return mScene.GetLayer( depth );
193 Dali::RenderTaskList Window::GetRenderTaskList() const
195 return mScene.GetRenderTaskList();
198 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
202 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
204 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
206 if( mAvailableOrientations[i] == orientation )
215 mAvailableOrientations.push_back( orientation );
216 SetAvailableOrientations( mAvailableOrientations );
221 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
223 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
224 iter != mAvailableOrientations.end(); ++iter )
226 if( *iter == orientation )
228 mAvailableOrientations.erase( iter );
232 SetAvailableOrientations( mAvailableOrientations );
235 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
237 if( orientations.size() > 4 )
239 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
243 mAvailableOrientations = orientations;
245 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
248 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
250 return mAvailableOrientations;
253 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
255 mPreferredOrientation = orientation;
257 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
260 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
262 return mPreferredOrientation;
265 Dali::Any Window::GetNativeHandle() const
267 return mWindowSurface->GetNativeWindow();
270 void Window::SetAcceptFocus( bool accept )
272 mIsFocusAcceptable = accept;
274 mWindowBase->SetAcceptFocus( accept );
277 bool Window::IsFocusAcceptable() const
279 return mIsFocusAcceptable;
290 WindowVisibilityObserver* observer( mAdaptor );
291 observer->OnWindowShown();
294 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
305 WindowVisibilityObserver* observer( mAdaptor );
306 observer->OnWindowHidden();
309 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
312 bool Window::IsVisible() const
314 return mVisible && !mIconified;
317 unsigned int Window::GetSupportedAuxiliaryHintCount() const
319 return mWindowBase->GetSupportedAuxiliaryHintCount();
322 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
324 return mWindowBase->GetSupportedAuxiliaryHint( index );
327 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
329 return mWindowBase->AddAuxiliaryHint( hint, value );
332 bool Window::RemoveAuxiliaryHint( unsigned int id )
334 return mWindowBase->RemoveAuxiliaryHint( id );
337 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
339 return mWindowBase->SetAuxiliaryHintValue( id, value );
342 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
344 return mWindowBase->GetAuxiliaryHintValue( id );
347 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
349 return mWindowBase->GetAuxiliaryHintId( hint );
352 void Window::SetInputRegion( const Rect< int >& inputRegion )
354 mWindowBase->SetInputRegion( inputRegion );
356 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 );
359 void Window::SetType( Dali::Window::Type type )
363 mWindowBase->SetType( type );
369 Dali::Window::Type Window::GetType() const
374 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
376 if( mType != Dali::Window::NOTIFICATION )
378 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
382 return mWindowBase->SetNotificationLevel( level );
385 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
387 if( mType != Dali::Window::NOTIFICATION )
389 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
390 return Dali::Window::NotificationLevel::NONE;
393 return mWindowBase->GetNotificationLevel();
396 void Window::SetOpaqueState( bool opaque )
398 mOpaqueState = opaque;
400 mWindowBase->SetOpaqueState( opaque );
402 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
405 bool Window::IsOpaqueState() const
410 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
412 return mWindowBase->SetScreenOffMode( screenOffMode );
415 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
417 return mWindowBase->GetScreenOffMode();
420 bool Window::SetBrightness( int brightness )
422 if( brightness < 0 || brightness > 100 )
424 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
428 return mWindowBase->SetBrightness( brightness );
431 int Window::GetBrightness() const
433 return mWindowBase->GetBrightness();
436 void Window::SetSize( Dali::Window::WindowSize size )
438 if( !mResizeEnabled )
440 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
441 mResizeEnabled = true;
444 PositionSize oldRect = mSurface->GetPositionSize();
446 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
448 PositionSize newRect = mSurface->GetPositionSize();
450 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
451 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
453 Uint16Pair newSize( newRect.width, newRect.height );
455 bool forceUpdate = false;
456 if( mWindowBase->IsEglWindowRotationSupported() )
461 SurfaceResized( forceUpdate );
463 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
465 mResizedSignal.Emit( 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 );
517 bool forceUpdate = false;
518 if( mWindowBase->IsEglWindowRotationSupported() )
523 SurfaceResized( forceUpdate );
525 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
527 mResizedSignal.Emit( 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();
575 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
583 WindowVisibilityObserver* observer( mAdaptor );
584 observer->OnWindowShown();
587 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
591 void Window::OnFocusChanged( bool focusIn )
593 mFocusChangedSignal.Emit( focusIn );
596 void Window::OnOutputTransformed()
598 bool forceUpdate = false;
599 if( mWindowBase->IsEglWindowRotationSupported() )
603 PositionSize positionSize = mSurface->GetPositionSize();
604 SurfaceResized( forceUpdate );
605 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
606 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
609 void Window::OnDeleteRequest()
611 mDeleteRequestSignal.Emit();
614 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
616 FeedTouchPoint( point, timeStamp );
619 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
621 FeedWheelEvent( wheelEvent );
624 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
626 FeedKeyEvent( keyEvent );
629 void Window::OnRotation( const RotationEvent& rotation )
631 mRotationAngle = rotation.angle;
632 mWindowWidth = rotation.width;
633 mWindowHeight = rotation.height;
635 // Notify that the orientation is changed
636 mOrientation->OnOrientationChange( rotation );
638 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
640 bool forceUpdate = false;
641 if( mWindowBase->IsEglWindowRotationSupported() )
646 SurfaceResized( forceUpdate );
648 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mRotationAngle, mWindowHeight ) );
651 mResizedSignal.Emit( Dali::Window::WindowSize( mRotationAngle, mWindowHeight ) );
653 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mRotationAngle, mWindowHeight ) );
656 void Window::OnPause()
660 mEventHandler->Pause();
664 void Window::OnResume()
668 mEventHandler->Resume();
672 void Window::RecalculateTouchPosition( Integration::Point& point )
674 Vector2 position = point.GetScreenPosition();
675 Vector2 convertedPosition;
677 switch( mRotationAngle )
681 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
682 convertedPosition.y = position.x;
687 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
688 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
693 convertedPosition.x = position.y;
694 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
699 convertedPosition = position;
704 point.SetScreenPosition( convertedPosition );
707 Dali::Window Window::Get( Dali::Actor actor )
709 Internal::Adaptor::Window* windowImpl = nullptr;
711 if ( Internal::Adaptor::Adaptor::IsAvailable() )
713 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
714 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
717 return Dali::Window( windowImpl );
720 void Window::SetParent( Dali::Window& parent )
722 if ( DALI_UNLIKELY( parent ) )
724 mParentWindow = parent;
725 Dali::Window grandParent = Dali::DevelWindow::GetParent( parent );
726 // check circular parent window setting
727 if ( DALI_UNLIKELY( grandParent ) && mWindowBase->IsMatchedWindow( grandParent.GetNativeHandle() ) )
729 Dali::DevelWindow::Unparent( parent );
731 mWindowBase->SetParent( parent.GetNativeHandle() );
735 void Window::Unparent()
738 mWindowBase->SetParent( parent );
741 Dali::Window Window::GetParent()
743 return mParentWindow;