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