[4.0] Pause adaptor when the window is hidden
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / window-impl-wl.cpp
1 /*
2  * Copyright (c) 2017 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 "window-impl.h"
20
21 // EXTERNAL HEADERS
22 #include <dali/integration-api/core.h>
23 #include <dali/integration-api/system-overlay.h>
24 #include <dali/public-api/render-tasks/render-task.h>
25 #include <dali/public-api/render-tasks/render-task-list.h>
26 #include <orientation.h>
27
28 // INTERNAL HEADERS
29 #include "render-surface/render-surface-wl.h"
30 #include <drag-and-drop-detector-impl.h>
31 #include <window-visibility-observer.h>
32 #include <orientation-impl.h>
33
34
35
36 namespace Dali
37 {
38 namespace Internal
39 {
40 namespace Adaptor
41 {
42 #if defined(DEBUG_ENABLED)
43 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_WINDOW");
44 #endif
45
46 struct Window::EventHandler
47 {
48   // place holder
49 };
50
51 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
52 {
53   Window* window = new Window();
54   window->mIsTransparent = isTransparent;
55   window->Initialize( positionSize, name, className );
56   return window;
57 }
58
59 void Window::SetAdaptor(Dali::Adaptor& adaptor)
60 {
61   DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
62   mStarted = true;
63
64   // Only create one overlay per window
65   Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
66   Integration::Core& core = adaptorImpl.GetCore();
67   mOverlay = &core.GetSystemOverlay();
68
69   Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
70   taskList.CreateTask();
71
72   mAdaptor = &adaptorImpl;
73   mAdaptor->AddObserver( *this );
74
75   // Can only create the detector when we know the Core has been instantiated.
76   mDragAndDropDetector = DragAndDropDetector::New();
77   mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
78
79
80 }
81
82 RenderSurface* Window::GetSurface()
83 {
84   return mSurface;
85 }
86
87 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
88 {
89
90 }
91
92 void Window::RotateIndicator(Dali::Window::WindowOrientation orientation)
93 {
94 }
95
96 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
97 {
98 }
99
100 void Window::SetClass(std::string name, std::string klass)
101 {
102 }
103
104 Window::Window()
105 : mSurface( NULL ),
106   mIndicatorVisible( Dali::Window::VISIBLE ),
107   mIndicatorIsShown( false ),
108   mShowRotatedIndicatorOnClose( false ),
109   mStarted( false ),
110   mIsTransparent( false ),
111   mWMRotationAppSet( false ),
112   mIsFocusAcceptable( true ),
113   mVisible( true ),
114   mIconified( false ),
115   mOpaqueState( false ),
116   mResizeEnabled( true ),
117   mIndicator( NULL ),
118   mIndicatorOrientation( Dali::Window::PORTRAIT ),
119   mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
120   mIndicatorOpacityMode( Dali::Window::OPAQUE ),
121   mOverlay( NULL ),
122   mAdaptor( NULL ),
123   mType( Dali::Window::NORMAL ),
124   mPreferredOrientation( Dali::Window::PORTRAIT ),
125   mSupportedAuxiliaryHints(),
126   mAuxiliaryHints(),
127   mIndicatorVisibilityChangedSignal(),
128   mFocusChangedSignal(),
129   mResizedSignal(),
130   mDeleteRequestSignal()
131 {
132   mEventHandler = NULL;
133 }
134
135 Window::~Window()
136 {
137   delete mEventHandler;
138
139   if ( mAdaptor )
140   {
141     mAdaptor->RemoveObserver( *this );
142     mAdaptor->SetDragAndDropDetector( NULL );
143     mAdaptor = NULL;
144   }
145
146   delete mSurface;
147 }
148
149 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
150 {
151   // create an Wayland window by default
152   Any surface;
153   Wayland::RenderSurface* windowSurface = new Wayland::RenderSurface( positionSize, surface, name, mIsTransparent );
154
155   mSurface = windowSurface;
156
157   mOrientation = Orientation::New(this);
158 }
159
160 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
161 {
162
163 }
164
165 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
166 {
167
168 }
169
170 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
171 {
172 }
173
174 void Window::IndicatorTypeChanged(IndicatorInterface::Type type)
175 {
176 }
177
178 void Window::IndicatorClosed( IndicatorInterface* indicator )
179 {
180
181 }
182
183 void Window::IndicatorVisibilityChanged(bool isVisible)
184 {
185
186 }
187
188 void Window::SetIndicatorActorRotation()
189 {
190
191 }
192
193 void Window::Raise()
194 {
195 }
196
197 void Window::Lower()
198 {
199 }
200
201 void Window::Activate()
202 {
203 }
204
205 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
206 {
207   return mDragAndDropDetector;
208 }
209
210 Dali::Any Window::GetNativeHandle() const
211 {
212   Wayland::RenderSurface* surface = static_cast<  Wayland::RenderSurface* >( mSurface );
213
214   return surface->GetWindow();
215 }
216
217 void Window::OnStart()
218 {
219 }
220
221 void Window::OnPause()
222 {
223 }
224
225 void Window::OnResume()
226 {
227 }
228
229 void Window::OnStop()
230 {
231 }
232
233 void Window::OnDestroy()
234 {
235   mAdaptor = NULL;
236 }
237
238 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
239 {
240   bool found = false;
241
242   for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
243   {
244     if(mAvailableOrientations[i] == orientation)
245     {
246       found = true;
247       break;
248     }
249   }
250
251   if( ! found )
252   {
253     mAvailableOrientations.push_back(orientation);
254     SetAvailableOrientations( mAvailableOrientations );
255   }
256 }
257
258 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
259 {
260   for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
261        iter != mAvailableOrientations.end(); ++iter )
262   {
263     if( *iter == orientation )
264     {
265       mAvailableOrientations.erase( iter );
266       break;
267     }
268   }
269   SetAvailableOrientations( mAvailableOrientations );
270 }
271
272 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
273 {
274   DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
275 }
276
277 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
278 {
279   return mAvailableOrientations;
280 }
281
282 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
283 {
284   mPreferredOrientation = orientation;
285 }
286
287 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
288 {
289   return mPreferredOrientation;
290 }
291
292 void Window::SetAcceptFocus( bool accept )
293 {
294   mIsFocusAcceptable = accept;
295 }
296
297 bool Window::IsFocusAcceptable() const
298 {
299   return mIsFocusAcceptable;
300 }
301
302 void Window::Show()
303 {
304   mVisible = true;
305 }
306
307 void Window::Hide()
308 {
309   mVisible = false;
310 }
311
312 bool Window::IsVisible() const
313 {
314   return mVisible;
315 }
316
317
318 void Window::RotationDone( int orientation, int width, int height )
319 {
320 }
321
322 void Window::SetIndicatorVisibleMode( Dali::Window::IndicatorVisibleMode mode )
323 {
324   mIndicatorVisible = mode;
325 }
326
327 unsigned int Window::GetSupportedAuxiliaryHintCount() const
328 {
329   return 0;
330 }
331
332 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
333 {
334   return std::string();
335 }
336
337 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
338 {
339   return -1;
340 }
341
342 bool Window::RemoveAuxiliaryHint( unsigned int id )
343 {
344   return false;
345 }
346
347 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
348 {
349   return false;
350 }
351
352 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
353 {
354   return std::string();
355 }
356
357 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
358 {
359   return -1;
360 }
361
362 void Window::SetInputRegion( const Rect< int >& inputRegion )
363 {
364 }
365
366 void Window::SetType( Dali::Window::Type type )
367 {
368   mType = type;
369 }
370
371 Dali::Window::Type Window::GetType() const
372 {
373   return mType;
374 }
375
376 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
377 {
378   return false;
379 }
380
381 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
382 {
383   return Dali::Window::NotificationLevel::NONE;
384 }
385
386 void Window::SetOpaqueState( bool opaque )
387 {
388   mOpaqueState = opaque;
389 }
390
391 bool Window::IsOpaqueState() const
392 {
393   return mOpaqueState;
394 }
395
396 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
397 {
398   return false;
399 }
400
401 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
402 {
403   return Dali::Window::ScreenOffMode::TIMEOUT;
404 }
405
406 bool Window::SetBrightness( int brightness )
407 {
408   return false;
409 }
410
411 int Window::GetBrightness() const
412 {
413   return 0;
414 }
415
416 void Window::SetSize( Dali::Window::WindowSize size )
417 {
418   PositionSize positionSize = mSurface->GetPositionSize();
419
420   if( positionSize.width != size.GetWidth() || positionSize.height != size.GetHeight() )
421   {
422     positionSize.width = size.GetWidth();
423     positionSize.height = size.GetHeight();
424
425     mSurface->MoveResize( positionSize );
426
427     mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
428
429     // Emit signal
430     mResizedSignal.Emit( Dali::Window::WindowSize( positionSize.width, positionSize.height ) );
431
432     mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
433   }
434 }
435
436 Dali::Window::WindowSize Window::GetSize() const
437 {
438   PositionSize positionSize = mSurface->GetPositionSize();
439
440   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
441 }
442
443 void Window::SetPosition( Dali::Window::WindowPosition position )
444 {
445   PositionSize positionSize = mSurface->GetPositionSize();
446
447   if( positionSize.x != position.GetX() || positionSize.y != position.GetY() )
448   {
449     positionSize.x = position.GetX();
450     positionSize.y = position.GetY();
451
452     mSurface->MoveResize( positionSize );
453   }
454 }
455
456 Dali::Window::WindowPosition Window::GetPosition() const
457 {
458   PositionSize positionSize = mSurface->GetPositionSize();
459
460   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
461 }
462
463 void Window::SetTransparency( bool transparent )
464 {
465 }
466
467 } // Adaptor
468 } // Internal
469 } // Dali