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 );
97 // Do we need to do it?
98 mEventHandler->SetRotationObserver( nullptr );
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 );
109 mWindowBase = mSurface->GetWindowBase();
112 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
113 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
114 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
116 mSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
118 if( !positionSize.IsEmpty() )
120 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
121 mResizeEnabled = true;
124 SetClass( name, className );
128 mOrientation = Orientation::New( this );
131 void Window::SetAdaptor(Dali::Adaptor& adaptor)
133 Window::SetAdaptor( Internal::Adaptor::Adaptor::GetImplementation( adaptor ) );
136 void Window::SetAdaptor(Adaptor& adaptor)
145 // Create scene for the window
146 PositionSize positionSize = mSurface->GetPositionSize();
147 mScene = Dali::Integration::Scene::New( Vector2( positionSize.width, positionSize.height ) );
148 mScene.SetSurface( *mSurface.get() );
150 unsigned int dpiHorizontal, dpiVertical;
151 dpiHorizontal = dpiVertical = 0;
153 mSurface->GetDpi( dpiHorizontal, dpiVertical );
154 mScene.SetDpi( Vector2( static_cast<float>( dpiHorizontal ), static_cast<float>( dpiVertical ) ) );
156 // Add the window to the adaptor observers
158 mAdaptor->AddObserver( *this );
160 // Can only create the detector when we know the Core has been instantiated.
161 mDragAndDropDetector = DragAndDropDetector::New();
165 mOrientation->SetAdaptor( adaptor );
168 mSurface->SetAdaptor( *mAdaptor );
170 mEventHandler = EventHandlerPtr(
171 new EventHandler( mScene, *mAdaptor, *mAdaptor->GetGestureManager(), *mAdaptor ) );
174 WindowRenderSurface* Window::GetSurface() const
176 return mSurface.get();
179 void Window::SetSurface(WindowRenderSurface* surface)
181 mSurface.reset( surface );
183 mScene.SetSurface( *mSurface.get() );
185 unsigned int dpiHorizontal, dpiVertical;
186 dpiHorizontal = dpiVertical = 0;
188 mSurface->GetDpi( dpiHorizontal, dpiVertical );
189 mScene.SetDpi( Vector2( static_cast<float>( dpiHorizontal ), static_cast<float>( dpiVertical ) ) );
191 mSurface->SetAdaptor( *mAdaptor );
194 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
198 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
202 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
206 void Window::SetClass( std::string name, std::string className )
209 mClassName = className;
210 mWindowBase->SetClass( name, className );
213 std::string Window::GetName() const
218 std::string Window::GetClassName() const
225 mWindowBase->Raise();
230 mWindowBase->Lower();
233 void Window::Activate()
235 mWindowBase->Activate();
238 void Window::Add( Dali::Actor actor )
243 void Window::Remove( Dali::Actor actor )
245 mScene.Remove( actor );
248 Dali::Layer Window::GetRootLayer() const
250 return mScene.GetRootLayer();
253 uint32_t Window::GetLayerCount() const
255 return mScene.GetLayerCount();
258 Dali::Layer Window::GetLayer( uint32_t depth ) const
260 return mScene.GetLayer( depth );
263 void Window::SetBackgroundColor( Vector4 color )
267 mSurface->SetBackgroundColor( color );
271 Vector4 Window::GetBackgroundColor() const
273 return mSurface ? mSurface->GetBackgroundColor() : Vector4();
276 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
280 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
282 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
284 if( mAvailableOrientations[i] == orientation )
293 mAvailableOrientations.push_back( orientation );
294 SetAvailableOrientations( mAvailableOrientations );
299 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
301 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
302 iter != mAvailableOrientations.end(); ++iter )
304 if( *iter == orientation )
306 mAvailableOrientations.erase( iter );
310 SetAvailableOrientations( mAvailableOrientations );
313 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
315 if( orientations.size() > 4 )
317 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
321 mAvailableOrientations = orientations;
323 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
326 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
328 return mAvailableOrientations;
331 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
333 mPreferredOrientation = orientation;
335 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
338 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
340 return mPreferredOrientation;
343 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
345 return mDragAndDropDetector;
348 Dali::Any Window::GetNativeHandle() const
350 return mSurface->GetNativeWindow();
353 void Window::SetAcceptFocus( bool accept )
355 mIsFocusAcceptable = accept;
357 mWindowBase->SetAcceptFocus( accept );
360 bool Window::IsFocusAcceptable() const
362 return mIsFocusAcceptable;
373 WindowVisibilityObserver* observer( mAdaptor );
374 observer->OnWindowShown();
377 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
388 WindowVisibilityObserver* observer( mAdaptor );
389 observer->OnWindowHidden();
392 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
395 bool Window::IsVisible() const
400 unsigned int Window::GetSupportedAuxiliaryHintCount() const
402 return mWindowBase->GetSupportedAuxiliaryHintCount();
405 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
407 return mWindowBase->GetSupportedAuxiliaryHint( index );
410 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
412 return mWindowBase->AddAuxiliaryHint( hint, value );
415 bool Window::RemoveAuxiliaryHint( unsigned int id )
417 return mWindowBase->RemoveAuxiliaryHint( id );
420 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
422 return mWindowBase->SetAuxiliaryHintValue( id, value );
425 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
427 return mWindowBase->GetAuxiliaryHintValue( id );
430 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
432 return mWindowBase->GetAuxiliaryHintId( hint );
435 void Window::SetInputRegion( const Rect< int >& inputRegion )
437 mWindowBase->SetInputRegion( inputRegion );
439 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 );
442 void Window::SetType( Dali::Window::Type type )
446 mWindowBase->SetType( type );
452 Dali::Window::Type Window::GetType() const
457 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
459 if( mType != Dali::Window::NOTIFICATION )
461 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
465 return mWindowBase->SetNotificationLevel( level );
468 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
470 if( mType != Dali::Window::NOTIFICATION )
472 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
473 return Dali::Window::NotificationLevel::NONE;
476 return mWindowBase->GetNotificationLevel();
479 void Window::SetOpaqueState( bool opaque )
481 mOpaqueState = opaque;
483 mWindowBase->SetOpaqueState( opaque );
485 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
488 bool Window::IsOpaqueState() const
493 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
495 return mWindowBase->SetScreenOffMode( screenOffMode );
498 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
500 return mWindowBase->GetScreenOffMode();
503 bool Window::SetBrightness( int brightness )
505 if( brightness < 0 || brightness > 100 )
507 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
511 return mWindowBase->SetBrightness( brightness );
514 int Window::GetBrightness() const
516 return mWindowBase->GetBrightness();
519 void Window::SetSize( Dali::Window::WindowSize size )
521 if( !mResizeEnabled )
523 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
524 mResizeEnabled = true;
527 PositionSize oldRect = mSurface->GetPositionSize();
529 mSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
531 PositionSize newRect = mSurface->GetPositionSize();
533 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
534 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
536 Uint16Pair newSize( newRect.width, newRect.height );
538 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
540 mResizedSignal.Emit( newSize );
542 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
546 Dali::Window::WindowSize Window::GetSize() const
548 PositionSize positionSize = mSurface->GetPositionSize();
550 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
553 void Window::SetPosition( Dali::Window::WindowPosition position )
555 if( !mResizeEnabled )
557 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
558 mResizeEnabled = true;
561 PositionSize oldRect = mSurface->GetPositionSize();
563 mSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
566 Dali::Window::WindowPosition Window::GetPosition() const
568 PositionSize positionSize = mSurface->GetPositionSize();
570 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
573 void Window::SetPositionSize( PositionSize positionSize )
575 if( !mResizeEnabled )
577 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
578 mResizeEnabled = true;
581 PositionSize oldRect = mSurface->GetPositionSize();
583 mSurface->MoveResize( positionSize );
585 PositionSize newRect = mSurface->GetPositionSize();
587 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
588 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
590 Uint16Pair newSize( newRect.width, newRect.height );
592 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
594 mResizedSignal.Emit( newSize );
596 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
600 Dali::Layer Window::GetRootLayer()
602 return mScene.GetRootLayer();
605 void Window::SetTransparency( bool transparent )
607 mSurface->SetTransparency( transparent );
610 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
612 return mWindowBase->GrabKey( key, grabMode );
615 bool Window::UngrabKey( Dali::KEY key )
617 return mWindowBase->UngrabKey( key );
620 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
622 return mWindowBase->GrabKeyList( key, grabMode, result );
625 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
627 return mWindowBase->UngrabKeyList( key, result );
630 void Window::RotationDone( int orientation, int width, int height )
632 mSurface->RequestRotation( orientation, width, height );
634 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
637 mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
639 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
642 void Window::OnIconifyChanged( bool iconified )
650 WindowVisibilityObserver* observer( mAdaptor );
651 observer->OnWindowHidden();
654 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
662 WindowVisibilityObserver* observer( mAdaptor );
663 observer->OnWindowShown();
666 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
670 void Window::OnFocusChanged( bool focusIn )
672 mFocusChangedSignal.Emit( focusIn );
675 void Window::OnOutputTransformed()
677 PositionSize positionSize = mSurface->GetPositionSize();
678 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
679 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
682 void Window::OnDeleteRequest()
684 mDeleteRequestSignal.Emit();
687 void Window::OnStart()
691 void Window::OnPause()
695 void Window::OnResume()
699 void Window::OnStop()
703 void Window::OnDestroy()
708 uint32_t Window::GetId() const
713 void Window::FeedTouchPoint( TouchPoint& point, int timeStamp )
717 mEventHandler->FeedTouchPoint( point, timeStamp );
721 void Window::FeedWheelEvent( WheelEvent& wheelEvent )
725 mEventHandler->FeedWheelEvent( wheelEvent );
729 void Window::FeedKeyEvent( KeyEvent& keyEvent )
733 mEventHandler->FeedKeyEvent( keyEvent );
741 mEventHandler->Pause();
745 void Window::Resume()
749 mEventHandler->Resume();
753 bool Window::SetRotationObserver( RotationObserver* observer )
757 mEventHandler->SetRotationObserver( observer );