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>
27 #include <dali/integration-api/processor-interface.h>
30 #include <dali/public-api/adaptor-framework/window.h>
31 #include <dali/public-api/adaptor-framework/application-configuration.h>
32 #include <dali/public-api/dali-adaptor-common.h>
34 #ifdef DALI_ADAPTOR_COMPILATION
35 #include <dali/integration-api/log-factory-interface.h>
37 #include <dali/integration-api/adaptors/log-factory-interface.h>
44 class RenderSurfaceInterface;
50 class GraphicsFactory;
56 * @brief An Adaptor object is used to initialize and control how Dali runs.
58 * It provides a lifecycle interface that allows the application
59 * writer to provide their own main loop and other platform related
62 * The Adaptor class provides a means for initialising the resources required by the Dali::Core.
64 * When dealing with platform events, the application writer MUST ensure that Dali is called in a
67 * As soon as the Adaptor class is created and started, the application writer can initialise their
68 * Dali::Actor objects straight away or as required by the main loop they intend to use (there is no
69 * need to wait for an initialise signal as per the Dali::Application class).
71 * The Adaptor does emit a Resize signal which informs the user when the surface is resized.
72 * Tizen and Linux Adaptors should follow the example below:
75 * void CreateProgram(DaliAdaptor& adaptor)
77 * // Create Dali components...
78 * // Can instantiate adaptor here instead, if required
83 * // Initialise platform
86 * // Create an 800 by 1280 window positioned at (0,0).
87 * Dali::PositionSize positionSize(0, 0, 800, 1280);
88 * Dali::Window window = Dali::Window::New( positionSize, "My Application" );
90 * // Create an adaptor which uses that window for rendering
91 * Dali::Adaptor adaptor = Dali::Adaptor::New( window );
94 * CreateProgram(adaptor);
95 * // Or use this as a callback function depending on the platform initialisation sequence.
97 * // Start Main Loop of your platform
98 * MyPlatform.StartMainLoop();
104 * If required, you can also connect class member functions to a signal:
107 * MyApplication application;
108 * adaptor.ResizedSignal().Connect(&application, &MyApplication::Resize);
113 class DALI_ADAPTOR_API Adaptor
117 typedef Signal< void (Adaptor&) > AdaptorSignalType; ///< Generic Type for adaptor signals
121 * @brief Create a new adaptor using the window.
123 * @param[in] window The window to draw onto
124 * @return a reference to the adaptor handle
126 static Adaptor& New( Window window );
129 * @brief Create a new adaptor using the window.
131 * @param[in] window The window to draw onto
132 * @param[in] configuration The context loss configuration.
133 * @return a reference to the adaptor handle
135 static Adaptor& New( Window window, Configuration::ContextLoss configuration );
138 * @brief Create a new adaptor using render surface.
140 * @param[in] nativeWindow native window handle
141 * @param[in] surface The surface to draw onto
142 * @return a reference to the adaptor handle
144 static Adaptor& New( Any nativeWindow, const Dali::RenderSurfaceInterface& surface );
147 * @brief Create a new adaptor using render surface.
149 * @param[in] nativeWindow native window handle
150 * @param[in] surface The surface to draw onto
151 * @param[in] configuration The context loss configuration.
152 * @return a reference to the adaptor handle
154 static Adaptor& New( Any nativeWindow, const Dali::RenderSurfaceInterface& surface, Configuration::ContextLoss configuration = Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
157 * @brief Virtual Destructor.
164 * @brief Starts the Adaptor.
169 * @brief Pauses the Adaptor.
174 * @brief Resumes the Adaptor, if previously paused.
176 * @note If the adaptor is not paused, this does not do anything.
181 * @brief Stops the Adaptor.
186 * @brief Ensures that the function passed in is called from the main loop when it is idle.
187 * @note Function must be called from the main event thread only.
189 * Callbacks of the following types may be used:
193 * This callback will be deleted once it is called.
198 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
200 * @param[in] callback The function to call.
201 * @param[in] hasReturnValue Sould be set to true if the callback function has a return value.
202 * @return true if added successfully, false otherwise
204 * @note Ownership of the callback is passed onto this class.
206 bool AddIdle( CallbackBase* callback, bool hasReturnValue );
209 * @brief Removes a previously added @p callback.
210 * @note Function must be called from the main event thread only.
212 * Does nothing if the @p callback doesn't exist.
214 * @param[in] callback The callback to be removed.
216 void RemoveIdle( CallbackBase* callback );
219 * @brief Replaces the rendering surface
221 * @param[in] nativeWindow native window handle
222 * @param[in] surface to use
224 void ReplaceSurface( Any nativeWindow, Dali::RenderSurfaceInterface& surface );
227 * @brief Get the render surface the adaptor is using to render to.
229 * @return reference to current render surface
231 Dali::RenderSurfaceInterface& GetSurface();
234 * @brief Gets native window handle
236 * @return Native window handle
238 Any GetNativeWindowHandle();
241 * @brief Get the native display associated with the graphics backend
243 * @return A handle to the native display
245 Any GetGraphicsDisplay();
248 * @brief Release any locks the surface may hold.
250 * For example, after compositing an offscreen surface, use this method to allow
251 * rendering to continue.
253 void ReleaseSurfaceLock();
256 * @brief Set the number of frames per render.
258 * This enables an application to deliberately render with a reduced FPS.
259 * @param[in] numberOfVSyncsPerRender The number of vsyncs between successive renders.
260 * Suggest this is a power of two:
261 * 1 - render each vsync frame
262 * 2 - render every other vsync frame
263 * 4 - render every fourth vsync frame
264 * 8 - render every eighth vsync frame
266 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
269 * @brief The callback is called from the Update/Render thread prior to rendering.
271 * @param[in] callback The function to call
273 * @note The function is called from the Update thread, so should do as little processing as possible.
274 * It is not possible to call any DALi event side APIs from within the callback; doing so will cause
275 * instability. Only 1 callback is supported. Setting the callback to NULL will remove the current callback.
277 * A callback of the following type should be used:
281 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
283 void SetPreRenderCallback( CallbackBase* callback );
286 * @brief Set whether the frame count per render is managed using the hardware VSync or
289 * @param[in] useHardware True if the hardware VSync should be used
291 void SetUseHardwareVSync(bool useHardware);
294 * @brief Returns a reference to the instance of the adaptor used by the current thread.
296 * @return A reference to the adaptor.
297 * @pre The adaptor has been initialised.
298 * @note This is only valid in the main thread.
300 static Adaptor& Get();
303 * @brief Checks whether the adaptor is available.
305 * @return true, if it is available, false otherwise.
307 static bool IsAvailable();
310 * @brief Call this method to notify Dali when scene is created and initialized.
312 * Notify Adaptor that the scene has been created.
314 void NotifySceneCreated();
317 * @brief Call this method to notify Dali when the system language changes.
319 * Use this only when NOT using Dali::Application, As Application created using
320 * Dali::Application will automatically receive notification of language change.
321 * When Dali::Application is not used, the application developer should
322 * use app-core to receive language change notifications and should update Dali
323 * by calling this method.
325 void NotifyLanguageChanged();
328 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
329 * trigger a pinch gesture
331 * @param[in] distance The minimum pinch distance in pixels
333 void SetMinimumPinchDistance(float distance);
336 * @brief Feed a touch point to the adaptor.
338 * @param[in] point touch point
339 * @param[in] timeStamp time value of event
341 void FeedTouchPoint( TouchPoint& point, int timeStamp );
344 * @brief Feed a wheel event to the adaptor.
346 * @param[in] wheelEvent wheel event
348 void FeedWheelEvent( WheelEvent& wheelEvent );
351 * @brief Feed a key event to the adaptor.
353 * @param[in] keyEvent The key event holding the key information.
355 void FeedKeyEvent( KeyEvent& keyEvent );
358 * @copydoc Dali::Core::SceneCreated();
363 * @brief Renders once more even if we're paused
364 * @note Will not work if the window is hidden.
369 * @brief The log factory allows installation of a logger function in worker threads.
370 * @return An interface to a logging factory
372 const LogFactoryInterface& GetLogFactory();
375 * @brief Register a processor implementing the Integration::Processor interface with dali-core.
376 * @param[in] processor the Processor to register
377 * @note using this api does not maintain the processor's lifecycle, must be done elsewhere.
379 void RegisterProcessor( Integration::Processor& processor );
382 * @brief Unregister a previously registered processor from dali-core.
383 * @param[in] processor the Processor to unregister
385 void UnregisterProcessor( Integration::Processor& processor );
390 * @brief The user should connect to this signal if they need to perform any
391 * special activities when the surface Dali is being rendered on is resized.
393 * @return The signal to connect to
395 AdaptorSignalType& ResizedSignal();
398 * @brief This signal is emitted when the language is changed on the device.
400 * @return The signal to connect to
402 AdaptorSignalType& LanguageChangedSignal();
407 Adaptor(const Adaptor&);
408 Adaptor& operator=(Adaptor&);
413 * @brief Create an uninitialized Adaptor.
417 Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
418 friend class Internal::Adaptor::Adaptor;
423 #endif // DALI_INTEGRATION_ADAPTOR_H