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(new EventHandler( mScene, *mAdaptor, *mAdaptor ) );
130 // TODO: Orientation should be passed into the constructor of EventHandler
133 SetRotationObserver( &(*mOrientation) );
137 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
139 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
142 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
146 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
150 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
154 void Window::SetClass( std::string name, std::string className )
157 mClassName = className;
158 mWindowBase->SetClass( name, className );
161 std::string Window::GetClassName() const
168 mWindowBase->Raise();
173 mWindowBase->Lower();
176 void Window::Activate()
178 mWindowBase->Activate();
181 uint32_t Window::GetLayerCount() const
183 return mScene.GetLayerCount();
186 Dali::Layer Window::GetLayer( uint32_t depth ) const
188 return mScene.GetLayer( depth );
191 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
195 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
197 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
199 if( mAvailableOrientations[i] == orientation )
208 mAvailableOrientations.push_back( orientation );
209 SetAvailableOrientations( mAvailableOrientations );
214 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
216 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
217 iter != mAvailableOrientations.end(); ++iter )
219 if( *iter == orientation )
221 mAvailableOrientations.erase( iter );
225 SetAvailableOrientations( mAvailableOrientations );
228 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
230 if( orientations.size() > 4 )
232 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
236 mAvailableOrientations = orientations;
238 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
241 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
243 return mAvailableOrientations;
246 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
248 mPreferredOrientation = orientation;
250 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
253 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
255 return mPreferredOrientation;
258 Dali::Any Window::GetNativeHandle() const
260 return mWindowSurface->GetNativeWindow();
263 void Window::SetAcceptFocus( bool accept )
265 mIsFocusAcceptable = accept;
267 mWindowBase->SetAcceptFocus( accept );
270 bool Window::IsFocusAcceptable() const
272 return mIsFocusAcceptable;
283 WindowVisibilityObserver* observer( mAdaptor );
284 observer->OnWindowShown();
287 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
298 WindowVisibilityObserver* observer( mAdaptor );
299 observer->OnWindowHidden();
302 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
305 bool Window::IsVisible() const
307 return mVisible && !mIconified;
310 unsigned int Window::GetSupportedAuxiliaryHintCount() const
312 return mWindowBase->GetSupportedAuxiliaryHintCount();
315 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
317 return mWindowBase->GetSupportedAuxiliaryHint( index );
320 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
322 return mWindowBase->AddAuxiliaryHint( hint, value );
325 bool Window::RemoveAuxiliaryHint( unsigned int id )
327 return mWindowBase->RemoveAuxiliaryHint( id );
330 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
332 return mWindowBase->SetAuxiliaryHintValue( id, value );
335 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
337 return mWindowBase->GetAuxiliaryHintValue( id );
340 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
342 return mWindowBase->GetAuxiliaryHintId( hint );
345 void Window::SetInputRegion( const Rect< int >& inputRegion )
347 mWindowBase->SetInputRegion( inputRegion );
349 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 );
352 void Window::SetType( Dali::Window::Type type )
356 mWindowBase->SetType( type );
362 Dali::Window::Type Window::GetType() const
367 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
369 if( mType != Dali::Window::NOTIFICATION )
371 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
375 return mWindowBase->SetNotificationLevel( level );
378 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
380 if( mType != Dali::Window::NOTIFICATION )
382 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
383 return Dali::Window::NotificationLevel::NONE;
386 return mWindowBase->GetNotificationLevel();
389 void Window::SetOpaqueState( bool opaque )
391 mOpaqueState = opaque;
393 mWindowBase->SetOpaqueState( opaque );
395 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
398 bool Window::IsOpaqueState() const
403 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
405 return mWindowBase->SetScreenOffMode( screenOffMode );
408 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
410 return mWindowBase->GetScreenOffMode();
413 bool Window::SetBrightness( int brightness )
415 if( brightness < 0 || brightness > 100 )
417 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
421 return mWindowBase->SetBrightness( brightness );
424 int Window::GetBrightness() const
426 return mWindowBase->GetBrightness();
429 void Window::SetSize( Dali::Window::WindowSize size )
431 if( !mResizeEnabled )
433 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
434 mResizeEnabled = true;
437 PositionSize oldRect = mSurface->GetPositionSize();
439 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
441 PositionSize newRect = mSurface->GetPositionSize();
443 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
444 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
446 Uint16Pair newSize( newRect.width, newRect.height );
448 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
450 mResizedSignal.Emit( newSize );
452 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
456 Dali::Window::WindowSize Window::GetSize() const
458 PositionSize positionSize = mSurface->GetPositionSize();
460 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
463 void Window::SetPosition( Dali::Window::WindowPosition position )
465 if( !mResizeEnabled )
467 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
468 mResizeEnabled = true;
471 PositionSize oldRect = mSurface->GetPositionSize();
473 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
476 Dali::Window::WindowPosition Window::GetPosition() const
478 PositionSize positionSize = mSurface->GetPositionSize();
480 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
483 void Window::SetPositionSize( PositionSize positionSize )
485 if( !mResizeEnabled )
487 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
488 mResizeEnabled = true;
491 PositionSize oldRect = mSurface->GetPositionSize();
493 mWindowSurface->MoveResize( positionSize );
495 PositionSize newRect = mSurface->GetPositionSize();
497 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
498 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
500 Uint16Pair newSize( newRect.width, newRect.height );
502 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
504 mResizedSignal.Emit( newSize );
506 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
510 Dali::Layer Window::GetRootLayer() const
512 return mScene.GetRootLayer();
515 void Window::SetTransparency( bool transparent )
517 mWindowSurface->SetTransparency( transparent );
520 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
522 return mWindowBase->GrabKey( key, grabMode );
525 bool Window::UngrabKey( Dali::KEY key )
527 return mWindowBase->UngrabKey( key );
530 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
532 return mWindowBase->GrabKeyList( key, grabMode, result );
535 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
537 return mWindowBase->UngrabKeyList( key, result );
540 void Window::RotationDone( int orientation, int width, int height )
542 mWindowSurface->RequestRotation( orientation, width, height );
544 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
547 mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
549 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
552 void Window::OnIconifyChanged( bool iconified )
560 WindowVisibilityObserver* observer( mAdaptor );
561 observer->OnWindowHidden();
564 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
572 WindowVisibilityObserver* observer( mAdaptor );
573 observer->OnWindowShown();
576 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
580 void Window::OnFocusChanged( bool focusIn )
582 mFocusChangedSignal.Emit( focusIn );
585 void Window::OnOutputTransformed()
587 PositionSize positionSize = mSurface->GetPositionSize();
588 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
589 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
592 void Window::OnDeleteRequest()
594 mDeleteRequestSignal.Emit();
597 void Window::FeedTouchPoint( TouchPoint& point, int timeStamp )
601 mEventHandler->FeedTouchPoint( point, timeStamp );
605 void Window::FeedWheelEvent( WheelEvent& wheelEvent )
609 mEventHandler->FeedWheelEvent( wheelEvent );
613 void Window::FeedKeyEvent( KeyEvent& keyEvent )
617 mEventHandler->FeedKeyEvent( keyEvent );
621 void Window::OnPause()
625 mEventHandler->Pause();
629 void Window::OnResume()
633 mEventHandler->Resume();
637 bool Window::SetRotationObserver( RotationObserver* observer )
641 mEventHandler->SetRotationObserver( observer );
648 Dali::Window Window::Get( Dali::Actor actor )
650 Internal::Adaptor::Window* windowImpl = nullptr;
652 if ( Internal::Adaptor::Adaptor::IsAvailable() )
654 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
655 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
658 return Dali::Window( windowImpl );