1 #ifndef DALI_INTEGRATION_ADAPTOR_H
2 #define DALI_INTEGRATION_ADAPTOR_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/devel-api/events/touch-point.h>
23 #include <dali/integration-api/processor-interface.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/math/uint-16-pair.h>
26 #include <dali/public-api/object/any.h>
27 #include <dali/public-api/signals/callback.h>
28 #include <dali/public-api/signals/dali-signal.h>
31 #include <dali/integration-api/adaptor-framework/log-factory-interface.h>
32 #include <dali/public-api/adaptor-framework/window.h>
33 #include <dali/public-api/dali-adaptor-common.h>
38 class RenderSurfaceInterface;
40 using WindowContainer = std::vector<Window>;
47 using SceneHolderList = std::vector<Dali::Integration::SceneHolder>;
53 class GraphicsFactory;
55 } // namespace Adaptor
56 } // namespace Internal
59 * @brief An Adaptor object is used to initialize and control how Dali runs.
61 * It provides a lifecycle interface that allows the application
62 * writer to provide their own main loop and other platform related
65 * The Adaptor class provides a means for initialising the resources required by the Dali::Core.
67 * When dealing with platform events, the application writer MUST ensure that Dali is called in a
70 * As soon as the Adaptor class is created and started, the application writer can initialise their
71 * Dali::Actor objects straight away or as required by the main loop they intend to use (there is no
72 * need to wait for an initialise signal as per the Dali::Application class).
74 * The Adaptor does emit a Resize signal which informs the user when the surface is resized.
75 * Tizen and Linux Adaptors should follow the example below:
78 * void CreateProgram(DaliAdaptor& adaptor)
80 * // Create Dali components...
81 * // Can instantiate adaptor here instead, if required
86 * // Initialise platform
89 * // Create an 800 by 1280 window positioned at (0,0).
90 * Dali::PositionSize positionSize(0, 0, 800, 1280);
91 * Dali::Window window = Dali::Window::New( positionSize, "My Application" );
93 * // Create an adaptor which uses that window for rendering
94 * Dali::Adaptor adaptor = Dali::Adaptor::New( window );
97 * CreateProgram(adaptor);
98 * // Or use this as a callback function depending on the platform initialisation sequence.
100 * // Start Main Loop of your platform
101 * MyPlatform.StartMainLoop();
107 * If required, you can also connect class member functions to a signal:
110 * MyApplication application;
111 * adaptor.ResizedSignal().Connect(&application, &MyApplication::Resize);
116 class DALI_ADAPTOR_API Adaptor
119 typedef Signal<void(Adaptor&)> AdaptorSignalType; ///< Generic Type for adaptor signals
120 typedef Signal<void(Dali::Integration::SceneHolder&)> WindowCreatedSignalType; ///< SceneHolder created signal type
122 using SurfaceSize = Uint16Pair; ///< Surface size type
126 * @brief Create a new adaptor using the window.
128 * @param[in] window The window to draw onto
129 * @return a reference to the adaptor handle
131 static Adaptor& New(Window window);
134 * @brief Create a new adaptor using render surface.
136 * @param[in] window The window to draw onto
137 * @param[in] surface The surface to draw onto
138 * @return a reference to the adaptor handle
140 static Adaptor& New(Window window, const Dali::RenderSurfaceInterface& surface);
143 * @brief Create a new adaptor using the SceneHolder.
145 * @param[in] sceneHolder The SceneHolder to draw onto
146 * @return a reference to the adaptor handle
148 static Adaptor& New(Dali::Integration::SceneHolder sceneHolder);
151 * @brief Create a new adaptor using render surface.
153 * @param[in] sceneHolder The SceneHolder to draw onto
154 * @param[in] surface The surface to draw onto
155 * @return a reference to the adaptor handle
157 static Adaptor& New(Dali::Integration::SceneHolder sceneHolder, const Dali::RenderSurfaceInterface& surface);
160 * @brief Virtual Destructor.
166 * @brief Starts the Adaptor.
171 * @brief Pauses the Adaptor.
176 * @brief Resumes the Adaptor, if previously paused.
178 * @note If the adaptor is not paused, this does not do anything.
183 * @brief Stops the Adaptor.
188 * @brief Ensures that the function passed in is called from the main loop when it is idle.
189 * @note Function must be called from the main event thread only.
191 * Callbacks of the following types may be used:
195 * This callback will be deleted once it is called.
200 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
202 * @param[in] callback The function to call.
203 * @param[in] hasReturnValue Sould be set to true if the callback function has a return value.
204 * @return true if added successfully, false otherwise
206 * @note Ownership of the callback is passed onto this class.
208 bool AddIdle(CallbackBase* callback, bool hasReturnValue);
211 * @brief Adds a new Window instance to the Adaptor
213 * @param[in] childWindow The child window instance
215 bool AddWindow(Dali::Integration::SceneHolder childWindow);
218 * @brief Removes a previously added @p callback.
219 * @note Function must be called from the main event thread only.
221 * Does nothing if the @p callback doesn't exist.
223 * @param[in] callback The callback to be removed.
225 void RemoveIdle(CallbackBase* callback);
228 * @brief Processes the idle callbacks.
230 * @note This function is intended to be used in the case there is no instance of a Dali::Application i.e. DALi is used in a implementation of a plugin of an application.
235 * @brief Replaces the rendering surface
237 * @param[in] window The window to replace the surface for
238 * @param[in] surface to use
240 void ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface);
243 * @brief Replaces the rendering surface
245 * @param[in] sceneHolder The SceneHolder to replace the surface for
246 * @param[in] surface to use
248 void ReplaceSurface(Dali::Integration::SceneHolder sceneHolder, Dali::RenderSurfaceInterface& surface);
251 * @brief Get the render surface the adaptor is using to render to.
253 * @return reference to current render surface
255 Dali::RenderSurfaceInterface& GetSurface();
258 * @brief Gets native window handle
260 * @return Native window handle
262 Any GetNativeWindowHandle();
265 * @brief Retrieve native window handle that the given actor is added to.
267 * @param[in] actor The actor
268 * @return native window handle
270 Any GetNativeWindowHandle(Actor actor);
273 * @brief Get the native display associated with the graphics backend
275 * @return A handle to the native display
277 Any GetGraphicsDisplay();
280 * @brief Release any locks the surface may hold.
282 * For example, after compositing an offscreen surface, use this method to allow
283 * rendering to continue.
285 void ReleaseSurfaceLock();
288 * @brief Set the number of frames per render.
290 * This enables an application to deliberately render with a reduced FPS.
291 * @param[in] numberOfVSyncsPerRender The number of vsyncs between successive renders.
292 * Suggest this is a power of two:
293 * 1 - render each vsync frame
294 * 2 - render every other vsync frame
295 * 4 - render every fourth vsync frame
296 * 8 - render every eighth vsync frame
298 void SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender);
301 * @brief The callback is called from the Update/Render thread prior to rendering.
303 * @param[in] callback The function to call
305 * @note The function is called from the Update thread, so should do as little processing as possible.
306 * It is not possible to call any DALi event side APIs from within the callback; doing so will cause
307 * instability. Only 1 callback is supported. Setting the callback to NULL will remove the current callback.
309 * A callback of the following type should be used:
313 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
315 void SetPreRenderCallback(CallbackBase* callback);
318 * @brief Returns a reference to the instance of the adaptor used by the current thread.
320 * @return A reference to the adaptor.
321 * @pre The adaptor has been initialised.
322 * @note This is only valid in the main thread.
324 static Adaptor& Get();
327 * @brief Checks whether the adaptor is available.
329 * @return true, if it is available, false otherwise.
331 static bool IsAvailable();
334 * @brief Call this method to notify Dali when scene is created and initialized.
336 * Notify Adaptor that the scene has been created.
338 void NotifySceneCreated();
341 * @brief Call this method to notify Dali when the system language changes.
343 * Use this only when NOT using Dali::Application, As Application created using
344 * Dali::Application will automatically receive notification of language change.
345 * When Dali::Application is not used, the application developer should
346 * use app-core to receive language change notifications and should update Dali
347 * by calling this method.
349 void NotifyLanguageChanged();
352 * @brief Feed a touch point to the adaptor.
354 * @param[in] point touch point
355 * @param[in] timeStamp time value of event
357 void FeedTouchPoint(TouchPoint& point, int timeStamp);
360 * @brief Feed a wheel event to the adaptor.
362 * @param[in] wheelEvent wheel event
364 void FeedWheelEvent(WheelEvent& wheelEvent);
367 * @brief Feed a key event to the adaptor.
369 * @param[in] keyEvent The key event holding the key information.
371 void FeedKeyEvent(KeyEvent& keyEvent);
374 * @copydoc Dali::Core::SceneCreated();
379 * @brief Informs core the surface size has changed.
381 * @param[in] surface The current render surface
382 * @param[in] surfaceSize The new surface size
384 void SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize);
387 * @brief Informs ThreadController the surface size has changed.
389 * @param[in] surface The current render surface
390 * @param[in] surfaceSize The new surface size
392 void SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize);
395 * @brief Renders once more even if we're paused
396 * @note Will not work if the window is hidden.
401 * @brief The log factory allows installation of a logger function in worker threads.
402 * @return An interface to a logging factory
404 const LogFactoryInterface& GetLogFactory();
407 * @brief Register a processor implementing the Integration::Processor interface with dali-core.
408 * @param[in] processor the Processor to register
409 * @note using this api does not maintain the processor's lifecycle, must be done elsewhere.
411 void RegisterProcessor(Integration::Processor& processor);
414 * @brief Unregister a previously registered processor from dali-core.
415 * @param[in] processor the Processor to unregister
417 void UnregisterProcessor(Integration::Processor& processor);
420 * @brief Get the list of windows created.
421 * @return The list of windows
423 Dali::WindowContainer GetWindows() const;
426 * @brief Get the list of scene holders.
427 * @return The list of scene holers
429 SceneHolderList GetSceneHolders() const;
432 * @brief Gets the Object registry.
433 * @return The object registry
435 Dali::ObjectRegistry GetObjectRegistry() const;
438 * @brief Called when the window becomes fully or partially visible.
440 void OnWindowShown();
443 * @brief Called when the window is fully hidden.
445 void OnWindowHidden();
449 * @brief The user should connect to this signal if they need to perform any
450 * special activities when the surface Dali is being rendered on is resized.
452 * @return The signal to connect to
454 AdaptorSignalType& ResizedSignal();
457 * @brief This signal is emitted when the language is changed on the device.
459 * @return The signal to connect to
461 AdaptorSignalType& LanguageChangedSignal();
464 * @brief This signal is emitted when a new window (scene holder) is created
466 * @return The signal to connect to
468 WindowCreatedSignalType& WindowCreatedSignal();
472 Adaptor(const Adaptor&);
473 Adaptor& operator=(Adaptor&);
477 * @brief Create an uninitialized Adaptor.
481 Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
482 friend class Internal::Adaptor::Adaptor;
487 #endif // DALI_INTEGRATION_ADAPTOR_H