Remove vsync-monitor since is not used anymore and move egl-image-extensions-ubuntu...
[platform/core/uifw/dali-adaptor.git] / dali / public-api / adaptor-framework / application.h
1 #ifndef DALI_APPLICATION_H
2 #define DALI_APPLICATION_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/common/view-mode.h>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/signals/callback.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/adaptor-framework/application-configuration.h>
28 #include <dali/public-api/adaptor-framework/device-status.h>
29 #include <dali/public-api/adaptor-framework/window.h>
30
31 namespace Dali
32 {
33 /**
34  * @addtogroup dali_adaptor_framework
35  * @{
36  */
37
38 namespace Internal DALI_INTERNAL
39 {
40 namespace Adaptor
41 {
42 class Application;
43 }
44 }
45 /**
46  * @brief An Application class object should be created by every application
47  * that wishes to use Dali.
48  *
49  * It provides a means for initializing the
50  * resources required by the Dali::Core.
51  *
52  * The Application class emits several signals which the user can
53  * connect to.  The user should not create any Dali objects in the main
54  * function and instead should connect to the Init signal of the
55  * Application and create the Dali objects in the connected callback.
56  *
57  * Applications should follow the example below:
58  *
59  * @code
60  * class ExampleController: public ConnectionTracker
61  * {
62  * public:
63  *   ExampleController( Application& application )
64  *   : mApplication( application )
65  *   {
66  *     mApplication.InitSignal().Connect( this, &ExampleController::Create );
67  *   }
68  *
69  *   void Create( Application& application )
70  *   {
71  *     // Create Dali components...
72  *   }
73  *  ...
74  * private:
75  *   Application& mApplication;
76  * };
77  *
78  * int main (int argc, char **argv)
79  * {
80  *   Application app = Application::New(&argc, &argv);
81  *   ExampleController example( app );
82  *   app.MainLoop();
83  * }
84  * @endcode
85  *
86  * If required, you can also connect class member functions to a signal:
87  *
88  * @code
89  * MyApplication app;
90  * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
91  * @endcode
92  *
93  * This class accepts command line arguments as well. The following options are supported:
94  *
95  * @code
96  *  -w|--width          Stage Width
97  *  -h|--height         Stage Height
98  *  -d|--dpi            Emulated DPI
99  *     --help           Help
100  * @endcode
101  *
102  * When the above options are found, they are stripped from argv, and argc is updated appropriately.
103  * @SINCE_1_0.0
104  */
105 class DALI_ADAPTOR_API Application : public BaseHandle
106 {
107 public:
108
109   typedef Signal< void (DeviceStatus::Battery::Status) > LowBatterySignalType; ///< Application device signal type @SINCE_1_2.62
110   typedef Signal< void (DeviceStatus::Memory::Status) > LowMemorySignalType;   ///< Application device signal type @SINCE_1_2.62
111   typedef Signal< void (Application&) > AppSignalType;  ///< Application lifecycle signal and system signal callback type @SINCE_1_0.0
112   typedef Signal< void (Application&, void *) > AppControlSignalType; ///< Application control signal callback type @SINCE_1_0.0
113
114   /**
115    * @brief Enumeration for deciding whether a Dali application window is opaque or transparent.
116    * @SINCE_1_0.0
117    */
118   enum WINDOW_MODE
119   {
120     OPAQUE = 0,       ///< The window will be opaque @SINCE_1_0.0
121     TRANSPARENT = 1   ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor() @SINCE_1_0.0
122   };
123
124 public:
125
126   /**
127    * @brief This is the constructor for applications without an argument list.
128    * @SINCE_1_0.0
129    * @PRIVLEVEL_PUBLIC
130    * @PRIVILEGE_DISPLAY
131    * @return A handle to the Application
132    */
133   static Application New();
134
135   /**
136    * @brief This is the constructor for applications.
137    *
138    * @SINCE_1_0.0
139    * @PRIVLEVEL_PUBLIC
140    * @PRIVILEGE_DISPLAY
141    * @param[in,out]  argc        A pointer to the number of arguments
142    * @param[in,out]  argv        A pointer to the argument list
143    * @return A handle to the Application
144    */
145   static Application New( int* argc, char **argv[] );
146
147   /**
148    * @brief This is the constructor for applications with a name.
149    *
150    * @SINCE_1_0.0
151    * @PRIVLEVEL_PUBLIC
152    * @PRIVILEGE_DISPLAY
153    * @param[in,out]  argc        A pointer to the number of arguments
154    * @param[in,out]  argv        A pointer to the argument list
155    * @param[in]      stylesheet  The path to user defined theme file
156    * @return A handle to the Application
157    * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
158    */
159   static Application New( int* argc, char **argv[], const std::string& stylesheet );
160
161   /**
162    * @brief This is the constructor for applications with a name.
163    *
164    * @SINCE_1_0.0
165    * @PRIVLEVEL_PUBLIC
166    * @PRIVILEGE_DISPLAY
167    * @param[in,out]  argc        A pointer to the number of arguments
168    * @param[in,out]  argv        A pointer to the argument list
169    * @param[in]      stylesheet  The path to user defined theme file
170    * @param[in]      windowMode  A member of WINDOW_MODE
171    * @return A handle to the Application
172    * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
173    */
174   static Application New( int* argc, char **argv[], const std::string& stylesheet, WINDOW_MODE windowMode );
175
176   /**
177    * @brief This is the constructor for applications.
178    *
179    * @SINCE_1_2.60
180    * @PRIVLEVEL_PUBLIC
181    * @PRIVILEGE_DISPLAY
182    * @param[in,out]  argc         A pointer to the number of arguments
183    * @param[in,out]  argv         A pointer to the argument list
184    * @param[in]      stylesheet   The path to user defined theme file
185    * @param[in]      windowMode   A member of WINDOW_MODE
186    * @param[in]      positionSize A position and a size of the window
187    * @return A handle to the Application
188    * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
189    */
190   static Application New( int* argc, char **argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize );
191
192   /**
193    * @brief Constructs an empty handle.
194    * @SINCE_1_0.0
195    */
196   Application();
197
198   /**
199    * @brief Copy Constructor.
200    * @SINCE_1_0.0
201    * @param[in] application Handle to an object
202    */
203   Application( const Application& application );
204
205   /**
206    * @brief Assignment operator.
207    * @SINCE_1_0.0
208    * @param[in] application Handle to an object
209    * @return A reference to this
210    */
211   Application& operator=( const Application& application );
212
213   /**
214    * @brief Destructor.
215    *
216    * This is non-virtual since derived Handle types must not contain data or virtual methods.
217    * @SINCE_1_0.0
218    */
219   ~Application();
220
221 public:
222   /**
223    * @brief This starts the application.
224    *
225    * Choosing this form of main loop indicates that the default
226    * application configuration of APPLICATION_HANDLES_CONTEXT_LOSS is used. On platforms where
227    * context loss can occur, the application is responsible for tearing down and re-loading UI.
228    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
229    * @SINCE_1_0.0
230    */
231   void MainLoop();
232
233   /**
234    * @brief This starts the application, and allows the app to choose a different configuration.
235    *
236    * If the application plans on using the ReplaceSurface or ReplaceWindow API, then this will
237    * trigger context loss & regain.
238    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
239    * @SINCE_1_0.0
240    * @param[in] configuration The context loss configuration
241    */
242   void MainLoop(Configuration::ContextLoss configuration);
243
244   /**
245    * @brief This lowers the application to bottom without actually quitting it.
246    * @SINCE_1_0.0
247    */
248   void Lower();
249
250   /**
251    * @brief This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
252    * @SINCE_1_0.0
253    */
254   void Quit();
255
256   /**
257    * @brief Ensures that the function passed in is called from the main loop when it is idle.
258    * @SINCE_1_0.0
259    * @param[in] callback The function to call
260    * @return @c true if added successfully, @c false otherwise
261    *
262    * @note Function must be called from main event thread only
263    *
264    * A callback of the following type may be used:
265    * @code
266    *   void MyFunction();
267    * @endcode
268    * This callback will be deleted once it is called.
269    *
270    * @note Ownership of the callback is passed onto this class.
271    */
272   bool AddIdle( CallbackBase* callback );
273
274   /**
275    * @brief Retrieves the main window used by the Application class.
276    *
277    * The application writer can use the window to change indicator and orientation
278    * properties.
279    * @SINCE_1_0.0
280    * @return A handle to the window
281    */
282   Window GetWindow();
283
284   /**
285    * @DEPRECATED_1_4.12
286    * @brief Replaces the current window.
287    *
288    * This will force context loss.
289    * If you plan on using this API in your application, then you should configure
290    * it to prevent discard behavior when handling the Init signal.
291    * @SINCE_1_0.0
292    * @param[in] windowPosition The position and size parameters of the new window
293    * @param[in] name The name of the new window
294    */
295   void ReplaceWindow(PositionSize windowPosition, const std::string& name)  DALI_DEPRECATED_API;
296
297   /**
298    * @brief Get path application resources are stored at
299    *
300    * @SINCE_1_2.2
301    * @return the full path of the resources
302    */
303   static std::string GetResourcePath();
304
305   /**
306    * @brief This is used to get region information from device.
307    *
308    * @SINCE_1_2.62
309    * @return Region information
310    */
311   std::string GetRegion() const;
312
313   /**
314    * @brief This is used to get language information from device.
315    *
316    * @SINCE_1_2.62
317    * @return Language information
318    */
319   std::string GetLanguage() const;
320
321 public: // Stereoscopy
322
323   /**
324    * @DEPRECATED_1_3_51
325    * @brief Sets the viewing mode for the application.
326    * @SINCE_1_0.0
327    * @param[in] viewMode The new viewing mode
328    */
329   void SetViewMode( ViewMode viewMode );
330
331   /**
332    * @DEPRECATED_1_3_51
333    * @brief Gets the current viewing mode.
334    * @SINCE_1_0.0
335    * @return The current viewing mode
336    */
337   ViewMode GetViewMode() const;
338
339   /**
340    * @DEPRECATED_1_3_51
341    * @brief Sets the stereo base (eye separation) for Stereoscopic 3D.
342    *
343    * The stereo base is the distance in millimetres between the eyes. Typical values are
344    * between 50mm and 70mm. The default value is 65mm.
345    * @SINCE_1_0.0
346    * @param[in] stereoBase The stereo base (eye separation) for Stereoscopic 3D
347    */
348   void SetStereoBase( float stereoBase );
349
350   /**
351    * @DEPRECATED_1_3_51
352    * @brief Gets the stereo base (eye separation) for Stereoscopic 3D.
353    *
354    * @SINCE_1_0.0
355    * @return The stereo base (eye separation) for Stereoscopic 3D
356    */
357   float GetStereoBase() const;
358
359 public:  // Signals
360
361   /**
362    * @brief The user should connect to this signal to determine when they should initialize
363    * their application.
364    * @SINCE_1_0.0
365    * @return The signal to connect to
366    */
367   AppSignalType& InitSignal();
368
369   /**
370    * @brief The user should connect to this signal to determine when they should terminate
371    * their application.
372    * @SINCE_1_0.0
373    * @return The signal to connect to
374    */
375   AppSignalType& TerminateSignal();
376
377   /**
378    * @brief The user should connect to this signal if they need to perform any special
379    * activities when the application is about to be paused.
380    * @SINCE_1_0.0
381    * @return The signal to connect to
382    */
383   AppSignalType& PauseSignal();
384
385   /**
386    * @brief The user should connect to this signal if they need to perform any special
387    * activities when the application has resumed.
388    * @SINCE_1_0.0
389    * @return The signal to connect to
390    */
391   AppSignalType& ResumeSignal();
392
393   /**
394    * @brief This signal is sent when the system requires the user to reinitialize itself.
395    * @SINCE_1_0.0
396    * @return The signal to connect to
397    */
398   AppSignalType& ResetSignal();
399
400   /**
401    * @DEPRECATED_1_2.62 Use Window::ResizedSignal() instead.
402    * @brief This signal is emitted when the window application rendering on is resized.
403    * @SINCE_1_0.0
404    * @return The signal to connect to
405    */
406   AppSignalType& ResizeSignal() DALI_DEPRECATED_API;
407
408   /**
409   * @brief This signal is emitted when another application sends a launch request to the application.
410   *
411   * When the application is launched, this signal is emitted after the main loop of the application starts up.
412   * The passed parameter describes the launch request and contains the information about why the application is launched.
413   * @SINCE_1_0.0
414   * @return The signal to connect to
415   */
416   AppControlSignalType& AppControlSignal();
417
418   /**
419    * @brief This signal is emitted when the language is changed on the device.
420    * @SINCE_1_0.0
421    * @return The signal to connect to
422    */
423   AppSignalType& LanguageChangedSignal();
424
425   /**
426   * @brief This signal is emitted when the region of the device is changed.
427   * @SINCE_1_0.0
428   * @return The signal to connect to
429   */
430   AppSignalType& RegionChangedSignal();
431
432   /**
433   * @DEPRECATED_1_2.62 Use LowBatterySignal() instead.
434   * @brief This signal is emitted when the battery level of the device is low.
435   * @SINCE_1_0.0
436   * @return The signal to connect to
437   */
438   AppSignalType& BatteryLowSignal() DALI_DEPRECATED_API;
439
440   /**
441   * @DEPRECATED_1_2.62 Use LowMemorySignal() instead.
442   * @brief This signal is emitted when the memory level of the device is low.
443   * @SINCE_1_0.0
444   * @return The signal to connect to
445   */
446   AppSignalType& MemoryLowSignal() DALI_DEPRECATED_API;
447
448   /**
449    * @brief This signal is emitted when the battery level of the device is low.
450    * @SINCE_1_2.62
451    * @return The signal to connect to
452    */
453   LowBatterySignalType& LowBatterySignal();
454
455   /**
456    * @brief This signal is emitted when the memory level of the device is low.
457    * @SINCE_1_2.62
458    * @return The signal to connect to
459    */
460   LowMemorySignalType& LowMemorySignal();
461
462 public: // Not intended for application developers
463   /// @cond internal
464   /**
465    * @brief Internal constructor.
466    * @SINCE_1_0.0
467    */
468   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
469   /// @endcond
470 };
471
472 /**
473  * @}
474  */
475 } // namespace Dali
476
477 #endif // DALI_APPLICATION_H