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>
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/input/common/drag-and-drop-detector-impl.h>
40 #include <dali/internal/window-system/common/event-handler.h>
41 #include <dali/internal/window-system/common/orientation-impl.h>
42 #include <dali/internal/window-system/common/render-surface-factory.h>
43 #include <dali/internal/window-system/common/window-factory.h>
44 #include <dali/internal/window-system/common/window-base.h>
45 #include <dali/internal/window-system/common/window-render-surface.h>
46 #include <dali/internal/window-system/common/window-visibility-observer.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 mPreferredOrientation( Dali::Window::PORTRAIT ),
82 mFocusChangedSignal(),
84 mDeleteRequestSignal()
92 mEventHandler->SetRotationObserver( nullptr );
96 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
98 // Create a window render surface
100 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
101 mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
102 mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
105 mWindowBase = mWindowSurface->GetWindowBase();
108 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
109 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
110 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
112 mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
114 if( !positionSize.IsEmpty() )
116 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
117 mResizeEnabled = true;
120 SetClass( name, className );
122 mWindowSurface->Map();
124 mOrientation = Orientation::New( this );
127 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
129 // Can only create the detector when we know the Core has been instantiated.
130 mDragAndDropDetector = DragAndDropDetector::New();
132 mEventHandler = EventHandlerPtr(
133 new EventHandler( mScene, *mAdaptor, *mAdaptor->GetGestureManager(), *mAdaptor ) );
135 // TODO: Orientation should be passed into the constructor of EventHandler
138 SetRotationObserver( &(*mOrientation) );
142 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
144 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
147 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
151 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
155 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
159 void Window::SetClass( std::string name, std::string className )
162 mClassName = className;
163 mWindowBase->SetClass( name, className );
166 std::string Window::GetClassName() const
173 mWindowBase->Raise();
178 mWindowBase->Lower();
181 void Window::Activate()
183 mWindowBase->Activate();
186 uint32_t Window::GetLayerCount() const
188 return mScene.GetLayerCount();
191 Dali::Layer Window::GetLayer( uint32_t depth ) const
193 return mScene.GetLayer( depth );
196 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
200 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
202 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
204 if( mAvailableOrientations[i] == orientation )
213 mAvailableOrientations.push_back( orientation );
214 SetAvailableOrientations( mAvailableOrientations );
219 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
221 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
222 iter != mAvailableOrientations.end(); ++iter )
224 if( *iter == orientation )
226 mAvailableOrientations.erase( iter );
230 SetAvailableOrientations( mAvailableOrientations );
233 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
235 if( orientations.size() > 4 )
237 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
241 mAvailableOrientations = orientations;
243 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
246 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
248 return mAvailableOrientations;
251 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
253 mPreferredOrientation = orientation;
255 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
258 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
260 return mPreferredOrientation;
263 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
265 return mDragAndDropDetector;
268 Dali::Any Window::GetNativeHandle() const
270 return mWindowSurface->GetNativeWindow();
273 void Window::SetAcceptFocus( bool accept )
275 mIsFocusAcceptable = accept;
277 mWindowBase->SetAcceptFocus( accept );
280 bool Window::IsFocusAcceptable() const
282 return mIsFocusAcceptable;
293 WindowVisibilityObserver* observer( mAdaptor );
294 observer->OnWindowShown();
297 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
308 WindowVisibilityObserver* observer( mAdaptor );
309 observer->OnWindowHidden();
312 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
315 bool Window::IsVisible() const
317 return mVisible && !mIconified;
320 unsigned int Window::GetSupportedAuxiliaryHintCount() const
322 return mWindowBase->GetSupportedAuxiliaryHintCount();
325 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
327 return mWindowBase->GetSupportedAuxiliaryHint( index );
330 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
332 return mWindowBase->AddAuxiliaryHint( hint, value );
335 bool Window::RemoveAuxiliaryHint( unsigned int id )
337 return mWindowBase->RemoveAuxiliaryHint( id );
340 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
342 return mWindowBase->SetAuxiliaryHintValue( id, value );
345 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
347 return mWindowBase->GetAuxiliaryHintValue( id );
350 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
352 return mWindowBase->GetAuxiliaryHintId( hint );
355 void Window::SetInputRegion( const Rect< int >& inputRegion )
357 mWindowBase->SetInputRegion( inputRegion );
359 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 );
362 void Window::SetType( Dali::Window::Type type )
366 mWindowBase->SetType( type );
372 Dali::Window::Type Window::GetType() const
377 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
379 if( mType != Dali::Window::NOTIFICATION )
381 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
385 return mWindowBase->SetNotificationLevel( level );
388 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
390 if( mType != Dali::Window::NOTIFICATION )
392 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
393 return Dali::Window::NotificationLevel::NONE;
396 return mWindowBase->GetNotificationLevel();
399 void Window::SetOpaqueState( bool opaque )
401 mOpaqueState = opaque;
403 mWindowBase->SetOpaqueState( opaque );
405 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
408 bool Window::IsOpaqueState() const
413 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
415 return mWindowBase->SetScreenOffMode( screenOffMode );
418 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
420 return mWindowBase->GetScreenOffMode();
423 bool Window::SetBrightness( int brightness )
425 if( brightness < 0 || brightness > 100 )
427 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
431 return mWindowBase->SetBrightness( brightness );
434 int Window::GetBrightness() const
436 return mWindowBase->GetBrightness();
439 void Window::SetSize( Dali::Window::WindowSize size )
441 if( !mResizeEnabled )
443 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
444 mResizeEnabled = true;
447 PositionSize oldRect = mSurface->GetPositionSize();
449 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
451 PositionSize newRect = mSurface->GetPositionSize();
453 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
454 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
456 Uint16Pair newSize( newRect.width, newRect.height );
458 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
460 mResizedSignal.Emit( newSize );
462 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
466 Dali::Window::WindowSize Window::GetSize() const
468 PositionSize positionSize = mSurface->GetPositionSize();
470 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
473 void Window::SetPosition( Dali::Window::WindowPosition position )
475 if( !mResizeEnabled )
477 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
478 mResizeEnabled = true;
481 PositionSize oldRect = mSurface->GetPositionSize();
483 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
486 Dali::Window::WindowPosition Window::GetPosition() const
488 PositionSize positionSize = mSurface->GetPositionSize();
490 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
493 void Window::SetPositionSize( PositionSize positionSize )
495 if( !mResizeEnabled )
497 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
498 mResizeEnabled = true;
501 PositionSize oldRect = mSurface->GetPositionSize();
503 mWindowSurface->MoveResize( positionSize );
505 PositionSize newRect = mSurface->GetPositionSize();
507 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
508 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
510 Uint16Pair newSize( newRect.width, newRect.height );
512 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
514 mResizedSignal.Emit( newSize );
516 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
520 Dali::Layer Window::GetRootLayer() const
522 return mScene.GetRootLayer();
525 void Window::SetTransparency( bool transparent )
527 mWindowSurface->SetTransparency( transparent );
530 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
532 return mWindowBase->GrabKey( key, grabMode );
535 bool Window::UngrabKey( Dali::KEY key )
537 return mWindowBase->UngrabKey( key );
540 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
542 return mWindowBase->GrabKeyList( key, grabMode, result );
545 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
547 return mWindowBase->UngrabKeyList( key, result );
550 void Window::RotationDone( int orientation, int width, int height )
552 mWindowSurface->RequestRotation( orientation, width, height );
554 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
557 mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
559 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
562 void Window::OnIconifyChanged( bool iconified )
570 WindowVisibilityObserver* observer( mAdaptor );
571 observer->OnWindowHidden();
574 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
582 WindowVisibilityObserver* observer( mAdaptor );
583 observer->OnWindowShown();
586 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
590 void Window::OnFocusChanged( bool focusIn )
592 mFocusChangedSignal.Emit( focusIn );
595 void Window::OnOutputTransformed()
597 PositionSize positionSize = mSurface->GetPositionSize();
598 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
599 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
602 void Window::OnDeleteRequest()
604 mDeleteRequestSignal.Emit();
607 void Window::FeedTouchPoint( TouchPoint& point, int timeStamp )
611 mEventHandler->FeedTouchPoint( point, timeStamp );
615 void Window::FeedWheelEvent( WheelEvent& wheelEvent )
619 mEventHandler->FeedWheelEvent( wheelEvent );
623 void Window::FeedKeyEvent( KeyEvent& keyEvent )
627 mEventHandler->FeedKeyEvent( keyEvent );
631 void Window::OnPause()
635 mEventHandler->Pause();
639 void Window::OnResume()
643 mEventHandler->Resume();
647 bool Window::SetRotationObserver( RotationObserver* observer )
651 mEventHandler->SetRotationObserver( observer );