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 mParentWindow( NULL ),
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();
168 DALI_LOG_RELEASE_INFO( "Window (%p) Raise() \n", this );
173 mWindowBase->Lower();
174 DALI_LOG_RELEASE_INFO( "Window (%p) Lower() \n", this );
177 void Window::Activate()
179 mWindowBase->Activate();
180 DALI_LOG_RELEASE_INFO( "Window (%p) Activate() \n", this );
183 uint32_t Window::GetLayerCount() const
185 return mScene.GetLayerCount();
188 Dali::Layer Window::GetLayer( uint32_t depth ) const
190 return mScene.GetLayer( depth );
193 Dali::RenderTaskList Window::GetRenderTaskList() const
195 return mScene.GetRenderTaskList();
198 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
202 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
204 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
206 if( mAvailableOrientations[i] == orientation )
215 mAvailableOrientations.push_back( orientation );
216 SetAvailableOrientations( mAvailableOrientations );
221 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
223 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
224 iter != mAvailableOrientations.end(); ++iter )
226 if( *iter == orientation )
228 mAvailableOrientations.erase( iter );
232 SetAvailableOrientations( mAvailableOrientations );
235 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
237 if( orientations.size() > 4 )
239 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
243 mAvailableOrientations = orientations;
245 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
248 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
250 return mAvailableOrientations;
253 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
255 mPreferredOrientation = orientation;
257 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
260 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
262 return mPreferredOrientation;
265 Dali::Any Window::GetNativeHandle() const
267 return mWindowSurface->GetNativeWindow();
270 void Window::SetAcceptFocus( bool accept )
272 mIsFocusAcceptable = accept;
274 mWindowBase->SetAcceptFocus( accept );
277 bool Window::IsFocusAcceptable() const
279 return mIsFocusAcceptable;
290 WindowVisibilityObserver* observer( mAdaptor );
291 observer->OnWindowShown();
294 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
305 WindowVisibilityObserver* observer( mAdaptor );
306 observer->OnWindowHidden();
309 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
312 bool Window::IsVisible() const
314 return mVisible && !mIconified;
317 unsigned int Window::GetSupportedAuxiliaryHintCount() const
319 return mWindowBase->GetSupportedAuxiliaryHintCount();
322 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
324 return mWindowBase->GetSupportedAuxiliaryHint( index );
327 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
329 return mWindowBase->AddAuxiliaryHint( hint, value );
332 bool Window::RemoveAuxiliaryHint( unsigned int id )
334 return mWindowBase->RemoveAuxiliaryHint( id );
337 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
339 return mWindowBase->SetAuxiliaryHintValue( id, value );
342 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
344 return mWindowBase->GetAuxiliaryHintValue( id );
347 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
349 return mWindowBase->GetAuxiliaryHintId( hint );
352 void Window::SetInputRegion( const Rect< int >& inputRegion )
354 mWindowBase->SetInputRegion( inputRegion );
356 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 );
359 void Window::SetType( Dali::Window::Type type )
363 mWindowBase->SetType( type );
369 Dali::Window::Type Window::GetType() const
374 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
376 if( mType != Dali::Window::NOTIFICATION )
378 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
382 return mWindowBase->SetNotificationLevel( level );
385 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
387 if( mType != Dali::Window::NOTIFICATION )
389 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
390 return Dali::Window::NotificationLevel::NONE;
393 return mWindowBase->GetNotificationLevel();
396 void Window::SetOpaqueState( bool opaque )
398 mOpaqueState = opaque;
400 mWindowBase->SetOpaqueState( opaque );
402 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
405 bool Window::IsOpaqueState() const
410 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
412 return mWindowBase->SetScreenOffMode( screenOffMode );
415 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
417 return mWindowBase->GetScreenOffMode();
420 bool Window::SetBrightness( int brightness )
422 if( brightness < 0 || brightness > 100 )
424 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
428 return mWindowBase->SetBrightness( brightness );
431 int Window::GetBrightness() const
433 return mWindowBase->GetBrightness();
436 void Window::SetSize( Dali::Window::WindowSize size )
438 if( !mResizeEnabled )
440 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
441 mResizeEnabled = true;
444 PositionSize oldRect = mSurface->GetPositionSize();
446 mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
448 PositionSize newRect = mSurface->GetPositionSize();
450 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
451 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
453 Uint16Pair newSize( newRect.width, newRect.height );
457 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
459 mResizedSignal.Emit( newSize );
461 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
465 Dali::Window::WindowSize Window::GetSize() const
467 PositionSize positionSize = mSurface->GetPositionSize();
469 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
472 void Window::SetPosition( Dali::Window::WindowPosition position )
474 if( !mResizeEnabled )
476 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
477 mResizeEnabled = true;
480 PositionSize oldRect = mSurface->GetPositionSize();
482 mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
485 Dali::Window::WindowPosition Window::GetPosition() const
487 PositionSize positionSize = mSurface->GetPositionSize();
489 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
492 void Window::SetPositionSize( PositionSize positionSize )
494 if( !mResizeEnabled )
496 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
497 mResizeEnabled = true;
500 PositionSize oldRect = mSurface->GetPositionSize();
502 mWindowSurface->MoveResize( positionSize );
504 PositionSize newRect = mSurface->GetPositionSize();
506 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
507 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
509 Uint16Pair newSize( newRect.width, newRect.height );
513 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
515 mResizedSignal.Emit( newSize );
517 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
521 Dali::Layer Window::GetRootLayer() const
523 return mScene.GetRootLayer();
526 void Window::SetTransparency( bool transparent )
528 mWindowSurface->SetTransparency( transparent );
531 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
533 return mWindowBase->GrabKey( key, grabMode );
536 bool Window::UngrabKey( Dali::KEY key )
538 return mWindowBase->UngrabKey( key );
541 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
543 return mWindowBase->GrabKeyList( key, grabMode, result );
546 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
548 return mWindowBase->UngrabKeyList( key, result );
551 void Window::OnIconifyChanged( bool iconified )
559 WindowVisibilityObserver* observer( mAdaptor );
560 observer->OnWindowHidden();
563 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
571 WindowVisibilityObserver* observer( mAdaptor );
572 observer->OnWindowShown();
575 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
579 void Window::OnFocusChanged( bool focusIn )
581 mFocusChangedSignal.Emit( focusIn );
584 void Window::OnOutputTransformed()
586 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::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
599 FeedTouchPoint( point, timeStamp );
602 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
604 FeedWheelEvent( wheelEvent );
607 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
609 FeedKeyEvent( keyEvent );
612 void Window::OnRotation( const RotationEvent& rotation )
614 mRotationAngle = rotation.angle;
615 mWindowWidth = rotation.width;
616 mWindowHeight = rotation.height;
618 // Notify that the orientation is changed
619 mOrientation->OnOrientationChange( rotation );
621 mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
625 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mRotationAngle, mWindowHeight ) );
628 mResizedSignal.Emit( Dali::Window::WindowSize( mRotationAngle, mWindowHeight ) );
630 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mRotationAngle, mWindowHeight ) );
633 void Window::OnPause()
637 mEventHandler->Pause();
641 void Window::OnResume()
645 mEventHandler->Resume();
649 void Window::RecalculateTouchPosition( Integration::Point& point )
651 Vector2 position = point.GetScreenPosition();
652 Vector2 convertedPosition;
654 switch( mRotationAngle )
658 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
659 convertedPosition.y = position.x;
664 convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
665 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
670 convertedPosition.x = position.y;
671 convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
676 convertedPosition = position;
681 point.SetScreenPosition( convertedPosition );
684 Dali::Window Window::Get( Dali::Actor actor )
686 Internal::Adaptor::Window* windowImpl = nullptr;
688 if ( Internal::Adaptor::Adaptor::IsAvailable() )
690 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
691 windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
694 return Dali::Window( windowImpl );
698 void Window::SetParent( Dali::Window& parent )
700 if ( DALI_UNLIKELY( parent ) )
702 mParentWindow = parent;
703 Dali::Window grandParent = Dali::DevelWindow::GetParent( parent );
704 // check circular parent window setting
705 if ( DALI_UNLIKELY( grandParent ) && mWindowBase->IsMatchedWindow( grandParent.GetNativeHandle() ) )
707 Dali::DevelWindow::Unparent( parent );
709 mWindowBase->SetParent( parent.GetNativeHandle() );
713 void Window::Unparent()
716 mWindowBase->SetParent( parent );
719 Dali::Window Window::GetParent()
721 return mParentWindow;