Revert "[Tizen]Revert "Basic support of keyboard focus for multiple windows""
[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) 2019 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 #include <dali/public-api/object/any.h>
28 #include <dali/integration-api/processor-interface.h>
29
30 // INTERNAL INCLUDES
31 #include <dali/public-api/adaptor-framework/window.h>
32 #include <dali/public-api/adaptor-framework/application-configuration.h>
33 #include <dali/public-api/dali-adaptor-common.h>
34
35 #ifdef DALI_ADAPTOR_COMPILATION
36 #include <dali/integration-api/log-factory-interface.h>
37 #else
38 #include <dali/integration-api/adaptors/log-factory-interface.h>
39 #endif
40
41
42 namespace Dali
43 {
44
45 class RenderSurfaceInterface;
46
47 using WindowContainer = std::vector<Window>;
48
49 namespace Integration
50 {
51 class SceneHolder;
52 }
53
54
55 namespace Internal
56 {
57 namespace Adaptor
58 {
59 class GraphicsFactory;
60 class Adaptor;
61 }
62 }
63
64 /**
65  * @brief An Adaptor object is used to initialize and control how Dali runs.
66  *
67  * It provides a lifecycle interface that allows the application
68  * writer to provide their own main loop and other platform related
69  * features.
70  *
71  * The Adaptor class provides a means for initialising the resources required by the Dali::Core.
72  *
73  * When dealing with platform events, the application writer MUST ensure that Dali is called in a
74  * thread-safe manner.
75  *
76  * As soon as the Adaptor class is created and started, the application writer can initialise their
77  * Dali::Actor objects straight away or as required by the main loop they intend to use (there is no
78  * need to wait for an initialise signal as per the Dali::Application class).
79  *
80  * The Adaptor does emit a Resize signal which informs the user when the surface is resized.
81  * Tizen and Linux Adaptors should follow the example below:
82  *
83  * @code
84  * void CreateProgram(DaliAdaptor& adaptor)
85  * {
86  *   // Create Dali components...
87  *   // Can instantiate adaptor here instead, if required
88  * }
89  *
90  * int main ()
91  * {
92  *   // Initialise platform
93  *   MyPlatform.Init();
94  *
95  *   // Create an 800 by 1280 window positioned at (0,0).
96  *   Dali::PositionSize positionSize(0, 0, 800, 1280);
97  *   Dali::Window window = Dali::Window::New( positionSize, "My Application" );
98  *
99  *   // Create an adaptor which uses that window for rendering
100  *   Dali::Adaptor adaptor = Dali::Adaptor::New( window );
101  *   adaptor.Start();
102  *
103  *   CreateProgram(adaptor);
104  *   // Or use this as a callback function depending on the platform initialisation sequence.
105  *
106  *   // Start Main Loop of your platform
107  *   MyPlatform.StartMainLoop();
108  *
109  *   return 0;
110  * }
111  * @endcode
112  *
113  * If required, you can also connect class member functions to a signal:
114  *
115  * @code
116  * MyApplication application;
117  * adaptor.ResizedSignal().Connect(&application, &MyApplication::Resize);
118  * @endcode
119  *
120  * @see RenderSurface
121  */
122 class DALI_ADAPTOR_API Adaptor
123 {
124 public:
125
126   typedef Signal< void (Adaptor&) > AdaptorSignalType; ///< Generic Type for adaptor signals
127   typedef Signal< void (Window&) > WindowCreatedSignalType;  ///< Window created signal type
128
129 public:
130   /**
131    * @brief Create a new adaptor using the window.
132    *
133    * @param[in] window The window to draw onto
134    * @return a reference to the adaptor handle
135    */
136   static Adaptor& New( Window window );
137
138   /**
139    * @brief Create a new adaptor using the window.
140    *
141    * @param[in] window The window to draw onto
142    * @param[in] configuration The context loss configuration.
143    * @return a reference to the adaptor handle
144    */
145   static Adaptor& New( Window window, Configuration::ContextLoss configuration );
146
147   /**
148    * @brief Create a new adaptor using render surface.
149    *
150    * @param[in] window The window to draw onto
151    * @param[in] surface The surface to draw onto
152    * @return a reference to the adaptor handle
153    */
154   static Adaptor& New( Window window, const Dali::RenderSurfaceInterface& surface );
155
156   /**
157    * @brief Create a new adaptor using render surface.
158    *
159    * @param[in] window The window to draw onto
160    * @param[in] surface The surface to draw onto
161    * @param[in] configuration The context loss configuration.
162    * @return a reference to the adaptor handle
163    */
164   static Adaptor& New( Window window, const Dali::RenderSurfaceInterface& surface, Configuration::ContextLoss configuration = Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
165
166   /**
167    * @brief Create a new adaptor using the SceneHolder.
168    *
169    * @param[in] sceneHolder The SceneHolder to draw onto
170    * @return a reference to the adaptor handle
171    */
172   static Adaptor& New( Dali::Integration::SceneHolder sceneHolder );
173
174   /**
175    * @brief Create a new adaptor using the SceneHolder.
176    *
177    * @param[in] sceneHolder The SceneHolder to draw onto
178    * @param[in] configuration The context loss configuration.
179    * @return a reference to the adaptor handle
180    */
181   static Adaptor& New( Dali::Integration::SceneHolder sceneHolder, Configuration::ContextLoss configuration );
182
183   /**
184    * @brief Create a new adaptor using render surface.
185    *
186    * @param[in] sceneHolder The SceneHolder to draw onto
187    * @param[in] surface The surface to draw onto
188    * @return a reference to the adaptor handle
189    */
190   static Adaptor& New( Dali::Integration::SceneHolder sceneHolder, const Dali::RenderSurfaceInterface& surface );
191
192   /**
193    * @brief Create a new adaptor using render surface.
194    *
195    * @param[in] sceneHolder The SceneHolder to draw onto
196    * @param[in] surface The surface to draw onto
197    * @param[in] configuration The context loss configuration.
198    * @return a reference to the adaptor handle
199    */
200   static Adaptor& New( Dali::Integration::SceneHolder sceneHolder, const Dali::RenderSurfaceInterface& surface, Configuration::ContextLoss configuration = Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
201
202   /**
203    * @brief Virtual Destructor.
204    */
205   virtual ~Adaptor();
206
207 public:
208
209   /**
210    * @brief Starts the Adaptor.
211    */
212   void Start();
213
214   /**
215    * @brief Pauses the Adaptor.
216    */
217   void Pause();
218
219   /**
220    * @brief Resumes the Adaptor, if previously paused.
221    *
222    * @note If the adaptor is not paused, this does not do anything.
223    */
224   void Resume();
225
226   /**
227    * @brief Stops the Adaptor.
228    */
229   void Stop();
230
231   /**
232    * @brief Ensures that the function passed in is called from the main loop when it is idle.
233    * @note Function must be called from the main event thread only.
234    *
235    * Callbacks of the following types may be used:
236    * @code
237    *   void MyFunction();
238    * @endcode
239    * This callback will be deleted once it is called.
240    *
241    * @code
242    *   bool MyFunction();
243    * @endcode
244    * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
245    *
246    * @param[in] callback The function to call.
247    * @param[in] hasReturnValue Sould be set to true if the callback function has a return value.
248    * @return true if added successfully, false otherwise
249    *
250    * @note Ownership of the callback is passed onto this class.
251    */
252   bool AddIdle( CallbackBase* callback, bool hasReturnValue );
253
254   /**
255    * @brief Removes a previously added @p callback.
256    * @note Function must be called from the main event thread only.
257    *
258    * Does nothing if the @p callback doesn't exist.
259    *
260    * @param[in] callback The callback to be removed.
261    */
262   void RemoveIdle( CallbackBase* callback );
263
264   /**
265    * @brief Replaces the rendering surface
266    *
267    * @param[in] window The window to replace the surface for
268    * @param[in] surface to use
269    */
270   void ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface );
271
272   /**
273    * @brief Replaces the rendering surface
274    *
275    * @param[in] sceneHolder The SceneHolder to replace the surface for
276    * @param[in] surface to use
277    */
278   void ReplaceSurface( Dali::Integration::SceneHolder sceneHolder, Dali::RenderSurfaceInterface& surface );
279
280   /**
281    * @brief Get the render surface the adaptor is using to render to.
282    *
283    * @return reference to current render surface
284    */
285   Dali::RenderSurfaceInterface& GetSurface();
286
287   /**
288    * @brief Gets native window handle
289    *
290    * @return Native window handle
291    */
292   Any GetNativeWindowHandle();
293
294   /**
295    * @brief Get the native display associated with the graphics backend
296    *
297    * @return A handle to the native display
298    */
299   Any GetGraphicsDisplay();
300
301   /**
302    * @brief Release any locks the surface may hold.
303    *
304    * For example, after compositing an offscreen surface, use this method to allow
305    * rendering to continue.
306    */
307   void ReleaseSurfaceLock();
308
309   /**
310    * @brief Set the number of frames per render.
311    *
312    * This enables an application to deliberately render with a reduced FPS.
313    * @param[in] numberOfVSyncsPerRender The number of vsyncs between successive renders.
314    * Suggest this is a power of two:
315    * 1 - render each vsync frame
316    * 2 - render every other vsync frame
317    * 4 - render every fourth vsync frame
318    * 8 - render every eighth vsync frame
319    */
320   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
321
322   /**
323    * @brief The callback is called from the Update/Render thread prior to rendering.
324    *
325    * @param[in] callback The function to call
326    *
327    * @note The function is called from the Update thread, so should do as little processing as possible.
328    * It is not possible to call any DALi event side APIs from within the callback; doing so will cause
329    * instability. Only 1 callback is supported. Setting the callback to NULL will remove the current callback.
330    *
331    * A callback of the following type should be used:
332    * @code
333    *   bool MyFunction();
334    * @endcode
335    * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
336    */
337   void SetPreRenderCallback( CallbackBase* callback );
338
339   /**
340    * @brief Set whether the frame count per render is managed using the hardware VSync or
341    * manually timed.
342    *
343    * @param[in] useHardware True if the hardware VSync should be used
344    */
345   void SetUseHardwareVSync(bool useHardware);
346
347   /**
348    * @brief Returns a reference to the instance of the adaptor used by the current thread.
349    *
350    * @return A reference to the adaptor.
351    * @pre The adaptor has been initialised.
352    * @note This is only valid in the main thread.
353    */
354   static Adaptor& Get();
355
356   /**
357    * @brief Checks whether the adaptor is available.
358    *
359    * @return true, if it is available, false otherwise.
360    */
361   static bool IsAvailable();
362
363   /**
364    * @brief Call this method to notify Dali when scene is created and initialized.
365    *
366    * Notify Adaptor that the scene has been created.
367    */
368   void NotifySceneCreated();
369
370   /**
371    * @brief Call this method to notify Dali when the system language changes.
372    *
373    * Use this only when NOT using Dali::Application, As Application created using
374    * Dali::Application will automatically receive notification of language change.
375    * When Dali::Application is not used, the application developer should
376    * use app-core to receive language change notifications and should update Dali
377    * by calling this method.
378    */
379   void NotifyLanguageChanged();
380
381   /**
382    * @brief Feed a touch point to the adaptor.
383    *
384    * @param[in] point touch point
385    * @param[in] timeStamp time value of event
386    */
387   void FeedTouchPoint( TouchPoint& point, int timeStamp );
388
389   /**
390    * @brief Feed a wheel event to the adaptor.
391    *
392    * @param[in]  wheelEvent wheel event
393    */
394   void FeedWheelEvent( WheelEvent& wheelEvent );
395
396   /**
397    * @brief Feed a key event to the adaptor.
398    *
399    * @param[in] keyEvent The key event holding the key information.
400    */
401   void FeedKeyEvent( KeyEvent& keyEvent );
402
403   /**
404    * @copydoc Dali::Core::SceneCreated();
405    */
406   void SceneCreated();
407
408   /**
409    * @brief Renders once more even if we're paused
410    * @note Will not work if the window is hidden.
411    */
412   void RenderOnce();
413
414   /**
415    * @brief The log factory allows installation of a logger function in worker threads.
416    * @return An interface to a logging factory
417    */
418   const LogFactoryInterface& GetLogFactory();
419
420   /**
421    * @brief Register a processor implementing the Integration::Processor interface with dali-core.
422    * @param[in] processor the Processor to register
423    * @note using this api does not maintain the processor's lifecycle, must be done elsewhere.
424    */
425   void RegisterProcessor( Integration::Processor& processor );
426
427   /**
428    * @brief Unregister a previously registered processor from dali-core.
429    * @param[in] processor the Processor to unregister
430    */
431   void UnregisterProcessor( Integration::Processor& processor );
432
433   /**
434    * @brief Get the list of windows created.
435    * @return The list of windows
436    */
437   Dali::WindowContainer GetWindows() const;
438
439 public:  // Signals
440
441   /**
442    * @brief The user should connect to this signal if they need to perform any
443    * special activities when the surface Dali is being rendered on is resized.
444    *
445    * @return The signal to connect to
446    */
447   AdaptorSignalType& ResizedSignal();
448
449   /**
450    * @brief This signal is emitted when the language is changed on the device.
451    *
452    * @return The signal to connect to
453    */
454   AdaptorSignalType& LanguageChangedSignal();
455
456   /**
457    * @brief This signal is emitted when a new window is created
458    *
459    * @return The signal to connect to
460    */
461   WindowCreatedSignalType& WindowCreatedSignal();
462
463 private:
464
465   // Undefined
466   Adaptor(const Adaptor&);
467   Adaptor& operator=(Adaptor&);
468
469 private:
470
471   /**
472    * @brief Create an uninitialized Adaptor.
473    */
474   Adaptor();
475
476   Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
477   friend class Internal::Adaptor::Adaptor;
478 };
479
480 } // namespace Dali
481
482 #endif // DALI_INTEGRATION_ADAPTOR_H