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 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 () >;
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
70 static GlWindow* New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false );
73 * @copydoc Dali::GlWindow::SetEglConfig()
75 void SetEglConfig( bool depth, bool stencil, int msaa, Dali::GlWindow::GlesVersion version );
78 * @copydoc Dali::GlWindow::Raise()
83 * @copydoc Dali::GlWindow::Lower()
88 * @copydoc Dali::GlWindow::Activate()
93 * @copydoc Dali::GlWindow::Show()
98 * @copydoc Dali::GlWindow::Hide()
103 * @copydoc Dali::GlWindow::GetSupportedAuxiliaryHintCount()
105 unsigned int GetSupportedAuxiliaryHintCount() const;
108 * @copydoc Dali::GlWindow::GetSupportedAuxiliaryHint()
110 std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
113 * @copydoc Dali::GlWindow::AddAuxiliaryHint()
115 unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
118 * @copydoc Dali::GlWindow::RemoveAuxiliaryHint()
120 bool RemoveAuxiliaryHint( unsigned int id );
123 * @copydoc Dali::GlWindow::SetAuxiliaryHintValue()
125 bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
128 * @copydoc Dali::GlWindow::GetAuxiliaryHintValue()
130 std::string GetAuxiliaryHintValue( unsigned int id ) const;
133 * @copydoc Dali::GlWindow::GetAuxiliaryHintId()
135 unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
138 * @copydoc Dali::GlWindow::SetInputRegion()
140 void SetInputRegion( const Rect< int >& inputRegion );
143 * @copydoc Dali::GlWindow::SetOpaqueState()
145 void SetOpaqueState( bool opaque );
148 * @copydoc Dali::GlWindow::IsOpaqueState()
150 bool IsOpaqueState() const;
153 * @copydoc Dali::GlWindow::SetPositionSize()
155 void SetPositionSize( PositionSize positionSize );
158 * @copydoc Dali::GlWindow::GetPositionSize()
160 PositionSize GetPositionSize() const;
163 * @copydoc Dali::GlWindow::GetCurrentOrientation() const
165 Dali::GlWindow::GlWindowOrientation GetCurrentOrientation() const;
168 * @copydoc Dali::GlWindow::SetAvailableOrientations()
170 void SetAvailableOrientations( const Dali::Vector< Dali::GlWindow::GlWindowOrientation >& orientations );
173 * @copydoc Dali::GlWindow::SetPreferredOrientation()
175 void SetPreferredOrientation( Dali::GlWindow::GlWindowOrientation orientation );
178 * @copydoc Dali::GlWindow::RegisterGlCallback()
180 void RegisterGlCallback( GlInitialize glInit, GlRenderFrame glRenderFrame, GlTerminate glTerminate );
183 * @copydoc Dali::GlWindow::RenderOnce()
187 public: // For implementation
189 * @brief Sets child window with Dali::Window
191 * Currently the child window is default window.
193 void SetChild( Dali::Window& child );
198 * Private constructor.
209 * Second stage initialization
211 void Initialize( const PositionSize& positionSize, const std::string& name, const std::string& className );
214 * Called when the window becomes iconified or deiconified.
216 void OnIconifyChanged( bool iconified );
219 * Called when the window focus is changed.
221 void OnFocusChanged( bool focusIn );
224 * Called when the output is transformed.
226 void OnOutputTransformed();
229 * Called when the window receives a delete request.
231 void OnDeleteRequest();
234 * @brief Set available rotation angle to window base.
236 void SetAvailableAnlges( const std::vector< int >& angles );
239 * @brief Check available window rotation angle for Available angle.
241 bool IsOrientationAvailable( Dali::GlWindow::GlWindowOrientation orientation ) const;
244 * @brief Convert from window orientation to angle using orientation mode value.
246 int ConvertToAngle( Dali::GlWindow::GlWindowOrientation orientation );
249 * @brief Convert from angle to window orientation using orientation mode value.
251 Dali::GlWindow::GlWindowOrientation ConvertToOrientation( int angle ) const;
254 * @brief Run Ui GL callback function.
259 * @brief Initialize and create EGL resource
261 void InitializeGraphics();
264 * @brief Sets event handler for window's events.
266 void SetEventHandler() ;
269 * @brief Gets the native window handle
271 Dali::Any GetNativeHandle() const;
274 * @brief Gets the native window handle ID
276 int32_t GetNativeId() const;
279 * @brief calculate touch position for rotation.
281 void RecalculateTouchPosition( Integration::Point& point ) ;
284 * @brief Sets window and class name.
286 void SetClass( const std::string name, const std::string className );
291 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
293 void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) override;
296 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
298 void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) override;
301 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
303 void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) override;
306 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
308 void OnRotation( const RotationEvent& rotation ) override;
310 private: // From Dali::Internal::Adaptor::DamageObserver
313 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
315 void OnDamaged( const DamageArea& area );
320 * @copydoc Dali::GlWindow::FocusChangeSignal()
322 FocusChangeSignalType& FocusChangeSignal() { return mFocusChangeSignal; }
325 * @copydoc Dali::GlWindow::ResizedSignal()
327 ResizedSignalType& ResizedSignal() { return mResizedSignal; }
330 * @copydoc Dali::GlWindow::KeyEventSignal()
332 KeyEventSignalType& KeyEventSignal() { return mKeyEventSignal; }
335 * @copydoc Dali::GlWindow::TouchSignal()
337 TouchSignalType& TouchSignal() { return mTouchSignal; }
340 * @copydoc Dali::GlWindow::VisibilityChangedSignal()
342 VisibilityChangedSignalType& VisibilityChangedSignal() { return mVisibilityChangedSignal; }
346 std::unique_ptr< WindowBase > mWindowBase;
347 std::unique_ptr< GraphicsInterface > mGraphics; ///< Graphics interface
348 Dali::DisplayConnection* mDisplayConnection;
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;
359 bool mResizedEnabled:1;
362 bool mIsWindowRotated:1;
365 std::vector< int > mAvailableAngles;
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
376 KeyEventSignalType mKeyEventSignal;
377 TouchSignalType mTouchSignal;
378 FocusChangeSignalType mFocusChangeSignal;
379 ResizedSignalType mResizedSignal;
380 VisibilityChangedSignalType mVisibilityChangedSignal;
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;
393 bool mIsEGLInitialize:1;
397 } // namespace Adaptor
398 } // namepsace Internal
400 // Helpers for public-api forwarding methods
402 inline Internal::Adaptor::GlWindow& GetImplementation(Dali::GlWindow& window)
404 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
405 BaseObject& object = window.GetBaseObject();
406 return static_cast<Internal::Adaptor::GlWindow&>(object);
409 inline const Internal::Adaptor::GlWindow& GetImplementation(const Dali::GlWindow& window)
411 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
412 const BaseObject& object = window.GetBaseObject();
413 return static_cast<const Internal::Adaptor::GlWindow&>(object);
418 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_IMPL_H