Merge "Remove CXX03 Build & old Tizen Version Builds" into devel/master
[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/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>
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/input/common/drag-and-drop-detector-impl.h>
40 #include <dali/internal/window-system/common/event-handler.h>
41 #include <dali/internal/window-system/common/orientation-impl.h>
42 #include <dali/internal/window-system/common/render-surface-factory.h>
43 #include <dali/internal/window-system/common/window-factory.h>
44 #include <dali/internal/window-system/common/window-base.h>
45 #include <dali/internal/window-system/common/window-render-surface.h>
46 #include <dali/internal/window-system/common/window-visibility-observer.h>
47
48 namespace Dali
49 {
50 namespace Internal
51 {
52 namespace Adaptor
53 {
54
55 namespace
56 {
57
58 #if defined(DEBUG_ENABLED)
59 Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW" );
60 #endif
61
62 } // unnamed namespace
63
64 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
65 {
66   Window* window = new Window();
67   window->mIsTransparent = isTransparent;
68   window->Initialize( positionSize, name, className );
69   return window;
70 }
71
72 Window::Window()
73 : mWindowSurface( nullptr ),
74   mWindowBase(),
75   mIsTransparent( false ),
76   mIsFocusAcceptable( true ),
77   mIconified( false ),
78   mOpaqueState( false ),
79   mResizeEnabled( false ),
80   mType( Dali::Window::NORMAL ),
81   mPreferredOrientation( Dali::Window::PORTRAIT ),
82   mFocusChangedSignal(),
83   mResizedSignal(),
84   mDeleteRequestSignal()
85 {
86 }
87
88 Window::~Window()
89 {
90   if ( mEventHandler )
91   {
92     mEventHandler->SetRotationObserver( nullptr );
93   }
94 }
95
96 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
97 {
98   // Create a window render surface
99   Any surface;
100   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
101   mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
102   mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
103
104   // Get a window base
105   mWindowBase = mWindowSurface->GetWindowBase();
106
107   // Connect signals
108   mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
109   mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
110   mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
111
112   mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
113
114   if( !positionSize.IsEmpty() )
115   {
116     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
117     mResizeEnabled = true;
118   }
119
120   SetClass( name, className );
121
122   mWindowSurface->Map();
123
124   mOrientation = Orientation::New( this );
125 }
126
127 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
128 {
129   // Can only create the detector when we know the Core has been instantiated.
130   mDragAndDropDetector = DragAndDropDetector::New();
131
132   mEventHandler = EventHandlerPtr(
133       new EventHandler( mScene, *mAdaptor, *mAdaptor->GetGestureManager(), *mAdaptor ) );
134
135   // TODO: Orientation should be passed into the constructor of EventHandler
136   if( mOrientation )
137   {
138     SetRotationObserver( &(*mOrientation) );
139   }
140 }
141
142 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
143 {
144   mWindowSurface = static_cast<WindowRenderSurface*>( surface );
145 }
146
147 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
148 {
149 }
150
151 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
152 {
153 }
154
155 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
156 {
157 }
158
159 void Window::SetClass( std::string name, std::string className )
160 {
161   mName = name;
162   mClassName = className;
163   mWindowBase->SetClass( name, className );
164 }
165
166 std::string Window::GetClassName() const
167 {
168   return mClassName;
169 }
170
171 void Window::Raise()
172 {
173   mWindowBase->Raise();
174 }
175
176 void Window::Lower()
177 {
178   mWindowBase->Lower();
179 }
180
181 void Window::Activate()
182 {
183   mWindowBase->Activate();
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 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
197 {
198   bool found = false;
199
200   if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
201   {
202     for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
203     {
204       if( mAvailableOrientations[i] == orientation )
205       {
206         found = true;
207         break;
208       }
209     }
210
211     if( !found )
212     {
213       mAvailableOrientations.push_back( orientation );
214       SetAvailableOrientations( mAvailableOrientations );
215     }
216   }
217 }
218
219 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
220 {
221   for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
222        iter != mAvailableOrientations.end(); ++iter )
223   {
224     if( *iter == orientation )
225     {
226       mAvailableOrientations.erase( iter );
227       break;
228     }
229   }
230   SetAvailableOrientations( mAvailableOrientations );
231 }
232
233 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
234 {
235   if( orientations.size() > 4 )
236   {
237     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
238     return;
239   }
240
241   mAvailableOrientations = orientations;
242
243   mWindowBase->SetAvailableOrientations( mAvailableOrientations );
244 }
245
246 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
247 {
248   return mAvailableOrientations;
249 }
250
251 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
252 {
253   mPreferredOrientation = orientation;
254
255   mWindowBase->SetPreferredOrientation( mPreferredOrientation );
256 }
257
258 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
259 {
260   return mPreferredOrientation;
261 }
262
263 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
264 {
265   return mDragAndDropDetector;
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
297   DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
298 }
299
300 void Window::Hide()
301 {
302   mVisible = false;
303
304   mWindowBase->Hide();
305
306   if( !mIconified )
307   {
308     WindowVisibilityObserver* observer( mAdaptor );
309     observer->OnWindowHidden();
310   }
311
312   DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
313 }
314
315 bool Window::IsVisible() const
316 {
317   return mVisible && !mIconified;
318 }
319
320 unsigned int Window::GetSupportedAuxiliaryHintCount() const
321 {
322   return mWindowBase->GetSupportedAuxiliaryHintCount();
323 }
324
325 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
326 {
327   return mWindowBase->GetSupportedAuxiliaryHint( index );
328 }
329
330 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
331 {
332   return mWindowBase->AddAuxiliaryHint( hint, value );
333 }
334
335 bool Window::RemoveAuxiliaryHint( unsigned int id )
336 {
337   return mWindowBase->RemoveAuxiliaryHint( id );
338 }
339
340 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
341 {
342   return mWindowBase->SetAuxiliaryHintValue( id, value );
343 }
344
345 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
346 {
347   return mWindowBase->GetAuxiliaryHintValue( id );
348 }
349
350 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
351 {
352   return mWindowBase->GetAuxiliaryHintId( hint );
353 }
354
355 void Window::SetInputRegion( const Rect< int >& inputRegion )
356 {
357   mWindowBase->SetInputRegion( inputRegion );
358
359   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 );
360 }
361
362 void Window::SetType( Dali::Window::Type type )
363 {
364   if( type != mType )
365   {
366     mWindowBase->SetType( type );
367
368     mType = type;
369   }
370 }
371
372 Dali::Window::Type Window::GetType() const
373 {
374   return mType;
375 }
376
377 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
378 {
379   if( mType != Dali::Window::NOTIFICATION )
380   {
381     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
382     return false;
383   }
384
385   return mWindowBase->SetNotificationLevel( level );
386 }
387
388 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
389 {
390   if( mType != Dali::Window::NOTIFICATION )
391   {
392     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
393     return Dali::Window::NotificationLevel::NONE;
394   }
395
396   return mWindowBase->GetNotificationLevel();
397 }
398
399 void Window::SetOpaqueState( bool opaque )
400 {
401   mOpaqueState = opaque;
402
403   mWindowBase->SetOpaqueState( opaque );
404
405   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
406 }
407
408 bool Window::IsOpaqueState() const
409 {
410   return mOpaqueState;
411 }
412
413 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
414 {
415   return mWindowBase->SetScreenOffMode( screenOffMode );
416 }
417
418 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
419 {
420   return mWindowBase->GetScreenOffMode();
421 }
422
423 bool Window::SetBrightness( int brightness )
424 {
425   if( brightness < 0 || brightness > 100 )
426   {
427     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
428     return false;
429   }
430
431   return mWindowBase->SetBrightness( brightness );
432 }
433
434 int Window::GetBrightness() const
435 {
436   return mWindowBase->GetBrightness();
437 }
438
439 void Window::SetSize( Dali::Window::WindowSize size )
440 {
441   if( !mResizeEnabled )
442   {
443     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
444     mResizeEnabled = true;
445   }
446
447   PositionSize oldRect = mSurface->GetPositionSize();
448
449   mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
450
451   PositionSize newRect = mSurface->GetPositionSize();
452
453   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
454   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
455   {
456     Uint16Pair newSize( newRect.width, newRect.height );
457
458     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
459
460     mResizedSignal.Emit( newSize );
461
462     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
463   }
464 }
465
466 Dali::Window::WindowSize Window::GetSize() const
467 {
468   PositionSize positionSize = mSurface->GetPositionSize();
469
470   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
471 }
472
473 void Window::SetPosition( Dali::Window::WindowPosition position )
474 {
475   if( !mResizeEnabled )
476   {
477     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
478     mResizeEnabled = true;
479   }
480
481   PositionSize oldRect = mSurface->GetPositionSize();
482
483   mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
484 }
485
486 Dali::Window::WindowPosition Window::GetPosition() const
487 {
488   PositionSize positionSize = mSurface->GetPositionSize();
489
490   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
491 }
492
493 void Window::SetPositionSize( PositionSize positionSize )
494 {
495   if( !mResizeEnabled )
496   {
497     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
498     mResizeEnabled = true;
499   }
500
501   PositionSize oldRect = mSurface->GetPositionSize();
502
503   mWindowSurface->MoveResize( positionSize );
504
505   PositionSize newRect = mSurface->GetPositionSize();
506
507   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
508   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
509   {
510     Uint16Pair newSize( newRect.width, newRect.height );
511
512     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
513
514     mResizedSignal.Emit( newSize );
515
516     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
517   }
518 }
519
520 Dali::Layer Window::GetRootLayer()
521 {
522   return mScene.GetRootLayer();
523 }
524
525 void Window::SetTransparency( bool transparent )
526 {
527   mWindowSurface->SetTransparency( transparent );
528 }
529
530 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
531 {
532   return mWindowBase->GrabKey( key, grabMode );
533 }
534
535 bool Window::UngrabKey( Dali::KEY key )
536 {
537   return mWindowBase->UngrabKey( key );
538 }
539
540 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
541 {
542   return mWindowBase->GrabKeyList( key, grabMode, result );
543 }
544
545 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
546 {
547   return mWindowBase->UngrabKeyList( key, result );
548 }
549
550 void Window::RotationDone( int orientation, int width, int height )
551 {
552   mWindowSurface->RequestRotation( orientation, width, height );
553
554   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
555
556   // Emit signal
557   mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
558
559   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( width, height ) );
560 }
561
562 void Window::OnIconifyChanged( bool iconified )
563 {
564   if( iconified )
565   {
566     mIconified = true;
567
568     if( mVisible )
569     {
570       WindowVisibilityObserver* observer( mAdaptor );
571       observer->OnWindowHidden();
572     }
573
574     DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
575   }
576   else
577   {
578     mIconified = false;
579
580     if( mVisible )
581     {
582       WindowVisibilityObserver* observer( mAdaptor );
583       observer->OnWindowShown();
584     }
585
586     DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
587   }
588 }
589
590 void Window::OnFocusChanged( bool focusIn )
591 {
592   mFocusChangedSignal.Emit( focusIn );
593 }
594
595 void Window::OnOutputTransformed()
596 {
597   PositionSize positionSize = mSurface->GetPositionSize();
598   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
599   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
600 }
601
602 void Window::OnDeleteRequest()
603 {
604   mDeleteRequestSignal.Emit();
605 }
606
607 void Window::FeedTouchPoint( TouchPoint& point, int timeStamp )
608 {
609   if( mEventHandler )
610   {
611     mEventHandler->FeedTouchPoint( point, timeStamp );
612   }
613 }
614
615 void Window::FeedWheelEvent( WheelEvent& wheelEvent )
616 {
617   if( mEventHandler )
618   {
619     mEventHandler->FeedWheelEvent( wheelEvent );
620   }
621 }
622
623 void Window::FeedKeyEvent( KeyEvent& keyEvent )
624 {
625   if( mEventHandler )
626   {
627     mEventHandler->FeedKeyEvent( keyEvent );
628   }
629 }
630
631 void Window::OnPause()
632 {
633   if( mEventHandler )
634   {
635     mEventHandler->Pause();
636   }
637 }
638
639 void Window::OnResume()
640 {
641   if( mEventHandler )
642   {
643     mEventHandler->Resume();
644   }
645 }
646
647 bool Window::SetRotationObserver( RotationObserver* observer )
648 {
649   if( mEventHandler )
650   {
651     mEventHandler->SetRotationObserver( observer );
652     return true;
653   }
654
655   return false;
656 }
657
658
659 } // Adaptor
660
661 } // Internal
662
663 } // Dali