Added Adaptor::GetGraphicsDisplay() to get EglDisplay
[platform/core/uifw/dali-adaptor.git] / dali / integration-api / adaptor.h
1 #ifndef __DALI_INTEGRATION_ADAPTOR_H__
2 #define __DALI_INTEGRATION_ADAPTOR_H__
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
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
28 // INTERNAL INCLUDES
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>
32
33 #ifdef DALI_ADAPTOR_COMPILATION
34 #include <dali/integration-api/log-factory-interface.h>
35 #else
36 #include <dali/integration-api/adaptors/log-factory-interface.h>
37 #endif
38
39
40 namespace Dali
41 {
42
43 class RenderSurface;
44
45 namespace Internal
46 {
47 namespace Adaptor
48 {
49 class Adaptor;
50 }
51 }
52
53 /**
54  * @brief An Adaptor object is used to initialize and control how Dali runs.
55  *
56  * It provides a lifecycle interface that allows the application
57  * writer to provide their own main loop and other platform related
58  * features.
59  *
60  * The Adaptor class provides a means for initialising the resources required by the Dali::Core.
61  *
62  * When dealing with platform events, the application writer MUST ensure that Dali is called in a
63  * thread-safe manner.
64  *
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).
68  *
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:
71  *
72  * @code
73  * void CreateProgram(DaliAdaptor& adaptor)
74  * {
75  *   // Create Dali components...
76  *   // Can instantiate adaptor here instead, if required
77  * }
78  *
79  * int main ()
80  * {
81  *   // Initialise platform
82  *   MyPlatform.Init();
83  *
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" );
87  *
88  *   // Create an adaptor which uses that window for rendering
89  *   Dali::Adaptor adaptor = Dali::Adaptor::New( window );
90  *   adaptor.Start();
91  *
92  *   CreateProgram(adaptor);
93  *   // Or use this as a callback function depending on the platform initialisation sequence.
94  *
95  *   // Start Main Loop of your platform
96  *   MyPlatform.StartMainLoop();
97  *
98  *   return 0;
99  * }
100  * @endcode
101  *
102  * If required, you can also connect class member functions to a signal:
103  *
104  * @code
105  * MyApplication application;
106  * adaptor.ResizedSignal().Connect(&application, &MyApplication::Resize);
107  * @endcode
108  *
109  * @see RenderSurface
110  */
111 class DALI_ADAPTOR_API Adaptor
112 {
113 public:
114
115   typedef Signal< void (Adaptor&) > AdaptorSignalType; ///< Generic Type for adaptor signals
116
117 public:
118   /**
119    * @brief Create a new adaptor using the window.
120    *
121    * @param[in] window The window to draw onto
122    * @return a reference to the adaptor handle
123    */
124   static Adaptor& New( Window window );
125
126   /**
127    * @brief Create a new adaptor using the window.
128    *
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
132    */
133   static Adaptor& New( Window window, Configuration::ContextLoss configuration );
134
135   /**
136    * @brief Create a new adaptor using render surface.
137    *
138    * @param[in] nativeWindow native window handle
139    * @param[in] surface The surface to draw onto
140    * @return a reference to the adaptor handle
141    */
142   static Adaptor& New( Any nativeWindow, const Dali::RenderSurface& surface );
143
144   /**
145    * @brief Create a new adaptor using render surface.
146    *
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
151    */
152   static Adaptor& New( Any nativeWindow, const Dali::RenderSurface& surface, Configuration::ContextLoss configuration = Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
153
154   /**
155    * @brief Virtual Destructor.
156    */
157   virtual ~Adaptor();
158
159 public:
160
161   /**
162    * @brief Starts the Adaptor.
163    */
164   void Start();
165
166   /**
167    * @brief Pauses the Adaptor.
168    */
169   void Pause();
170
171   /**
172    * @brief Resumes the Adaptor, if previously paused.
173    *
174    * @note If the adaptor is not paused, this does not do anything.
175    */
176   void Resume();
177
178   /**
179    * @brief Stops the Adaptor.
180    */
181   void Stop();
182
183   /**
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.
186    *
187    * Callbacks of the following types may be used:
188    * @code
189    *   void MyFunction();
190    * @endcode
191    * This callback will be deleted once it is called.
192    *
193    * @code
194    *   bool MyFunction();
195    * @endcode
196    * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
197    *
198    * @param[in] callback The function to call.
199    * @param[in] hasReturnValue Sould be set to true if the callback function has a return value.
200    * @return true if added successfully, false otherwise
201    *
202    * @note Ownership of the callback is passed onto this class.
203    */
204   bool AddIdle( CallbackBase* callback, bool hasReturnValue );
205
206   /**
207    * @brief Removes a previously added @p callback.
208    * @note Function must be called from the main event thread only.
209    *
210    * Does nothing if the @p callback doesn't exist.
211    *
212    * @param[in] callback The callback to be removed.
213    */
214   void RemoveIdle( CallbackBase* callback );
215
216   /**
217    * @brief Replaces the rendering surface
218    *
219    * @param[in] nativeWindow native window handle
220    * @param[in] surface to use
221    */
222   void ReplaceSurface( Any nativeWindow, Dali::RenderSurface& surface );
223
224   /**
225    * @brief Get the render surface the adaptor is using to render to.
226    *
227    * @return reference to current render surface
228    */
229   RenderSurface& GetSurface();
230
231   /**
232    * @brief Gets native window handle
233    *
234    * @return Native window handle
235    */
236   Any GetNativeWindowHandle();
237
238   /**
239    * @brief Get the native display associated with the graphics backend
240    *
241    * @return A handle to the native display
242    */
243   Any GetGraphicsDisplay();
244
245   /**
246    * @brief Release any locks the surface may hold.
247    *
248    * For example, after compositing an offscreen surface, use this method to allow
249    * rendering to continue.
250    */
251   void ReleaseSurfaceLock();
252
253   /**
254    * @brief Set the number of frames per render.
255    *
256    * This enables an application to deliberately render with a reduced FPS.
257    * @param[in] numberOfVSyncsPerRender The number of vsyncs between successive renders.
258    * Suggest this is a power of two:
259    * 1 - render each vsync frame
260    * 2 - render every other vsync frame
261    * 4 - render every fourth vsync frame
262    * 8 - render every eighth vsync frame
263    */
264   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
265
266   /**
267    * @brief The callback is called from the Update/Render thread prior to rendering.
268    *
269    * @param[in] callback The function to call
270    *
271    * @note The function is called from the Update thread, so should do as little processing as possible.
272    * It is not possible to call any DALi event side APIs from within the callback; doing so will cause
273    * instability. Only 1 callback is supported. Setting the callback to NULL will remove the current callback.
274    *
275    * A callback of the following type should be used:
276    * @code
277    *   bool MyFunction();
278    * @endcode
279    * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
280    */
281   void SetPreRenderCallback( CallbackBase* callback );
282
283   /**
284    * @brief Set whether the frame count per render is managed using the hardware VSync or
285    * manually timed.
286    *
287    * @param[in] useHardware True if the hardware VSync should be used
288    */
289   void SetUseHardwareVSync(bool useHardware);
290
291   /**
292    * @brief Returns a reference to the instance of the adaptor used by the current thread.
293    *
294    * @return A reference to the adaptor.
295    * @pre The adaptor has been initialised.
296    * @note This is only valid in the main thread.
297    */
298   static Adaptor& Get();
299
300   /**
301    * @brief Checks whether the adaptor is available.
302    *
303    * @return true, if it is available, false otherwise.
304    */
305   static bool IsAvailable();
306
307   /**
308    * @brief Call this method to notify Dali when scene is created and initialized.
309    *
310    * Notify Adaptor that the scene has been created.
311    */
312   void NotifySceneCreated();
313
314   /**
315    * @brief Call this method to notify Dali when the system language changes.
316    *
317    * Use this only when NOT using Dali::Application, As Application created using
318    * Dali::Application will automatically receive notification of language change.
319    * When Dali::Application is not used, the application developer should
320    * use app-core to receive language change notifications and should update Dali
321    * by calling this method.
322    */
323   void NotifyLanguageChanged();
324
325   /**
326    * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
327    * trigger a pinch gesture
328    *
329    * @param[in] distance The minimum pinch distance in pixels
330    */
331   void SetMinimumPinchDistance(float distance);
332
333   /**
334    * @brief Feed a touch point to the adaptor.
335    *
336    * @param[in] point touch point
337    * @param[in] timeStamp time value of event
338    */
339   void FeedTouchPoint( TouchPoint& point, int timeStamp );
340
341   /**
342    * @brief Feed a wheel event to the adaptor.
343    *
344    * @param[in]  wheelEvent wheel event
345    */
346   void FeedWheelEvent( WheelEvent& wheelEvent );
347
348   /**
349    * @brief Feed a key event to the adaptor.
350    *
351    * @param[in] keyEvent The key event holding the key information.
352    */
353   void FeedKeyEvent( KeyEvent& keyEvent );
354
355   /**
356    * @copydoc Dali::Core::SceneCreated();
357    */
358   void SceneCreated();
359
360   /**
361    * @copydoc Dali::Application::SetViewMode();
362    */
363   void SetViewMode( ViewMode viewMode );
364
365   /**
366    * @copydoc Dali::Application::SetStereoBase();
367    */
368   void SetStereoBase( float stereoBase );
369
370   /**
371    * @brief Renders once more even if we're paused
372    * @note Will not work if the window is hidden.
373    */
374   void RenderOnce();
375
376   /**
377    * @brief The log factory allows installation of a logger function in worker threads.
378    * @return An interface to a logging factory
379    */
380   const LogFactoryInterface& GetLogFactory();
381
382 public:  // Signals
383
384   /**
385    * @brief The user should connect to this signal if they need to perform any
386    * special activities when the surface Dali is being rendered on is resized.
387    *
388    * @return The signal to connect to
389    */
390   AdaptorSignalType& ResizedSignal();
391
392   /**
393    * @brief This signal is emitted when the language is changed on the device.
394    *
395    * @return The signal to connect to
396    */
397   AdaptorSignalType& LanguageChangedSignal();
398
399 private:
400
401   // Undefined
402   Adaptor(const Adaptor&);
403   Adaptor& operator=(Adaptor&);
404
405 private:
406
407   /**
408    * @brief Create an uninitialized Adaptor.
409    */
410   Adaptor();
411
412   Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
413   friend class Internal::Adaptor::Adaptor;
414 };
415
416 } // namespace Dali
417
418 #endif // __DALI_INTEGRATION_ADAPTOR_H__