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