Merge "Pixmap render surface synchronization moved to thread-synchronization" into...
[platform/core/uifw/dali-adaptor.git] / adaptors / public-api / adaptor-framework / application.h
1 #ifndef __DALI_APPLICATION_H__
2 #define __DALI_APPLICATION_H__
3
4 /*
5  * Copyright (c) 2015 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 <string>
23 #include <dali/public-api/common/view-mode.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/signals/callback.h>
26
27
28 // INTERNAL INCLUDES
29 #include "application-configuration.h"
30 #include "window.h"
31
32 namespace Dali
33 {
34 /**
35  * @addtogroup dali-adaptor-framework
36  * @{
37  */
38
39 namespace Internal DALI_INTERNAL
40 {
41 namespace Adaptor
42 {
43 class Application;
44 }
45 }
46 /**
47  * An Application class object should be created by every application
48  * that wishes to use Dali.  It provides a means for initialising the
49  * resources required by the Dali::Core.
50  *
51  * The Application class emits several signals which the user can
52  * connect to.  The user should not create any Dali objects in the main
53  * function and instead should connect to the Init signal of the
54  * Application and create the Dali objects in the connected callback.
55  *
56  * Applications should follow the example below:
57  *
58  * @code
59  * void CreateProgram(Application app)
60  * {
61  *   // Create Dali components...
62  *   // Can instantiate here, if required
63  * }
64  *
65  * int main (int argc, char **argv)
66  * {
67  *   Application app = Application::New(&argc, &argv);
68  *   app.InitSignal().Connect(&CreateProgram);
69  *   app.MainLoop();
70  * }
71  * @endcode
72  *
73  * If required, you can also connect class member functions to a signal:
74  *
75  * @code
76  * MyApplication app;
77  * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
78  * @endcode
79  *
80  * This class accepts command line arguments as well. The following options are supported:
81  *
82  * @code
83  *     --no-vsync       Disable VSync on Render
84  *  -w|--width          Stage Width
85  *  -h|--height         Stage Height
86  *  -d|--dpi            Emulated DPI
87  *     --help           Help
88  * @endcode
89  *
90  * When the above options are found, they are stripped from argv, and argc is updated appropriately.
91  */
92 class DALI_IMPORT_API Application : public BaseHandle
93 {
94 public:
95
96   typedef Signal< void (Application&) > AppSignalType;
97   typedef Signal< void (Application&, void *) > AppControlSignalType;
98
99   /**
100    * Decides whether a Dali application window is opaque or transparent.
101    */
102   enum WINDOW_MODE
103   {
104     OPAQUE = 0,       ///< The window will be opaque
105     TRANSPARENT = 1   ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor()
106   };
107
108 public:
109
110   /**
111    * This is the constructor for applications without an argument list.
112    */
113   static Application New();
114
115   /**
116    * This is the constructor for applications.
117    *
118    * @param[in,out]  argc        A pointer to the number of arguments
119    * @param[in,out]  argv        A pointer the the argument list
120    */
121   static Application New( int* argc, char **argv[] );
122
123   /**
124    * This is the constructor for applications with a name
125    *
126    * @param[in,out]  argc        A pointer to the number of arguments
127    * @param[in,out]  argv        A pointer the the argument list
128    * @param[in]      stylesheet  The path to user defined theme file
129    */
130   static Application New( int* argc, char **argv[], const std::string& stylesheet );
131
132   /**
133    * This is the constructor for applications with a name
134    *
135    * @param[in,out]  argc        A pointer to the number of arguments
136    * @param[in,out]  argv        A pointer the the argument list
137    * @param[in]      stylesheet  The path to user defined theme file
138    * @param[in]      windowMode  A member of WINDOW_MODE
139    */
140   static Application New( int* argc, char **argv[], const std::string& stylesheet, WINDOW_MODE windowMode );
141
142   /**
143    * Construct an empty handle
144    */
145   Application();
146
147   /**
148    * Copy Constructor
149    */
150   Application( const Application& application );
151
152   /**
153    * Assignment operator
154    */
155   Application& operator=( const Application& applicaton );
156
157   /**
158    * @brief Destructor
159    *
160    * This is non-virtual since derived Handle types must not contain data or virtual methods.
161    */
162   ~Application();
163
164 public:
165   /**
166    * This starts the application. Choosing this form of main loop indicates that the default
167    * application configuration of APPLICATION_HANDLES_CONTEXT_LOSS is used. On platforms where
168    * context loss can occur, the application is responsible for tearing down and re-loading UI.
169    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
170    */
171   void MainLoop();
172
173   /**
174    * This starts the application, and allows the app to choose a different configuration.
175    * If the application plans on using the ReplaceSurface or ReplaceWindow API, then this will
176    * trigger context loss & regain.
177    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
178    */
179   void MainLoop(Configuration::ContextLoss configuration);
180
181   /**
182    * This lowers the application to bottom without actually quitting it
183    */
184   void Lower();
185
186   /**
187    * This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
188    */
189   void Quit();
190
191   /**
192    * Ensures that the function passed in is called from the main loop when it is idle.
193    * @note Function must be called from main event thread only
194    *
195    * A callback of the following type may be used:
196    * @code
197    *   void MyFunction();
198    * @endcode
199    *
200    * @param[in]  callback  The function to call.
201    * @return true if added successfully, false otherwise
202    *
203    * @note Ownership of the callback is passed onto this class.
204    */
205   bool AddIdle( CallbackBase* callback );
206
207   /**
208    * Retrieves the window used by the Application class.
209    * The application writer can use the window to change indicator and orientation
210    * properties.
211    * @return A handle to the window
212    */
213   Window GetWindow();
214
215   /**
216    * Replace the current window.
217    * This will force context loss.
218    * If you plan on using this API in your application, then you should configure
219    * it to prevent discard behaviour when handling the Init signal.
220    * @param[in] windowPosition The position and size parameters of the new window
221    * @param[in] name The name of the new window
222    */
223   void ReplaceWindow(PositionSize windowPosition, const std::string& name);
224
225 public: // Stereoscopy
226
227   /**
228    * Set the viewing mode for the application.
229    * @param[in] viewMode The new viewing mode.
230    */
231   void SetViewMode( ViewMode viewMode );
232
233   /**
234    * Get the current viewing mode.
235    * @return The current viewing mode.
236    */
237   ViewMode GetViewMode() const;
238
239   /**
240    * Set the stereo base (eye separation) for Stereoscopic 3D
241    *
242    * @param[in] stereoBase The stereo base (eye separation) for Stereoscopic 3D
243    */
244   void SetStereoBase( float stereoBase );
245
246   /**
247    * Get the stereo base (eye separation) for Stereoscopic 3D
248    *
249    * @return The stereo base (eye separation) for Stereoscopic 3D
250    */
251   float GetStereoBase() const;
252
253 public:  // Signals
254
255   /**
256    * The user should connect to this signal to determine when they should initialise
257    * their application.
258    */
259   AppSignalType& InitSignal();
260
261   /**
262    * The user should connect to this signal to determine when they should terminate
263    * their application
264    */
265   AppSignalType& TerminateSignal();
266
267   /**
268    * The user should connect to this signal if they need to perform any special
269    * activities when the application is about to be paused.
270    */
271   AppSignalType& PauseSignal();
272
273   /**
274    * The user should connect to this signal if they need to perform any special
275    * activities when the application has resumed.
276    */
277   AppSignalType& ResumeSignal();
278
279   /**
280    * This signal is sent when the system requires the user to reinitialise itself.
281    */
282   AppSignalType& ResetSignal();
283
284   /**
285    * This signal is emitted when the window the application is rendering on is resized.
286    */
287   AppSignalType& ResizeSignal();
288
289   /**
290   * This signal is emitted when another application sends a launch request to the application.
291   * When the application is launched, this signal is emitted after the main loop of the application starts up.
292   * The passed parameter describes the launch request and contains the information about why the application is launched.
293   */
294   AppControlSignalType& AppControlSignal();
295
296   /**
297    * This signal is emitted when the language is changed on the device.
298    */
299   AppSignalType& LanguageChangedSignal();
300
301   /**
302   * This signal is emitted when the region of the device is changed.
303   */
304   AppSignalType& RegionChangedSignal();
305
306   /**
307   * This signal is emitted when the battery level of the device is low.
308   */
309   AppSignalType& BatteryLowSignal();
310
311   /**
312   * This signal is emitted when the memory level of the device is low.
313   */
314   AppSignalType& MemoryLowSignal();
315
316 public: // Not intended for application developers
317   /**
318    * Internal constructor
319    */
320   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
321 };
322
323 /**
324  * @}
325  */
326 } // namespace Dali
327
328 #endif // __DALI_APPLICATION_H__