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);
144 WindowRenderSurface* Window::GetSurface()
149 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
153 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
157 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
161 void Window::SetClass( std::string name, std::string className )
163 mWindowBase->SetClass( name, className );
168 mWindowBase->Raise();
173 mWindowBase->Lower();
176 void Window::Activate()
178 mWindowBase->Activate();
181 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
185 if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
187 for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
189 if( mAvailableOrientations[i] == orientation )
198 mAvailableOrientations.push_back( orientation );
199 SetAvailableOrientations( mAvailableOrientations );
204 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
206 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
207 iter != mAvailableOrientations.end(); ++iter )
209 if( *iter == orientation )
211 mAvailableOrientations.erase( iter );
215 SetAvailableOrientations( mAvailableOrientations );
218 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
220 if( orientations.size() > 4 )
222 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
226 mAvailableOrientations = orientations;
228 mWindowBase->SetAvailableOrientations( mAvailableOrientations );
231 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
233 return mAvailableOrientations;
236 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
238 mPreferredOrientation = orientation;
240 mWindowBase->SetPreferredOrientation( mPreferredOrientation );
243 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
245 return mPreferredOrientation;
248 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
250 return mDragAndDropDetector;
253 Dali::Any Window::GetNativeHandle() const
255 return mSurface->GetNativeWindow();
258 void Window::SetAcceptFocus( bool accept )
260 mIsFocusAcceptable = accept;
262 mWindowBase->SetAcceptFocus( accept );
265 bool Window::IsFocusAcceptable() const
267 return mIsFocusAcceptable;
278 WindowVisibilityObserver* observer( mAdaptor );
279 observer->OnWindowShown();
282 DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
293 WindowVisibilityObserver* observer( mAdaptor );
294 observer->OnWindowHidden();
297 DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
300 bool Window::IsVisible() const
305 unsigned int Window::GetSupportedAuxiliaryHintCount() const
307 return mWindowBase->GetSupportedAuxiliaryHintCount();
310 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
312 return mWindowBase->GetSupportedAuxiliaryHint( index );
315 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
317 return mWindowBase->AddAuxiliaryHint( hint, value );
320 bool Window::RemoveAuxiliaryHint( unsigned int id )
322 return mWindowBase->RemoveAuxiliaryHint( id );
325 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
327 return mWindowBase->SetAuxiliaryHintValue( id, value );
330 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
332 return mWindowBase->GetAuxiliaryHintValue( id );
335 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
337 return mWindowBase->GetAuxiliaryHintId( hint );
340 void Window::SetInputRegion( const Rect< int >& inputRegion )
342 mWindowBase->SetInputRegion( inputRegion );
344 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 );
347 void Window::SetType( Dali::Window::Type type )
351 mWindowBase->SetType( type );
357 Dali::Window::Type Window::GetType() const
362 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
364 if( mType != Dali::Window::NOTIFICATION )
366 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
370 return mWindowBase->SetNotificationLevel( level );
373 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
375 if( mType != Dali::Window::NOTIFICATION )
377 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
378 return Dali::Window::NotificationLevel::NONE;
381 return mWindowBase->GetNotificationLevel();
384 void Window::SetOpaqueState( bool opaque )
386 mOpaqueState = opaque;
388 mWindowBase->SetOpaqueState( opaque );
390 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
393 bool Window::IsOpaqueState() const
398 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
400 return mWindowBase->SetScreenOffMode( screenOffMode );
403 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
405 return mWindowBase->GetScreenOffMode();
408 bool Window::SetBrightness( int brightness )
410 if( brightness < 0 || brightness > 100 )
412 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
416 return mWindowBase->SetBrightness( brightness );
419 int Window::GetBrightness() const
421 return mWindowBase->GetBrightness();
424 void Window::SetSize( Dali::Window::WindowSize size )
426 if( !mResizeEnabled )
428 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
429 mResizeEnabled = true;
432 PositionSize oldRect = mSurface->GetPositionSize();
434 mSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
436 PositionSize newRect = mSurface->GetPositionSize();
438 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
439 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
441 Uint16Pair newSize( newRect.width, newRect.height );
443 mAdaptor->SurfaceResizePrepare( newSize );
445 mResizedSignal.Emit( newSize );
447 mAdaptor->SurfaceResizeComplete( newSize );
451 Dali::Window::WindowSize Window::GetSize() const
453 PositionSize positionSize = mSurface->GetPositionSize();
455 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
458 void Window::SetPosition( Dali::Window::WindowPosition position )
460 if( !mResizeEnabled )
462 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
463 mResizeEnabled = true;
466 PositionSize oldRect = mSurface->GetPositionSize();
468 mSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
471 Dali::Window::WindowPosition Window::GetPosition() const
473 PositionSize positionSize = mSurface->GetPositionSize();
475 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
478 void Window::SetPositionSize( PositionSize positionSize )
480 if( !mResizeEnabled )
482 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
483 mResizeEnabled = true;
486 PositionSize oldRect = mSurface->GetPositionSize();
488 mSurface->MoveResize( positionSize );
490 PositionSize newRect = mSurface->GetPositionSize();
492 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
493 if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
495 Uint16Pair newSize( newRect.width, newRect.height );
497 mAdaptor->SurfaceResizePrepare( newSize );
499 mResizedSignal.Emit( newSize );
501 mAdaptor->SurfaceResizeComplete( newSize );
505 void Window::SetTransparency( bool transparent )
507 mSurface->SetTransparency( transparent );
510 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
512 return mWindowBase->GrabKey( key, grabMode );
515 bool Window::UngrabKey( Dali::KEY key )
517 return mWindowBase->UngrabKey( key );
520 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
522 return mWindowBase->GrabKeyList( key, grabMode, result );
525 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
527 return mWindowBase->UngrabKeyList( key, result );
530 void Window::RotationDone( int orientation, int width, int height )
532 mSurface->RequestRotation( orientation, width, height );
534 mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( width, height ) );
537 mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
539 mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( width, height ) );
542 void Window::OnIconifyChanged( bool iconified )
550 WindowVisibilityObserver* observer( mAdaptor );
551 observer->OnWindowHidden();
554 DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
562 WindowVisibilityObserver* observer( mAdaptor );
563 observer->OnWindowShown();
566 DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
570 void Window::OnFocusChanged( bool focusIn )
572 mFocusChangedSignal.Emit( focusIn );
575 void Window::OnOutputTransformed()
577 PositionSize positionSize = mSurface->GetPositionSize();
578 mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
579 mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
582 void Window::OnDeleteRequest()
584 mDeleteRequestSignal.Emit();
587 void Window::OnStart()
591 void Window::OnPause()
595 void Window::OnResume()
599 void Window::OnStop()
603 void Window::OnDestroy()