1 #ifndef __DALI_INTEGRATION_ADAPTOR_H__
2 #define __DALI_INTEGRATION_ADAPTOR_H__
5 * Copyright (c) 2016 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>
31 #ifdef DALI_ADAPTOR_COMPILATION // full path doesn't exist until adaptor is installed so we have to use relative
32 // @todo Make dali-adaptor code folder structure mirror the folder structure installed to dali-env
34 #include <application-configuration.h>
36 #include <dali/public-api/adaptor-framework/window.h>
37 #include <dali/public-api/adaptor-framework/application-configuration.h>
55 * @brief An Adaptor object is used to initialize and control how Dali runs.
57 * It provides a lifecycle interface that allows the application
58 * writer to provide their own main loop and other platform related
61 * The Adaptor class provides a means for initialising the resources required by the Dali::Core.
63 * When dealing with platform events, the application writer MUST ensure that Dali is called in a
66 * As soon as the Adaptor class is created and started, the application writer can initialise their
67 * Dali::Actor objects straight away or as required by the main loop they intend to use (there is no
68 * need to wait for an initialise signal as per the Dali::Application class).
70 * The Adaptor does emit a Resize signal which informs the user when the surface is resized.
71 * Tizen and Linux Adaptors should follow the example below:
74 * void CreateProgram(DaliAdaptor& adaptor)
76 * // Create Dali components...
77 * // Can instantiate adaptor here instead, if required
82 * // Initialise platform
85 * // Create an 800 by 1280 window positioned at (0,0).
86 * Dali::PositionSize positionSize(0, 0, 800, 1280);
87 * Dali::Window window = Dali::Window::New( positionSize, "My Application" );
89 * // Create an adaptor which uses that window for rendering
90 * Dali::Adaptor adaptor = Dali::Adaptor::New( window );
93 * CreateProgram(adaptor);
94 * // Or use this as a callback function depending on the platform initialisation sequence.
96 * // Start Main Loop of your platform
97 * MyPlatform.StartMainLoop();
103 * If required, you can also connect class member functions to a signal:
106 * MyApplication application;
107 * adaptor.ResizedSignal().Connect(&application, &MyApplication::Resize);
112 class DALI_IMPORT_API Adaptor
116 typedef Signal< void (Adaptor&) > AdaptorSignalType; ///< Generic Type for adaptor signals
120 * @brief Create a new adaptor using the window.
122 * @param[in] window The window to draw onto
123 * @return a reference to the adaptor handle
125 static Adaptor& New( Window window );
128 * @brief Create a new adaptor using the window.
130 * @param[in] window The window to draw onto
131 * @param[in] configuration The context loss configuration.
132 * @return a reference to the adaptor handle
134 static Adaptor& New( Window window, Configuration::ContextLoss configuration );
137 * @brief Create a new adaptor using render surface.
139 * @param[in] nativeWindow native window handle
140 * @param[in] surface The surface to draw onto
141 * @return a reference to the adaptor handle
143 static Adaptor& New( Any nativeWindow, const Dali::RenderSurface& surface );
146 * @brief Create a new adaptor using render surface.
148 * @param[in] nativeWindow native window handle
149 * @param[in] surface The surface to draw onto
150 * @param[in] configuration The context loss configuration.
151 * @return a reference to the adaptor handle
153 static Adaptor& New( Any nativeWindow, const Dali::RenderSurface& surface, Configuration::ContextLoss configuration = Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
156 * @brief Virtual Destructor.
163 * @brief Starts the Adaptor.
168 * @brief Pauses the Adaptor.
173 * @brief Resumes the Adaptor, if previously paused.
175 * @note If the adaptor is not paused, this does not do anything.
180 * @brief Stops the Adaptor.
185 * @brief Ensures that the function passed in is called from the main loop when it is idle.
186 * @note Function must be called from the main event thread only.
188 * A callback of the following type may be used:
193 * @param[in] callback The function to call.
194 * @return true if added successfully, false otherwise
196 * @note Ownership of the callback is passed onto this class.
198 bool AddIdle( CallbackBase* callback );
201 * @brief Removes a previously added @p callback.
202 * @note Function must be called from the main event thread only.
204 * Does nothing if the @p callback doesn't exist.
206 * @param[in] callback The callback to be removed.
208 void RemoveIdle( CallbackBase* callback );
211 * @brief Replaces the rendering surface
213 * @param[in] nativeWindow native window handle
214 * @param[in] surface to use
216 void ReplaceSurface( Any nativeWindow, Dali::RenderSurface& surface );
219 * @brief Get the render surface the adaptor is using to render to.
221 * @return reference to current render surface
223 RenderSurface& GetSurface();
226 * @brief Gets native window handle
228 * @return Native window handle
230 Any GetNativeWindowHandle();
233 * @brief Release any locks the surface may hold.
235 * For example, after compositing an offscreen surface, use this method to allow
236 * rendering to continue.
238 void ReleaseSurfaceLock();
241 * @brief Set the number of frames per render.
243 * This enables an application to deliberately render with a reduced FPS.
244 * @param[in] numberOfVSyncsPerRender The number of vsyncs between successive renders.
245 * Suggest this is a power of two:
246 * 1 - render each vsync frame
247 * 2 - render every other vsync frame
248 * 4 - render every fourth vsync frame
249 * 8 - render every eighth vsync frame
251 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
254 * @brief Set whether the frame count per render is managed using the hardware VSync or
257 * @param[in] useHardware True if the hardware VSync should be used
259 void SetUseHardwareVSync(bool useHardware);
262 * @brief Returns a reference to the instance of the adaptor used by the current thread.
264 * @return A reference to the adaptor.
265 * @pre The adaptor has been initialised.
266 * @note This is only valid in the main thread.
268 static Adaptor& Get();
271 * @brief Checks whether the adaptor is available.
273 * @return true, if it is available, false otherwise.
275 static bool IsAvailable();
278 * @brief Call this method to notify Dali when scene is created and initialized.
280 * Notify Adaptor that the scene has been created.
282 void NotifySceneCreated();
285 * @brief Call this method to notify Dali when the system language changes.
287 * Use this only when NOT using Dali::Application, As Application created using
288 * Dali::Application will automatically receive notification of language change.
289 * When Dali::Application is not used, the application developer should
290 * use app-core to receive language change notifications and should update Dali
291 * by calling this method.
293 void NotifyLanguageChanged();
296 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
297 * trigger a pinch gesture
299 * @param[in] distance The minimum pinch distance in pixels
301 void SetMinimumPinchDistance(float distance);
304 * @brief Feed a touch point to the adaptor.
306 * @param[in] point touch point
307 * @param[in] timeStamp time value of event
309 void FeedTouchPoint( TouchPoint& point, int timeStamp );
312 * @brief Feed a wheel event to the adaptor.
314 * @param[in] wheelEvent wheel event
316 void FeedWheelEvent( WheelEvent& wheelEvent );
319 * @brief Feed a key event to the adaptor.
321 * @param[in] keyEvent The key event holding the key information.
323 void FeedKeyEvent( KeyEvent& keyEvent );
326 * @copydoc Dali::Core::SceneCreated();
331 * @copydoc Dali::Application::SetViewMode();
333 void SetViewMode( ViewMode viewMode );
336 * @copydoc Dali::Application::SetStereoBase();
338 void SetStereoBase( float stereoBase );
341 * @brief Informs core the surface size has changed
343 void SurfaceSizeChanged( const PositionSize& positionSize );
348 * @brief The user should connect to this signal if they need to perform any
349 * special activities when the surface Dali is being rendered on is resized.
351 * @return The signal to connect to
353 AdaptorSignalType& ResizedSignal();
356 * @brief This signal is emitted when the language is changed on the device.
358 * @return The signal to connect to
360 AdaptorSignalType& LanguageChangedSignal();
365 Adaptor(const Adaptor&);
366 Adaptor& operator=(Adaptor&);
371 * @brief Create an uninitialized Adaptor.
375 Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
376 friend class Internal::Adaptor::Adaptor;
381 #endif // __DALI_INTEGRATION_ADAPTOR_H__