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>
31 #include <dali/integration-api/events/touch-event-integ.h>
33 #ifdef DALI_ADAPTOR_COMPILATION
34 #include <dali/integration-api/render-surface-interface.h>
36 #include <dali/integration-api/adaptors/render-surface-interface.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 ),
85 mFocusChangedSignal(),
87 mDeleteRequestSignal()
95 mEventHandler->RemoveObserver( *this );
99 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
101 // Create a window render surface
103 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
104 mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
105 mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
108 mWindowBase = mWindowSurface->GetWindowBase();
111 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
112 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
113 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
115 mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
117 if( !positionSize.IsEmpty() )
119 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
120 mResizeEnabled = true;
123 SetClass( name, className );
125 mWindowSurface->Map();
127 mOrientation = Orientation::New( this );
130 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
132 mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
133 mEventHandler->AddObserver( *this );
136 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
138 mWindowSurface = static_cast<WindowRenderSurface*>( surface );
141 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
145 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
149 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
153 void Window::SetClass( std::string name, std::string className )
156 mClassName = className;
157 mWindowBase->SetClass( name, className );
160 std::string Window::GetClassName() const
167 mWindowBase->Raise();
172 mWindowBase->Lower();
175 void Window::Activate()
177 mWindowBase->Activate();
180 uint32_t Window::GetLayerCount() const
182 return mScene.GetLayerCount();
185 Dali::Layer Window::GetLayer( uint32_t depth ) const
187 return mScene.GetLayer( depth );
190 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
194 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
196 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
198 if( mAvailableOrientations[i] == orientation )
207 mAvailableOrientations.push_back( orientation );
208 SetAvailableOrientations( mAvailableOrientations );
213 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
215 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
216 iter != mAvailableOrientations.end(); ++iter )
218 if( *iter == orientation )
220 mAvailableOrientations.erase( iter );
224 SetAvailableOrientations( mAvailableOrientations );
227 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
229 if( orientations.size() > 4 )
231 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
235 mAvailableOrientations = orientations;
237 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
240 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
242 return mAvailableOrientations;
245 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
247 mPreferredOrientation = orientation;
249 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
252 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
254 return mPreferredOrientation;
257 Dali::Any Window::GetNativeHandle() const
259 return mWindowSurface->GetNativeWindow();
262 void Window::SetAcceptFocus( bool accept )
264 mIsFocusAcceptable = accept;
266 mWindowBase->SetAcceptFocus( accept );
269 bool Window::IsFocusAcceptable() const
271 return mIsFocusAcceptable;
282 WindowVisibilityObserver* observer( mAdaptor );
283 observer->OnWindowShown();
286 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
297 WindowVisibilityObserver* observer( mAdaptor );
298 observer->OnWindowHidden();
301 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
304 bool Window::IsVisible() const
306 return mVisible && !mIconified;
309 unsigned int Window::GetSupportedAuxiliaryHintCount() const
311 return mWindowBase->GetSupportedAuxiliaryHintCount();
314 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
316 return mWindowBase->GetSupportedAuxiliaryHint( index );
319 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
321 return mWindowBase->AddAuxiliaryHint( hint, value );
324 bool Window::RemoveAuxiliaryHint( unsigned int id )
326 return mWindowBase->RemoveAuxiliaryHint( id );
329 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
331 return mWindowBase->SetAuxiliaryHintValue( id, value );
334 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
336 return mWindowBase->GetAuxiliaryHintValue( id );
339 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
341 return mWindowBase->GetAuxiliaryHintId( hint );
344 void Window::SetInputRegion( const Rect< int >& inputRegion )
346 mWindowBase->SetInputRegion( inputRegion );
348 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 );
351 void Window::SetType( Dali::Window::Type type )
355 mWindowBase->SetType( type );
361 Dali::Window::Type Window::GetType() const
366 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
368 if( mType != Dali::Window::NOTIFICATION )
370 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
374 return mWindowBase->SetNotificationLevel( level );
377 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
379 if( mType != Dali::Window::NOTIFICATION )
381 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
382 return Dali::Window::NotificationLevel::NONE;
385 return mWindowBase->GetNotificationLevel();
388 void Window::SetOpaqueState( bool opaque )
390 mOpaqueState = opaque;
392 mWindowBase->SetOpaqueState( opaque );
394 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
397 bool Window::IsOpaqueState() const
402 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
404 return mWindowBase->SetScreenOffMode( screenOffMode );
407 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
409 return mWindowBase->GetScreenOffMode();
412 bool Window::SetBrightness( int brightness )
414 if( brightness < 0 || brightness > 100 )
416 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
420 return mWindowBase->SetBrightness( brightness );
423 int Window::GetBrightness() const
425 return mWindowBase->GetBrightness();
428 void Window::SetSize( Dali::Window::WindowSize size )
430 if( !mResizeEnabled )
432 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
433 mResizeEnabled = true;
436 PositionSize oldRect = mSurface->GetPositionSize();
438 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
440 PositionSize newRect = mSurface->GetPositionSize();
442 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
443 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
445 Uint16Pair newSize( newRect.width, newRect.height );
447 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
449 mResizedSignal.Emit( newSize );
451 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
455 Dali::Window::WindowSize Window::GetSize() const
457 PositionSize positionSize = mSurface->GetPositionSize();
459 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
462 void Window::SetPosition( Dali::Window::WindowPosition position )
464 if( !mResizeEnabled )
466 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
467 mResizeEnabled = true;
470 PositionSize oldRect = mSurface->GetPositionSize();
472 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
475 Dali::Window::WindowPosition Window::GetPosition() const
477 PositionSize positionSize = mSurface->GetPositionSize();
479 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
482 void Window::SetPositionSize( PositionSize positionSize )
484 if( !mResizeEnabled )
486 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
487 mResizeEnabled = true;
490 PositionSize oldRect = mSurface->GetPositionSize();
492 mWindowSurface->MoveResize( positionSize );
494 PositionSize newRect = mSurface->GetPositionSize();
496 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
497 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
499 Uint16Pair newSize( newRect.width, newRect.height );
501 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
503 mResizedSignal.Emit( newSize );
505 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
509 Dali::Layer Window::GetRootLayer() const
511 return mScene.GetRootLayer();
514 void Window::SetTransparency( bool transparent )
516 mWindowSurface->SetTransparency( transparent );
519 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
521 return mWindowBase->GrabKey( key, grabMode );
524 bool Window::UngrabKey( Dali::KEY key )
526 return mWindowBase->UngrabKey( key );
529 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
531 return mWindowBase->GrabKeyList( key, grabMode, result );
534 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
536 return mWindowBase->UngrabKeyList( key, result );
539 void Window::OnIconifyChanged( bool iconified )
547 WindowVisibilityObserver* observer( mAdaptor );
548 observer->OnWindowHidden();
551 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
559 WindowVisibilityObserver* observer( mAdaptor );
560 observer->OnWindowShown();
563 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
567 void Window::OnFocusChanged( bool focusIn )
569 mFocusChangedSignal.Emit( focusIn );
572 void Window::OnOutputTransformed()
574 PositionSize positionSize = mSurface->GetPositionSize();
575 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
576 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
579 void Window::OnDeleteRequest()
581 mDeleteRequestSignal.Emit();
584 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
586 FeedTouchPoint( point, timeStamp );
589 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
591 FeedWheelEvent( wheelEvent );
594 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
596 FeedKeyEvent( keyEvent );
599 void Window::OnRotation( const RotationEvent& rotation )
601 mRotationAngle = rotation.angle;
602 mWindowWidth = rotation.width;
603 mWindowHeight = rotation.height;
605 // Notify that the orientation is changed
606 mOrientation->OnOrientationChange( rotation );
608 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
610 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mRotationAngle, mWindowHeight ) );
613 mResizedSignal.Emit( Dali::Window::WindowSize( mRotationAngle, mWindowHeight ) );
615 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mRotationAngle, mWindowHeight ) );
618 void Window::OnPause()
622 mEventHandler->Pause();
626 void Window::OnResume()
630 mEventHandler->Resume();
634 void Window::RecalculateTouchPosition( Integration::Point& point )
636 Vector2 position = point.GetScreenPosition();
637 Vector2 convertedPosition;
639 switch( mRotationAngle )
643 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
644 convertedPosition.y = position.x;
649 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
650 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
655 convertedPosition.x = position.y;
656 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
661 convertedPosition = position;
666 point.SetScreenPosition( convertedPosition );
669 Dali::Window Window::Get( Dali::Actor actor )
671 Internal::Adaptor::Window* windowImpl = nullptr;
673 if ( Internal::Adaptor::Adaptor::IsAvailable() )
675 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
676 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
679 return Dali::Window( windowImpl );