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();
171 mWindowBase->Lower();
174 void Window::Activate()
176 mWindowBase->Activate();
179 uint32_t Window::GetLayerCount() const
181 return mScene.GetLayerCount();
184 Dali::Layer Window::GetLayer( uint32_t depth ) const
186 return mScene.GetLayer( depth );
189 Dali::RenderTaskList Window::GetRenderTaskList() const
191 return mScene.GetRenderTaskList();
194 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
198 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
200 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
202 if( mAvailableOrientations[i] == orientation )
211 mAvailableOrientations.push_back( orientation );
212 SetAvailableOrientations( mAvailableOrientations );
217 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
219 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
220 iter != mAvailableOrientations.end(); ++iter )
222 if( *iter == orientation )
224 mAvailableOrientations.erase( iter );
228 SetAvailableOrientations( mAvailableOrientations );
231 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
233 if( orientations.size() > 4 )
235 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
239 mAvailableOrientations = orientations;
241 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
244 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
246 return mAvailableOrientations;
249 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
251 mPreferredOrientation = orientation;
253 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
256 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
258 return mPreferredOrientation;
261 Dali::Any Window::GetNativeHandle() const
263 return mWindowSurface->GetNativeWindow();
266 void Window::SetAcceptFocus( bool accept )
268 mIsFocusAcceptable = accept;
270 mWindowBase->SetAcceptFocus( accept );
273 bool Window::IsFocusAcceptable() const
275 return mIsFocusAcceptable;
286 WindowVisibilityObserver* observer( mAdaptor );
287 observer->OnWindowShown();
290 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
301 WindowVisibilityObserver* observer( mAdaptor );
302 observer->OnWindowHidden();
305 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
308 bool Window::IsVisible() const
310 return mVisible && !mIconified;
313 unsigned int Window::GetSupportedAuxiliaryHintCount() const
315 return mWindowBase->GetSupportedAuxiliaryHintCount();
318 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
320 return mWindowBase->GetSupportedAuxiliaryHint( index );
323 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
325 return mWindowBase->AddAuxiliaryHint( hint, value );
328 bool Window::RemoveAuxiliaryHint( unsigned int id )
330 return mWindowBase->RemoveAuxiliaryHint( id );
333 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
335 return mWindowBase->SetAuxiliaryHintValue( id, value );
338 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
340 return mWindowBase->GetAuxiliaryHintValue( id );
343 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
345 return mWindowBase->GetAuxiliaryHintId( hint );
348 void Window::SetInputRegion( const Rect< int >& inputRegion )
350 mWindowBase->SetInputRegion( inputRegion );
352 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 );
355 void Window::SetType( Dali::Window::Type type )
359 mWindowBase->SetType( type );
365 Dali::Window::Type Window::GetType() const
370 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
372 if( mType != Dali::Window::NOTIFICATION )
374 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
378 return mWindowBase->SetNotificationLevel( level );
381 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
383 if( mType != Dali::Window::NOTIFICATION )
385 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
386 return Dali::Window::NotificationLevel::NONE;
389 return mWindowBase->GetNotificationLevel();
392 void Window::SetOpaqueState( bool opaque )
394 mOpaqueState = opaque;
396 mWindowBase->SetOpaqueState( opaque );
398 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
401 bool Window::IsOpaqueState() const
406 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
408 return mWindowBase->SetScreenOffMode( screenOffMode );
411 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
413 return mWindowBase->GetScreenOffMode();
416 bool Window::SetBrightness( int brightness )
418 if( brightness < 0 || brightness > 100 )
420 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
424 return mWindowBase->SetBrightness( brightness );
427 int Window::GetBrightness() const
429 return mWindowBase->GetBrightness();
432 void Window::SetSize( Dali::Window::WindowSize size )
434 if( !mResizeEnabled )
436 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
437 mResizeEnabled = true;
440 PositionSize oldRect = mSurface->GetPositionSize();
442 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
444 PositionSize newRect = mSurface->GetPositionSize();
446 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
447 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
449 Uint16Pair newSize( newRect.width, newRect.height );
451 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
453 mResizedSignal.Emit( newSize );
455 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
459 Dali::Window::WindowSize Window::GetSize() const
461 PositionSize positionSize = mSurface->GetPositionSize();
463 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
466 void Window::SetPosition( Dali::Window::WindowPosition position )
468 if( !mResizeEnabled )
470 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
471 mResizeEnabled = true;
474 PositionSize oldRect = mSurface->GetPositionSize();
476 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
479 Dali::Window::WindowPosition Window::GetPosition() const
481 PositionSize positionSize = mSurface->GetPositionSize();
483 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
486 void Window::SetPositionSize( PositionSize positionSize )
488 if( !mResizeEnabled )
490 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
491 mResizeEnabled = true;
494 PositionSize oldRect = mSurface->GetPositionSize();
496 mWindowSurface->MoveResize( positionSize );
498 PositionSize newRect = mSurface->GetPositionSize();
500 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
501 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
503 Uint16Pair newSize( newRect.width, newRect.height );
505 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
507 mResizedSignal.Emit( newSize );
509 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
513 Dali::Layer Window::GetRootLayer() const
515 return mScene.GetRootLayer();
518 void Window::SetTransparency( bool transparent )
520 mWindowSurface->SetTransparency( transparent );
523 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
525 return mWindowBase->GrabKey( key, grabMode );
528 bool Window::UngrabKey( Dali::KEY key )
530 return mWindowBase->UngrabKey( key );
533 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
535 return mWindowBase->GrabKeyList( key, grabMode, result );
538 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
540 return mWindowBase->UngrabKeyList( key, result );
543 void Window::OnIconifyChanged( bool iconified )
551 WindowVisibilityObserver* observer( mAdaptor );
552 observer->OnWindowHidden();
555 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
563 WindowVisibilityObserver* observer( mAdaptor );
564 observer->OnWindowShown();
567 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
571 void Window::OnFocusChanged( bool focusIn )
573 mFocusChangedSignal.Emit( focusIn );
576 void Window::OnOutputTransformed()
578 PositionSize positionSize = mSurface->GetPositionSize();
579 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
580 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
583 void Window::OnDeleteRequest()
585 mDeleteRequestSignal.Emit();
588 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
590 FeedTouchPoint( point, timeStamp );
593 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
595 FeedWheelEvent( wheelEvent );
598 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
600 FeedKeyEvent( keyEvent );
603 void Window::OnRotation( const RotationEvent& rotation )
605 mRotationAngle = rotation.angle;
606 mWindowWidth = rotation.width;
607 mWindowHeight = rotation.height;
609 // Notify that the orientation is changed
610 mOrientation->OnOrientationChange( rotation );
612 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
614 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mRotationAngle, mWindowHeight ) );
617 mResizedSignal.Emit( Dali::Window::WindowSize( mRotationAngle, mWindowHeight ) );
619 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mRotationAngle, mWindowHeight ) );
622 void Window::OnPause()
626 mEventHandler->Pause();
630 void Window::OnResume()
634 mEventHandler->Resume();
638 void Window::RecalculateTouchPosition( Integration::Point& point )
640 Vector2 position = point.GetScreenPosition();
641 Vector2 convertedPosition;
643 switch( mRotationAngle )
647 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
648 convertedPosition.y = position.x;
653 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
654 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
659 convertedPosition.x = position.y;
660 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
665 convertedPosition = position;
670 point.SetScreenPosition( convertedPosition );
673 Dali::Window Window::Get( Dali::Actor actor )
675 Internal::Adaptor::Window* windowImpl = nullptr;
677 if ( Internal::Adaptor::Adaptor::IsAvailable() )
679 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
680 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
683 return Dali::Window( windowImpl );