1 #ifndef DALI_INTEGRATION_ADAPTOR_H
2 #define DALI_INTEGRATION_ADAPTOR_H
5 * Copyright (c) 2018 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/signals/callback.h>
23 #include <dali/public-api/signals/dali-signal.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/events/touch-event.h>
26 #include <dali/public-api/common/view-mode.h>
29 #include <dali/public-api/adaptor-framework/window.h>
30 #include <dali/public-api/adaptor-framework/application-configuration.h>
31 #include <dali/public-api/dali-adaptor-common.h>
33 #ifdef DALI_ADAPTOR_COMPILATION
34 #include <dali/integration-api/log-factory-interface.h>
36 #include <dali/integration-api/adaptors/log-factory-interface.h>
49 class GraphicsFactory;
55 * @brief An Adaptor object is used to initialize and control how Dali runs.
57 * It provides a lifecycle interface that allows the application
58 * writer to provide their own main loop and other platform related
61 * The Adaptor class provides a means for initialising the resources required by the Dali::Core.
63 * When dealing with platform events, the application writer MUST ensure that Dali is called in a
66 * As soon as the Adaptor class is created and started, the application writer can initialise their
67 * Dali::Actor objects straight away or as required by the main loop they intend to use (there is no
68 * need to wait for an initialise signal as per the Dali::Application class).
70 * The Adaptor does emit a Resize signal which informs the user when the surface is resized.
71 * Tizen and Linux Adaptors should follow the example below:
74 * void CreateProgram(DaliAdaptor& adaptor)
76 * // Create Dali components...
77 * // Can instantiate adaptor here instead, if required
82 * // Initialise platform
85 * // Create an 800 by 1280 window positioned at (0,0).
86 * Dali::PositionSize positionSize(0, 0, 800, 1280);
87 * Dali::Window window = Dali::Window::New( positionSize, "My Application" );
89 * // Create an adaptor which uses that window for rendering
90 * Dali::Adaptor adaptor = Dali::Adaptor::New( window );
93 * CreateProgram(adaptor);
94 * // Or use this as a callback function depending on the platform initialisation sequence.
96 * // Start Main Loop of your platform
97 * MyPlatform.StartMainLoop();
103 * If required, you can also connect class member functions to a signal:
106 * MyApplication application;
107 * adaptor.ResizedSignal().Connect(&application, &MyApplication::Resize);
112 class DALI_ADAPTOR_API Adaptor
116 typedef Signal< void (Adaptor&) > AdaptorSignalType; ///< Generic Type for adaptor signals
120 * @brief Create a new adaptor using the window.
122 * @param[in] window The window to draw onto
123 * @return a reference to the adaptor handle
125 static Adaptor& New( Window window );
128 * @brief Create a new adaptor using the window.
130 * @param[in] window The window to draw onto
131 * @param[in] configuration The context loss configuration.
132 * @return a reference to the adaptor handle
134 static Adaptor& New( Window window, Configuration::ContextLoss configuration );
137 * @brief Create a new adaptor using render surface.
139 * @param[in] nativeWindow native window handle
140 * @param[in] surface The surface to draw onto
141 * @return a reference to the adaptor handle
143 static Adaptor& New( Any nativeWindow, const Dali::RenderSurface& surface );
146 * @brief Create a new adaptor using render surface.
148 * @param[in] nativeWindow native window handle
149 * @param[in] surface The surface to draw onto
150 * @param[in] configuration The context loss configuration.
151 * @return a reference to the adaptor handle
153 static Adaptor& New( Any nativeWindow, const Dali::RenderSurface& surface, Configuration::ContextLoss configuration = Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
156 * @brief Virtual Destructor.
163 * @brief Starts the Adaptor.
168 * @brief Pauses the Adaptor.
173 * @brief Resumes the Adaptor, if previously paused.
175 * @note If the adaptor is not paused, this does not do anything.
180 * @brief Stops the Adaptor.
185 * @brief Ensures that the function passed in is called from the main loop when it is idle.
186 * @note Function must be called from the main event thread only.
188 * Callbacks of the following types may be used:
192 * This callback will be deleted once it is called.
197 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
199 * @param[in] callback The function to call.
200 * @param[in] hasReturnValue Sould be set to true if the callback function has a return value.
201 * @return true if added successfully, false otherwise
203 * @note Ownership of the callback is passed onto this class.
205 bool AddIdle( CallbackBase* callback, bool hasReturnValue );
208 * @brief Removes a previously added @p callback.
209 * @note Function must be called from the main event thread only.
211 * Does nothing if the @p callback doesn't exist.
213 * @param[in] callback The callback to be removed.
215 void RemoveIdle( CallbackBase* callback );
218 * @brief Replaces the rendering surface
220 * @param[in] nativeWindow native window handle
221 * @param[in] surface to use
223 void ReplaceSurface( Any nativeWindow, Dali::RenderSurface& surface );
226 * @brief Get the render surface the adaptor is using to render to.
228 * @return reference to current render surface
230 RenderSurface& GetSurface();
233 * @brief Gets native window handle
235 * @return Native window handle
237 Any GetNativeWindowHandle();
240 * @brief Get the native display associated with the graphics backend
242 * @return A handle to the native display
244 Any GetGraphicsDisplay();
247 * @brief Release any locks the surface may hold.
249 * For example, after compositing an offscreen surface, use this method to allow
250 * rendering to continue.
252 void ReleaseSurfaceLock();
255 * @brief Set the number of frames per render.
257 * This enables an application to deliberately render with a reduced FPS.
258 * @param[in] numberOfVSyncsPerRender The number of vsyncs between successive renders.
259 * Suggest this is a power of two:
260 * 1 - render each vsync frame
261 * 2 - render every other vsync frame
262 * 4 - render every fourth vsync frame
263 * 8 - render every eighth vsync frame
265 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
268 * @brief The callback is called from the Update/Render thread prior to rendering.
270 * @param[in] callback The function to call
272 * @note The function is called from the Update thread, so should do as little processing as possible.
273 * It is not possible to call any DALi event side APIs from within the callback; doing so will cause
274 * instability. Only 1 callback is supported. Setting the callback to NULL will remove the current callback.
276 * A callback of the following type should be used:
280 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
282 void SetPreRenderCallback( CallbackBase* callback );
285 * @brief Set whether the frame count per render is managed using the hardware VSync or
288 * @param[in] useHardware True if the hardware VSync should be used
290 void SetUseHardwareVSync(bool useHardware);
293 * @brief Returns a reference to the instance of the adaptor used by the current thread.
295 * @return A reference to the adaptor.
296 * @pre The adaptor has been initialised.
297 * @note This is only valid in the main thread.
299 static Adaptor& Get();
302 * @brief Checks whether the adaptor is available.
304 * @return true, if it is available, false otherwise.
306 static bool IsAvailable();
309 * @brief Call this method to notify Dali when scene is created and initialized.
311 * Notify Adaptor that the scene has been created.
313 void NotifySceneCreated();
316 * @brief Call this method to notify Dali when the system language changes.
318 * Use this only when NOT using Dali::Application, As Application created using
319 * Dali::Application will automatically receive notification of language change.
320 * When Dali::Application is not used, the application developer should
321 * use app-core to receive language change notifications and should update Dali
322 * by calling this method.
324 void NotifyLanguageChanged();
327 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
328 * trigger a pinch gesture
330 * @param[in] distance The minimum pinch distance in pixels
332 void SetMinimumPinchDistance(float distance);
335 * @brief Feed a touch point to the adaptor.
337 * @param[in] point touch point
338 * @param[in] timeStamp time value of event
340 void FeedTouchPoint( TouchPoint& point, int timeStamp );
343 * @brief Feed a wheel event to the adaptor.
345 * @param[in] wheelEvent wheel event
347 void FeedWheelEvent( WheelEvent& wheelEvent );
350 * @brief Feed a key event to the adaptor.
352 * @param[in] keyEvent The key event holding the key information.
354 void FeedKeyEvent( KeyEvent& keyEvent );
357 * @copydoc Dali::Core::SceneCreated();
362 * @brief Renders once more even if we're paused
363 * @note Will not work if the window is hidden.
368 * @brief The log factory allows installation of a logger function in worker threads.
369 * @return An interface to a logging factory
371 const LogFactoryInterface& GetLogFactory();
376 * @brief The user should connect to this signal if they need to perform any
377 * special activities when the surface Dali is being rendered on is resized.
379 * @return The signal to connect to
381 AdaptorSignalType& ResizedSignal();
384 * @brief This signal is emitted when the language is changed on the device.
386 * @return The signal to connect to
388 AdaptorSignalType& LanguageChangedSignal();
393 Adaptor(const Adaptor&);
394 Adaptor& operator=(Adaptor&);
399 * @brief Create an uninitialized Adaptor.
403 Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
404 friend class Internal::Adaptor::Adaptor;
409 #endif // DALI_INTEGRATION_ADAPTOR_H