1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_IMPL_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
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>
44 using GlWindowPtr = IntrusivePtr< GlWindow >;
45 using EventHandlerPtr = IntrusivePtr< EventHandler >;
48 * Window provides a surface to render onto with orientation.
50 class GlWindow : public BaseObject, public EventHandler::Observer, public DamageObserver, public ConnectionTracker
54 using KeyEventSignalType = Dali::GlWindow::KeyEventSignalType;
55 using TouchEventSignalType = Dali::GlWindow::TouchEventSignalType;
56 using FocusChangeSignalType = Dali::GlWindow::FocusChangeSignalType;
57 using ResizeSignalType = Dali::GlWindow::ResizeSignalType;
58 using VisibilityChangedSignalType = Dali::GlWindow::VisibilityChangedSignalType;
59 using SignalType = Signal< void () >;
62 * @brief Create a new GlWindow. This should only be called once by the Application class
63 * @param[in] positionSize The position and size of the window
64 * @param[in] name The window title
65 * @param[in] className The window class name
66 * @param[in] isTransparent Whether window is transparent
67 * @return A newly allocated Window
69 static GlWindow* New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false );
72 * @copydoc Dali::GlWindow::SetEglConfig()
74 void SetEglConfig( bool depth, bool stencil, int msaa, Dali::GlWindow::GlesVersion version );
77 * @copydoc Dali::GlWindow::Raise()
82 * @copydoc Dali::GlWindow::Lower()
87 * @copydoc Dali::GlWindow::Activate()
92 * @copydoc Dali::GlWindow::Show()
97 * @copydoc Dali::GlWindow::Hide()
102 * @copydoc Dali::GlWindow::GetSupportedAuxiliaryHintCount()
104 unsigned int GetSupportedAuxiliaryHintCount() const;
107 * @copydoc Dali::GlWindow::GetSupportedAuxiliaryHint()
109 std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
112 * @copydoc Dali::GlWindow::AddAuxiliaryHint()
114 unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
117 * @copydoc Dali::GlWindow::RemoveAuxiliaryHint()
119 bool RemoveAuxiliaryHint( unsigned int id );
122 * @copydoc Dali::GlWindow::SetAuxiliaryHintValue()
124 bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
127 * @copydoc Dali::GlWindow::GetAuxiliaryHintValue()
129 std::string GetAuxiliaryHintValue( unsigned int id ) const;
132 * @copydoc Dali::GlWindow::GetAuxiliaryHintId()
134 unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
137 * @copydoc Dali::GlWindow::SetInputRegion()
139 void SetInputRegion( const Rect< int >& inputRegion );
142 * @copydoc Dali::GlWindow::SetOpaqueState()
144 void SetOpaqueState( bool opaque );
147 * @copydoc Dali::GlWindow::IsOpaqueState()
149 bool IsOpaqueState() const;
152 * @copydoc Dali::GlWindow::SetPositionSize()
154 void SetPositionSize( PositionSize positionSize );
157 * @copydoc Dali::GlWindow::GetPositionSize()
159 PositionSize GetPositionSize() const;
162 * @copydoc Dali::GlWindow::GetCurrentOrientation() const
164 Dali::GlWindow::GlWindowOrientation GetCurrentOrientation() const;
167 * @copydoc Dali::GlWindow::SetAvailableOrientations()
169 void SetAvailableOrientations( const Dali::Vector< Dali::GlWindow::GlWindowOrientation >& orientations );
172 * @copydoc Dali::GlWindow::SetPreferredOrientation()
174 void SetPreferredOrientation( Dali::GlWindow::GlWindowOrientation orientation );
177 * @copydoc Dali::GlWindow::RegisterGlCallback()
179 void RegisterGlCallback( GlInitialize glInit, GlRenderFrame glRenderFrame, GlTerminate glTerminate );
182 * @copydoc Dali::GlWindow::RenderOnce()
186 public: // For implementation
188 * @brief Sets child window with Dali::Window
190 * @param[in] child The child window.
192 * Most of cases, child window is the default window in adaptor
194 * Currently the child window is default window.
196 void SetChild( Dali::Window& child );
201 * Private constructor.
212 * Second stage initialization
214 * @param[in] positionSize The position and size of the window
215 * @param[in] name The window title
216 * @param[in] className The window class name
218 void Initialize( const PositionSize& positionSize, const std::string& name, const std::string& className );
221 * Called when the window becomes iconified or deiconified.
223 * @param[in] iconified The flag whether window is iconifed or deiconfied.
225 void OnIconifyChanged( bool iconified );
228 * Called when the window focus is changed.
229 * @param[in] focusIn The flag whether window is focused or not.
231 void OnFocusChanged( bool focusIn );
234 * Called when the output is transformed.
236 void OnOutputTransformed();
239 * Called when the window receives a delete request.
241 void OnDeleteRequest();
244 * @brief Set available rotation angle to window base.
246 * @param[in] angles The list of the avaiabled rotation angle.
248 void SetAvailableAnlges( const std::vector< int >& angles );
251 * @brief Check available window orientation for Available angle.
253 * @param[in] orientation the oritation value of window rotation.
255 * @return true is available window orientation. false is not available.
257 bool IsOrientationAvailable( Dali::GlWindow::GlWindowOrientation orientation ) const;
260 * @brief Convert from window orientation to angle using orientation mode value.
262 * @param[in] orientation the oritation value of window rotation.
264 * @return The coverted angle value is returned.
266 int ConvertToAngle( Dali::GlWindow::GlWindowOrientation orientation );
269 * @brief Convert from angle to window orientation using orientation mode value.
271 * @param[in] angle the angle value of window rotation.
273 * @return The converted window orientation value is returned.
275 Dali::GlWindow::GlWindowOrientation ConvertToOrientation( int angle ) const;
278 * @brief Run Ui GL callback function.
280 * @return true is the callback function works continuos.
285 * @brief Initialize and create EGL resource
287 void InitializeGraphics();
290 * @brief Sets event handler for window's events.
292 void SetEventHandler() ;
295 * @brief calculate touch position for rotation.
297 void RecalculateTouchPosition( Integration::Point& point ) ;
300 * @brief Sets window and class name.
302 * @param[in] name The name of the window
303 * @param[in] className The class of the window
305 void SetClass( const std::string& name, const std::string className );
310 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
312 void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) override;
315 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
317 void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) override;
320 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
322 void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) override;
325 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
327 void OnRotation( const RotationEvent& rotation ) override;
329 private: // From Dali::Internal::Adaptor::DamageObserver
332 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
334 void OnDamaged( const DamageArea& area );
339 * @copydoc Dali::GlWindow::FocusChangeSignal()
341 FocusChangeSignalType& FocusChangeSignal() { return mFocusChangeSignal; }
344 * @copydoc Dali::GlWindow::ResizeSignal()
346 ResizeSignalType& ResizeSignal() { return mResizeSignal; }
349 * @copydoc Dali::GlWindow::KeyEventSignal()
351 KeyEventSignalType& KeyEventSignal() { return mKeyEventSignal; }
354 * @copydoc Dali::GlWindow::TouchSignal()
356 TouchEventSignalType& TouchedSignal() { return mTouchedSignal; }
359 * @copydoc Dali::GlWindow::VisibilityChangedSignal()
361 VisibilityChangedSignalType& VisibilityChangedSignal() { return mVisibilityChangedSignal; }
365 std::unique_ptr< WindowBase > mWindowBase;
366 GraphicsInterface* mGraphics; ///< Graphics interface
368 std::string mClassName;
369 EventHandlerPtr mEventHandler; ///< The window events handler
370 PositionSize mPositionSize;
371 ColorDepth mColorDepth;
372 Dali::Window mChildWindow;
373 bool mIsTransparent:1;
374 bool mIsFocusAcceptable:1;
377 bool mResizeEnabled:1;
380 bool mIsWindowRotated:1;
383 std::vector< int > mAvailableAngles;
385 int mTotalRotationAngle; ///< The angle of window + screen rotation angle % 360
386 int mWindowRotationAngle; ///< The angle of window rotation angle
387 int mScreenRotationAngle; ///< The angle of screen rotation angle
388 int mOrientationMode; ///< 0: Default portrati, 1:Default landscape
389 int mWindowWidth; ///< The width of the window
390 int mWindowHeight; ///< The height of the window
391 int mNativeWindowId; ///< The Native Window Id
394 KeyEventSignalType mKeyEventSignal;
395 TouchEventSignalType mTouchedSignal;
396 FocusChangeSignalType mFocusChangeSignal;
397 ResizeSignalType mResizeSignal;
398 VisibilityChangedSignalType mVisibilityChangedSignal;
401 GlInitialize mGLInitCallback;
402 GlRenderFrame mGLRenderFrameCallback;
403 GlTerminate mGLTerminateCallback;
404 CallbackBase* mGLRenderCallback;
405 EGLSurface mEGLSurface;
406 EGLContext mEGLContext;
407 Dali::GlWindow::GlesVersion mGLESVersion;
408 bool mInitCallback:1;
411 bool mIsEGLInitialize:1;
415 } // namespace Adaptor
416 } // namepsace Internal
418 // Helpers for public-api forwarding methods
420 inline Internal::Adaptor::GlWindow& GetImplementation(Dali::GlWindow& window)
422 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
423 BaseObject& object = window.GetBaseObject();
424 return static_cast<Internal::Adaptor::GlWindow&>(object);
427 inline const Internal::Adaptor::GlWindow& GetImplementation(const Dali::GlWindow& window)
429 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
430 const BaseObject& object = window.GetBaseObject();
431 return static_cast<const Internal::Adaptor::GlWindow&>(object);
436 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_IMPL_H