1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_IMPL_H
5 * Copyright (c) 2021 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/adaptor-framework/window.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/object/ref-object.h>
27 #include <dali/devel-api/adaptor-framework/gl-window.h>
28 #include <dali/internal/adaptor/common/adaptor-impl.h>
29 #include <dali/internal/graphics/gles/egl-graphics.h>
30 #include <dali/internal/window-system/common/event-handler.h>
31 #include <dali/internal/window-system/common/gl-window-render-thread.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
53 using KeyEventSignalType = Dali::GlWindow::KeyEventSignalType;
54 using TouchEventSignalType = Dali::GlWindow::TouchEventSignalType;
55 using FocusChangeSignalType = Dali::GlWindow::FocusChangeSignalType;
56 using ResizeSignalType = Dali::GlWindow::ResizeSignalType;
57 using VisibilityChangedSignalType = Dali::GlWindow::VisibilityChangedSignalType;
58 using SignalType = Signal<void()>;
61 * @brief Create a new GlWindow. This should only be called once by the Application class
62 * @param[in] positionSize The position and size of the window
63 * @param[in] name The window title
64 * @param[in] className The window class name
65 * @param[in] isTransparent Whether window is transparent
66 * @return A newly allocated Window
68 static GlWindow* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
71 * @copydoc Dali::GlWindow::SetGraphicsConfig()
73 void SetGraphicsConfig(bool depth, bool stencil, int msaa, Dali::GlWindow::GlesVersion version);
76 * @copydoc Dali::GlWindow::Raise()
81 * @copydoc Dali::GlWindow::Lower()
86 * @copydoc Dali::GlWindow::Activate()
91 * @copydoc Dali::GlWindow::Show()
96 * @copydoc Dali::GlWindow::Hide()
101 * @copydoc Dali::GlWindow::GetSupportedAuxiliaryHintCount()
103 unsigned int GetSupportedAuxiliaryHintCount() const;
106 * @copydoc Dali::GlWindow::GetSupportedAuxiliaryHint()
108 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
111 * @copydoc Dali::GlWindow::AddAuxiliaryHint()
113 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
116 * @copydoc Dali::GlWindow::RemoveAuxiliaryHint()
118 bool RemoveAuxiliaryHint(unsigned int id);
121 * @copydoc Dali::GlWindow::SetAuxiliaryHintValue()
123 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
126 * @copydoc Dali::GlWindow::GetAuxiliaryHintValue()
128 std::string GetAuxiliaryHintValue(unsigned int id) const;
131 * @copydoc Dali::GlWindow::GetAuxiliaryHintId()
133 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
136 * @copydoc Dali::GlWindow::SetInputRegion()
138 void SetInputRegion(const Rect<int>& inputRegion);
141 * @copydoc Dali::GlWindow::SetOpaqueState()
143 void SetOpaqueState(bool opaque);
146 * @copydoc Dali::GlWindow::IsOpaqueState()
148 bool IsOpaqueState() const;
151 * @copydoc Dali::GlWindow::SetPositionSize()
153 void SetPositionSize(PositionSize positionSize);
156 * @copydoc Dali::GlWindow::GetPositionSize()
158 PositionSize GetPositionSize() const;
161 * @copydoc Dali::GlWindow::GetCurrentOrientation() const
163 WindowOrientation GetCurrentOrientation() const;
166 * @copydoc Dali::GlWindow::SetAvailableOrientations()
168 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
171 * @copydoc Dali::GlWindow::SetPreferredOrientation()
173 void SetPreferredOrientation(WindowOrientation orientation);
176 * @copydoc Dali::GlWindow::RegisterGlCallbacks()
178 void RegisterGlCallbacks(CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback);
181 * @copydoc Dali::GlWindow::RenderOnce()
186 * @copydoc Dali::GlWindow::SetRenderingMode()
188 void SetRenderingMode(Dali::GlWindow::RenderingMode mode);
191 * @copydoc Dali::GlWindow::GetRenderingMode()
193 Dali::GlWindow::RenderingMode GetRenderingMode() const;
195 public: // For implementation
197 * @brief Sets child window with Dali::Window
199 * @param[in] child The child window.
201 * Most of cases, child window is the default window in adaptor
203 * Currently the child window is default window.
205 void SetChild(Dali::Window& child);
209 * Private constructor.
220 * Second stage initialization
222 * @param[in] positionSize The position and size of the window
223 * @param[in] name The window title
224 * @param[in] className The window class name
226 void Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className);
229 * Called when the window becomes iconified or deiconified.
231 * @param[in] iconified The flag whether window is iconifed or deiconfied.
233 void OnIconifyChanged(bool iconified);
236 * Called when the window focus is changed.
237 * @param[in] focusIn The flag whether window is focused or not.
239 void OnFocusChanged(bool focusIn);
242 * Called when the output is transformed.
244 void OnOutputTransformed();
247 * Called when the window receives a delete request.
249 void OnDeleteRequest();
252 * @brief Set available rotation angle to window base.
254 * @param[in] angles The list of the avaiabled rotation angle.
256 void SetAvailableAnlges(const std::vector<int>& angles);
259 * @brief Check available window orientation for Available angle.
261 * @param[in] orientation the oritation value of window rotation.
263 * @return true is available window orientation. false is not available.
265 bool IsOrientationAvailable(WindowOrientation orientation) const;
268 * @brief Convert from window orientation to angle using orientation mode value.
270 * @param[in] orientation the oritation value of window rotation.
272 * @return The coverted angle value is returned.
274 int ConvertToAngle(WindowOrientation orientation);
277 * @brief Convert from angle to window orientation using orientation mode value.
279 * @param[in] angle the angle value of window rotation.
281 * @return The converted window orientation value is returned.
283 WindowOrientation ConvertToOrientation(int angle) const;
286 * @brief Initialize and create EGL resource
288 void InitializeGraphics();
291 * @brief Sets event handler for window's events.
293 void SetEventHandler();
296 * @brief calculate touch position for rotation.
298 void RecalculateTouchPosition(Integration::Point& point);
301 * @brief Sets window and class name.
303 * @param[in] name The name of the window
304 * @param[in] className The class of the window
306 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
331 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
333 void OnDamaged(const DamageArea& area);
336 * @brief Updates screen rotation value and screen rotation works.
338 * @param[in] newAngle new screen rotation angle
340 void UpdateScreenRotation(int newAngle);
344 * @copydoc Dali::GlWindow::FocusChangeSignal()
346 FocusChangeSignalType& FocusChangeSignal()
348 return mFocusChangeSignal;
352 * @copydoc Dali::GlWindow::ResizeSignal()
354 ResizeSignalType& ResizeSignal()
356 return mResizeSignal;
360 * @copydoc Dali::GlWindow::KeyEventSignal()
362 KeyEventSignalType& KeyEventSignal()
364 return mKeyEventSignal;
368 * @copydoc Dali::GlWindow::TouchSignal()
370 TouchEventSignalType& TouchedSignal()
372 return mTouchedSignal;
376 * @copydoc Dali::GlWindow::VisibilityChangedSignal()
378 VisibilityChangedSignalType& VisibilityChangedSignal()
380 return mVisibilityChangedSignal;
384 std::unique_ptr<WindowBase> mWindowBase;
385 std::unique_ptr<GraphicsInterface> mGraphics; ///< Graphics interface
386 std::unique_ptr<Dali::DisplayConnection> mDisplayConnection; ///< The native display connection
387 std::unique_ptr<GlWindowRenderThread> mGlWindowRenderThread; ///< The render thread
388 EventHandlerPtr mEventHandler; ///< The window events handler
389 Dali::Window mChildWindow; ///< The default child UI Window
391 std::string mClassName;
392 bool mIsTransparent : 1;
393 bool mIsFocusAcceptable : 1;
395 bool mOpaqueState : 1;
396 bool mResizeEnabled : 1;
398 bool mIsWindowRotated : 1;
400 bool mIsEGLInitialized : 1;
404 PositionSize mPositionSize; ///< The window position and size
405 EnvironmentOptions mEnvironmentOptions;
406 std::vector<int> mAvailableAngles; ///< The list of available angle
407 ColorDepth mColorDepth; ///< The color depth of window
408 Dali::GlWindow::RenderingMode mRenderingMode; ///< The rendering mode
410 int mPreferredAngle; ///< The angle of preferred angle
411 int mTotalRotationAngle; ///< The angle of window + screen rotation angle % 360
412 int mWindowRotationAngle; ///< The angle of window rotation angle
413 int mScreenRotationAngle; ///< The angle of screen rotation angle
414 int mOrientationMode; ///< 0: Default portrati, 1:Default landscape
415 int mWindowWidth; ///< The width of the window
416 int mWindowHeight; ///< The height of the window
417 int mNativeWindowId; ///< The Native Window Id
418 int mMSAA; ///< The multisample anti-aliasing for EGL Configuration
421 KeyEventSignalType mKeyEventSignal;
422 TouchEventSignalType mTouchedSignal;
423 FocusChangeSignalType mFocusChangeSignal;
424 ResizeSignalType mResizeSignal;
425 VisibilityChangedSignalType mVisibilityChangedSignal;
428 } // namespace Adaptor
429 } // namespace Internal
431 // Helpers for public-api forwarding methods
433 inline Internal::Adaptor::GlWindow& GetImplementation(Dali::GlWindow& window)
435 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
436 BaseObject& object = window.GetBaseObject();
437 return static_cast<Internal::Adaptor::GlWindow&>(object);
440 inline const Internal::Adaptor::GlWindow& GetImplementation(const Dali::GlWindow& window)
442 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
443 const BaseObject& object = window.GetBaseObject();
444 return static_cast<const Internal::Adaptor::GlWindow&>(object);
449 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_IMPL_H