[Tizen] Add screen and client rotation itself function
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl / window-base-ecore-wl.h
1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_TIZENWAYLAND_WINDOW_BASE_ECORE_WL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_TIZENWAYLAND_WINDOW_BASE_ECORE_WL_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/window-system/common/window-base.h>
23
24 // EXTERNAL HEADERS
25 #include <Ecore.h>
26 #include <Ecore_Wayland.h>
27 #include <tizen-extension-client-protocol.h>
28 #include <wayland-egl.h>
29
30 #ifdef DALI_ELDBUS_AVAILABLE
31 #include <Eldbus.h>
32 #endif
33
34 namespace Dali
35 {
36 namespace Internal
37 {
38 namespace Adaptor
39 {
40
41 class WindowRenderSurface;
42 class WindowRenderSurfaceEcoreWl;
43
44 /**
45  * WindowBaseEcoreWl class provides an WindowBase Ecore-Wayland implementation.
46  */
47 class WindowBaseEcoreWl : public WindowBase
48 {
49 public:
50
51   /**
52    * @brief Constructor
53    */
54   WindowBaseEcoreWl( PositionSize positionSize, Any surface, bool isTransparent );
55
56   /**
57    * @brief Destructor
58    */
59   virtual ~WindowBaseEcoreWl();
60
61 public:
62
63   /**
64    * @brief Called when the window iconify state is changed.
65    */
66   Eina_Bool OnIconifyStateChanged( void* data, int type, void* event );
67
68   /**
69    * @brief Called when the window gains focus.
70    */
71   Eina_Bool OnFocusIn( void* data, int type, void* event );
72
73   /**
74    * @brief Called when the window loses focus.
75    */
76   Eina_Bool OnFocusOut( void* data, int type, void* event );
77
78   /**
79    * @brief Called when the output is transformed.
80    */
81   Eina_Bool OnOutputTransform( void* data, int type, void* event );
82
83   /**
84    * @brief Called when the output transform should be ignored.
85    */
86   Eina_Bool OnIgnoreOutputTransform( void* data, int type, void* event );
87
88   /**
89    * @brief Called when a rotation event is recevied.
90    */
91   void OnRotation( void* data, int type, void* event );
92
93   /**
94    * @brief Called when a touch down is received.
95    */
96   void OnMouseButtonDown( void* data, int type, void* event );
97
98   /**
99    * @brief Called when a touch up is received.
100    */
101   void OnMouseButtonUp( void* data, int type, void* event );
102
103   /**
104    * @brief Called when a touch motion is received.
105    */
106   void OnMouseButtonMove( void* data, int type, void* event );
107
108   /**
109    * @brief Called when a touch is canceled.
110    */
111   void OnMouseButtonCancel( void* data, int type, void* event );
112
113   /**
114    * @brief Called when a mouse wheel is received.
115    */
116   void OnMouseWheel( void* data, int type, void* event );
117
118   /**
119    * @brief Called when a detent rotation event is recevied.
120    */
121   void OnDetentRotation( void* data, int type, void* event );
122
123   /**
124    * @brief Called when a key down is received.
125    */
126   void OnKeyDown( void* data, int type, void* event );
127
128   /**
129    * @brief Called when a key up is received.
130    */
131   void OnKeyUp( void* data, int type, void* event );
132
133   /**
134    * @brief Called when the source window notifies us the content in clipboard is selected.
135    */
136   void OnDataSend( void* data, int type, void* event );
137
138   /**
139    * @brief Called when the source window sends us about the selected content.
140    */
141   void OnDataReceive( void* data, int type, void* event );
142
143   /**
144    * @brief Called when a font name is changed.
145    */
146   void OnFontNameChanged();
147
148   /**
149    * @brief Called when a font size is changed.
150    */
151   void OnFontSizeChanged();
152
153 #ifdef DALI_ELDBUS_AVAILABLE
154   /**
155    * @brief Called when Ecore ElDBus accessibility event is received.
156    */
157   void OnEcoreElDBusAccessibilityNotification( void* context, const Eldbus_Message* message );
158 #endif
159
160   /**
161    * @brief RegistryGlobalCallback
162    */
163   void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version );
164
165   /**
166    * @brief RegistryGlobalCallbackRemove
167    */
168   void RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id );
169
170   /**
171    * @brief TizenPolicyNotificationChangeDone
172    */
173   void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state );
174
175   /**
176    * @brief TizenPolicyScreenModeChangeDone
177    */
178   void TizenPolicyScreenModeChangeDone( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state );
179
180   /**
181    * @brief DisplayPolicyBrightnessChangeDone
182    */
183   void DisplayPolicyBrightnessChangeDone( void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state );
184
185 public:
186
187   /**
188    * @copydoc Dali::Internal::Adaptor::WindowBase::GetNativeWindow()
189    */
190   Any GetNativeWindow() override;
191
192   /**
193    * @copydoc Dali::Internal::Adaptor::WindowBase::GetNativeWindowId()
194    */
195   int GetNativeWindowId() override;
196
197   /**
198    * @copydoc Dali::Internal::Adaptor::WindowBase::CreateEglWindow()
199    */
200   EGLNativeWindowType CreateEglWindow( int width, int height ) override;
201
202   /**
203    * @copydoc Dali::Internal::Adaptor::WindowBase::DestroyEglWindow()
204    */
205   void DestroyEglWindow() override;
206
207   /**
208    * @copydoc Dali::Internal::Adaptor::WindowBase::SetEglWindowRotation()
209    */
210   void SetEglWindowRotation( int angle ) override;
211
212   /**
213    * @copydoc Dali::Internal::Adaptor::WindowBase::SetEglWindowBufferTransform()
214    */
215   void SetEglWindowBufferTransform( int angle ) override;
216
217   /**
218    * @copydoc Dali::Internal::Adaptor::WindowBase::SetEglWindowTransform()
219    */
220   void SetEglWindowTransform( int angle ) override;
221
222   /**
223    * @copydoc Dali::Internal::Adaptor::WindowBase::ResizeEglWindow()
224    */
225   void ResizeEglWindow( PositionSize positionSize ) override;
226
227   /**
228    * @copydoc Dali::Internal::Adaptor::WindowBase::IsEglWindowRotationSupported()
229    */
230   bool IsEglWindowRotationSupported() override;
231
232   /**
233    * @copydoc Dali::Internal::Adaptor::WindowBase::Move()
234    */
235   void Move( PositionSize positionSize ) override;
236
237   /**
238    * @copydoc Dali::Internal::Adaptor::WindowBase::Resize()
239    */
240   void Resize( PositionSize positionSize ) override;
241
242   /**
243    * @copydoc Dali::Internal::Adaptor::WindowBase::MoveResize()
244    */
245   void MoveResize( PositionSize positionSize ) override;
246
247   /**
248    * @copydoc Dali::Internal::Adaptor::WindowBase::SetClass()
249    */
250   void SetClass( const std::string& name, const std::string& className ) override;
251
252   /**
253    * @copydoc Dali::Internal::Adaptor::WindowBase::Raise()
254    */
255   void Raise() override;
256
257   /**
258    * @copydoc Dali::Internal::Adaptor::WindowBase::Lower()
259    */
260   void Lower() override;
261
262   /**
263    * @copydoc Dali::Internal::Adaptor::WindowBase::Activate()
264    */
265   void Activate() override;
266
267   /**
268    * @copydoc Dali::Internal::Adaptor::WindowBase::SetAvailableAnlges()
269    */
270   void SetAvailableAnlges( const std::vector< int >& angles ) override;
271
272   /**
273    * @copydoc Dali::Internal::Adaptor::WindowBase::SetPreferredAngle()
274    */
275   void SetPreferredAngle( int angle ) override;
276
277   /**
278    * @copydoc Dali::Internal::Adaptor::WindowBase::SetAcceptFocus()
279    */
280   void SetAcceptFocus( bool accept ) override;
281
282   /**
283    * @copydoc Dali::Internal::Adaptor::WindowBase::Show()
284    */
285   void Show() override;
286
287   /**
288    * @copydoc Dali::Internal::Adaptor::WindowBase::Hide()
289    */
290   void Hide() override;
291
292   /**
293    * @copydoc Dali::Internal::Adaptor::WindowBase::GetSupportedAuxiliaryHintCount()
294    */
295   unsigned int GetSupportedAuxiliaryHintCount() const override;
296
297   /**
298    * @copydoc Dali::Internal::Adaptor::WindowBase::GetSupportedAuxiliaryHint()
299    */
300   std::string GetSupportedAuxiliaryHint( unsigned int index ) const override;
301
302   /**
303    * @copydoc Dali::Internal::Adaptor::WindowBase::AddAuxiliaryHint()
304    */
305   unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value ) override;
306
307   /**
308    * @copydoc Dali::Internal::Adaptor::WindowBase::RemoveAuxiliaryHint()
309    */
310   bool RemoveAuxiliaryHint( unsigned int id ) override;
311
312   /**
313    * @copydoc Dali::Internal::Adaptor::WindowBase::SetAuxiliaryHintValue()
314    */
315   bool SetAuxiliaryHintValue( unsigned int id, const std::string& value ) override;
316
317   /**
318    * @copydoc Dali::Internal::Adaptor::WindowBase::GetAuxiliaryHintValue()
319    */
320   std::string GetAuxiliaryHintValue( unsigned int id ) const override;
321
322   /**
323    * @copydoc Dali::Internal::Adaptor::WindowBase::GetAuxiliaryHintId()
324    */
325   unsigned int GetAuxiliaryHintId( const std::string& hint ) const override;
326
327   /**
328    * @copydoc Dali::Internal::Adaptor::WindowBase::SetInputRegion()
329    */
330   void SetInputRegion( const Rect< int >& inputRegion ) override;
331
332   /**
333    * @copydoc Dali::Internal::Adaptor::WindowBase::SetType()
334    */
335   void SetType( Dali::Window::Type type ) override;
336
337   /**
338    * @copydoc Dali::Internal::Adaptor::WindowBase::SetNotificationLevel()
339    */
340   bool SetNotificationLevel( Dali::Window::NotificationLevel::Type level ) override;
341
342   /**
343    * @copydoc Dali::Internal::Adaptor::WindowBase::GetNotificationLevel()
344    */
345   Dali::Window::NotificationLevel::Type GetNotificationLevel() const override;
346
347   /**
348    * @copydoc Dali::Internal::Adaptor::WindowBase::SetOpaqueState()
349    */
350   void SetOpaqueState( bool opaque ) override;
351
352   /**
353    * @copydoc Dali::Internal::Adaptor::WindowBase::SetScreenOffMode()
354    */
355   bool SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode) override;
356
357   /**
358    * @copydoc Dali::Internal::Adaptor::WindowBase::GetScreenOffMode()
359    */
360   Dali::Window::ScreenOffMode::Type GetScreenOffMode() const override;
361
362   /**
363    * @copydoc Dali::Internal::Adaptor::WindowBase::SetBrightness()
364    */
365   bool SetBrightness( int brightness ) override;
366
367   /**
368    * @copydoc Dali::Internal::Adaptor::WindowBase::GetBrightness()
369    */
370   int GetBrightness() const override;
371
372   /**
373    * @copydoc Dali::Internal::Adaptor::WindowBase::GrabKey()
374    */
375   bool GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode ) override;
376
377   /**
378    * @copydoc Dali::Internal::Adaptor::WindowBase::UngrabKey()
379    */
380   bool UngrabKey( Dali::KEY key ) override;
381
382   /**
383    * @copydoc Dali::Internal::Adaptor::WindowBase::GrabKeyList()
384    */
385   bool GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result ) override;
386
387   /**
388    * @copydoc Dali::Internal::Adaptor::WindowBase::UngrabKeyList()
389    */
390   bool UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result ) override;
391
392   /**
393    * @copydoc Dali::Internal::Adaptor::WindowBase::GetDpi()
394    */
395   void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) override;
396
397   /**
398    * @brief Return the orientation of the surface.
399    * @return The orientation
400    */
401   virtual int GetOrientation() const override;
402
403   /**
404    * @copydoc Dali::Internal::Adaptor::WindowBase::GetScreenRotationAngle()
405    */
406   int GetScreenRotationAngle() override;
407
408   /**
409    * @copydoc Dali::Internal::Adaptor::WindowBase::SetWindowRotationAngle()
410    */
411   void SetWindowRotationAngle( int degree ) override;
412
413   /**
414    * @copydoc Dali::Internal::Adaptor::WindowBase::GetWindowRotationAngle()
415    */
416   virtual int GetWindowRotationAngle() override;
417
418   /**
419    * @copydoc Dali::Internal::Adaptor::WindowBase::WindowRotationCompleted()
420    */
421   void WindowRotationCompleted( int degree, int width, int height ) override;
422
423   /**
424    * @copydoc Dali::Internal::Adaptor::WindowBase::SetTransparency()
425    */
426   void SetTransparency( bool transparent ) override;
427
428   /**
429    * @copydoc Dali::Internal::Adaptor::WindowBase::SetParent()
430    */
431   void SetParent( WindowBase* parentWinBase ) override;
432
433   /**
434    * @copydoc  Dali::Internal::Adaptor::WindowBase::CreateFrameRenderedSyncFence()
435    */
436   int CreateFrameRenderedSyncFence() override;
437
438   /**
439    * @copydoc  Dali::Internal::Adaptor::WindowBase::CreateFramePresentedSyncFence()
440    */
441   int CreateFramePresentedSyncFence() override;
442
443 private:
444
445   /**
446    * Second stage initialization
447    */
448   void Initialize( PositionSize positionSize, Any surface, bool isTransparent );
449
450   /**
451    * Initialize Ecore ElDBus
452    */
453   void InitializeEcoreElDBus();
454
455   /**
456    * @brief Create window
457    */
458   void CreateWindow( PositionSize positionSize );
459
460 protected:
461
462   // Undefined
463   WindowBaseEcoreWl(const WindowBaseEcoreWl&) = delete;
464
465   // Undefined
466   WindowBaseEcoreWl& operator=(const WindowBaseEcoreWl& rhs) = delete;
467
468 private:
469
470   typedef std::vector< std::pair< std::string, std::string > > AuxiliaryHints;
471
472   Dali::Vector< Ecore_Event_Handler* > mEcoreEventHandler;
473
474   Ecore_Wl_Window*                     mEcoreWindow;
475   wl_surface*                          mWlSurface;
476   wl_egl_window*                       mEglWindow;
477   wl_display*                          mDisplay;
478   wl_event_queue*                      mEventQueue;
479   tizen_policy*                        mTizenPolicy;
480   tizen_display_policy*                mTizenDisplayPolicy;
481
482   std::vector< std::string >           mSupportedAuxiliaryHints;
483   AuxiliaryHints                       mAuxiliaryHints;
484
485   int                                  mNotificationLevel;
486   uint32_t                             mNotificationChangeState;
487   bool                                 mNotificationLevelChangeDone;
488
489   int                                  mScreenOffMode;
490   uint32_t                             mScreenOffModeChangeState;
491   bool                                 mScreenOffModeChangeDone;
492
493   int                                  mBrightness;
494   uint32_t                             mBrightnessChangeState;
495   bool                                 mBrightnessChangeDone;
496
497   bool                                 mOwnSurface;
498
499   int                                  mWindowRotationAngle;
500   int                                  mScreenRotationAngle;
501   int                                  mSupportedPreProtation;
502 #ifdef DALI_ELDBUS_AVAILABLE
503   Eldbus_Connection*                   mSystemConnection;
504 #endif // DALI_ELDBUS_AVAILABLE
505
506 };
507
508 } // namespace Adaptor
509
510 } // namespace internal
511
512 } // namespace Dali
513
514 #endif // DALI_INTERNAL_WINDOWSYSTEM_TIZENWAYLAND_WINDOW_BASE_ECORE_WL_H