Merge "(Build) Ensure CXX11 libraries are marked as provided when building the RPM...
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/window-system/common/window-impl.h>
20
21 // EXTERNAL HEADERS
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>
31
32 #ifdef DALI_ADAPTOR_COMPILATION
33 #include <dali/integration-api/render-surface-interface.h>
34 #else
35 #include <dali/integration-api/adaptors/render-surface-interface.h>
36 #endif
37
38 // INTERNAL HEADERS
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>
46
47 namespace Dali
48 {
49 namespace Internal
50 {
51 namespace Adaptor
52 {
53
54 namespace
55 {
56
57 #if defined(DEBUG_ENABLED)
58 Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW" );
59 #endif
60
61 } // unnamed namespace
62
63 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
64 {
65   Window* window = new Window();
66   window->mIsTransparent = isTransparent;
67   window->Initialize( positionSize, name, className );
68   return window;
69 }
70
71 Window::Window()
72 : mWindowSurface( nullptr ),
73   mWindowBase(),
74   mIsTransparent( false ),
75   mIsFocusAcceptable( true ),
76   mIconified( false ),
77   mOpaqueState( false ),
78   mResizeEnabled( false ),
79   mType( Dali::Window::NORMAL ),
80   mParentWindow( NULL ),
81   mPreferredOrientation( Dali::Window::PORTRAIT ),
82   mRotationAngle( 0 ),
83   mWindowWidth( 0 ),
84   mWindowHeight( 0 ),
85   mFocusChangedSignal(),
86   mResizedSignal(),
87   mDeleteRequestSignal(),
88   mFocusChangeSignal(),
89   mResizeSignal(),
90   mVisibilityChangedSignal()
91 {
92 }
93
94 Window::~Window()
95 {
96   if ( mEventHandler )
97   {
98     mEventHandler->RemoveObserver( *this );
99   }
100 }
101
102 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
103 {
104   // Create a window render surface
105   Any surface;
106   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
107   mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
108   mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
109
110   // Get a window base
111   mWindowBase = mWindowSurface->GetWindowBase();
112
113   // Connect signals
114   mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
115   mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
116   mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
117
118   mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
119
120   if( !positionSize.IsEmpty() )
121   {
122     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
123     mResizeEnabled = true;
124   }
125
126   SetClass( name, className );
127
128   mWindowSurface->Map();
129
130   mOrientation = Orientation::New( this );
131 }
132
133 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
134 {
135   mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
136   mEventHandler->AddObserver( *this );
137 }
138
139 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
140 {
141   mWindowSurface = static_cast<WindowRenderSurface*>( surface );
142 }
143
144 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
145 {
146 }
147
148 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
149 {
150 }
151
152 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
153 {
154 }
155
156 void Window::SetClass( std::string name, std::string className )
157 {
158   mName = name;
159   mClassName = className;
160   mWindowBase->SetClass( name, className );
161 }
162
163 std::string Window::GetClassName() const
164 {
165   return mClassName;
166 }
167
168 void Window::Raise()
169 {
170   mWindowBase->Raise();
171   DALI_LOG_RELEASE_INFO( "Window (%p) Raise() \n", this );
172 }
173
174 void Window::Lower()
175 {
176   mWindowBase->Lower();
177   DALI_LOG_RELEASE_INFO( "Window (%p) Lower() \n", this );
178 }
179
180 void Window::Activate()
181 {
182   mWindowBase->Activate();
183   DALI_LOG_RELEASE_INFO( "Window (%p) Activate() \n", this );
184 }
185
186 uint32_t Window::GetLayerCount() const
187 {
188   return mScene.GetLayerCount();
189 }
190
191 Dali::Layer Window::GetLayer( uint32_t depth ) const
192 {
193   return mScene.GetLayer( depth );
194 }
195
196 Dali::RenderTaskList Window::GetRenderTaskList() const
197 {
198   return mScene.GetRenderTaskList();
199 }
200
201 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
202 {
203   bool found = false;
204
205   if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
206   {
207     for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
208     {
209       if( mAvailableOrientations[i] == orientation )
210       {
211         found = true;
212         break;
213       }
214     }
215
216     if( !found )
217     {
218       mAvailableOrientations.push_back( orientation );
219       SetAvailableOrientations( mAvailableOrientations );
220     }
221   }
222 }
223
224 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
225 {
226   for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
227        iter != mAvailableOrientations.end(); ++iter )
228   {
229     if( *iter == orientation )
230     {
231       mAvailableOrientations.erase( iter );
232       break;
233     }
234   }
235   SetAvailableOrientations( mAvailableOrientations );
236 }
237
238 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
239 {
240   if( orientations.size() > 4 )
241   {
242     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
243     return;
244   }
245
246   mAvailableOrientations = orientations;
247
248   mWindowBase->SetAvailableOrientations( mAvailableOrientations );
249 }
250
251 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
252 {
253   return mAvailableOrientations;
254 }
255
256 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
257 {
258   mPreferredOrientation = orientation;
259
260   mWindowBase->SetPreferredOrientation( mPreferredOrientation );
261 }
262
263 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
264 {
265   return mPreferredOrientation;
266 }
267
268 Dali::Any Window::GetNativeHandle() const
269 {
270   return mWindowSurface->GetNativeWindow();
271 }
272
273 void Window::SetAcceptFocus( bool accept )
274 {
275   mIsFocusAcceptable = accept;
276
277   mWindowBase->SetAcceptFocus( accept );
278 }
279
280 bool Window::IsFocusAcceptable() const
281 {
282   return mIsFocusAcceptable;
283 }
284
285 void Window::Show()
286 {
287   mVisible = true;
288
289   mWindowBase->Show();
290
291   if( !mIconified )
292   {
293     WindowVisibilityObserver* observer( mAdaptor );
294     observer->OnWindowShown();
295
296     Dali::Window handle( this );
297     mVisibilityChangedSignal.Emit( handle, true );
298   }
299
300   DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
301 }
302
303 void Window::Hide()
304 {
305   mVisible = false;
306
307   mWindowBase->Hide();
308
309   if( !mIconified )
310   {
311     WindowVisibilityObserver* observer( mAdaptor );
312     observer->OnWindowHidden();
313
314     Dali::Window handle( this );
315     mVisibilityChangedSignal.Emit( handle, false );
316   }
317
318   DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
319 }
320
321 bool Window::IsVisible() const
322 {
323   return mVisible && !mIconified;
324 }
325
326 unsigned int Window::GetSupportedAuxiliaryHintCount() const
327 {
328   return mWindowBase->GetSupportedAuxiliaryHintCount();
329 }
330
331 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
332 {
333   return mWindowBase->GetSupportedAuxiliaryHint( index );
334 }
335
336 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
337 {
338   return mWindowBase->AddAuxiliaryHint( hint, value );
339 }
340
341 bool Window::RemoveAuxiliaryHint( unsigned int id )
342 {
343   return mWindowBase->RemoveAuxiliaryHint( id );
344 }
345
346 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
347 {
348   return mWindowBase->SetAuxiliaryHintValue( id, value );
349 }
350
351 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
352 {
353   return mWindowBase->GetAuxiliaryHintValue( id );
354 }
355
356 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
357 {
358   return mWindowBase->GetAuxiliaryHintId( hint );
359 }
360
361 void Window::SetInputRegion( const Rect< int >& inputRegion )
362 {
363   mWindowBase->SetInputRegion( inputRegion );
364
365   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 );
366 }
367
368 void Window::SetType( Dali::Window::Type type )
369 {
370   if( type != mType )
371   {
372     mWindowBase->SetType( type );
373
374     mType = type;
375   }
376 }
377
378 Dali::Window::Type Window::GetType() const
379 {
380   return mType;
381 }
382
383 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
384 {
385   if( mType != Dali::Window::NOTIFICATION )
386   {
387     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
388     return false;
389   }
390
391   return mWindowBase->SetNotificationLevel( level );
392 }
393
394 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
395 {
396   if( mType != Dali::Window::NOTIFICATION )
397   {
398     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
399     return Dali::Window::NotificationLevel::NONE;
400   }
401
402   return mWindowBase->GetNotificationLevel();
403 }
404
405 void Window::SetOpaqueState( bool opaque )
406 {
407   mOpaqueState = opaque;
408
409   mWindowBase->SetOpaqueState( opaque );
410
411   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
412 }
413
414 bool Window::IsOpaqueState() const
415 {
416   return mOpaqueState;
417 }
418
419 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
420 {
421   return mWindowBase->SetScreenOffMode( screenOffMode );
422 }
423
424 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
425 {
426   return mWindowBase->GetScreenOffMode();
427 }
428
429 bool Window::SetBrightness( int brightness )
430 {
431   if( brightness < 0 || brightness > 100 )
432   {
433     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
434     return false;
435   }
436
437   return mWindowBase->SetBrightness( brightness );
438 }
439
440 int Window::GetBrightness() const
441 {
442   return mWindowBase->GetBrightness();
443 }
444
445 void Window::SetSize( Dali::Window::WindowSize size )
446 {
447   if( !mResizeEnabled )
448   {
449     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
450     mResizeEnabled = true;
451   }
452
453   PositionSize oldRect = mSurface->GetPositionSize();
454
455   mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
456
457   PositionSize newRect = mSurface->GetPositionSize();
458
459   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
460   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
461   {
462     Uint16Pair newSize( newRect.width, newRect.height );
463
464     SurfaceResized();
465
466     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
467
468     Dali::Window handle( this );
469     mResizedSignal.Emit( newSize );
470     mResizeSignal.Emit( handle, newSize );
471
472     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
473   }
474 }
475
476 Dali::Window::WindowSize Window::GetSize() const
477 {
478   PositionSize positionSize = mSurface->GetPositionSize();
479
480   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
481 }
482
483 void Window::SetPosition( Dali::Window::WindowPosition position )
484 {
485   if( !mResizeEnabled )
486   {
487     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
488     mResizeEnabled = true;
489   }
490
491   PositionSize oldRect = mSurface->GetPositionSize();
492
493   mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
494 }
495
496 Dali::Window::WindowPosition Window::GetPosition() const
497 {
498   PositionSize positionSize = mSurface->GetPositionSize();
499
500   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
501 }
502
503 void Window::SetPositionSize( PositionSize positionSize )
504 {
505   if( !mResizeEnabled )
506   {
507     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
508     mResizeEnabled = true;
509   }
510
511   PositionSize oldRect = mSurface->GetPositionSize();
512
513   mWindowSurface->MoveResize( positionSize );
514
515   PositionSize newRect = mSurface->GetPositionSize();
516
517   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
518   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
519   {
520     Uint16Pair newSize( newRect.width, newRect.height );
521
522     SurfaceResized();
523
524     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
525
526     Dali::Window handle( this );
527     mResizedSignal.Emit( newSize );
528     mResizeSignal.Emit( handle, newSize );
529     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
530   }
531 }
532
533 Dali::Layer Window::GetRootLayer() const
534 {
535   return mScene.GetRootLayer();
536 }
537
538 void Window::SetTransparency( bool transparent )
539 {
540   mWindowSurface->SetTransparency( transparent );
541 }
542
543 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
544 {
545   return mWindowBase->GrabKey( key, grabMode );
546 }
547
548 bool Window::UngrabKey( Dali::KEY key )
549 {
550   return mWindowBase->UngrabKey( key );
551 }
552
553 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
554 {
555   return mWindowBase->GrabKeyList( key, grabMode, result );
556 }
557
558 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
559 {
560   return mWindowBase->UngrabKeyList( key, result );
561 }
562
563 void Window::OnIconifyChanged( bool iconified )
564 {
565   if( iconified )
566   {
567     mIconified = true;
568
569     if( mVisible )
570     {
571       WindowVisibilityObserver* observer( mAdaptor );
572       observer->OnWindowHidden();
573
574       Dali::Window handle( this );
575       mVisibilityChangedSignal.Emit( handle, false );
576     }
577
578     DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
579   }
580   else
581   {
582     mIconified = false;
583
584     if( mVisible )
585     {
586       WindowVisibilityObserver* observer( mAdaptor );
587       observer->OnWindowShown();
588
589       Dali::Window handle( this );
590       mVisibilityChangedSignal.Emit( handle, true );
591     }
592
593     DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
594   }
595 }
596
597 void Window::OnFocusChanged( bool focusIn )
598 {
599   Dali::Window handle( this );
600   mFocusChangedSignal.Emit( focusIn );
601   mFocusChangeSignal.Emit( handle, focusIn );
602 }
603
604 void Window::OnOutputTransformed()
605 {
606   PositionSize positionSize = mSurface->GetPositionSize();
607   SurfaceResized();
608   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
609   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
610 }
611
612 void Window::OnDeleteRequest()
613 {
614   mDeleteRequestSignal.Emit();
615 }
616
617 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
618 {
619   FeedTouchPoint( point, timeStamp );
620 }
621
622 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
623 {
624   FeedWheelEvent( wheelEvent );
625 }
626
627 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
628 {
629   FeedKeyEvent( keyEvent );
630 }
631
632 void Window::OnRotation( const RotationEvent& rotation )
633 {
634   mRotationAngle = rotation.angle;
635   mWindowWidth = rotation.width;
636   mWindowHeight = rotation.height;
637
638   // Notify that the orientation is changed
639   mOrientation->OnOrientationChange( rotation );
640
641   mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
642
643   SurfaceResized();
644
645   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
646
647   // Emit signal
648   Dali::Window handle( this );
649   mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
650   mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
651
652   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
653 }
654
655 void Window::OnPause()
656 {
657   if( mEventHandler )
658   {
659     mEventHandler->Pause();
660   }
661 }
662
663 void Window::OnResume()
664 {
665   if( mEventHandler )
666   {
667     mEventHandler->Resume();
668   }
669 }
670
671 void Window::RecalculateTouchPosition( Integration::Point& point )
672 {
673   Vector2 position = point.GetScreenPosition();
674   Vector2 convertedPosition;
675
676   switch( mRotationAngle )
677   {
678     case 90:
679     {
680       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
681       convertedPosition.y = position.x;
682       break;
683     }
684     case 180:
685     {
686       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
687       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
688       break;
689     }
690     case 270:
691     {
692       convertedPosition.x = position.y;
693       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
694       break;
695     }
696     default:
697     {
698       convertedPosition = position;
699       break;
700     }
701   }
702
703   point.SetScreenPosition( convertedPosition );
704 }
705
706 Dali::Window Window::Get( Dali::Actor actor )
707 {
708   Internal::Adaptor::Window* windowImpl = nullptr;
709
710   if ( Internal::Adaptor::Adaptor::IsAvailable() )
711   {
712     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
713     windowImpl = static_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
714   }
715
716   return Dali::Window( windowImpl );
717 }
718
719 void Window::SetParent( Dali::Window& parent )
720 {
721   if ( DALI_UNLIKELY( parent ) )
722   {
723     mParentWindow = parent;
724     Dali::Window self = Dali::Window( this );
725     // check circular parent window setting
726     if ( Dali::DevelWindow::GetParent( parent ) == self )
727     {
728       Dali::DevelWindow::Unparent( parent );
729     }
730     mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
731   }
732 }
733
734 void Window::Unparent()
735 {
736   mWindowBase->SetParent( nullptr );
737   mParentWindow.Reset();
738 }
739
740 Dali::Window Window::GetParent()
741 {
742   return mParentWindow;
743 }
744
745 } // Adaptor
746
747 } // Internal
748
749 } // Dali