1 #ifndef __DALI_INTEGRATION_ADAPTOR_H__
2 #define __DALI_INTEGRATION_ADAPTOR_H__
5 * Copyright (c) 2017 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>
30 #ifdef DALI_ADAPTOR_COMPILATION // full path doesn't exist until adaptor is installed so we have to use relative
31 // @todo Make dali-adaptor code folder structure mirror the folder structure installed to dali-env
33 #include <application-configuration.h>
35 #include <dali/public-api/adaptor-framework/window.h>
36 #include <dali/public-api/adaptor-framework/application-configuration.h>
39 #ifdef DALI_ADAPTOR_COMPILATION
40 #include <log-factory-interface.h>
42 #include <dali/integration-api/adaptors/log-factory-interface.h>
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_IMPORT_API Adaptor
121 typedef Signal< void (Adaptor&) > AdaptorSignalType; ///< Generic Type for adaptor signals
125 * @brief Create a new adaptor using the window.
127 * @param[in] window The window to draw onto
128 * @return a reference to the adaptor handle
130 static Adaptor& New( Window window );
133 * @brief Create a new adaptor using the window.
135 * @param[in] window The window to draw onto
136 * @param[in] configuration The context loss configuration.
137 * @return a reference to the adaptor handle
139 static Adaptor& New( Window window, Configuration::ContextLoss configuration );
142 * @brief Create a new adaptor using render surface.
144 * @param[in] nativeWindow native window handle
145 * @param[in] surface The surface to draw onto
146 * @return a reference to the adaptor handle
148 static Adaptor& New( Any nativeWindow, const Dali::RenderSurface& surface );
151 * @brief Create a new adaptor using render surface.
153 * @param[in] nativeWindow native window handle
154 * @param[in] surface The surface to draw onto
155 * @param[in] configuration The context loss configuration.
156 * @return a reference to the adaptor handle
158 static Adaptor& New( Any nativeWindow, const Dali::RenderSurface& surface, Configuration::ContextLoss configuration = Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
161 * @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 * A callback of the following type may be used:
198 * @param[in] callback The function to call.
199 * @return true if added successfully, false otherwise
201 * @note Ownership of the callback is passed onto this class.
203 bool AddIdle( CallbackBase* callback );
206 * @brief Removes a previously added @p callback.
207 * @note Function must be called from the main event thread only.
209 * Does nothing if the @p callback doesn't exist.
211 * @param[in] callback The callback to be removed.
213 void RemoveIdle( CallbackBase* callback );
216 * @brief Replaces the rendering surface
218 * @param[in] nativeWindow native window handle
219 * @param[in] surface to use
221 void ReplaceSurface( Any nativeWindow, Dali::RenderSurface& surface );
224 * @brief Get the render surface the adaptor is using to render to.
226 * @return reference to current render surface
228 RenderSurface& GetSurface();
231 * @brief Gets native window handle
233 * @return Native window handle
235 Any GetNativeWindowHandle();
238 * @brief Release any locks the surface may hold.
240 * For example, after compositing an offscreen surface, use this method to allow
241 * rendering to continue.
243 void ReleaseSurfaceLock();
246 * @brief Set the number of frames per render.
248 * This enables an application to deliberately render with a reduced FPS.
249 * @param[in] numberOfVSyncsPerRender The number of vsyncs between successive renders.
250 * Suggest this is a power of two:
251 * 1 - render each vsync frame
252 * 2 - render every other vsync frame
253 * 4 - render every fourth vsync frame
254 * 8 - render every eighth vsync frame
256 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
259 * @brief Set whether the frame count per render is managed using the hardware VSync or
262 * @param[in] useHardware True if the hardware VSync should be used
264 void SetUseHardwareVSync(bool useHardware);
267 * @brief Returns a reference to the instance of the adaptor used by the current thread.
269 * @return A reference to the adaptor.
270 * @pre The adaptor has been initialised.
271 * @note This is only valid in the main thread.
273 static Adaptor& Get();
276 * @brief Checks whether the adaptor is available.
278 * @return true, if it is available, false otherwise.
280 static bool IsAvailable();
283 * @brief Call this method to notify Dali when scene is created and initialized.
285 * Notify Adaptor that the scene has been created.
287 void NotifySceneCreated();
290 * @brief Call this method to notify Dali when the system language changes.
292 * Use this only when NOT using Dali::Application, As Application created using
293 * Dali::Application will automatically receive notification of language change.
294 * When Dali::Application is not used, the application developer should
295 * use app-core to receive language change notifications and should update Dali
296 * by calling this method.
298 void NotifyLanguageChanged();
301 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
302 * trigger a pinch gesture
304 * @param[in] distance The minimum pinch distance in pixels
306 void SetMinimumPinchDistance(float distance);
309 * @brief Feed a touch point to the adaptor.
311 * @param[in] point touch point
312 * @param[in] timeStamp time value of event
314 void FeedTouchPoint( TouchPoint& point, int timeStamp );
317 * @brief Feed a wheel event to the adaptor.
319 * @param[in] wheelEvent wheel event
321 void FeedWheelEvent( WheelEvent& wheelEvent );
324 * @brief Feed a key event to the adaptor.
326 * @param[in] keyEvent The key event holding the key information.
328 void FeedKeyEvent( KeyEvent& keyEvent );
331 * @copydoc Dali::Core::SceneCreated();
336 * @copydoc Dali::Application::SetViewMode();
338 void SetViewMode( ViewMode viewMode );
341 * @copydoc Dali::Application::SetStereoBase();
343 void SetStereoBase( float stereoBase );
346 * @brief Renders once more even if we're paused
347 * @note Will not work if the window is hidden.
352 * @brief The log factory allows installation of a logger function in worker threads.
353 * @return An interface to a logging factory
355 const LogFactoryInterface& GetLogFactory();
360 * @brief The user should connect to this signal if they need to perform any
361 * special activities when the surface Dali is being rendered on is resized.
363 * @return The signal to connect to
365 AdaptorSignalType& ResizedSignal();
368 * @brief This signal is emitted when the language is changed on the device.
370 * @return The signal to connect to
372 AdaptorSignalType& LanguageChangedSignal();
377 Adaptor(const Adaptor&);
378 Adaptor& operator=(Adaptor&);
383 * @brief Create an uninitialized Adaptor.
387 Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
388 friend class Internal::Adaptor::Adaptor;
393 #endif // __DALI_INTEGRATION_ADAPTOR_H__