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/integration-api/render-task-list-integ.h>
24 #include <dali/public-api/actors/actor.h>
25 #include <dali/public-api/actors/layer.h>
26 #include <dali/public-api/actors/camera-actor.h>
27 #include <dali/public-api/render-tasks/render-task.h>
28 #include <dali/public-api/render-tasks/render-task-list.h>
29 #include <dali/public-api/rendering/frame-buffer.h>
30 #include <dali/devel-api/adaptor-framework/orientation.h>
33 #include <dali/internal/input/common/drag-and-drop-detector-impl.h>
34 #include <dali/internal/window-system/common/event-handler.h>
35 #include <dali/internal/window-system/common/orientation-impl.h>
36 #include <dali/internal/window-system/common/render-surface-factory.h>
37 #include <dali/internal/window-system/common/window-factory.h>
38 #include <dali/internal/window-system/common/window-base.h>
39 #include <dali/internal/window-system/common/window-render-surface.h>
40 #include <dali/internal/window-system/common/window-visibility-observer.h>
49 uint32_t Window::mWindowCounter = 0;
54 #if defined(DEBUG_ENABLED)
55 Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW" );
58 } // unnamed namespace
60 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
62 Window* window = new Window();
63 window->mIsTransparent = isTransparent;
64 window->Initialize( positionSize, name, className );
69 : mId( mWindowCounter++ ),
73 mIsTransparent( false ),
74 mIsFocusAcceptable( true ),
77 mOpaqueState( false ),
78 mResizeEnabled( false ),
80 mType( Dali::Window::NORMAL ),
81 mPreferredOrientation( Dali::Window::PORTRAIT ),
82 mFocusChangedSignal(),
84 mDeleteRequestSignal()
92 mAdaptor->RemoveObserver( *this );
93 mAdaptor->RemoveWindow( this );
99 mEventHandler->SetRotationObserver( nullptr );
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 );
111 mWindowBase = mSurface->GetWindowBase();
114 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
115 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
116 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
118 mSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
120 if( !positionSize.IsEmpty() )
122 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
123 mResizeEnabled = true;
126 SetClass( name, className );
130 mOrientation = Orientation::New( this );
133 void Window::SetAdaptor(Dali::Adaptor& adaptor)
135 Window::SetAdaptor( Internal::Adaptor::Adaptor::GetImplementation( adaptor ) );
138 void Window::SetAdaptor(Adaptor& adaptor)
147 // Create scene for the window
148 PositionSize positionSize = mSurface->GetPositionSize();
149 mScene = Dali::Integration::Scene::New( Vector2( positionSize.width, positionSize.height ) );
150 mScene.SetSurface( *mSurface.get() );
152 unsigned int dpiHorizontal, dpiVertical;
153 dpiHorizontal = dpiVertical = 0;
155 mSurface->GetDpi( dpiHorizontal, dpiVertical );
156 mScene.SetDpi( Vector2( static_cast<float>( dpiHorizontal ), static_cast<float>( dpiVertical ) ) );
158 // Add the window to the adaptor observers
160 mAdaptor->AddObserver( *this );
162 // Can only create the detector when we know the Core has been instantiated.
163 mDragAndDropDetector = DragAndDropDetector::New();
167 mOrientation->SetAdaptor( adaptor );
170 mSurface->SetAdaptor( *mAdaptor );
172 mEventHandler = EventHandlerPtr(
173 new EventHandler( mScene, *mAdaptor, *mAdaptor->GetGestureManager(), *mAdaptor ) );
176 WindowRenderSurface* Window::GetSurface() const
178 return mSurface.get();
181 void Window::SetSurface(WindowRenderSurface* surface)
183 mSurface.reset( surface );
185 mScene.SetSurface( *mSurface.get() );
187 unsigned int dpiHorizontal, dpiVertical;
188 dpiHorizontal = dpiVertical = 0;
190 mSurface->GetDpi( dpiHorizontal, dpiVertical );
191 mScene.SetDpi( Vector2( static_cast<float>( dpiHorizontal ), static_cast<float>( dpiVertical ) ) );
193 mSurface->SetAdaptor( *mAdaptor );
196 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
200 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
204 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
208 void Window::SetClass( std::string name, std::string className )
211 mClassName = className;
212 mWindowBase->SetClass( name, className );
215 std::string Window::GetName() const
220 std::string Window::GetClassName() const
227 mWindowBase->Raise();
232 mWindowBase->Lower();
235 void Window::Activate()
237 mWindowBase->Activate();
240 void Window::Add( Dali::Actor actor )
245 void Window::Remove( Dali::Actor actor )
247 mScene.Remove( actor );
250 Dali::Layer Window::GetRootLayer() const
252 return mScene.GetRootLayer();
255 uint32_t Window::GetLayerCount() const
257 return mScene.GetLayerCount();
260 Dali::Layer Window::GetLayer( uint32_t depth ) const
262 return mScene.GetLayer( depth );
265 void Window::SetBackgroundColor( Vector4 color )
269 mSurface->SetBackgroundColor( color );
273 Vector4 Window::GetBackgroundColor() const
275 return mSurface ? mSurface->GetBackgroundColor() : Vector4();
278 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
282 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
284 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
286 if( mAvailableOrientations[i] == orientation )
295 mAvailableOrientations.push_back( orientation );
296 SetAvailableOrientations( mAvailableOrientations );
301 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
303 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
304 iter != mAvailableOrientations.end(); ++iter )
306 if( *iter == orientation )
308 mAvailableOrientations.erase( iter );
312 SetAvailableOrientations( mAvailableOrientations );
315 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
317 if( orientations.size() > 4 )
319 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
323 mAvailableOrientations = orientations;
325 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
328 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
330 return mAvailableOrientations;
333 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
335 mPreferredOrientation = orientation;
337 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
340 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
342 return mPreferredOrientation;
345 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
347 return mDragAndDropDetector;
350 Dali::Any Window::GetNativeHandle() const
352 return mSurface->GetNativeWindow();
355 void Window::SetAcceptFocus( bool accept )
357 mIsFocusAcceptable = accept;
359 mWindowBase->SetAcceptFocus( accept );
362 bool Window::IsFocusAcceptable() const
364 return mIsFocusAcceptable;
375 WindowVisibilityObserver* observer( mAdaptor );
376 observer->OnWindowShown();
379 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
390 WindowVisibilityObserver* observer( mAdaptor );
391 observer->OnWindowHidden();
394 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
397 bool Window::IsVisible() const
402 unsigned int Window::GetSupportedAuxiliaryHintCount() const
404 return mWindowBase->GetSupportedAuxiliaryHintCount();
407 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
409 return mWindowBase->GetSupportedAuxiliaryHint( index );
412 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
414 return mWindowBase->AddAuxiliaryHint( hint, value );
417 bool Window::RemoveAuxiliaryHint( unsigned int id )
419 return mWindowBase->RemoveAuxiliaryHint( id );
422 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
424 return mWindowBase->SetAuxiliaryHintValue( id, value );
427 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
429 return mWindowBase->GetAuxiliaryHintValue( id );
432 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
434 return mWindowBase->GetAuxiliaryHintId( hint );
437 void Window::SetInputRegion( const Rect< int >& inputRegion )
439 mWindowBase->SetInputRegion( inputRegion );
441 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 );
444 void Window::SetType( Dali::Window::Type type )
448 mWindowBase->SetType( type );
454 Dali::Window::Type Window::GetType() const
459 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
461 if( mType != Dali::Window::NOTIFICATION )
463 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
467 return mWindowBase->SetNotificationLevel( level );
470 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
472 if( mType != Dali::Window::NOTIFICATION )
474 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
475 return Dali::Window::NotificationLevel::NONE;
478 return mWindowBase->GetNotificationLevel();
481 void Window::SetOpaqueState( bool opaque )
483 mOpaqueState = opaque;
485 mWindowBase->SetOpaqueState( opaque );
487 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
490 bool Window::IsOpaqueState() const
495 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
497 return mWindowBase->SetScreenOffMode( screenOffMode );
500 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
502 return mWindowBase->GetScreenOffMode();
505 bool Window::SetBrightness( int brightness )
507 if( brightness < 0 || brightness > 100 )
509 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
513 return mWindowBase->SetBrightness( brightness );
516 int Window::GetBrightness() const
518 return mWindowBase->GetBrightness();
521 void Window::SetSize( Dali::Window::WindowSize size )
523 if( !mResizeEnabled )
525 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
526 mResizeEnabled = true;
529 PositionSize oldRect = mSurface->GetPositionSize();
531 mSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
533 PositionSize newRect = mSurface->GetPositionSize();
535 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
536 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
538 Uint16Pair newSize( newRect.width, newRect.height );
540 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
542 mResizedSignal.Emit( newSize );
544 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
548 Dali::Window::WindowSize Window::GetSize() const
550 PositionSize positionSize = mSurface->GetPositionSize();
552 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
555 void Window::SetPosition( Dali::Window::WindowPosition position )
557 if( !mResizeEnabled )
559 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
560 mResizeEnabled = true;
563 PositionSize oldRect = mSurface->GetPositionSize();
565 mSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
568 Dali::Window::WindowPosition Window::GetPosition() const
570 PositionSize positionSize = mSurface->GetPositionSize();
572 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
575 void Window::SetPositionSize( PositionSize positionSize )
577 if( !mResizeEnabled )
579 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
580 mResizeEnabled = true;
583 PositionSize oldRect = mSurface->GetPositionSize();
585 mSurface->MoveResize( positionSize );
587 PositionSize newRect = mSurface->GetPositionSize();
589 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
590 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
592 Uint16Pair newSize( newRect.width, newRect.height );
594 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
596 mResizedSignal.Emit( newSize );
598 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
602 Dali::Layer Window::GetRootLayer()
604 return mScene.GetRootLayer();
607 void Window::SetTransparency( bool transparent )
609 mSurface->SetTransparency( transparent );
612 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
614 return mWindowBase->GrabKey( key, grabMode );
617 bool Window::UngrabKey( Dali::KEY key )
619 return mWindowBase->UngrabKey( key );
622 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
624 return mWindowBase->GrabKeyList( key, grabMode, result );
627 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
629 return mWindowBase->UngrabKeyList( key, result );
632 void Window::RotationDone( int orientation, int width, int height )
634 mSurface->RequestRotation( orientation, width, height );
636 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
639 mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
641 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
644 void Window::OnIconifyChanged( bool iconified )
652 WindowVisibilityObserver* observer( mAdaptor );
653 observer->OnWindowHidden();
656 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
664 WindowVisibilityObserver* observer( mAdaptor );
665 observer->OnWindowShown();
668 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
672 void Window::OnFocusChanged( bool focusIn )
674 mFocusChangedSignal.Emit( focusIn );
677 void Window::OnOutputTransformed()
679 PositionSize positionSize = mSurface->GetPositionSize();
680 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
681 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
684 void Window::OnDeleteRequest()
686 mDeleteRequestSignal.Emit();
689 void Window::OnStart()
693 void Window::OnPause()
697 void Window::OnResume()
701 void Window::OnStop()
705 void Window::OnDestroy()
710 uint32_t Window::GetId() const
715 void Window::FeedTouchPoint( TouchPoint& point, int timeStamp )
719 mEventHandler->FeedTouchPoint( point, timeStamp );
723 void Window::FeedWheelEvent( WheelEvent& wheelEvent )
727 mEventHandler->FeedWheelEvent( wheelEvent );
731 void Window::FeedKeyEvent( KeyEvent& keyEvent )
735 mEventHandler->FeedKeyEvent( keyEvent );
743 mEventHandler->Pause();
747 void Window::Resume()
751 mEventHandler->Resume();
755 bool Window::SetRotationObserver( RotationObserver* observer )
759 mEventHandler->SetRotationObserver( observer );