Merge "Fix svace issue - Application Destructor & egl controller debug" into devel...
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / application-impl.h
1 #ifndef DALI_INTERNAL_APPLICATION_H
2 #define DALI_INTERNAL_APPLICATION_H
3
4 /*
5  * Copyright (c) 2022 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/math/rect.h>
23 #include <dali/public-api/object/base-object.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/devel-api/common/singleton-service.h>
27 #include <dali/public-api/adaptor-framework/application.h>
28
29 #include <dali/internal/adaptor/common/adaptor-builder-impl.h>
30 #include <dali/internal/adaptor/common/framework.h>
31 #include <dali/internal/system/common/environment-options.h>
32
33 namespace Dali
34 {
35 class Adaptor;
36 class Window;
37
38 namespace Internal
39 {
40 namespace Adaptor
41 {
42 namespace Launchpad
43 {
44 /**
45  * @brief Launchpad is used to improve application launch performance.
46  * When an application is pre-initialized, so files are preloaded, some functions are initialized and a window is made in advance.
47  */
48 enum State
49 {
50   NONE,           ///< The default state
51   PRE_INITIALIZED ///< Application is pre-initialized.
52 };
53
54 } // namespace Launchpad
55
56 class CommandLineOptions;
57 class EventLoop;
58
59 typedef Dali::Rect<int> PositionSize;
60
61 class Application;
62 typedef IntrusivePtr<Application> ApplicationPtr;
63
64 /**
65  * Implementation of the Application class.
66  */
67 class Application : public BaseObject, public Framework::Observer, public Framework::TaskObserver
68 {
69 public:
70   typedef Dali::Application::LowBatterySignalType               LowBatterySignalType;
71   typedef Dali::Application::LowMemorySignalType                LowMemorySignalType;
72   typedef Dali::Application::DeviceOrientationChangedSignalType DeviceOrientationChangedSignalType;
73   typedef Dali::Application::AppSignalType                      AppSignalType;
74   typedef Dali::Application::AppControlSignalType               AppControlSignalType;
75   typedef Dali::Application::WINDOW_MODE                        WINDOW_MODE;
76
77   /**
78    * Create a new application
79    * @param[in]  argc              A pointer to the number of arguments
80    * @param[in]  argv              A pointer to the argument list
81    * @param[in]  stylesheet        The path to user defined theme file
82    * @param[in]  windowMode        A member of Dali::Application::WINDOW_MODE
83    * @param[in]  positionSize      A position and a size of the window
84    * @param[in]  applicationType   A member of Dali::Framework::Type
85    * @param[in]  type              It is window type for default window.
86    * @param[in]  useUiThread       True if the application would create a UI thread
87    */
88   static ApplicationPtr New(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType, WindowType type, bool useUiThread);
89
90   /**
91    * @copydoc Dali::DevelApplication::PreInitialize()
92    */
93   static void PreInitialize(int* argc, char** argv[]);
94
95 public:
96   /**
97    * @copydoc Dali::Application::MainLoop()
98    */
99   void MainLoop();
100
101   /**
102    * @copydoc Dali::Application::Lower()
103    */
104   void Lower();
105
106   /**
107    * @copydoc Dali::Application::Quit()
108    */
109   void Quit();
110
111   /**
112    * @copydoc Dali::Application::AddIdle()
113    */
114   bool AddIdle(CallbackBase* callback, bool hasReturnValue);
115
116   /**
117    * @copydoc Dali::Application::GetAdaptor();
118    */
119   Dali::Adaptor& GetAdaptor();
120
121   /**
122    * @copydoc Dali::Application::GetWindow();
123    */
124   Dali::Window GetWindow();
125
126   /**
127    * @copydoc Dali::Application::GetRegion();
128    */
129   std::string GetRegion() const;
130
131   /**
132    * @copydoc Dali::Application::GetLanguage();
133    */
134   std::string GetLanguage() const;
135
136   /**
137    * @copydoc Dali::Application::GetObjectRegistry();
138    */
139   Dali::ObjectRegistry GetObjectRegistry() const;
140
141   /**
142    * @copydoc Dali::Application::GetResourcePath();
143    */
144   static std::string GetResourcePath();
145
146   /**
147    * @copydoc Dali::DevelApplication::GetDataPath()
148    */
149   static std::string GetDataPath();
150
151   /**
152    * Retrieves the pre-initialized application.
153    *
154    * @return A pointer to the pre-initialized application
155    */
156   static ApplicationPtr GetPreInitializedApplication();
157
158   /**
159    * Stores PositionSize of window
160    */
161   void StoreWindowPositionSize(PositionSize positionSize);
162
163 public: // From Framework::Observer
164   /**
165    * Called when the framework is initialised.
166    */
167   void OnInit() override;
168
169   /**
170    * Called when the framework is terminated.
171    */
172   void OnTerminate() override;
173
174   /**
175    * Called when the framework is paused.
176    */
177   void OnPause() override;
178
179   /**
180    * Called when the framework resumes from a paused state.
181    */
182   void OnResume() override;
183
184   /**
185    * Called when the framework received AppControlSignal.
186    * @param[in] The bundle data of AppControl event.
187    */
188   void OnAppControl(void* data) override;
189
190   /**
191    * Called when the framework informs the application that it should reset itself.
192    */
193   void OnReset() override;
194
195   /**
196    * Called when the framework informs the application that the language of the device has changed.
197    */
198   void OnLanguageChanged() override;
199
200   /**
201    * Called when the framework informs the application that the region of the device has changed.
202    */
203   void OnRegionChanged() override;
204
205   /**
206    * Called when the framework informs the application that the battery level of the device is low.
207    */
208   void OnBatteryLow(Dali::DeviceStatus::Battery::Status status) override;
209
210   /**
211    * Called when the framework informs the application that the memory level of the device is low.
212    */
213   void OnMemoryLow(Dali::DeviceStatus::Memory::Status status) override;
214
215   /**
216    * Called when the framework informs the application that device orientation is changed.
217    */
218   void OnDeviceOrientationChanged(Dali::DeviceStatus::Orientation::Status status) override;
219
220   /**
221    * Called when the framework informs the application that the platform surface is created.
222    */
223   void OnSurfaceCreated(Any newSurface) override;
224
225   /**
226    * Called when the framework informs the application that the platform surface is destroyed.
227    */
228   void OnSurfaceDestroyed(Any newSurface) override;
229
230 public: // From Framework::TaskObserver
231   /**
232    * Called when the framework is initialised.
233    */
234   void OnTaskInit() override;
235
236   /**
237    * Called when the framework is terminated.
238    */
239   void OnTaskTerminate() override;
240
241   /**
242    * Called when the framework received AppControlSignal.
243    * @param[in] The bundle data of AppControl event.
244    */
245   void OnTaskAppControl(void* data) override;
246
247   /**
248    * Called when the framework informs the application that the language of the device has changed.
249    */
250   void OnTaskLanguageChanged() override;
251
252   /**
253    * Called when the framework informs the application that the region of the device has changed.
254    */
255   void OnTaskRegionChanged() override;
256
257   /**
258    * Called when the framework informs the application that the battery level of the device is low.
259    */
260   void OnTaskBatteryLow(Dali::DeviceStatus::Battery::Status status) override;
261
262   /**
263    * Called when the framework informs the application that the memory level of the device is low.
264    */
265   void OnTaskMemoryLow(Dali::DeviceStatus::Memory::Status status) override;
266
267   /**
268    * Called when the framework informs the application that the device orientation is changed.
269    *
270    * Device orientation changed event is from Application Framework(Sensor Framework), it means it is system event.
271    * If UIThreading is enable, DALI application has the main thread and UI thread.
272    * This event is emitted in main thread, then it is posted to the UI thread in this callback function.
273    */
274   void OnTaskDeviceOrientationChanged(Dali::DeviceStatus::Orientation::Status status) override;
275
276 public:
277   /**
278    * Sets a user defined theme file.
279    * This should be called before initialization.
280    * @param[in] stylesheet The path to user defined theme file
281    */
282   void SetStyleSheet(const std::string& stylesheet);
283
284   /**
285    * Sets a command line options.
286    * This is used in case of the preinitialized application.
287    * @param[in] argc A pointer to the number of arguments
288    * @param[in] argv A pointer to the argument list
289    */
290   void SetCommandLineOptions(int* argc, char** argv[]);
291
292   /**
293    * Sets default window type.
294    * This is used in case of the preinitialized application.
295    * @param[in] type the window type for default window
296    */
297   void SetDefaultWindowType(WindowType type);
298
299 public: // Signals
300   /**
301    * @copydoc Dali::Application::InitSignal()
302    */
303   Dali::Application::AppSignalType& InitSignal()
304   {
305     return mInitSignal;
306   }
307
308   /**
309    * @copydoc Dali::Application::TerminateSignal()
310    */
311   Dali::Application::AppSignalType& TerminateSignal()
312   {
313     return mTerminateSignal;
314   }
315
316   /**
317    * @copydoc Dali::Application::PauseSignal()
318    */
319   Dali::Application::AppSignalType& PauseSignal()
320   {
321     return mPauseSignal;
322   }
323
324   /**
325    * @copydoc Dali::Application::ResumeSignal()
326    */
327   Dali::Application::AppSignalType& ResumeSignal()
328   {
329     return mResumeSignal;
330   }
331
332   /**
333    * @copydoc Dali::Application::ResetSignal()
334    */
335   Dali::Application::AppSignalType& ResetSignal()
336   {
337     return mResetSignal;
338   }
339
340   /**
341    * @copydoc Dali::Application::AppControlSignal()
342    */
343   Dali::Application::AppControlSignalType& AppControlSignal()
344   {
345     return mAppControlSignal;
346   }
347
348   /**
349    * @copydoc Dali::Application::LanguageChangedSignal()
350    */
351   Dali::Application::AppSignalType& LanguageChangedSignal()
352   {
353     return mLanguageChangedSignal;
354   }
355
356   /**
357    * @copydoc Dali::Application::RegionChangedSignal()
358    */
359   Dali::Application::AppSignalType& RegionChangedSignal()
360   {
361     return mRegionChangedSignal;
362   }
363
364   /**
365    * @copydoc Dali::Application::LowBatterySignal()
366    */
367   Dali::Application::LowBatterySignalType& LowBatterySignal()
368   {
369     return mLowBatterySignal;
370   }
371
372   /**
373    * @copydoc Dali::Application:::LowMemorySignal()
374    */
375   Dali::Application::LowMemorySignalType& LowMemorySignal()
376   {
377     return mLowMemorySignal;
378   }
379
380   /**
381    * @copydoc Dali::Application:::DeviceOrientationChangedSignalType()
382    */
383   Dali::Application::DeviceOrientationChangedSignalType& DeviceOrientationChangedSignal()
384   {
385     return mDeviceOrientationChangedSignal;
386   }
387
388   /**
389    * @copydoc Dali::Application::TaskInitSignal()
390    */
391   Dali::Application::AppSignalType& TaskInitSignal()
392   {
393     return mTaskInitSignal;
394   }
395
396   /**
397    * @copydoc Dali::Application::TaskTerminateSignal()
398    */
399   Dali::Application::AppSignalType& TaskTerminateSignal()
400   {
401     return mTaskTerminateSignal;
402   }
403
404   /**
405    * @copydoc Dali::Application::TaskAppControlSignal()
406    */
407   Dali::Application::AppControlSignalType& TaskAppControlSignal()
408   {
409     return mTaskAppControlSignal;
410   }
411
412   /**
413    * @copydoc Dali::Application::TaskLanguageChangedSignal()
414    */
415   Dali::Application::AppSignalType& TaskLanguageChangedSignal()
416   {
417     return mTaskLanguageChangedSignal;
418   }
419
420   /**
421    * @copydoc Dali::Application::TaskRegionChangedSignal()
422    */
423   Dali::Application::AppSignalType& TaskRegionChangedSignal()
424   {
425     return mTaskRegionChangedSignal;
426   }
427
428   /**
429    * @copydoc Dali::Application::TaskLowBatterySignal()
430    */
431   Dali::Application::LowBatterySignalType& TaskLowBatterySignal()
432   {
433     return mTaskLowBatterySignal;
434   }
435
436   /**
437    * @copydoc Dali::Application::TaskLowMemorySignal()
438    */
439   Dali::Application::LowMemorySignalType& TaskLowMemorySignal()
440   {
441     return mTaskLowMemorySignal;
442   }
443
444   /**
445    * @copydoc Dali::Application::TaskDeviceOrientationChangedSignal()
446    */
447   Dali::Application::DeviceOrientationChangedSignalType& TaskDeviceOrientationChangedSignal()
448   {
449     return mTaskDeviceOrientationChangedSignal;
450   }
451
452 protected:
453   /**
454    * Private Constructor
455    * @param[in]  argc               A pointer to the number of arguments
456    * @param[in]  argv               A pointer to the argument list
457    * @param[in]  stylesheet         The path to user defined theme file
458    * @param[in]  windowMode         A member of Dali::Application::WINDOW_MODE
459    * @param[in]  positionSize       A position and a size of the window
460    * @param[in]  applicationType    A member of Dali::Framework::Type
461    * @param[in]  type               The default window's type.
462    * @param[in]  useUiThread         True if the application would create UI thread
463    */
464   Application(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType, WindowType type, bool useUiThread);
465
466   /**
467    * Destructor
468    */
469   virtual ~Application() override;
470
471   // Undefined
472   Application(const Application&);
473   Application& operator=(Application&);
474
475   /**
476    * Creates the default window
477    */
478   void CreateWindow();
479
480   /**
481    * Creates the adaptor
482    */
483   void CreateAdaptor();
484
485   /**
486    * Creates the adaptor builder
487    */
488   void CreateAdaptorBuilder();
489
490   /**
491    * Quits from the main loop
492    */
493   void QuitFromMainLoop();
494
495   /**
496    * Changes size of preInitialized window
497    */
498   void ChangePreInitializedWindowSize();
499
500 private:
501   AppSignalType                      mInitSignal;
502   AppSignalType                      mTerminateSignal;
503   AppSignalType                      mPauseSignal;
504   AppSignalType                      mResumeSignal;
505   AppSignalType                      mResetSignal;
506   AppControlSignalType               mAppControlSignal;
507   AppSignalType                      mLanguageChangedSignal;
508   AppSignalType                      mRegionChangedSignal;
509   LowBatterySignalType               mLowBatterySignal;
510   LowMemorySignalType                mLowMemorySignal;
511   DeviceOrientationChangedSignalType mDeviceOrientationChangedSignal;
512
513   AppSignalType                      mTaskInitSignal;
514   AppSignalType                      mTaskTerminateSignal;
515   AppControlSignalType               mTaskAppControlSignal;
516   AppSignalType                      mTaskLanguageChangedSignal;
517   AppSignalType                      mTaskRegionChangedSignal;
518   LowBatterySignalType               mTaskLowBatterySignal;
519   LowMemorySignalType                mTaskLowMemorySignal;
520   DeviceOrientationChangedSignalType mTaskDeviceOrientationChangedSignal;
521
522   EventLoop* mEventLoop;
523   Framework* mFramework;
524
525   CommandLineOptions* mCommandLineOptions;
526
527   Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder; ///< The adaptor builder
528   Dali::Adaptor*                           mAdaptor;
529
530   // The Main Window is that window created by the Application during initial startup
531   // (previously this was the only window)
532   Dali::Window                   mMainWindow;     ///< Main Window instance
533   Dali::Application::WINDOW_MODE mMainWindowMode; ///< Window mode of the main window
534   std::string                    mMainWindowName; ///< Name of the main window as obtained from environment options
535
536   std::string        mStylesheet;
537   EnvironmentOptions mEnvironmentOptions;
538   PositionSize       mWindowPositionSize;
539   Launchpad::State   mLaunchpadState;
540   bool               mUseRemoteSurface;
541   WindowType         mDefaultWindowType; ///< Default window's type. It is used when Application is created.
542   bool               mUseUiThread;
543
544   SlotDelegate<Application> mSlotDelegate;
545
546   static ApplicationPtr gPreInitializedApplication;
547 };
548
549 inline Application& GetImplementation(Dali::Application& application)
550 {
551   DALI_ASSERT_ALWAYS(application && "application handle is empty");
552
553   BaseObject& handle = application.GetBaseObject();
554
555   return static_cast<Internal::Adaptor::Application&>(handle);
556 }
557
558 inline const Application& GetImplementation(const Dali::Application& application)
559 {
560   DALI_ASSERT_ALWAYS(application && "application handle is empty");
561
562   const BaseObject& handle = application.GetBaseObject();
563
564   return static_cast<const Internal::Adaptor::Application&>(handle);
565 }
566
567 } // namespace Adaptor
568
569 } // namespace Internal
570
571 } // namespace Dali
572
573 #endif // DALI_INTERNAL_APPLICATION_H