1 #ifndef DALI_INTEGRATION_ADAPTOR_H
2 #define DALI_INTEGRATION_ADAPTOR_H
5 * Copyright (c) 2024 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/integration-api/adaptor-framework/trace-factory-interface.h>
33 #include <dali/public-api/adaptor-framework/window.h>
34 #include <dali/public-api/dali-adaptor-common.h>
39 class RenderSurfaceInterface;
41 using WindowContainer = std::vector<Window>;
48 using SceneHolderList = std::vector<Dali::Integration::SceneHolder>;
54 class GraphicsFactory;
56 } // namespace Adaptor
57 } // namespace Internal
60 * @brief An Adaptor object is used to initialize and control how Dali runs.
62 * It provides a lifecycle interface that allows the application
63 * writer to provide their own main loop and other platform related
66 * The Adaptor class provides a means for initialising the resources required by the Dali::Core.
68 * When dealing with platform events, the application writer MUST ensure that Dali is called in a
71 * As soon as the Adaptor class is created and started, the application writer can initialise their
72 * Dali::Actor objects straight away or as required by the main loop they intend to use (there is no
73 * need to wait for an initialise signal as per the Dali::Application class).
75 * The Adaptor does emit a Resize signal which informs the user when the surface is resized.
76 * Tizen and Linux Adaptors should follow the example below:
79 * void CreateProgram(DaliAdaptor& adaptor)
81 * // Create Dali components...
82 * // Can instantiate adaptor here instead, if required
87 * // Initialise platform
90 * // Create an 800 by 1280 window positioned at (0,0).
91 * Dali::PositionSize positionSize(0, 0, 800, 1280);
92 * Dali::Window window = Dali::Window::New( positionSize, "My Application" );
94 * // Create an adaptor which uses that window for rendering
95 * Dali::Adaptor adaptor = Dali::Adaptor::New( window );
98 * CreateProgram(adaptor);
99 * // Or use this as a callback function depending on the platform initialisation sequence.
101 * // Start Main Loop of your platform
102 * MyPlatform.StartMainLoop();
108 * If required, you can also connect class member functions to a signal:
111 * MyApplication application;
112 * adaptor.ResizedSignal().Connect(&application, &MyApplication::Resize);
117 class DALI_ADAPTOR_API Adaptor
120 typedef Signal<void(Adaptor&)> AdaptorSignalType; ///< Generic Type for adaptor signals
121 typedef Signal<void(Dali::Integration::SceneHolder&)> WindowCreatedSignalType; ///< SceneHolder created signal type
122 typedef Signal<void(std::string)> LocaleChangedSignalType; ///< Locale changed signal type
124 using SurfaceSize = Uint16Pair; ///< Surface size type
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 render surface.
138 * @param[in] window The window to draw onto
139 * @param[in] surface The surface to draw onto
140 * @return a reference to the adaptor handle
142 static Adaptor& New(Window window, const Dali::RenderSurfaceInterface& surface);
145 * @brief Create a new adaptor using the SceneHolder.
147 * @param[in] sceneHolder The SceneHolder to draw onto
148 * @return a reference to the adaptor handle
150 static Adaptor& New(Dali::Integration::SceneHolder sceneHolder);
153 * @brief Create a new adaptor using render surface.
155 * @param[in] sceneHolder The SceneHolder to draw onto
156 * @param[in] surface The surface to draw onto
157 * @return a reference to the adaptor handle
159 static Adaptor& New(Dali::Integration::SceneHolder sceneHolder, const Dali::RenderSurfaceInterface& surface);
162 * @brief Virtual Destructor.
168 * @brief Starts the Adaptor.
173 * @brief Pauses the Adaptor.
178 * @brief Resumes the Adaptor, if previously paused.
180 * @note If the adaptor is not paused, this does not do anything.
185 * @brief Stops the Adaptor.
190 * @brief Ensures that the function passed in is called from the main loop when it is idle.
191 * @note Function must be called from the main event thread only.
193 * Callbacks of the following types may be used:
197 * This callback will be deleted once it is called.
202 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
204 * @param[in] callback The function to call.
205 * @param[in] hasReturnValue Sould be set to true if the callback function has a return value.
206 * @return true if added successfully, false otherwise
208 * @note Ownership of the callback is passed onto this class.
210 bool AddIdle(CallbackBase* callback, bool hasReturnValue);
213 * @brief Adds a new Window instance to the Adaptor
215 * @param[in] childWindow The child window instance
217 bool AddWindow(Dali::Integration::SceneHolder childWindow);
220 * @brief Removes a previously added @p callback.
221 * @note Function must be called from the main event thread only.
223 * Does nothing if the @p callback doesn't exist.
225 * @param[in] callback The callback to be removed.
227 void RemoveIdle(CallbackBase* callback);
230 * @brief Processes the idle callbacks.
232 * @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.
237 * @brief Replaces the rendering surface
239 * @param[in] window The window to replace the surface for
240 * @param[in] surface to use
242 void ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface);
245 * @brief Replaces the rendering surface
247 * @param[in] sceneHolder The SceneHolder to replace the surface for
248 * @param[in] surface to use
250 void ReplaceSurface(Dali::Integration::SceneHolder sceneHolder, Dali::RenderSurfaceInterface& surface);
253 * @brief Get the render surface the adaptor is using to render to.
255 * @return reference to current render surface
257 Dali::RenderSurfaceInterface& GetSurface();
260 * @brief Gets native window handle
262 * @return Native window handle
264 Any GetNativeWindowHandle();
267 * @brief Retrieve native window handle that the given actor is added to.
269 * @param[in] actor The actor
270 * @return native window handle
272 Any GetNativeWindowHandle(Actor actor);
275 * @brief Get the native display associated with the graphics backend
277 * @return A handle to the native display
279 Any GetGraphicsDisplay();
282 * @brief Release any locks the surface may hold.
284 * For example, after compositing an offscreen surface, use this method to allow
285 * rendering to continue.
287 void ReleaseSurfaceLock();
290 * @brief Set the number of frames per render.
292 * This enables an application to deliberately render with a reduced FPS.
293 * @param[in] numberOfVSyncsPerRender The number of vsyncs between successive renders.
294 * Suggest this is a power of two:
295 * 1 - render each vsync frame
296 * 2 - render every other vsync frame
297 * 4 - render every fourth vsync frame
298 * 8 - render every eighth vsync frame
300 void SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender);
303 * @brief The callback is called from the Update/Render thread prior to rendering.
305 * @param[in] callback The function to call
307 * @note The function is called from the Update thread, so should do as little processing as possible.
308 * It is not possible to call any DALi event side APIs from within the callback; doing so will cause
309 * instability. Only 1 callback is supported. Setting the callback to NULL will remove the current callback.
311 * A callback of the following type should be used:
315 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
317 void SetPreRenderCallback(CallbackBase* callback);
320 * @brief Returns a reference to the instance of the adaptor used by the current thread.
322 * @return A reference to the adaptor.
323 * @pre The adaptor has been initialised.
324 * @note This is only valid in the main thread.
326 static Adaptor& Get();
329 * @brief Checks whether the adaptor is available.
331 * @return true, if it is available, false otherwise.
333 static bool IsAvailable();
336 * @brief Call this method to notify Dali when scene is created and initialized.
338 * Notify Adaptor that the scene has been created.
340 void NotifySceneCreated();
343 * @brief Call this method to notify Dali when the system language changes.
345 * Use this only when NOT using Dali::Application, As Application created using
346 * Dali::Application will automatically receive notification of language change.
347 * When Dali::Application is not used, the application developer should
348 * use app-core to receive language change notifications and should update Dali
349 * by calling this method.
351 void NotifyLanguageChanged();
354 * @brief Feed a touch point to the adaptor.
356 * @param[in] point touch point
357 * @param[in] timeStamp time value of event
359 void FeedTouchPoint(TouchPoint& point, int timeStamp);
362 * @brief Feed a wheel event to the adaptor.
364 * @param[in] wheelEvent wheel event
366 void FeedWheelEvent(WheelEvent& wheelEvent);
369 * @brief Feed a key event to the adaptor.
371 * @param[in] keyEvent The key event holding the key information.
373 void FeedKeyEvent(KeyEvent& keyEvent);
376 * @copydoc Dali::Core::SceneCreated();
381 * @brief Informs core the surface size has changed.
383 * @param[in] surface The current render surface
384 * @param[in] surfaceSize The new surface size
386 void SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize);
389 * @brief Informs ThreadController the surface size has changed.
391 * @param[in] surface The current render surface
392 * @param[in] surfaceSize The new surface size
394 void SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize);
397 * @brief Update once. It will not wake up the update thread if we're paused.
398 * @note Will not work if the window is hidden.
403 * @brief Renders once more even if we're paused
408 * @brief Relayout and ensure all pending operations are flushed to the update thread.
410 void FlushUpdateMessages();
413 * @brief Requests a future call to Dali::Integration::Core::ProcessEvents(), when the application is idle.
415 void RequestProcessEventsOnIdle();
418 * @brief The log factory allows installation of a logger function in worker threads.
419 * @return An interface to a logging factory
421 const LogFactoryInterface& GetLogFactory();
424 * @brief The trace factory allows installation of a trace function in worker threads.
425 * @return An interface to a tracing factory
427 const TraceFactoryInterface& GetTraceFactory();
430 * @brief Register a processor implementing the Integration::Processor interface with dali-core.
431 * @param[in] processor the Processor to register
432 * @param[in] postProcessor set this processor required to be called after size negotiation. Default is false.
433 * @note using this api does not maintain the processor's lifecycle, must be done elsewhere.
435 void RegisterProcessor(Integration::Processor& processor, bool postProcessor = false);
438 * @brief Unregister a previously registered processor from dali-core.
439 * @param[in] processor the Processor to unregister
440 * @param[in] postProcessor True if the processor to be unregister is for post processor.
442 void UnregisterProcessor(Integration::Processor& processor, bool postProcessor = false);
445 * @brief Get the list of windows created.
446 * @return The list of windows
448 Dali::WindowContainer GetWindows() const;
451 * @brief Get the list of scene holders.
452 * @return The list of scene holers
454 SceneHolderList GetSceneHolders() const;
457 * @brief Gets the Object registry.
458 * @return The object registry
460 Dali::ObjectRegistry GetObjectRegistry() const;
463 * @brief Called when the window becomes fully or partially visible.
465 void OnWindowShown();
468 * @brief Called when the window is fully hidden.
470 void OnWindowHidden();
474 * @brief The user should connect to this signal if they need to perform any
475 * special activities when the surface Dali is being rendered on is resized.
477 * @return The signal to connect to
479 AdaptorSignalType& ResizedSignal();
482 * @brief This signal is emitted when the language is changed on the device.
484 * @return The signal to connect to
486 AdaptorSignalType& LanguageChangedSignal();
489 * @brief This signal is emitted when a new window (scene holder) is created
491 * @return The signal to connect to
493 WindowCreatedSignalType& WindowCreatedSignal();
496 * @brief This signal is emitted when the system locale is changed
498 * @return The signal to connect to
500 LocaleChangedSignalType& LocaleChangedSignal();
504 Adaptor(const Adaptor&);
505 Adaptor& operator=(Adaptor&);
509 * @brief Create an uninitialized Adaptor.
513 Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
514 friend class Internal::Adaptor::Adaptor;
519 #endif // DALI_INTEGRATION_ADAPTOR_H