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>
54 * @brief An Adaptor object is used to initialize and control how Dali runs.
56 * It provides a lifecycle interface that allows the application
57 * writer to provide their own main loop and other platform related
60 * The Adaptor class provides a means for initialising the resources required by the Dali::Core.
62 * When dealing with platform events, the application writer MUST ensure that Dali is called in a
65 * As soon as the Adaptor class is created and started, the application writer can initialise their
66 * Dali::Actor objects straight away or as required by the main loop they intend to use (there is no
67 * need to wait for an initialise signal as per the Dali::Application class).
69 * The Adaptor does emit a Resize signal which informs the user when the surface is resized.
70 * Tizen and Linux Adaptors should follow the example below:
73 * void CreateProgram(DaliAdaptor& adaptor)
75 * // Create Dali components...
76 * // Can instantiate adaptor here instead, if required
81 * // Initialise platform
84 * // Create an 800 by 1280 window positioned at (0,0).
85 * Dali::PositionSize positionSize(0, 0, 800, 1280);
86 * Dali::Window window = Dali::Window::New( positionSize, "My Application" );
88 * // Create an adaptor which uses that window for rendering
89 * Dali::Adaptor adaptor = Dali::Adaptor::New( window );
92 * CreateProgram(adaptor);
93 * // Or use this as a callback function depending on the platform initialisation sequence.
95 * // Start Main Loop of your platform
96 * MyPlatform.StartMainLoop();
102 * If required, you can also connect class member functions to a signal:
105 * MyApplication application;
106 * adaptor.ResizedSignal().Connect(&application, &MyApplication::Resize);
111 class DALI_ADAPTOR_API Adaptor
115 typedef Signal< void (Adaptor&) > AdaptorSignalType; ///< Generic Type for adaptor signals
119 * @brief Create a new adaptor using the window.
121 * @param[in] window The window to draw onto
122 * @return a reference to the adaptor handle
124 static Adaptor& New( Window window );
127 * @brief Create a new adaptor using the window.
129 * @param[in] window The window to draw onto
130 * @param[in] configuration The context loss configuration.
131 * @return a reference to the adaptor handle
133 static Adaptor& New( Window window, Configuration::ContextLoss configuration );
136 * @brief Create a new adaptor using render surface.
138 * @param[in] nativeWindow native window handle
139 * @param[in] surface The surface to draw onto
140 * @return a reference to the adaptor handle
142 static Adaptor& New( Any nativeWindow, const Dali::RenderSurface& surface );
145 * @brief Create a new adaptor using render surface.
147 * @param[in] nativeWindow native window handle
148 * @param[in] surface The surface to draw onto
149 * @param[in] configuration The context loss configuration.
150 * @return a reference to the adaptor handle
152 static Adaptor& New( Any nativeWindow, const Dali::RenderSurface& surface, Configuration::ContextLoss configuration = Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
155 * @brief Virtual Destructor.
162 * @brief Starts the Adaptor.
167 * @brief Pauses the Adaptor.
172 * @brief Resumes the Adaptor, if previously paused.
174 * @note If the adaptor is not paused, this does not do anything.
179 * @brief Stops the Adaptor.
184 * @brief Ensures that the function passed in is called from the main loop when it is idle.
185 * @note Function must be called from the main event thread only.
187 * A callback of the following type may be used:
192 * @param[in] callback The function to call.
193 * @return true if added successfully, false otherwise
195 * @note Ownership of the callback is passed onto this class.
197 bool AddIdle( CallbackBase* callback );
200 * @brief Removes a previously added @p callback.
201 * @note Function must be called from the main event thread only.
203 * Does nothing if the @p callback doesn't exist.
205 * @param[in] callback The callback to be removed.
207 void RemoveIdle( CallbackBase* callback );
210 * @brief Replaces the rendering surface
212 * @param[in] nativeWindow native window handle
213 * @param[in] surface to use
215 void ReplaceSurface( Any nativeWindow, Dali::RenderSurface& surface );
218 * @brief Get the render surface the adaptor is using to render to.
220 * @return reference to current render surface
222 RenderSurface& GetSurface();
225 * @brief Gets native window handle
227 * @return Native window handle
229 Any GetNativeWindowHandle();
232 * @brief Release any locks the surface may hold.
234 * For example, after compositing an offscreen surface, use this method to allow
235 * rendering to continue.
237 void ReleaseSurfaceLock();
240 * @brief Set the number of frames per render.
242 * This enables an application to deliberately render with a reduced FPS.
243 * @param[in] numberOfVSyncsPerRender The number of vsyncs between successive renders.
244 * Suggest this is a power of two:
245 * 1 - render each vsync frame
246 * 2 - render every other vsync frame
247 * 4 - render every fourth vsync frame
248 * 8 - render every eighth vsync frame
250 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
253 * @brief Set whether the frame count per render is managed using the hardware VSync or
256 * @param[in] useHardware True if the hardware VSync should be used
258 void SetUseHardwareVSync(bool useHardware);
261 * @brief Returns a reference to the instance of the adaptor used by the current thread.
263 * @return A reference to the adaptor.
264 * @pre The adaptor has been initialised.
265 * @note This is only valid in the main thread.
267 static Adaptor& Get();
270 * @brief Checks whether the adaptor is available.
272 * @return true, if it is available, false otherwise.
274 static bool IsAvailable();
277 * @brief Call this method to notify Dali when scene is created and initialized.
279 * Notify Adaptor that the scene has been created.
281 void NotifySceneCreated();
284 * @brief Call this method to notify Dali when the system language changes.
286 * Use this only when NOT using Dali::Application, As Application created using
287 * Dali::Application will automatically receive notification of language change.
288 * When Dali::Application is not used, the application developer should
289 * use app-core to receive language change notifications and should update Dali
290 * by calling this method.
292 void NotifyLanguageChanged();
295 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
296 * trigger a pinch gesture
298 * @param[in] distance The minimum pinch distance in pixels
300 void SetMinimumPinchDistance(float distance);
303 * @brief Feed a touch point to the adaptor.
305 * @param[in] point touch point
306 * @param[in] timeStamp time value of event
308 void FeedTouchPoint( TouchPoint& point, int timeStamp );
311 * @brief Feed a wheel event to the adaptor.
313 * @param[in] wheelEvent wheel event
315 void FeedWheelEvent( WheelEvent& wheelEvent );
318 * @brief Feed a key event to the adaptor.
320 * @param[in] keyEvent The key event holding the key information.
322 void FeedKeyEvent( KeyEvent& keyEvent );
325 * @copydoc Dali::Core::SceneCreated();
330 * @copydoc Dali::Application::SetViewMode();
332 void SetViewMode( ViewMode viewMode );
335 * @copydoc Dali::Application::SetStereoBase();
337 void SetStereoBase( float stereoBase );
340 * @brief Renders once more even if we're paused
341 * @note Will not work if the window is hidden.
346 * @brief The log factory allows installation of a logger function in worker threads.
347 * @return An interface to a logging factory
349 const LogFactoryInterface& GetLogFactory();
354 * @brief The user should connect to this signal if they need to perform any
355 * special activities when the surface Dali is being rendered on is resized.
357 * @return The signal to connect to
359 AdaptorSignalType& ResizedSignal();
362 * @brief This signal is emitted when the language is changed on the device.
364 * @return The signal to connect to
366 AdaptorSignalType& LanguageChangedSignal();
371 Adaptor(const Adaptor&);
372 Adaptor& operator=(Adaptor&);
377 * @brief Create an uninitialized Adaptor.
381 Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
382 friend class Internal::Adaptor::Adaptor;
387 #endif // __DALI_INTEGRATION_ADAPTOR_H__