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>
33 #include <dali/internal/input/common/drag-and-drop-detector-impl.h>
34 #include <dali/internal/window-system/common/window-visibility-observer.h>
35 #include <dali/internal/window-system/common/orientation-impl.h>
36 #include <dali/internal/window-system/common/render-surface-factory.h>
37 #include <dali/internal/window-system/common/window-factory.h>
38 #include <dali/internal/window-system/common/window-base.h>
39 #include <dali/internal/window-system/common/window-render-surface.h>
48 uint32_t Window::mWindowCounter = 0;
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW" );
57 } // unnamed namespace
59 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
61 Window* window = new Window();
62 window->mIsTransparent = isTransparent;
63 window->Initialize( positionSize, name, className );
68 : mId( mWindowCounter++ ),
72 mIsFocusAcceptable( true ),
75 mOpaqueState( false ),
76 mResizeEnabled( false ),
78 mType( Dali::Window::NORMAL ),
79 mPreferredOrientation( Dali::Window::PORTRAIT ),
80 mFocusChangedSignal(),
82 mDeleteRequestSignal()
90 mAdaptor->RemoveObserver( *this );
91 mAdaptor->SetDragAndDropDetector( NULL );
92 mAdaptor->RemoveWindow( this );
96 mSurface.reset( nullptr );
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 );
107 mWindowBase = mSurface->GetWindowBase();
110 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
111 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
112 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
114 mSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
116 if( !positionSize.IsEmpty() )
118 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
119 mResizeEnabled = true;
122 SetClass( name, className );
126 mOrientation = Orientation::New( this );
129 void Window::SetAdaptor(Dali::Adaptor& adaptor)
131 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
134 PositionSize positionSize = mSurface->GetPositionSize();
135 mScene = Dali::Integration::Scene::New( Vector2(positionSize.width, positionSize.height) );
136 mScene.SetSurface( *mSurface.get() );
138 unsigned int dpiHorizontal, dpiVertical;
139 dpiHorizontal = dpiVertical = 0;
141 mSurface->GetDpi( dpiHorizontal, dpiVertical );
142 mScene.SetDpi( Vector2( static_cast<float>( dpiHorizontal ), static_cast<float>( dpiVertical ) ) );
144 // Create one overlay for the main window only
145 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
146 mAdaptor = &adaptorImpl;
147 mAdaptor->AddObserver( *this );
149 // Can only create the detector when we know the Core has been instantiated.
150 mDragAndDropDetector = DragAndDropDetector::New();
151 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
155 mOrientation->SetAdaptor(adaptor);
158 mSurface->SetAdaptor( *mAdaptor );
161 WindowRenderSurface* Window::GetSurface()
163 return mSurface.get();
166 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
170 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
174 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
178 void Window::SetClass( std::string name, std::string className )
180 mWindowBase->SetClass( name, className );
185 mWindowBase->Raise();
190 mWindowBase->Lower();
193 void Window::Activate()
195 mWindowBase->Activate();
198 void Window::Add( Dali::Actor actor )
203 void Window::Remove( Dali::Actor actor )
205 mScene.Remove( actor );
208 Dali::Layer Window::GetRootLayer() const
210 return mScene.GetRootLayer();
213 uint32_t Window::GetLayerCount() const
215 return mScene.GetLayerCount();
218 Dali::Layer Window::GetLayer( uint32_t depth ) const
220 return mScene.GetLayer( depth );
223 void Window::SetBackgroundColor( Vector4 color )
227 mSurface->SetBackgroundColor( color );
231 Vector4 Window::GetBackgroundColor() const
233 return mSurface ? mSurface->GetBackgroundColor() : Vector4();
236 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
240 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
242 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
244 if( mAvailableOrientations[i] == orientation )
253 mAvailableOrientations.push_back( orientation );
254 SetAvailableOrientations( mAvailableOrientations );
259 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
261 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
262 iter != mAvailableOrientations.end(); ++iter )
264 if( *iter == orientation )
266 mAvailableOrientations.erase( iter );
270 SetAvailableOrientations( mAvailableOrientations );
273 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
275 if( orientations.size() > 4 )
277 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
281 mAvailableOrientations = orientations;
283 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
286 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
288 return mAvailableOrientations;
291 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
293 mPreferredOrientation = orientation;
295 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
298 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
300 return mPreferredOrientation;
303 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
305 return mDragAndDropDetector;
308 Dali::Any Window::GetNativeHandle() const
310 return mSurface->GetNativeWindow();
313 void Window::SetAcceptFocus( bool accept )
315 mIsFocusAcceptable = accept;
317 mWindowBase->SetAcceptFocus( accept );
320 bool Window::IsFocusAcceptable() const
322 return mIsFocusAcceptable;
333 WindowVisibilityObserver* observer( mAdaptor );
334 observer->OnWindowShown();
335 DALI_LOG_RELEASE_INFO( "Window (%p) ::Show()\n", this );
347 WindowVisibilityObserver* observer( mAdaptor );
348 observer->OnWindowHidden();
349 DALI_LOG_RELEASE_INFO( "Window (%p) ::Hide() \n", this );
353 bool Window::IsVisible() const
358 unsigned int Window::GetSupportedAuxiliaryHintCount() const
360 return mWindowBase->GetSupportedAuxiliaryHintCount();
363 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
365 return mWindowBase->GetSupportedAuxiliaryHint( index );
368 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
370 return mWindowBase->AddAuxiliaryHint( hint, value );
373 bool Window::RemoveAuxiliaryHint( unsigned int id )
375 return mWindowBase->RemoveAuxiliaryHint( id );
378 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
380 return mWindowBase->SetAuxiliaryHintValue( id, value );
383 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
385 return mWindowBase->GetAuxiliaryHintValue( id );
388 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
390 return mWindowBase->GetAuxiliaryHintId( hint );
393 void Window::SetInputRegion( const Rect< int >& inputRegion )
395 mWindowBase->SetInputRegion( inputRegion );
397 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 );
400 void Window::SetType( Dali::Window::Type type )
404 mWindowBase->SetType( type );
410 Dali::Window::Type Window::GetType() const
415 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
417 if( mType != Dali::Window::NOTIFICATION )
419 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
423 return mWindowBase->SetNotificationLevel( level );
426 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
428 if( mType != Dali::Window::NOTIFICATION )
430 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
431 return Dali::Window::NotificationLevel::NONE;
434 return mWindowBase->GetNotificationLevel();
437 void Window::SetOpaqueState( bool opaque )
439 mOpaqueState = opaque;
441 mWindowBase->SetOpaqueState( opaque );
443 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
446 bool Window::IsOpaqueState() const
451 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
453 return mWindowBase->SetScreenOffMode( screenOffMode );
456 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
458 return mWindowBase->GetScreenOffMode();
461 bool Window::SetBrightness( int brightness )
463 if( brightness < 0 || brightness > 100 )
465 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
469 return mWindowBase->SetBrightness( brightness );
472 int Window::GetBrightness() const
474 return mWindowBase->GetBrightness();
477 void Window::SetSize( Dali::Window::WindowSize size )
479 if( !mResizeEnabled )
481 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
482 mResizeEnabled = true;
485 PositionSize oldRect = mSurface->GetPositionSize();
487 mSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
489 PositionSize newRect = mSurface->GetPositionSize();
491 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
492 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
494 Uint16Pair newSize( newRect.width, newRect.height );
496 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
498 mResizedSignal.Emit( newSize );
500 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
504 Dali::Window::WindowSize Window::GetSize() const
506 PositionSize positionSize = mSurface->GetPositionSize();
508 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
511 void Window::SetPosition( Dali::Window::WindowPosition position )
513 if( !mResizeEnabled )
515 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
516 mResizeEnabled = true;
519 PositionSize oldRect = mSurface->GetPositionSize();
521 mSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
524 Dali::Window::WindowPosition Window::GetPosition() const
526 PositionSize positionSize = mSurface->GetPositionSize();
528 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
531 void Window::SetPositionSize( PositionSize positionSize )
533 if( !mResizeEnabled )
535 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
536 mResizeEnabled = true;
539 PositionSize oldRect = mSurface->GetPositionSize();
541 mSurface->MoveResize( positionSize );
543 PositionSize newRect = mSurface->GetPositionSize();
545 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
546 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
548 Uint16Pair newSize( newRect.width, newRect.height );
550 mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
552 mResizedSignal.Emit( newSize );
554 mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
558 void Window::SetTransparency( bool transparent )
560 mSurface->SetTransparency( transparent );
563 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
565 return mWindowBase->GrabKey( key, grabMode );
568 bool Window::UngrabKey( Dali::KEY key )
570 return mWindowBase->UngrabKey( key );
573 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
575 return mWindowBase->GrabKeyList( key, grabMode, result );
578 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
580 return mWindowBase->UngrabKeyList( key, result );
583 void Window::RotationDone( int orientation, int width, int height )
585 mSurface->RequestRotation( orientation, width, height );
587 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
590 mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
592 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
595 void Window::OnIconifyChanged( bool iconified )
603 WindowVisibilityObserver* observer( mAdaptor );
604 observer->OnWindowHidden();
605 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified\n", this );
614 WindowVisibilityObserver* observer( mAdaptor );
615 observer->OnWindowShown();
616 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified\n", this );
621 void Window::OnFocusChanged( bool focusIn )
623 mFocusChangedSignal.Emit( focusIn );
626 void Window::OnOutputTransformed()
628 PositionSize positionSize = mSurface->GetPositionSize();
629 mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
630 mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
633 void Window::OnDeleteRequest()
635 mDeleteRequestSignal.Emit();
638 void Window::OnStart()
642 void Window::OnPause()
646 void Window::OnResume()
650 void Window::OnStop()
654 void Window::OnDestroy()
659 uint32_t Window::GetId() const