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();
165 mSurface->SetAdaptor( *mAdaptor );
167 mEventHandler = EventHandlerPtr(
168 new EventHandler( mScene, *mAdaptor, *mAdaptor->GetGestureManager(), *mAdaptor ) );
170 // TODO: Orientation should be passed into the constructor of EventHandler
173 SetRotationObserver( &(*mOrientation) );
177 WindowRenderSurface* Window::GetSurface() const
179 return mSurface.get();
182 void Window::SetSurface(WindowRenderSurface* surface)
184 mSurface.reset( surface );
186 mScene.SetSurface( *mSurface.get() );
188 unsigned int dpiHorizontal, dpiVertical;
189 dpiHorizontal = dpiVertical = 0;
191 mSurface->GetDpi( dpiHorizontal, dpiVertical );
192 mScene.SetDpi( Vector2( static_cast<float>( dpiHorizontal ), static_cast<float>( dpiVertical ) ) );
194 mSurface->SetAdaptor( *mAdaptor );
197 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
201 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
205 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
209 void Window::SetClass( std::string name, std::string className )
212 mClassName = className;
213 mWindowBase->SetClass( name, className );
216 std::string Window::GetName() const
221 std::string Window::GetClassName() const
228 mWindowBase->Raise();
233 mWindowBase->Lower();
236 void Window::Activate()
238 mWindowBase->Activate();
241 void Window::Add( Dali::Actor actor )
246 void Window::Remove( Dali::Actor actor )
248 mScene.Remove( actor );
251 Dali::Layer Window::GetRootLayer() const
253 return mScene.GetRootLayer();
256 uint32_t Window::GetLayerCount() const
258 return mScene.GetLayerCount();
261 Dali::Layer Window::GetLayer( uint32_t depth ) const
263 return mScene.GetLayer( depth );
266 void Window::SetBackgroundColor( Vector4 color )
270 mSurface->SetBackgroundColor( color );
274 Vector4 Window::GetBackgroundColor() const
276 return mSurface ? mSurface->GetBackgroundColor() : Vector4();
279 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
283 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
285 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
287 if( mAvailableOrientations[i] == orientation )
296 mAvailableOrientations.push_back( orientation );
297 SetAvailableOrientations( mAvailableOrientations );
302 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
304 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
305 iter != mAvailableOrientations.end(); ++iter )
307 if( *iter == orientation )
309 mAvailableOrientations.erase( iter );
313 SetAvailableOrientations( mAvailableOrientations );
316 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
318 if( orientations.size() > 4 )
320 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
324 mAvailableOrientations = orientations;
326 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
329 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
331 return mAvailableOrientations;
334 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
336 mPreferredOrientation = orientation;
338 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
341 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
343 return mPreferredOrientation;
346 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
348 return mDragAndDropDetector;
351 Dali::Any Window::GetNativeHandle() const
353 return mSurface->GetNativeWindow();
356 void Window::SetAcceptFocus( bool accept )
358 mIsFocusAcceptable = accept;
360 mWindowBase->SetAcceptFocus( accept );
363 bool Window::IsFocusAcceptable() const
365 return mIsFocusAcceptable;
376 WindowVisibilityObserver* observer( mAdaptor );
377 observer->OnWindowShown();
380 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
391 WindowVisibilityObserver* observer( mAdaptor );
392 observer->OnWindowHidden();
395 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
398 bool Window::IsVisible() const
403 unsigned int Window::GetSupportedAuxiliaryHintCount() const
405 return mWindowBase->GetSupportedAuxiliaryHintCount();
408 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
410 return mWindowBase->GetSupportedAuxiliaryHint( index );
413 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
415 return mWindowBase->AddAuxiliaryHint( hint, value );
418 bool Window::RemoveAuxiliaryHint( unsigned int id )
420 return mWindowBase->RemoveAuxiliaryHint( id );
423 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
425 return mWindowBase->SetAuxiliaryHintValue( id, value );
428 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
430 return mWindowBase->GetAuxiliaryHintValue( id );
433 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
435 return mWindowBase->GetAuxiliaryHintId( hint );
438 void Window::SetInputRegion( const Rect< int >& inputRegion )
440 mWindowBase->SetInputRegion( inputRegion );
442 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 );
445 void Window::SetType( Dali::Window::Type type )
449 mWindowBase->SetType( type );
455 Dali::Window::Type Window::GetType() const
460 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
462 if( mType != Dali::Window::NOTIFICATION )
464 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
468 return mWindowBase->SetNotificationLevel( level );
471 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
473 if( mType != Dali::Window::NOTIFICATION )
475 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
476 return Dali::Window::NotificationLevel::NONE;
479 return mWindowBase->GetNotificationLevel();
482 void Window::SetOpaqueState( bool opaque )
484 mOpaqueState = opaque;
486 mWindowBase->SetOpaqueState( opaque );
488 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
491 bool Window::IsOpaqueState() const
496 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
498 return mWindowBase->SetScreenOffMode( screenOffMode );
501 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
503 return mWindowBase->GetScreenOffMode();
506 bool Window::SetBrightness( int brightness )
508 if( brightness < 0 || brightness > 100 )
510 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
514 return mWindowBase->SetBrightness( brightness );
517 int Window::GetBrightness() const
519 return mWindowBase->GetBrightness();
522 void Window::SetSize( Dali::Window::WindowSize size )
524 if( !mResizeEnabled )
526 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
527 mResizeEnabled = true;
530 PositionSize oldRect = mSurface->GetPositionSize();
532 mSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
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 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
543 mResizedSignal.Emit( newSize );
545 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
549 Dali::Window::WindowSize Window::GetSize() const
551 PositionSize positionSize = mSurface->GetPositionSize();
553 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
556 void Window::SetPosition( Dali::Window::WindowPosition position )
558 if( !mResizeEnabled )
560 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
561 mResizeEnabled = true;
564 PositionSize oldRect = mSurface->GetPositionSize();
566 mSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
569 Dali::Window::WindowPosition Window::GetPosition() const
571 PositionSize positionSize = mSurface->GetPositionSize();
573 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
576 void Window::SetPositionSize( PositionSize positionSize )
578 if( !mResizeEnabled )
580 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
581 mResizeEnabled = true;
584 PositionSize oldRect = mSurface->GetPositionSize();
586 mSurface->MoveResize( positionSize );
588 PositionSize newRect = mSurface->GetPositionSize();
590 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
591 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
593 Uint16Pair newSize( newRect.width, newRect.height );
595 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
597 mResizedSignal.Emit( newSize );
599 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
603 Dali::Layer Window::GetRootLayer()
605 return mScene.GetRootLayer();
608 void Window::SetTransparency( bool transparent )
610 mSurface->SetTransparency( transparent );
613 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
615 return mWindowBase->GrabKey( key, grabMode );
618 bool Window::UngrabKey( Dali::KEY key )
620 return mWindowBase->UngrabKey( key );
623 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
625 return mWindowBase->GrabKeyList( key, grabMode, result );
628 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
630 return mWindowBase->UngrabKeyList( key, result );
633 void Window::RotationDone( int orientation, int width, int height )
635 mSurface->RequestRotation( orientation, width, height );
637 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
640 mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
642 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
645 void Window::OnIconifyChanged( bool iconified )
653 WindowVisibilityObserver* observer( mAdaptor );
654 observer->OnWindowHidden();
657 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
665 WindowVisibilityObserver* observer( mAdaptor );
666 observer->OnWindowShown();
669 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
673 void Window::OnFocusChanged( bool focusIn )
675 mFocusChangedSignal.Emit( focusIn );
678 void Window::OnOutputTransformed()
680 PositionSize positionSize = mSurface->GetPositionSize();
681 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
682 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
685 void Window::OnDeleteRequest()
687 mDeleteRequestSignal.Emit();
690 void Window::OnStart()
694 void Window::OnPause()
698 void Window::OnResume()
702 void Window::OnStop()
706 void Window::OnDestroy()
711 uint32_t Window::GetId() const
716 void Window::FeedTouchPoint( TouchPoint& point, int timeStamp )
720 mEventHandler->FeedTouchPoint( point, timeStamp );
724 void Window::FeedWheelEvent( WheelEvent& wheelEvent )
728 mEventHandler->FeedWheelEvent( wheelEvent );
732 void Window::FeedKeyEvent( KeyEvent& keyEvent )
736 mEventHandler->FeedKeyEvent( keyEvent );
744 mEventHandler->Pause();
748 void Window::Resume()
752 mEventHandler->Resume();
756 bool Window::SetRotationObserver( RotationObserver* observer )
760 mEventHandler->SetRotationObserver( observer );