1 #ifndef DALI_GL_WINDOW_H
2 #define DALI_GL_WINDOW_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.
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/math/uint-16-pair.h>
25 #include <dali/public-api/math/vector2.h>
26 #include <dali/public-api/math/vector4.h>
27 #include <dali/public-api/object/base-handle.h>
28 #include <dali/public-api/object/any.h>
29 #include <dali/public-api/signals/dali-signal.h>
30 #include <dali/public-api/adaptor-framework/window-enumerations.h>
33 #include <dali/public-api/dali-adaptor-common.h>
38 * @addtogroup dali_adaptor_framework
42 typedef Dali::Rect<int> PositionSize;
44 namespace Internal DALI_INTERNAL
56 * @brief The GlWindow class is to draw with native GLES.
58 * This class is the special window. It is for native GLES application.
59 * So, some special funtions and type are supported.
60 * In addition, basic window's functions are supported, too.
63 class DALI_ADAPTOR_API GlWindow : public BaseHandle
67 using WindowSize = Uint16Pair ;
69 typedef Signal< void ( const KeyEvent& ) > KeyEventSignalType; ///< GlWindow Key Event signal type
70 typedef Signal< void ( const TouchEvent& ) > TouchEventSignalType; ///< GlWindow Touch Event signal type
71 typedef Signal< void ( GlWindow, bool ) > FocusChangeSignalType; ///< GlWindow Focus signal type
72 typedef Signal< void ( WindowSize ) > ResizeSignalType; ///< GlWindow resize signal type
73 typedef Signal< void ( GlWindow, bool ) > VisibilityChangedSignalType; ///< GlWindow visibility change signal type
80 * @brief Enumeration for GLES verion
82 * This Enumeration is used the GLES version for EGL configuration.
83 * If the device can not support GLES version 3.0 over, the version will be chosen with GLES version 2.0
86 enum class GlesVersion
88 VERSION_2_0 = 0, ///< GLES version 2.0
89 VERSION_3_0, ///< GLES version 3.0
93 * @brief Creates an initialized handle to a new GlWindow.
95 * @return A new GlWindow
96 * @note This creates an extra GlWindow in addition to the default main GlWindow
98 static GlWindow New();
101 * @brief Creates an initialized handle to a new GlWindow.
103 * @param[in] positionSize The position and size of the GlWindow
104 * @param[in] name The GlWindow title
105 * @param[in] className The GlWindow class name
106 * @param[in] isTransparent Whether GlWindow is transparent
107 * @note This creates an extra GlWindow in addition to the default main GlWindow
108 * @return A new GlWindow
110 static GlWindow New( PositionSize positionSize, const std::string& name, const std::string& className, bool isTransparent = false );
113 * @brief Creates an uninitialized handle.
115 * This can be initialized using Dali::Application::GetGlWindow() or
116 * Dali::GlWindow::New().
124 * This is non-virtual since derived Handle types must not contain data or virtual methods.
130 * @brief This copy constructor is required for (smart) pointer semantics.
132 * @param[in] handle A reference to the copied handle
134 GlWindow(const GlWindow& handle);
137 * @brief This assignment operator is required for (smart) pointer semantics.
139 * @param[in] rhs A reference to the copied handle
140 * @return A reference to this
142 GlWindow& operator=(const GlWindow& rhs);
145 * @brief Move constructor.
147 * @param[in] rhs A reference to the moved handle
149 GlWindow(GlWindow&& rhs);
152 * @brief Move assignment operator.
154 * @param[in] rhs A reference to the moved handle
155 * @return A reference to this handle
157 GlWindow& operator=(GlWindow&& rhs);
160 * @brief Sets egl configuration for GlWindow
162 * @param[in] depth the flag of depth buffer. If true is set, 24bit depth buffer is enabled.
163 * @param[in] stencil the flag of stencil. it true is set, 8bit stencil buffer is enabled.
164 * @param[in] msaa the bit of msaa.
165 * @param[in] version the GLES version
168 void SetEglConfig( bool depth, bool stencil, int msaa, GlesVersion version );
171 * @brief Raises GlWindow to the top of GlWindow stack.
177 * @brief Lowers GlWindow to the bottom of GlWindow stack.
183 * @brief Activates GlWindow to the top of GlWindow stack even it is iconified.
189 * @brief Shows the GlWindow if it is hidden.
195 * @brief Hides the GlWindow if it is showing.
201 * @brief Sets a position of the GlWindow.
203 * @param[in] positionSize The new GlWindow position
205 void SetPositionSize( PositionSize positionSize );
208 * @brief Gets a position of the GlWindow.
210 * @return The position of the GlWindow
212 PositionSize GetPositionSize() const;
215 * @brief Gets the count of supported auxiliary hints of the window.
217 * @return The number of supported auxiliary hints.
219 * @note The window auxiliary hint is the value which is used to decide which actions should be made available to the user by the window manager.
220 * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
222 unsigned int GetSupportedAuxiliaryHintCount() const;
225 * @brief Gets the supported auxiliary hint string of the window.
227 * @param[in] index The index of the supported auxiliary hint lists
228 * @return The auxiliary hint string of the index.
230 * @note The window auxiliary hint is the value which is used to decide which actions should be made available to the user by the window manager.
231 * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
233 std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
236 * @brief Creates an auxiliary hint of the window.
238 * @param[in] hint The auxiliary hint string.
239 * @param[in] value The value string.
240 * @return The ID of created auxiliary hint, or @c 0 on failure.
242 unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
245 * @brief Removes an auxiliary hint of the window.
247 * @param[in] id The ID of the auxiliary hint.
248 * @return True if no error occurred, false otherwise.
250 bool RemoveAuxiliaryHint( unsigned int id );
253 * @brief Changes a value of the auxiliary hint.
255 * @param[in] id The auxiliary hint ID.
256 * @param[in] value The value string to be set.
257 * @return True if no error occurred, false otherwise.
259 bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
262 * @brief Gets a value of the auxiliary hint.
264 * @param[in] id The auxiliary hint ID.
265 * @return The string value of the auxiliary hint ID, or an empty string if none exists.
267 std::string GetAuxiliaryHintValue( unsigned int id ) const;
270 * @brief Gets a ID of the auxiliary hint string.
272 * @param[in] hint The auxiliary hint string.
273 * @return The ID of the auxiliary hint string, or @c 0 if none exists.
275 unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
278 * @brief Sets a region to accept input events.
280 * @param[in] inputRegion The region to accept input events.
282 void SetInputRegion( const Rect< int >& inputRegion );
285 * @brief Sets a transparent window's visual state to opaque.
286 * @details If a visual state of a transparent window is opaque,
287 * then the window manager could handle it as an opaque window when calculating visibility.
289 * @param[in] opaque Whether the window's visual state is opaque.
290 * @remarks This will have no effect on an opaque window.
291 * It doesn't change transparent window to opaque window but lets the window manager know the visual state of the window.
293 void SetOpaqueState( bool opaque );
296 * @brief Returns whether a transparent window's visual state is opaque or not.
298 * @return True if the window's visual state is opaque, false otherwise.
299 * @remarks The return value has no meaning on an opaque window.
301 bool IsOpaqueState() const;
304 * @brief Gets current rotation angle of the window.
306 * @return The current GlWindow rotation angle if previously set, or none
308 WindowOrientation GetCurrentOrientation() const;
311 * @brief Sets available orientations of the window.
313 * This API is for setting several orientations one time.
315 * @param[in] orientations The available orientations list to add
317 void SetAvailableOrientations( const Dali::Vector<WindowOrientation>& orientations );
320 * @brief Sets a preferred orientation.
322 * @param[in] orientation The preferred orientation
323 * @pre angle is in the list of available orientation.
325 * @note To unset the preferred orientation, angle should be set NO_ORIENTATION_PREFERENCE.
327 void SetPreferredOrientation( WindowOrientation orientation );
330 * @brief Registers a GL callback function for application.
332 * @param[in] initCallback the callback function for application initialize
333 * @param[in] renderFrameCallback the callback function to render for the frame.
334 * @param[in] terminateCallback the callback function to clean-up application GL resource.
336 * @note Function must be called on idle time
338 * A initCallback of the following type should be used:
340 * void intializeGL();
342 * This callback will be called before renderFrame callback is called at once.
344 * A renderFrameCallback of the following type should be used:
346 * int renderFrameGL();
348 * This callback's return value is not 0, the eglSwapBuffers() will be called.
350 * A terminateCallback of the following type should be used:
352 * void terminateGL();
354 * This callback is called when GlWindow is deleted.
356 void RegisterGlCallback( CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback );
359 * @brief Renders once more even if GL render functions are not added to idler.
360 * @note Will not work if the window is hidden or GL render functions are added to idler
368 * @brief The user should connect to this signal to get a timing when GlWindow gains focus or loses focus.
370 * A callback of the following type may be connected:
372 * void YourCallbackName( GlWindow GlWindow, bool focusIn );
374 * The parameter is true if GlWindow gains focus, otherwise false.
375 * and GlWindow means this signal was called from what GlWindow
377 * @return The signal to connect to
379 FocusChangeSignalType& FocusChangeSignal();
382 * @brief This signal is emitted when the GlWindow is resized.
384 * A callback of the following type may be connected:
386 * void YourCallbackName( GlWindow GlWindow, int width, int height );
388 * The parameters are the resized width and height.
389 * and GlWindow means this signal was called from what GlWindow
391 * @return The signal to connect to
393 ResizeSignalType& ResizeSignal();
396 * @brief This signal is emitted when key event is received.
398 * A callback of the following type may be connected:
400 * void YourCallbackName(const KeyEvent& event);
403 * @return The signal to connect to
405 KeyEventSignalType& KeyEventSignal();
408 * @brief This signal is emitted when the screen is touched and when the touch ends
409 * (i.e. the down & up touch events only).
411 * If there are multiple touch points, then this will be emitted when the first touch occurs and
412 * then when the last finger is lifted.
413 * An interrupted event will also be emitted (if it occurs).
414 * A callback of the following type may be connected:
416 * void YourCallbackName(const TouchEvent& event);
419 * @return The touch signal to connect to
421 * @note Motion events are not emitted.
423 TouchEventSignalType& TouchedSignal();
426 * @brief This signal is emitted when the window is shown or hidden.
428 * A callback of the following type may be connected:
430 * void YourCallbackName( Window window, bool visible );
433 * @return The signal to connect to
435 VisibilityChangedSignalType& VisibilityChangedSignal();
437 public: // Not intended for application developers
440 * @brief This constructor is used by Dali::Application::GetGlWindow().
441 * @param[in] GlWindow A pointer to the GlWindow
443 explicit DALI_INTERNAL GlWindow( Internal::Adaptor::GlWindow* GlWindow );
452 #endif // DALI_GL_WINDOW_H