[dali_1.2.61] Merge branch 'devel/master'
[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   mOpaqueState( false ),
115   mResizeEnabled( true ),
116   mIndicator( NULL ),
117   mIndicatorOrientation( Dali::Window::PORTRAIT ),
118   mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
119   mIndicatorOpacityMode( Dali::Window::OPAQUE ),
120   mOverlay( NULL ),
121   mAdaptor( NULL ),
122   mType( Dali::Window::NORMAL ),
123   mPreferredOrientation( Dali::Window::PORTRAIT ),
124   mSupportedAuxiliaryHints(),
125   mAuxiliaryHints(),
126   mIndicatorVisibilityChangedSignal(),
127   mFocusChangedSignal(),
128   mResizedSignal(),
129   mDeleteRequestSignal()
130 {
131   mEventHandler = NULL;
132 }
133
134 Window::~Window()
135 {
136   delete mEventHandler;
137
138   if ( mAdaptor )
139   {
140     mAdaptor->RemoveObserver( *this );
141     mAdaptor->SetDragAndDropDetector( NULL );
142     mAdaptor = NULL;
143   }
144
145   delete mSurface;
146 }
147
148 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
149 {
150   // create an Wayland window by default
151   Any surface;
152   Wayland::RenderSurface* windowSurface = new Wayland::RenderSurface( positionSize, surface, name, mIsTransparent );
153
154   mSurface = windowSurface;
155
156   mOrientation = Orientation::New(this);
157 }
158
159 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
160 {
161
162 }
163
164 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
165 {
166
167 }
168
169 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
170 {
171 }
172
173 void Window::IndicatorTypeChanged(IndicatorInterface::Type type)
174 {
175 }
176
177 void Window::IndicatorClosed( IndicatorInterface* indicator )
178 {
179
180 }
181
182 void Window::IndicatorVisibilityChanged(bool isVisible)
183 {
184
185 }
186
187 void Window::SetIndicatorActorRotation()
188 {
189
190 }
191
192 void Window::Raise()
193 {
194 }
195
196 void Window::Lower()
197 {
198 }
199
200 void Window::Activate()
201 {
202 }
203
204 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
205 {
206   return mDragAndDropDetector;
207 }
208
209 Dali::Any Window::GetNativeHandle() const
210 {
211   Wayland::RenderSurface* surface = static_cast<  Wayland::RenderSurface* >( mSurface );
212
213   return surface->GetWindow();
214 }
215
216 void Window::OnStart()
217 {
218 }
219
220 void Window::OnPause()
221 {
222 }
223
224 void Window::OnResume()
225 {
226 }
227
228 void Window::OnStop()
229 {
230 }
231
232 void Window::OnDestroy()
233 {
234   mAdaptor = NULL;
235 }
236
237 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
238 {
239   bool found = false;
240
241   for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
242   {
243     if(mAvailableOrientations[i] == orientation)
244     {
245       found = true;
246       break;
247     }
248   }
249
250   if( ! found )
251   {
252     mAvailableOrientations.push_back(orientation);
253     SetAvailableOrientations( mAvailableOrientations );
254   }
255 }
256
257 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
258 {
259   for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
260        iter != mAvailableOrientations.end(); ++iter )
261   {
262     if( *iter == orientation )
263     {
264       mAvailableOrientations.erase( iter );
265       break;
266     }
267   }
268   SetAvailableOrientations( mAvailableOrientations );
269 }
270
271 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
272 {
273   DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
274 }
275
276 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
277 {
278   return mAvailableOrientations;
279 }
280
281 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
282 {
283   mPreferredOrientation = orientation;
284 }
285
286 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
287 {
288   return mPreferredOrientation;
289 }
290
291 void Window::SetAcceptFocus( bool accept )
292 {
293   mIsFocusAcceptable = accept;
294 }
295
296 bool Window::IsFocusAcceptable() const
297 {
298   return mIsFocusAcceptable;
299 }
300
301 void Window::Show()
302 {
303   mVisible = true;
304 }
305
306 void Window::Hide()
307 {
308   mVisible = false;
309 }
310
311 bool Window::IsVisible() const
312 {
313   return mVisible;
314 }
315
316
317 void Window::RotationDone( int orientation, int width, int height )
318 {
319 }
320
321 void Window::SetIndicatorVisibleMode( Dali::Window::IndicatorVisibleMode mode )
322 {
323   mIndicatorVisible = mode;
324 }
325
326 unsigned int Window::GetSupportedAuxiliaryHintCount() const
327 {
328   return 0;
329 }
330
331 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
332 {
333   return std::string();
334 }
335
336 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
337 {
338   return -1;
339 }
340
341 bool Window::RemoveAuxiliaryHint( unsigned int id )
342 {
343   return false;
344 }
345
346 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
347 {
348   return false;
349 }
350
351 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
352 {
353   return std::string();
354 }
355
356 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
357 {
358   return -1;
359 }
360
361 void Window::SetInputRegion( const Rect< int >& inputRegion )
362 {
363 }
364
365 void Window::SetType( Dali::Window::Type type )
366 {
367   mType = type;
368 }
369
370 Dali::Window::Type Window::GetType() const
371 {
372   return mType;
373 }
374
375 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
376 {
377   return false;
378 }
379
380 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
381 {
382   return Dali::Window::NotificationLevel::NONE;
383 }
384
385 void Window::SetOpaqueState( bool opaque )
386 {
387   mOpaqueState = opaque;
388 }
389
390 bool Window::IsOpaqueState() const
391 {
392   return mOpaqueState;
393 }
394
395 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
396 {
397   return false;
398 }
399
400 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
401 {
402   return Dali::Window::ScreenOffMode::TIMEOUT;
403 }
404
405 bool Window::SetBrightness( int brightness )
406 {
407   return false;
408 }
409
410 int Window::GetBrightness() const
411 {
412   return 0;
413 }
414
415 void Window::SetSize( Dali::Window::WindowSize size )
416 {
417   PositionSize positionSize = mSurface->GetPositionSize();
418
419   if( positionSize.width != size.GetWidth() || positionSize.height != size.GetHeight() )
420   {
421     positionSize.width = size.GetWidth();
422     positionSize.height = size.GetHeight();
423
424     mSurface->MoveResize( positionSize );
425
426     mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
427
428     // Emit signal
429     mResizedSignal.Emit( Dali::Window::WindowSize( positionSize.width, positionSize.height ) );
430
431     mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
432   }
433 }
434
435 Dali::Window::WindowSize Window::GetSize() const
436 {
437   PositionSize positionSize = mSurface->GetPositionSize();
438
439   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
440 }
441
442 void Window::SetPosition( Dali::Window::WindowPosition position )
443 {
444   PositionSize positionSize = mSurface->GetPositionSize();
445
446   if( positionSize.x != position.GetX() || positionSize.y != position.GetY() )
447   {
448     positionSize.x = position.GetX();
449     positionSize.y = position.GetY();
450
451     mSurface->MoveResize( positionSize );
452   }
453 }
454
455 Dali::Window::WindowPosition Window::GetPosition() const
456 {
457   PositionSize positionSize = mSurface->GetPositionSize();
458
459   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
460 }
461
462 void Window::SetTransparency( bool transparent )
463 {
464 }
465
466 } // Adaptor
467 } // Internal
468 } // Dali