1 #ifndef DALI_INTEGRATION_ADAPTOR_H
2 #define DALI_INTEGRATION_ADAPTOR_H
5 * Copyright (c) 2019 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>
27 #include <dali/public-api/object/any.h>
28 #include <dali/integration-api/processor-interface.h>
31 #include <dali/public-api/adaptor-framework/window.h>
32 #include <dali/public-api/adaptor-framework/application-configuration.h>
33 #include <dali/public-api/dali-adaptor-common.h>
35 #ifdef DALI_ADAPTOR_COMPILATION
36 #include <dali/integration-api/log-factory-interface.h>
38 #include <dali/integration-api/adaptors/log-factory-interface.h>
45 class RenderSurfaceInterface;
57 class GraphicsFactory;
63 * @brief An Adaptor object is used to initialize and control how Dali runs.
65 * It provides a lifecycle interface that allows the application
66 * writer to provide their own main loop and other platform related
69 * The Adaptor class provides a means for initialising the resources required by the Dali::Core.
71 * When dealing with platform events, the application writer MUST ensure that Dali is called in a
74 * As soon as the Adaptor class is created and started, the application writer can initialise their
75 * Dali::Actor objects straight away or as required by the main loop they intend to use (there is no
76 * need to wait for an initialise signal as per the Dali::Application class).
78 * The Adaptor does emit a Resize signal which informs the user when the surface is resized.
79 * Tizen and Linux Adaptors should follow the example below:
82 * void CreateProgram(DaliAdaptor& adaptor)
84 * // Create Dali components...
85 * // Can instantiate adaptor here instead, if required
90 * // Initialise platform
93 * // Create an 800 by 1280 window positioned at (0,0).
94 * Dali::PositionSize positionSize(0, 0, 800, 1280);
95 * Dali::Window window = Dali::Window::New( positionSize, "My Application" );
97 * // Create an adaptor which uses that window for rendering
98 * Dali::Adaptor adaptor = Dali::Adaptor::New( window );
101 * CreateProgram(adaptor);
102 * // Or use this as a callback function depending on the platform initialisation sequence.
104 * // Start Main Loop of your platform
105 * MyPlatform.StartMainLoop();
111 * If required, you can also connect class member functions to a signal:
114 * MyApplication application;
115 * adaptor.ResizedSignal().Connect(&application, &MyApplication::Resize);
120 class DALI_ADAPTOR_API Adaptor
124 typedef Signal< void (Adaptor&) > AdaptorSignalType; ///< Generic Type for adaptor signals
128 * @brief Create a new adaptor using the window.
130 * @param[in] window The window to draw onto
131 * @return a reference to the adaptor handle
133 static Adaptor& New( Window window );
136 * @brief Create a new adaptor using the window.
138 * @param[in] window The window to draw onto
139 * @param[in] configuration The context loss configuration.
140 * @return a reference to the adaptor handle
142 static Adaptor& New( Window window, Configuration::ContextLoss configuration );
145 * @brief Create a new adaptor using render surface.
147 * @param[in] window The window to draw onto
148 * @param[in] surface The surface to draw onto
149 * @return a reference to the adaptor handle
151 static Adaptor& New( Window window, const Dali::RenderSurfaceInterface& surface );
154 * @brief Create a new adaptor using render surface.
156 * @param[in] window The window to draw onto
157 * @param[in] surface The surface to draw onto
158 * @param[in] configuration The context loss configuration.
159 * @return a reference to the adaptor handle
161 static Adaptor& New( Window window, const Dali::RenderSurfaceInterface& surface, Configuration::ContextLoss configuration = Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
164 * @brief Create a new adaptor using the SceneHolder.
166 * @param[in] sceneHolder The SceneHolder to draw onto
167 * @return a reference to the adaptor handle
169 static Adaptor& New( Dali::Integration::SceneHolder sceneHolder );
172 * @brief Create a new adaptor using the SceneHolder.
174 * @param[in] sceneHolder The SceneHolder to draw onto
175 * @param[in] configuration The context loss configuration.
176 * @return a reference to the adaptor handle
178 static Adaptor& New( Dali::Integration::SceneHolder sceneHolder, Configuration::ContextLoss configuration );
181 * @brief Create a new adaptor using render surface.
183 * @param[in] sceneHolder The SceneHolder to draw onto
184 * @param[in] surface The surface to draw onto
185 * @return a reference to the adaptor handle
187 static Adaptor& New( Dali::Integration::SceneHolder sceneHolder, const Dali::RenderSurfaceInterface& surface );
190 * @brief Create a new adaptor using render surface.
192 * @param[in] sceneHolder The SceneHolder to draw onto
193 * @param[in] surface The surface to draw onto
194 * @param[in] configuration The context loss configuration.
195 * @return a reference to the adaptor handle
197 static Adaptor& New( Dali::Integration::SceneHolder sceneHolder, const Dali::RenderSurfaceInterface& surface, Configuration::ContextLoss configuration = Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
200 * @brief Virtual Destructor.
207 * @brief Starts the Adaptor.
212 * @brief Pauses the Adaptor.
217 * @brief Resumes the Adaptor, if previously paused.
219 * @note If the adaptor is not paused, this does not do anything.
224 * @brief Stops the Adaptor.
229 * @brief Ensures that the function passed in is called from the main loop when it is idle.
230 * @note Function must be called from the main event thread only.
232 * Callbacks of the following types may be used:
236 * This callback will be deleted once it is called.
241 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
243 * @param[in] callback The function to call.
244 * @param[in] hasReturnValue Sould be set to true if the callback function has a return value.
245 * @return true if added successfully, false otherwise
247 * @note Ownership of the callback is passed onto this class.
249 bool AddIdle( CallbackBase* callback, bool hasReturnValue );
252 * @brief Removes a previously added @p callback.
253 * @note Function must be called from the main event thread only.
255 * Does nothing if the @p callback doesn't exist.
257 * @param[in] callback The callback to be removed.
259 void RemoveIdle( CallbackBase* callback );
262 * @brief Replaces the rendering surface
264 * @param[in] window The window to replace the surface for
265 * @param[in] surface to use
267 void ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface );
270 * @brief Replaces the rendering surface
272 * @param[in] sceneHolder The SceneHolder to replace the surface for
273 * @param[in] surface to use
275 void ReplaceSurface( Dali::Integration::SceneHolder sceneHolder, Dali::RenderSurfaceInterface& surface );
278 * @brief Get the render surface the adaptor is using to render to.
280 * @return reference to current render surface
282 Dali::RenderSurfaceInterface& GetSurface();
285 * @brief Gets native window handle
287 * @return Native window handle
289 Any GetNativeWindowHandle();
292 * @brief Get the native display associated with the graphics backend
294 * @return A handle to the native display
296 Any GetGraphicsDisplay();
299 * @brief Release any locks the surface may hold.
301 * For example, after compositing an offscreen surface, use this method to allow
302 * rendering to continue.
304 void ReleaseSurfaceLock();
307 * @brief Set the number of frames per render.
309 * This enables an application to deliberately render with a reduced FPS.
310 * @param[in] numberOfVSyncsPerRender The number of vsyncs between successive renders.
311 * Suggest this is a power of two:
312 * 1 - render each vsync frame
313 * 2 - render every other vsync frame
314 * 4 - render every fourth vsync frame
315 * 8 - render every eighth vsync frame
317 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
320 * @brief The callback is called from the Update/Render thread prior to rendering.
322 * @param[in] callback The function to call
324 * @note The function is called from the Update thread, so should do as little processing as possible.
325 * It is not possible to call any DALi event side APIs from within the callback; doing so will cause
326 * instability. Only 1 callback is supported. Setting the callback to NULL will remove the current callback.
328 * A callback of the following type should be used:
332 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
334 void SetPreRenderCallback( CallbackBase* callback );
337 * @brief Set whether the frame count per render is managed using the hardware VSync or
340 * @param[in] useHardware True if the hardware VSync should be used
342 void SetUseHardwareVSync(bool useHardware);
345 * @brief Returns a reference to the instance of the adaptor used by the current thread.
347 * @return A reference to the adaptor.
348 * @pre The adaptor has been initialised.
349 * @note This is only valid in the main thread.
351 static Adaptor& Get();
354 * @brief Checks whether the adaptor is available.
356 * @return true, if it is available, false otherwise.
358 static bool IsAvailable();
361 * @brief Call this method to notify Dali when scene is created and initialized.
363 * Notify Adaptor that the scene has been created.
365 void NotifySceneCreated();
368 * @brief Call this method to notify Dali when the system language changes.
370 * Use this only when NOT using Dali::Application, As Application created using
371 * Dali::Application will automatically receive notification of language change.
372 * When Dali::Application is not used, the application developer should
373 * use app-core to receive language change notifications and should update Dali
374 * by calling this method.
376 void NotifyLanguageChanged();
379 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
380 * trigger a pinch gesture
382 * @param[in] distance The minimum pinch distance in pixels
384 void SetMinimumPinchDistance(float distance);
387 * @brief Feed a touch point to the adaptor.
389 * @param[in] point touch point
390 * @param[in] timeStamp time value of event
392 void FeedTouchPoint( TouchPoint& point, int timeStamp );
395 * @brief Feed a wheel event to the adaptor.
397 * @param[in] wheelEvent wheel event
399 void FeedWheelEvent( WheelEvent& wheelEvent );
402 * @brief Feed a key event to the adaptor.
404 * @param[in] keyEvent The key event holding the key information.
406 void FeedKeyEvent( KeyEvent& keyEvent );
409 * @copydoc Dali::Core::SceneCreated();
414 * @brief Renders once more even if we're paused
415 * @note Will not work if the window is hidden.
420 * @brief The log factory allows installation of a logger function in worker threads.
421 * @return An interface to a logging factory
423 const LogFactoryInterface& GetLogFactory();
426 * @brief Register a processor implementing the Integration::Processor interface with dali-core.
427 * @param[in] processor the Processor to register
428 * @note using this api does not maintain the processor's lifecycle, must be done elsewhere.
430 void RegisterProcessor( Integration::Processor& processor );
433 * @brief Unregister a previously registered processor from dali-core.
434 * @param[in] processor the Processor to unregister
436 void UnregisterProcessor( Integration::Processor& processor );
441 * @brief The user should connect to this signal if they need to perform any
442 * special activities when the surface Dali is being rendered on is resized.
444 * @return The signal to connect to
446 AdaptorSignalType& ResizedSignal();
449 * @brief This signal is emitted when the language is changed on the device.
451 * @return The signal to connect to
453 AdaptorSignalType& LanguageChangedSignal();
458 Adaptor(const Adaptor&);
459 Adaptor& operator=(Adaptor&);
464 * @brief Create an uninitialized Adaptor.
468 Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
469 friend class Internal::Adaptor::Adaptor;
474 #endif // DALI_INTEGRATION_ADAPTOR_H