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