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 WindowOrientation GetCurrentOrientation() const;
167 * @copydoc Dali::GlWindow::SetAvailableOrientations()
169 void SetAvailableOrientations( const Dali::Vector< WindowOrientation >& orientations );
172 * @copydoc Dali::GlWindow::SetPreferredOrientation()
174 void SetPreferredOrientation( WindowOrientation orientation );
177 * @copydoc Dali::GlWindow::RegisterGlCallback()
179 void RegisterGlCallback( CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback );
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( WindowOrientation 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( WindowOrientation 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 WindowOrientation 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 std::unique_ptr< GraphicsInterface > mGraphics; ///< Graphics interface
367 std::unique_ptr< Dali::DisplayConnection > mDisplayConnection;
369 std::string mClassName;
370 EventHandlerPtr mEventHandler; ///< The window events handler
371 PositionSize mPositionSize;
372 ColorDepth mColorDepth;
373 Dali::Window mChildWindow;
374 bool mIsTransparent:1;
375 bool mIsFocusAcceptable:1;
378 bool mResizeEnabled:1;
381 bool mIsWindowRotated:1;
384 std::vector< int > mAvailableAngles;
386 int mTotalRotationAngle; ///< The angle of window + screen rotation angle % 360
387 int mWindowRotationAngle; ///< The angle of window rotation angle
388 int mScreenRotationAngle; ///< The angle of screen rotation angle
389 int mOrientationMode; ///< 0: Default portrati, 1:Default landscape
390 int mWindowWidth; ///< The width of the window
391 int mWindowHeight; ///< The height of the window
392 int mNativeWindowId; ///< The Native Window Id
395 KeyEventSignalType mKeyEventSignal;
396 TouchEventSignalType mTouchedSignal;
397 FocusChangeSignalType mFocusChangeSignal;
398 ResizeSignalType mResizeSignal;
399 VisibilityChangedSignalType mVisibilityChangedSignal;
402 std::unique_ptr< CallbackBase > mGLInitCallback;
403 std::unique_ptr< CallbackBase > mGLRenderFrameCallback;
404 std::unique_ptr< CallbackBase > mGLTerminateCallback;
405 CallbackBase* mGLRenderCallback;
406 EGLSurface mEGLSurface;
407 EGLContext mEGLContext;
408 Dali::GlWindow::GlesVersion mGLESVersion;
409 bool mInitCallback:1;
412 bool mIsEGLInitialize:1;
416 } // namespace Adaptor
417 } // namepsace Internal
419 // Helpers for public-api forwarding methods
421 inline Internal::Adaptor::GlWindow& GetImplementation(Dali::GlWindow& window)
423 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
424 BaseObject& object = window.GetBaseObject();
425 return static_cast<Internal::Adaptor::GlWindow&>(object);
428 inline const Internal::Adaptor::GlWindow& GetImplementation(const Dali::GlWindow& window)
430 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
431 const BaseObject& object = window.GetBaseObject();
432 return static_cast<const Internal::Adaptor::GlWindow&>(object);
437 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_IMPL_H