Merge "Support window rotation" into 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& posSize, const std::string& name, const std::string& className, bool isTransparent)
52 {
53   Window* window = new Window();
54   window->mIsTransparent = isTransparent;
55   window->Initialize(posSize, 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   mIndicator( NULL ),
116   mIndicatorOrientation( Dali::Window::PORTRAIT ),
117   mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
118   mIndicatorOpacityMode( Dali::Window::OPAQUE ),
119   mOverlay( NULL ),
120   mAdaptor( NULL ),
121   mType( Dali::DevelWindow::NORMAL ),
122   mPreferredOrientation( Dali::Window::PORTRAIT ),
123   mSupportedAuxiliaryHints(),
124   mAuxiliaryHints(),
125   mIndicatorVisibilityChangedSignal(),
126   mFocusChangedSignal(),
127   mResizedSignal(),
128   mDeleteRequestSignal()
129 {
130   mEventHandler = NULL;
131 }
132
133 Window::~Window()
134 {
135   delete mEventHandler;
136
137   if ( mAdaptor )
138   {
139     mAdaptor->RemoveObserver( *this );
140     mAdaptor->SetDragAndDropDetector( NULL );
141     mAdaptor = NULL;
142   }
143
144   delete mSurface;
145 }
146
147 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
148 {
149   // create an Wayland window by default
150   Any surface;
151   Wayland::RenderSurface* windowSurface = new Wayland::RenderSurface( windowPosition, surface, name, mIsTransparent );
152
153   mSurface = windowSurface;
154
155   mOrientation = Orientation::New(this);
156
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()
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 unsigned int Window::GetSupportedAuxiliaryHintCount()
322 {
323   return 0;
324 }
325
326 std::string Window::GetSupportedAuxiliaryHint( unsigned int index )
327 {
328   return std::string();
329 }
330
331 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
332 {
333   return -1;
334 }
335
336 bool Window::RemoveAuxiliaryHint( unsigned int id )
337 {
338   return false;
339 }
340
341 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
342 {
343   return false;
344 }
345
346 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
347 {
348   return std::string();
349 }
350
351 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
352 {
353   return -1;
354 }
355
356 void Window::SetInputRegion( const Rect< int >& inputRegion )
357 {
358 }
359
360 void Window::SetType( Dali::DevelWindow::Type type )
361 {
362   mType = type;
363 }
364
365 Dali::DevelWindow::Type Window::GetType() const
366 {
367   return mType;
368 }
369
370 bool Window::SetNotificationLevel( Dali::DevelWindow::NotificationLevel::Type level )
371 {
372   return false;
373 }
374
375 Dali::DevelWindow::NotificationLevel::Type Window::GetNotificationLevel()
376 {
377   return Dali::DevelWindow::NotificationLevel::NONE;
378 }
379
380 void Window::SetOpaqueState( bool opaque )
381 {
382   mOpaqueState = opaque;
383 }
384
385 bool Window::IsOpaqueState()
386 {
387   return mOpaqueState;
388 }
389
390 bool Window::SetScreenMode( Dali::DevelWindow::ScreenMode::Type screenMode )
391 {
392   return false;
393 }
394
395 Dali::DevelWindow::ScreenMode::Type Window::GetScreenMode()
396 {
397   return Dali::DevelWindow::ScreenMode::DEFAULT;
398 }
399
400 bool Window::SetBrightness( int brightness )
401 {
402   return false;
403 }
404
405 int Window::GetBrightness()
406 {
407   return 0;
408 }
409
410 } // Adaptor
411 } // Internal
412 } // Dali