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