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/public-api/actors/actor.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/actors/camera-actor.h>
26 #include <dali/public-api/render-tasks/render-task.h>
27 #include <dali/public-api/render-tasks/render-task-list.h>
28 #include <dali/public-api/rendering/frame-buffer.h>
29 #include <dali/devel-api/adaptor-framework/orientation.h>
30 #include <dali/integration-api/events/touch-event-integ.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 ),
84 mFocusChangedSignal(),
86 mDeleteRequestSignal()
94 mEventHandler->RemoveObserver( *this );
98 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
100 // Create a window render surface
102 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
103 mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
104 mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
107 mWindowBase = mWindowSurface->GetWindowBase();
110 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
111 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
112 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
114 mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
116 if( !positionSize.IsEmpty() )
118 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
119 mResizeEnabled = true;
122 SetClass( name, className );
124 mWindowSurface->Map();
126 mOrientation = Orientation::New( this );
129 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
131 mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
132 mEventHandler->AddObserver( *this );
135 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
137 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
140 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
144 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
148 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
152 void Window::SetClass( std::string name, std::string className )
155 mClassName = className;
156 mWindowBase->SetClass( name, className );
159 std::string Window::GetClassName() const
166 mWindowBase->Raise();
167 DALI_LOG_RELEASE_INFO( "Window (%p) Raise() \n", this );
172 mWindowBase->Lower();
173 DALI_LOG_RELEASE_INFO( "Window (%p) Lower() \n", this );
176 void Window::Activate()
178 mWindowBase->Activate();
179 DALI_LOG_RELEASE_INFO( "Window (%p) Activate() \n", this );
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 Dali::RenderTaskList Window::GetRenderTaskList() const
194 return mScene.GetRenderTaskList();
197 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
201 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
203 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
205 if( mAvailableOrientations[i] == orientation )
214 mAvailableOrientations.push_back( orientation );
215 SetAvailableOrientations( mAvailableOrientations );
220 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
222 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
223 iter != mAvailableOrientations.end(); ++iter )
225 if( *iter == orientation )
227 mAvailableOrientations.erase( iter );
231 SetAvailableOrientations( mAvailableOrientations );
234 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
236 if( orientations.size() > 4 )
238 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
242 mAvailableOrientations = orientations;
244 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
247 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
249 return mAvailableOrientations;
252 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
254 mPreferredOrientation = orientation;
256 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
259 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
261 return mPreferredOrientation;
264 Dali::Any Window::GetNativeHandle() const
266 return mWindowSurface->GetNativeWindow();
269 void Window::SetAcceptFocus( bool accept )
271 mIsFocusAcceptable = accept;
273 mWindowBase->SetAcceptFocus( accept );
276 bool Window::IsFocusAcceptable() const
278 return mIsFocusAcceptable;
289 WindowVisibilityObserver* observer( mAdaptor );
290 observer->OnWindowShown();
293 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
304 WindowVisibilityObserver* observer( mAdaptor );
305 observer->OnWindowHidden();
308 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
311 bool Window::IsVisible() const
313 return mVisible && !mIconified;
316 unsigned int Window::GetSupportedAuxiliaryHintCount() const
318 return mWindowBase->GetSupportedAuxiliaryHintCount();
321 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
323 return mWindowBase->GetSupportedAuxiliaryHint( index );
326 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
328 return mWindowBase->AddAuxiliaryHint( hint, value );
331 bool Window::RemoveAuxiliaryHint( unsigned int id )
333 return mWindowBase->RemoveAuxiliaryHint( id );
336 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
338 return mWindowBase->SetAuxiliaryHintValue( id, value );
341 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
343 return mWindowBase->GetAuxiliaryHintValue( id );
346 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
348 return mWindowBase->GetAuxiliaryHintId( hint );
351 void Window::SetInputRegion( const Rect< int >& inputRegion )
353 mWindowBase->SetInputRegion( inputRegion );
355 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 );
358 void Window::SetType( Dali::Window::Type type )
362 mWindowBase->SetType( type );
368 Dali::Window::Type Window::GetType() const
373 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
375 if( mType != Dali::Window::NOTIFICATION )
377 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
381 return mWindowBase->SetNotificationLevel( level );
384 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
386 if( mType != Dali::Window::NOTIFICATION )
388 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
389 return Dali::Window::NotificationLevel::NONE;
392 return mWindowBase->GetNotificationLevel();
395 void Window::SetOpaqueState( bool opaque )
397 mOpaqueState = opaque;
399 mWindowBase->SetOpaqueState( opaque );
401 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
404 bool Window::IsOpaqueState() const
409 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
411 return mWindowBase->SetScreenOffMode( screenOffMode );
414 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
416 return mWindowBase->GetScreenOffMode();
419 bool Window::SetBrightness( int brightness )
421 if( brightness < 0 || brightness > 100 )
423 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
427 return mWindowBase->SetBrightness( brightness );
430 int Window::GetBrightness() const
432 return mWindowBase->GetBrightness();
435 void Window::SetSize( Dali::Window::WindowSize size )
437 if( !mResizeEnabled )
439 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
440 mResizeEnabled = true;
443 PositionSize oldRect = mSurface->GetPositionSize();
445 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
447 PositionSize newRect = mSurface->GetPositionSize();
449 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
450 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
452 Uint16Pair newSize( newRect.width, newRect.height );
456 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
458 mResizedSignal.Emit( newSize );
460 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
464 Dali::Window::WindowSize Window::GetSize() const
466 PositionSize positionSize = mSurface->GetPositionSize();
468 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
471 void Window::SetPosition( Dali::Window::WindowPosition position )
473 if( !mResizeEnabled )
475 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
476 mResizeEnabled = true;
479 PositionSize oldRect = mSurface->GetPositionSize();
481 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
484 Dali::Window::WindowPosition Window::GetPosition() const
486 PositionSize positionSize = mSurface->GetPositionSize();
488 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
491 void Window::SetPositionSize( PositionSize positionSize )
493 if( !mResizeEnabled )
495 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
496 mResizeEnabled = true;
499 PositionSize oldRect = mSurface->GetPositionSize();
501 mWindowSurface->MoveResize( positionSize );
503 PositionSize newRect = mSurface->GetPositionSize();
505 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
506 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
508 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::OnIconifyChanged( bool iconified )
558 WindowVisibilityObserver* observer( mAdaptor );
559 observer->OnWindowHidden();
562 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
570 WindowVisibilityObserver* observer( mAdaptor );
571 observer->OnWindowShown();
574 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
578 void Window::OnFocusChanged( bool focusIn )
580 mFocusChangedSignal.Emit( focusIn );
583 void Window::OnOutputTransformed()
585 PositionSize positionSize = mSurface->GetPositionSize();
587 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
588 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
591 void Window::OnDeleteRequest()
593 mDeleteRequestSignal.Emit();
596 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
598 FeedTouchPoint( point, timeStamp );
601 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
603 FeedWheelEvent( wheelEvent );
606 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
608 FeedKeyEvent( keyEvent );
611 void Window::OnRotation( const RotationEvent& rotation )
613 mRotationAngle = rotation.angle;
614 mWindowWidth = rotation.width;
615 mWindowHeight = rotation.height;
617 // Notify that the orientation is changed
618 mOrientation->OnOrientationChange( rotation );
620 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
624 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mRotationAngle, mWindowHeight ) );
627 mResizedSignal.Emit( Dali::Window::WindowSize( mRotationAngle, mWindowHeight ) );
629 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mRotationAngle, mWindowHeight ) );
632 void Window::OnPause()
636 mEventHandler->Pause();
640 void Window::OnResume()
644 mEventHandler->Resume();
648 void Window::RecalculateTouchPosition( Integration::Point& point )
650 Vector2 position = point.GetScreenPosition();
651 Vector2 convertedPosition;
653 switch( mRotationAngle )
657 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
658 convertedPosition.y = position.x;
663 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
664 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
669 convertedPosition.x = position.y;
670 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
675 convertedPosition = position;
680 point.SetScreenPosition( convertedPosition );
683 Dali::Window Window::Get( Dali::Actor actor )
685 Internal::Adaptor::Window* windowImpl = nullptr;
687 if ( Internal::Adaptor::Adaptor::IsAvailable() )
689 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
690 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
693 return Dali::Window( windowImpl );