[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
144 WindowRenderSurface* Window::GetSurface()
145 {
146   return mSurface;
147 }
148
149 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
150 {
151 }
152
153 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
154 {
155 }
156
157 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
158 {
159 }
160
161 void Window::SetClass( std::string name, std::string className )
162 {
163   mWindowBase->SetClass( name, className );
164 }
165
166 void Window::Raise()
167 {
168   mWindowBase->Raise();
169 }
170
171 void Window::Lower()
172 {
173   mWindowBase->Lower();
174 }
175
176 void Window::Activate()
177 {
178   mWindowBase->Activate();
179 }
180
181 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
182 {
183   bool found = false;
184
185   if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
186   {
187     for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
188     {
189       if( mAvailableOrientations[i] == orientation )
190       {
191         found = true;
192         break;
193       }
194     }
195
196     if( !found )
197     {
198       mAvailableOrientations.push_back( orientation );
199       SetAvailableOrientations( mAvailableOrientations );
200     }
201   }
202 }
203
204 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
205 {
206   for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
207        iter != mAvailableOrientations.end(); ++iter )
208   {
209     if( *iter == orientation )
210     {
211       mAvailableOrientations.erase( iter );
212       break;
213     }
214   }
215   SetAvailableOrientations( mAvailableOrientations );
216 }
217
218 void Window::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
219 {
220   if( orientations.size() > 4 )
221   {
222     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableOrientations: Invalid vector size! [%d]\n", orientations.size() );
223     return;
224   }
225
226   mAvailableOrientations = orientations;
227
228   mWindowBase->SetAvailableOrientations( mAvailableOrientations );
229 }
230
231 const std::vector< Dali::Window::WindowOrientation >& Window::GetAvailableOrientations()
232 {
233   return mAvailableOrientations;
234 }
235
236 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
237 {
238   mPreferredOrientation = orientation;
239
240   mWindowBase->SetPreferredOrientation( mPreferredOrientation );
241 }
242
243 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
244 {
245   return mPreferredOrientation;
246 }
247
248 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
249 {
250   return mDragAndDropDetector;
251 }
252
253 Dali::Any Window::GetNativeHandle() const
254 {
255   return mSurface->GetNativeWindow();
256 }
257
258 void Window::SetAcceptFocus( bool accept )
259 {
260   mIsFocusAcceptable = accept;
261
262   mWindowBase->SetAcceptFocus( accept );
263 }
264
265 bool Window::IsFocusAcceptable() const
266 {
267   return mIsFocusAcceptable;
268 }
269
270 void Window::Show()
271 {
272   mVisible = true;
273
274   mWindowBase->Show();
275
276   if( !mIconified )
277   {
278     WindowVisibilityObserver* observer( mAdaptor );
279     observer->OnWindowShown();
280   }
281
282   DALI_LOG_RELEASE_INFO( "Window (%p) Show(): iconified = %d\n", this, mIconified );
283 }
284
285 void Window::Hide()
286 {
287   mVisible = false;
288
289   mWindowBase->Hide();
290
291   if( !mIconified )
292   {
293     WindowVisibilityObserver* observer( mAdaptor );
294     observer->OnWindowHidden();
295   }
296
297   DALI_LOG_RELEASE_INFO( "Window (%p) Hide(): iconified = %d\n", this, mIconified );
298 }
299
300 bool Window::IsVisible() const
301 {
302   return mVisible;
303 }
304
305 unsigned int Window::GetSupportedAuxiliaryHintCount() const
306 {
307   return mWindowBase->GetSupportedAuxiliaryHintCount();
308 }
309
310 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
311 {
312   return mWindowBase->GetSupportedAuxiliaryHint( index );
313 }
314
315 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
316 {
317   return mWindowBase->AddAuxiliaryHint( hint, value );
318 }
319
320 bool Window::RemoveAuxiliaryHint( unsigned int id )
321 {
322   return mWindowBase->RemoveAuxiliaryHint( id );
323 }
324
325 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
326 {
327   return mWindowBase->SetAuxiliaryHintValue( id, value );
328 }
329
330 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
331 {
332   return mWindowBase->GetAuxiliaryHintValue( id );
333 }
334
335 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
336 {
337   return mWindowBase->GetAuxiliaryHintId( hint );
338 }
339
340 void Window::SetInputRegion( const Rect< int >& inputRegion )
341 {
342   mWindowBase->SetInputRegion( inputRegion );
343
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 );
345 }
346
347 void Window::SetType( Dali::Window::Type type )
348 {
349   if( type != mType )
350   {
351     mWindowBase->SetType( type );
352
353     mType = type;
354   }
355 }
356
357 Dali::Window::Type Window::GetType() const
358 {
359   return mType;
360 }
361
362 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
363 {
364   if( mType != Dali::Window::NOTIFICATION )
365   {
366     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
367     return false;
368   }
369
370   return mWindowBase->SetNotificationLevel( level );
371 }
372
373 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
374 {
375   if( mType != Dali::Window::NOTIFICATION )
376   {
377     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
378     return Dali::Window::NotificationLevel::NONE;
379   }
380
381   return mWindowBase->GetNotificationLevel();
382 }
383
384 void Window::SetOpaqueState( bool opaque )
385 {
386   mOpaqueState = opaque;
387
388   mWindowBase->SetOpaqueState( opaque );
389
390   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
391 }
392
393 bool Window::IsOpaqueState() const
394 {
395   return mOpaqueState;
396 }
397
398 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
399 {
400   return mWindowBase->SetScreenOffMode( screenOffMode );
401 }
402
403 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
404 {
405   return mWindowBase->GetScreenOffMode();
406 }
407
408 bool Window::SetBrightness( int brightness )
409 {
410   if( brightness < 0 || brightness > 100 )
411   {
412     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
413     return false;
414   }
415
416   return mWindowBase->SetBrightness( brightness );
417 }
418
419 int Window::GetBrightness() const
420 {
421   return mWindowBase->GetBrightness();
422 }
423
424 void Window::SetSize( Dali::Window::WindowSize size )
425 {
426   if( !mResizeEnabled )
427   {
428     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
429     mResizeEnabled = true;
430   }
431
432   PositionSize oldRect = mSurface->GetPositionSize();
433
434   mSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
435
436   PositionSize newRect = mSurface->GetPositionSize();
437
438   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
439   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
440   {
441     Uint16Pair newSize( newRect.width, newRect.height );
442
443     mAdaptor->SurfaceResizePrepare( newSize );
444
445     mResizedSignal.Emit( newSize );
446
447     mAdaptor->SurfaceResizeComplete( newSize );
448   }
449 }
450
451 Dali::Window::WindowSize Window::GetSize() const
452 {
453   PositionSize positionSize = mSurface->GetPositionSize();
454
455   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
456 }
457
458 void Window::SetPosition( Dali::Window::WindowPosition position )
459 {
460   if( !mResizeEnabled )
461   {
462     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
463     mResizeEnabled = true;
464   }
465
466   PositionSize oldRect = mSurface->GetPositionSize();
467
468   mSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
469 }
470
471 Dali::Window::WindowPosition Window::GetPosition() const
472 {
473   PositionSize positionSize = mSurface->GetPositionSize();
474
475   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
476 }
477
478 void Window::SetPositionSize( PositionSize positionSize )
479 {
480   if( !mResizeEnabled )
481   {
482     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
483     mResizeEnabled = true;
484   }
485
486   PositionSize oldRect = mSurface->GetPositionSize();
487
488   mSurface->MoveResize( positionSize );
489
490   PositionSize newRect = mSurface->GetPositionSize();
491
492   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
493   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
494   {
495     Uint16Pair newSize( newRect.width, newRect.height );
496
497     mAdaptor->SurfaceResizePrepare( newSize );
498
499     mResizedSignal.Emit( newSize );
500
501     mAdaptor->SurfaceResizeComplete( newSize );
502   }
503 }
504
505 void Window::SetTransparency( bool transparent )
506 {
507   mSurface->SetTransparency( transparent );
508 }
509
510 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
511 {
512   return mWindowBase->GrabKey( key, grabMode );
513 }
514
515 bool Window::UngrabKey( Dali::KEY key )
516 {
517   return mWindowBase->UngrabKey( key );
518 }
519
520 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
521 {
522   return mWindowBase->GrabKeyList( key, grabMode, result );
523 }
524
525 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
526 {
527   return mWindowBase->UngrabKeyList( key, result );
528 }
529
530 void Window::RotationDone( int orientation, int width, int height )
531 {
532   mSurface->RequestRotation( orientation, width, height );
533
534   mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( width, height ) );
535
536   // Emit signal
537   mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
538
539   mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( width, height ) );
540 }
541
542 void Window::OnIconifyChanged( bool iconified )
543 {
544   if( iconified )
545   {
546     mIconified = true;
547
548     if( mVisible )
549     {
550       WindowVisibilityObserver* observer( mAdaptor );
551       observer->OnWindowHidden();
552     }
553
554     DALI_LOG_RELEASE_INFO( "Window (%p) Iconified: visible = %d\n", this, mVisible );
555   }
556   else
557   {
558     mIconified = false;
559
560     if( mVisible )
561     {
562       WindowVisibilityObserver* observer( mAdaptor );
563       observer->OnWindowShown();
564     }
565
566     DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified: visible = %d\n", this, mVisible );
567   }
568 }
569
570 void Window::OnFocusChanged( bool focusIn )
571 {
572   mFocusChangedSignal.Emit( focusIn );
573 }
574
575 void Window::OnOutputTransformed()
576 {
577   PositionSize positionSize = mSurface->GetPositionSize();
578   mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
579   mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
580 }
581
582 void Window::OnDeleteRequest()
583 {
584   mDeleteRequestSignal.Emit();
585 }
586
587 void Window::OnStart()
588 {
589 }
590
591 void Window::OnPause()
592 {
593 }
594
595 void Window::OnResume()
596 {
597 }
598
599 void Window::OnStop()
600 {
601 }
602
603 void Window::OnDestroy()
604 {
605   mAdaptor = NULL;
606 }
607
608 } // Adaptor
609
610 } // Internal
611
612 } // Dali