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/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 mPreferredOrientation( Dali::Window::PORTRAIT ),
81 mFocusChangedSignal(),
83 mDeleteRequestSignal()
91 mEventHandler->SetRotationObserver( nullptr );
95 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
97 // Create a window render surface
99 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
100 mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
101 mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
104 mWindowBase = mWindowSurface->GetWindowBase();
107 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
108 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
109 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
111 mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
113 if( !positionSize.IsEmpty() )
115 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
116 mResizeEnabled = true;
119 SetClass( name, className );
121 mWindowSurface->Map();
123 mOrientation = Orientation::New( this );
126 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
128 mEventHandler = EventHandlerPtr(
129 new EventHandler( mScene, *mAdaptor, *mAdaptor->GetGestureManager(), *mAdaptor ) );
131 // TODO: Orientation should be passed into the constructor of EventHandler
134 SetRotationObserver( &(*mOrientation) );
138 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
140 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
143 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
147 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
151 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
155 void Window::SetClass( std::string name, std::string className )
158 mClassName = className;
159 mWindowBase->SetClass( name, className );
162 std::string Window::GetClassName() const
169 mWindowBase->Raise();
174 mWindowBase->Lower();
177 void Window::Activate()
179 mWindowBase->Activate();
182 uint32_t Window::GetLayerCount() const
184 return mScene.GetLayerCount();
187 Dali::Layer Window::GetLayer( uint32_t depth ) const
189 return mScene.GetLayer( depth );
192 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
196 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
198 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
200 if( mAvailableOrientations[i] == orientation )
209 mAvailableOrientations.push_back( orientation );
210 SetAvailableOrientations( mAvailableOrientations );
215 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
217 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
218 iter != mAvailableOrientations.end(); ++iter )
220 if( *iter == orientation )
222 mAvailableOrientations.erase( iter );
226 SetAvailableOrientations( mAvailableOrientations );
229 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
231 if( orientations.size() > 4 )
233 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
237 mAvailableOrientations = orientations;
239 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
242 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
244 return mAvailableOrientations;
247 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
249 mPreferredOrientation = orientation;
251 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
254 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
256 return mPreferredOrientation;
259 Dali::Any Window::GetNativeHandle() const
261 return mWindowSurface->GetNativeWindow();
264 void Window::SetAcceptFocus( bool accept )
266 mIsFocusAcceptable = accept;
268 mWindowBase->SetAcceptFocus( accept );
271 bool Window::IsFocusAcceptable() const
273 return mIsFocusAcceptable;
284 WindowVisibilityObserver* observer( mAdaptor );
285 observer->OnWindowShown();
288 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
299 WindowVisibilityObserver* observer( mAdaptor );
300 observer->OnWindowHidden();
303 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
306 bool Window::IsVisible() const
308 return mVisible && !mIconified;
311 unsigned int Window::GetSupportedAuxiliaryHintCount() const
313 return mWindowBase->GetSupportedAuxiliaryHintCount();
316 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
318 return mWindowBase->GetSupportedAuxiliaryHint( index );
321 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
323 return mWindowBase->AddAuxiliaryHint( hint, value );
326 bool Window::RemoveAuxiliaryHint( unsigned int id )
328 return mWindowBase->RemoveAuxiliaryHint( id );
331 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
333 return mWindowBase->SetAuxiliaryHintValue( id, value );
336 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
338 return mWindowBase->GetAuxiliaryHintValue( id );
341 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
343 return mWindowBase->GetAuxiliaryHintId( hint );
346 void Window::SetInputRegion( const Rect< int >& inputRegion )
348 mWindowBase->SetInputRegion( inputRegion );
350 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 );
353 void Window::SetType( Dali::Window::Type type )
357 mWindowBase->SetType( type );
363 Dali::Window::Type Window::GetType() const
368 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
370 if( mType != Dali::Window::NOTIFICATION )
372 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
376 return mWindowBase->SetNotificationLevel( level );
379 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
381 if( mType != Dali::Window::NOTIFICATION )
383 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
384 return Dali::Window::NotificationLevel::NONE;
387 return mWindowBase->GetNotificationLevel();
390 void Window::SetOpaqueState( bool opaque )
392 mOpaqueState = opaque;
394 mWindowBase->SetOpaqueState( opaque );
396 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
399 bool Window::IsOpaqueState() const
404 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
406 return mWindowBase->SetScreenOffMode( screenOffMode );
409 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
411 return mWindowBase->GetScreenOffMode();
414 bool Window::SetBrightness( int brightness )
416 if( brightness < 0 || brightness > 100 )
418 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
422 return mWindowBase->SetBrightness( brightness );
425 int Window::GetBrightness() const
427 return mWindowBase->GetBrightness();
430 void Window::SetSize( Dali::Window::WindowSize size )
432 if( !mResizeEnabled )
434 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
435 mResizeEnabled = true;
438 PositionSize oldRect = mSurface->GetPositionSize();
440 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
442 PositionSize newRect = mSurface->GetPositionSize();
444 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
445 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
447 Uint16Pair newSize( newRect.width, newRect.height );
449 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
451 mResizedSignal.Emit( newSize );
453 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
457 Dali::Window::WindowSize Window::GetSize() const
459 PositionSize positionSize = mSurface->GetPositionSize();
461 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
464 void Window::SetPosition( Dali::Window::WindowPosition position )
466 if( !mResizeEnabled )
468 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
469 mResizeEnabled = true;
472 PositionSize oldRect = mSurface->GetPositionSize();
474 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
477 Dali::Window::WindowPosition Window::GetPosition() const
479 PositionSize positionSize = mSurface->GetPositionSize();
481 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
484 void Window::SetPositionSize( PositionSize positionSize )
486 if( !mResizeEnabled )
488 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
489 mResizeEnabled = true;
492 PositionSize oldRect = mSurface->GetPositionSize();
494 mWindowSurface->MoveResize( positionSize );
496 PositionSize newRect = mSurface->GetPositionSize();
498 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
499 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
501 Uint16Pair newSize( newRect.width, newRect.height );
503 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
505 mResizedSignal.Emit( newSize );
507 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
511 Dali::Layer Window::GetRootLayer() const
513 return mScene.GetRootLayer();
516 void Window::SetTransparency( bool transparent )
518 mWindowSurface->SetTransparency( transparent );
521 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
523 return mWindowBase->GrabKey( key, grabMode );
526 bool Window::UngrabKey( Dali::KEY key )
528 return mWindowBase->UngrabKey( key );
531 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
533 return mWindowBase->GrabKeyList( key, grabMode, result );
536 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
538 return mWindowBase->UngrabKeyList( key, result );
541 void Window::RotationDone( int orientation, int width, int height )
543 mWindowSurface->RequestRotation( orientation, width, height );
545 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
548 mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
550 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
553 void Window::OnIconifyChanged( bool iconified )
561 WindowVisibilityObserver* observer( mAdaptor );
562 observer->OnWindowHidden();
565 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
573 WindowVisibilityObserver* observer( mAdaptor );
574 observer->OnWindowShown();
577 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
581 void Window::OnFocusChanged( bool focusIn )
583 mFocusChangedSignal.Emit( focusIn );
586 void Window::OnOutputTransformed()
588 PositionSize positionSize = mSurface->GetPositionSize();
589 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
590 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
593 void Window::OnDeleteRequest()
595 mDeleteRequestSignal.Emit();
598 void Window::FeedTouchPoint( TouchPoint& point, int timeStamp )
602 mEventHandler->FeedTouchPoint( point, timeStamp );
606 void Window::FeedWheelEvent( WheelEvent& wheelEvent )
610 mEventHandler->FeedWheelEvent( wheelEvent );
614 void Window::FeedKeyEvent( KeyEvent& keyEvent )
618 mEventHandler->FeedKeyEvent( keyEvent );
622 void Window::OnPause()
626 mEventHandler->Pause();
630 void Window::OnResume()
634 mEventHandler->Resume();
638 bool Window::SetRotationObserver( RotationObserver* observer )
642 mEventHandler->SetRotationObserver( observer );
649 Dali::Window Window::Get( Dali::Actor actor )
651 Internal::Adaptor::Window* windowImpl = nullptr;
653 if ( Internal::Adaptor::Adaptor::IsAvailable() )
655 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
656 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
659 return Dali::Window( windowImpl );