2 * Copyright (c) 2018 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/camera-actor.h>
25 #include <dali/public-api/render-tasks/render-task.h>
26 #include <dali/public-api/render-tasks/render-task-list.h>
27 #include <dali/devel-api/adaptor-framework/orientation.h>
30 #include <dali/internal/input/common/drag-and-drop-detector-impl.h>
31 #include <dali/internal/window-system/common/window-visibility-observer.h>
32 #include <dali/internal/window-system/common/orientation-impl.h>
33 #include <dali/internal/window-system/common/render-surface-factory.h>
34 #include <dali/internal/window-system/common/window-factory.h>
35 #include <dali/internal/window-system/common/window-base.h>
36 #include <dali/internal/window-system/common/window-render-surface.h>
48 #if defined(DEBUG_ENABLED)
49 Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW" );
52 } // unnamed namespace
54 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
56 Window* window = new Window();
57 window->mIsTransparent = isTransparent;
58 window->Initialize( positionSize, name, className );
66 mIsTransparent( false ),
67 mIsFocusAcceptable( true ),
70 mOpaqueState( false ),
71 mResizeEnabled( false ),
73 mType( Dali::Window::NORMAL ),
74 mPreferredOrientation( Dali::Window::PORTRAIT ),
75 mFocusChangedSignal(),
77 mDeleteRequestSignal()
85 mAdaptor->RemoveObserver( *this );
86 mAdaptor->SetDragAndDropDetector( NULL );
93 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
95 // Create a window render surface
97 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
98 auto windowRenderSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
99 mSurface = windowRenderSurface.release();
102 mWindowBase = mSurface->GetWindowBase();
105 mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
106 mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
107 mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
109 mSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
111 if( !positionSize.IsEmpty() )
113 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
114 mResizeEnabled = true;
117 SetClass( name, className );
121 mOrientation = Orientation::New( this );
124 void Window::SetAdaptor(Dali::Adaptor& adaptor)
126 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
129 // Create one overlay for the main window only
130 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
131 mAdaptor = &adaptorImpl;
132 mAdaptor->AddObserver( *this );
134 // Can only create the detector when we know the Core has been instantiated.
135 mDragAndDropDetector = DragAndDropDetector::New();
136 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
140 mOrientation->SetAdaptor(adaptor);
143 mSurface->SetAdaptor( *mAdaptor );
146 WindowRenderSurface* Window::GetSurface()
151 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
155 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
159 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
163 void Window::SetClass( std::string name, std::string className )
165 mWindowBase->SetClass( name, className );
170 mWindowBase->Raise();
175 mWindowBase->Lower();
178 void Window::Activate()
180 mWindowBase->Activate();
183 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
187 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
189 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
191 if( mAvailableOrientations[i] == orientation )
200 mAvailableOrientations.push_back( orientation );
201 SetAvailableOrientations( mAvailableOrientations );
206 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
208 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
209 iter != mAvailableOrientations.end(); ++iter )
211 if( *iter == orientation )
213 mAvailableOrientations.erase( iter );
217 SetAvailableOrientations( mAvailableOrientations );
220 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
222 if( orientations.size() > 4 )
224 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
228 mAvailableOrientations = orientations;
230 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
233 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
235 return mAvailableOrientations;
238 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
240 mPreferredOrientation = orientation;
242 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
245 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
247 return mPreferredOrientation;
250 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
252 return mDragAndDropDetector;
255 Dali::Any Window::GetNativeHandle() const
257 return mSurface->GetNativeWindow();
260 void Window::SetAcceptFocus( bool accept )
262 mIsFocusAcceptable = accept;
264 mWindowBase->SetAcceptFocus( accept );
267 bool Window::IsFocusAcceptable() const
269 return mIsFocusAcceptable;
280 WindowVisibilityObserver* observer( mAdaptor );
281 observer->OnWindowShown();
284 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
295 WindowVisibilityObserver* observer( mAdaptor );
296 observer->OnWindowHidden();
299 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
302 bool Window::IsVisible() const
307 unsigned int Window::GetSupportedAuxiliaryHintCount() const
309 return mWindowBase->GetSupportedAuxiliaryHintCount();
312 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
314 return mWindowBase->GetSupportedAuxiliaryHint( index );
317 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
319 return mWindowBase->AddAuxiliaryHint( hint, value );
322 bool Window::RemoveAuxiliaryHint( unsigned int id )
324 return mWindowBase->RemoveAuxiliaryHint( id );
327 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
329 return mWindowBase->SetAuxiliaryHintValue( id, value );
332 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
334 return mWindowBase->GetAuxiliaryHintValue( id );
337 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
339 return mWindowBase->GetAuxiliaryHintId( hint );
342 void Window::SetInputRegion( const Rect< int >& inputRegion )
344 mWindowBase->SetInputRegion( inputRegion );
346 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 );
349 void Window::SetType( Dali::Window::Type type )
353 mWindowBase->SetType( type );
359 Dali::Window::Type Window::GetType() const
364 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
366 if( mType != Dali::Window::NOTIFICATION )
368 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
372 return mWindowBase->SetNotificationLevel( level );
375 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
377 if( mType != Dali::Window::NOTIFICATION )
379 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
380 return Dali::Window::NotificationLevel::NONE;
383 return mWindowBase->GetNotificationLevel();
386 void Window::SetOpaqueState( bool opaque )
388 mOpaqueState = opaque;
390 mWindowBase->SetOpaqueState( opaque );
392 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
395 bool Window::IsOpaqueState() const
400 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
402 return mWindowBase->SetScreenOffMode( screenOffMode );
405 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
407 return mWindowBase->GetScreenOffMode();
410 bool Window::SetBrightness( int brightness )
412 if( brightness < 0 || brightness > 100 )
414 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
418 return mWindowBase->SetBrightness( brightness );
421 int Window::GetBrightness() const
423 return mWindowBase->GetBrightness();
426 void Window::SetSize( Dali::Window::WindowSize size )
428 if( !mResizeEnabled )
430 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
431 mResizeEnabled = true;
434 PositionSize oldRect = mSurface->GetPositionSize();
436 mSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
438 PositionSize newRect = mSurface->GetPositionSize();
440 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
441 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
443 Uint16Pair newSize( newRect.width, newRect.height );
445 mAdaptor->SurfaceResizePrepare( newSize );
447 mResizedSignal.Emit( newSize );
449 mAdaptor->SurfaceResizeComplete( newSize );
453 Dali::Window::WindowSize Window::GetSize() const
455 PositionSize positionSize = mSurface->GetPositionSize();
457 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
460 void Window::SetPosition( Dali::Window::WindowPosition position )
462 if( !mResizeEnabled )
464 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
465 mResizeEnabled = true;
468 PositionSize oldRect = mSurface->GetPositionSize();
470 mSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
473 Dali::Window::WindowPosition Window::GetPosition() const
475 PositionSize positionSize = mSurface->GetPositionSize();
477 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
480 void Window::SetPositionSize( PositionSize positionSize )
482 if( !mResizeEnabled )
484 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
485 mResizeEnabled = true;
488 PositionSize oldRect = mSurface->GetPositionSize();
490 mSurface->MoveResize( positionSize );
492 PositionSize newRect = mSurface->GetPositionSize();
494 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
495 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
497 Uint16Pair newSize( newRect.width, newRect.height );
499 mAdaptor->SurfaceResizePrepare( newSize );
501 mResizedSignal.Emit( newSize );
503 mAdaptor->SurfaceResizeComplete( newSize );
507 void Window::SetTransparency( bool transparent )
509 mSurface->SetTransparency( transparent );
512 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
514 return mWindowBase->GrabKey( key, grabMode );
517 bool Window::UngrabKey( Dali::KEY key )
519 return mWindowBase->UngrabKey( key );
522 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
524 return mWindowBase->GrabKeyList( key, grabMode, result );
527 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
529 return mWindowBase->UngrabKeyList( key, result );
532 void Window::RotationDone( int orientation, int width, int height )
534 mSurface->RequestRotation( orientation, width, height );
536 mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( width, height ) );
539 mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
541 mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( width, height ) );
544 void Window::OnIconifyChanged( bool iconified )
552 WindowVisibilityObserver* observer( mAdaptor );
553 observer->OnWindowHidden();
556 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
564 WindowVisibilityObserver* observer( mAdaptor );
565 observer->OnWindowShown();
568 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
572 void Window::OnFocusChanged( bool focusIn )
574 mFocusChangedSignal.Emit( focusIn );
577 void Window::OnOutputTransformed()
579 PositionSize positionSize = mSurface->GetPositionSize();
580 mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
581 mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
584 void Window::OnDeleteRequest()
586 mDeleteRequestSignal.Emit();
589 void Window::OnStart()
593 void Window::OnPause()
597 void Window::OnResume()
601 void Window::OnStop()
605 void Window::OnDestroy()