Revert "[Tizen] Fix the converity issue of GlWindow"
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / gl-window-impl.h
1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_IMPL_H
3
4 /*
5  * Copyright (c) 2020 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/adaptor-framework/window.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/internal/graphics/gles/egl-graphics.h>
28 #include <dali/public-api/adaptor-framework/key-grab.h>
29 #include <dali/devel-api/adaptor-framework/gl-window.h>
30 #include <dali/internal/adaptor/common/adaptor-impl.h>
31 #include <dali/internal/window-system/common/event-handler.h>
32
33 namespace Dali
34 {
35 class Adaptor;
36
37 namespace Internal
38 {
39 namespace Adaptor
40 {
41 class WindowBase;
42
43 class GlWindow;
44 using GlWindowPtr = IntrusivePtr< GlWindow >;
45 using EventHandlerPtr = IntrusivePtr< EventHandler >;
46
47 /**
48  * Window provides a surface to render onto with orientation.
49  */
50 class GlWindow : public BaseObject, public EventHandler::Observer, public DamageObserver, public ConnectionTracker
51 {
52 public:
53
54   using KeyEventSignalType = Dali::GlWindow::KeyEventSignalType;
55   using TouchSignalType = Dali::GlWindow::TouchSignalType;
56   using FocusChangeSignalType = Dali::GlWindow::FocusChangeSignalType;
57   using ResizedSignalType = Dali::GlWindow::ResizedSignalType;
58   using VisibilityChangedSignalType = Dali::GlWindow::VisibilityChangedSignalType;
59   using SignalType = Signal< void () >;
60
61   /**
62    * @brief Create a new GlWindow. This should only be called once by the Application class
63    * @param[in] surface The surface used to render on.
64    * @param[in] positionSize The position and size of the window
65    * @param[in] name The window title
66    * @param[in] className The window class name
67    * @param[in] isTransparent Whether window is transparent
68    * @return A newly allocated Window
69    */
70   static GlWindow* New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false );
71
72   /**
73    * @copydoc Dali::GlWindow::SetEglConfig()
74    */
75   void SetEglConfig( bool depth, bool stencil, int msaa, Dali::GlWindow::GlesVersion version );
76
77   /**
78    * @copydoc Dali::GlWindow::Raise()
79    */
80   void Raise();
81
82   /**
83    * @copydoc Dali::GlWindow::Lower()
84    */
85   void Lower();
86
87   /**
88    * @copydoc Dali::GlWindow::Activate()
89    */
90   void Activate();
91
92   /**
93    * @copydoc Dali::GlWindow::Show()
94    */
95   void Show();
96
97   /**
98    * @copydoc Dali::GlWindow::Hide()
99    */
100   void Hide();
101
102   /**
103    * @copydoc Dali::GlWindow::GetSupportedAuxiliaryHintCount()
104    */
105   unsigned int GetSupportedAuxiliaryHintCount() const;
106
107   /**
108    * @copydoc Dali::GlWindow::GetSupportedAuxiliaryHint()
109    */
110   std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
111
112   /**
113    * @copydoc Dali::GlWindow::AddAuxiliaryHint()
114    */
115   unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
116
117   /**
118    * @copydoc Dali::GlWindow::RemoveAuxiliaryHint()
119    */
120   bool RemoveAuxiliaryHint( unsigned int id );
121
122   /**
123    * @copydoc Dali::GlWindow::SetAuxiliaryHintValue()
124    */
125   bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
126
127   /**
128    * @copydoc Dali::GlWindow::GetAuxiliaryHintValue()
129    */
130   std::string GetAuxiliaryHintValue( unsigned int id ) const;
131
132   /**
133    * @copydoc Dali::GlWindow::GetAuxiliaryHintId()
134    */
135   unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
136
137   /**
138    * @copydoc Dali::GlWindow::SetInputRegion()
139    */
140   void SetInputRegion( const Rect< int >& inputRegion );
141
142   /**
143    * @copydoc Dali::GlWindow::SetOpaqueState()
144    */
145   void SetOpaqueState( bool opaque );
146
147   /**
148    * @copydoc Dali::GlWindow::IsOpaqueState()
149    */
150   bool IsOpaqueState() const;
151
152   /**
153    * @copydoc Dali::GlWindow::SetPositionSize()
154    */
155   void SetPositionSize( PositionSize positionSize );
156
157   /**
158    * @copydoc Dali::GlWindow::GetPositionSize()
159    */
160   PositionSize GetPositionSize() const;
161
162   /**
163    * @copydoc Dali::GlWindow::GetCurrentOrientation() const
164    */
165   Dali::GlWindow::GlWindowOrientation GetCurrentOrientation() const;
166
167   /**
168    * @copydoc Dali::GlWindow::SetAvailableOrientations()
169    */
170   void SetAvailableOrientations( const Dali::Vector< Dali::GlWindow::GlWindowOrientation >& orientations );
171
172   /**
173    * @copydoc Dali::GlWindow::SetPreferredOrientation()
174    */
175   void SetPreferredOrientation( Dali::GlWindow::GlWindowOrientation orientation );
176
177   /**
178    * @copydoc Dali::GlWindow::RegisterGlCallback()
179    */
180   void RegisterGlCallback( GlInitialize glInit, GlRenderFrame glRenderFrame, GlTerminate glTerminate );
181
182   /**
183    * @copydoc Dali::GlWindow::RenderOnce()
184    */
185   void RenderOnce();
186
187 public: // For implementation
188   /**
189    * @brief Sets child window with Dali::Window
190    *
191    * Currently the child window is default window.
192    */
193   void SetChild( Dali::Window& child );
194
195 private:
196
197   /**
198    * Private constructor.
199    * @sa Window::New()
200    */
201   GlWindow();
202
203   /**
204    * Destructor
205    */
206   virtual ~GlWindow();
207
208   /**
209    * Second stage initialization
210    */
211   void Initialize( const PositionSize& positionSize, const std::string& name, const std::string& className );
212
213   /**
214    * Called when the window becomes iconified or deiconified.
215    */
216   void OnIconifyChanged( bool iconified );
217
218   /**
219    * Called when the window focus is changed.
220    */
221   void OnFocusChanged( bool focusIn );
222
223   /**
224    * Called when the output is transformed.
225    */
226   void OnOutputTransformed();
227
228   /**
229    * Called when the window receives a delete request.
230    */
231   void OnDeleteRequest();
232
233   /**
234    * @brief Set available rotation angle to window base.
235    */
236   void SetAvailableAnlges( const std::vector< int >& angles );
237
238   /**
239    * @brief Check available window rotation angle for Available angle.
240    */
241   bool IsOrientationAvailable( Dali::GlWindow::GlWindowOrientation orientation ) const;
242
243   /**
244    * @brief Convert from window orientation to angle using orientation mode value.
245    */
246   int ConvertToAngle( Dali::GlWindow::GlWindowOrientation orientation );
247
248   /**
249    * @brief Convert from angle to window orientation using orientation mode value.
250    */
251   Dali::GlWindow::GlWindowOrientation ConvertToOrientation( int angle ) const;
252
253   /**
254    * @brief Run Ui GL callback function.
255    */
256   bool RunCallback();
257
258   /**
259    * @brief Initialize and create EGL resource
260    */
261   void InitializeGraphics();
262
263   /**
264    * @brief Sets event handler for window's events.
265    */
266   void SetEventHandler() ;
267
268   /**
269    * @brief Gets the native window handle
270    */
271   Dali::Any GetNativeHandle() const;
272
273   /**
274    * @brief Gets the native window handle ID
275    */
276   int32_t GetNativeId() const;
277
278   /**
279    * @brief calculate touch position for rotation.
280    */
281   void RecalculateTouchPosition( Integration::Point& point ) ;
282
283   /**
284    * @brief Sets window and class name.
285    */
286   void SetClass( const std::string name, const std::string className );
287
288 private:
289
290   /**
291    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
292    */
293   void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) override;
294
295   /**
296    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
297    */
298   void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) override;
299
300   /**
301    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
302    */
303   void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) override;
304
305   /**
306    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
307    */
308   void OnRotation( const RotationEvent& rotation ) override;
309
310 private: // From Dali::Internal::Adaptor::DamageObserver
311
312   /**
313    * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
314    */
315   void OnDamaged( const DamageArea& area );
316
317 public: // Signals
318
319   /**
320    * @copydoc Dali::GlWindow::FocusChangeSignal()
321    */
322   FocusChangeSignalType& FocusChangeSignal() { return mFocusChangeSignal; }
323
324   /**
325    * @copydoc Dali::GlWindow::ResizedSignal()
326    */
327   ResizedSignalType& ResizedSignal() { return mResizedSignal; }
328
329   /**
330    * @copydoc Dali::GlWindow::KeyEventSignal()
331    */
332   KeyEventSignalType& KeyEventSignal() { return mKeyEventSignal; }
333
334   /**
335    * @copydoc Dali::GlWindow::TouchSignal()
336    */
337   TouchSignalType& TouchSignal() { return mTouchSignal; }
338
339   /**
340    * @copydoc Dali::GlWindow::VisibilityChangedSignal()
341    */
342   VisibilityChangedSignalType& VisibilityChangedSignal() { return mVisibilityChangedSignal; }
343
344 private:
345
346   std::unique_ptr< WindowBase >         mWindowBase;
347   std::unique_ptr< GraphicsInterface >  mGraphics;                    ///< Graphics interface
348   Dali::DisplayConnection*              mDisplayConnection;
349   std::string                           mName;
350   std::string                           mClassName;
351   EventHandlerPtr                       mEventHandler;         ///< The window events handler
352   PositionSize                          mPositionSize;
353   ColorDepth                            mColorDepth;
354   Dali::Window                          mChildWindow;
355   bool                                  mIsTransparent:1;
356   bool                                  mIsFocusAcceptable:1;
357   bool                                  mIconified:1;
358   bool                                  mOpaqueState:1;
359   bool                                  mResizedEnabled:1;
360   bool                                  mVisible:1;
361   bool                                  mIsRotated:1;
362   bool                                  mIsWindowRotated:1;
363   bool                                  mIsTouched:1;
364
365   std::vector< int >                    mAvailableAngles;
366   int                                   mPreferredAngle;
367   int                                   mTotalRotationAngle;   ///< The angle of window + screen rotation angle % 360
368   int                                   mWindowRotationAngle;  ///< The angle of window rotation angle
369   int                                   mScreenRotationAngle;  ///< The angle of screen rotation angle
370   int                                   mOrientationMode;      ///< 0: Default portrati, 1:Default landscape
371   int                                   mWindowWidth;          ///< The width of the window
372   int                                   mWindowHeight;         ///< The height of the window
373   int                                   mNativeWindowId;       ///< The Native Window Id
374
375   // Signals
376   KeyEventSignalType                    mKeyEventSignal;
377   TouchSignalType                       mTouchSignal;
378   FocusChangeSignalType                 mFocusChangeSignal;
379   ResizedSignalType                     mResizedSignal;
380   VisibilityChangedSignalType           mVisibilityChangedSignal;
381
382   // EGL, GL Resource
383   GlInitialize                          mGLInitCallback;
384   GlRenderFrame                         mGLRenderFrameCallback;
385   GlTerminate                           mGLTerminateCallback;
386   CallbackBase*                         mGLRenderCallback;
387   EGLSurface                            mEGLSurface;
388   EGLContext                            mEGLContext;
389   Dali::GlWindow::GlesVersion           mGLESVersion;
390   bool                                  mInitCallback:1;
391   bool                                  mDepth:1;
392   bool                                  mStencil:1;
393   bool                                  mIsEGLInitialize:1;
394   int                                   mMSAA;
395 };
396
397 } // namespace Adaptor
398 } // namepsace Internal
399
400 // Helpers for public-api forwarding methods
401
402 inline Internal::Adaptor::GlWindow& GetImplementation(Dali::GlWindow& window)
403 {
404   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
405   BaseObject& object = window.GetBaseObject();
406   return static_cast<Internal::Adaptor::GlWindow&>(object);
407 }
408
409 inline const Internal::Adaptor::GlWindow& GetImplementation(const Dali::GlWindow& window)
410 {
411   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
412   const BaseObject& object = window.GetBaseObject();
413   return static_cast<const Internal::Adaptor::GlWindow&>(object);
414 }
415
416 } // namespace Dali
417
418 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_IMPL_H