Added an devel-API to check whether video texture is supported
[platform/core/uifw/dali-adaptor.git] / adaptors / common / application-impl.h
1 #ifndef __DALI_INTERNAL_APPLICATION_H__
2 #define __DALI_INTERNAL_APPLICATION_H__
3
4 /*
5  * Copyright (c) 2017 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 <application.h>
27 #include <singleton-service.h>
28
29 #include <framework.h>
30 #include <window-impl.h>
31 #include <base/environment-options.h>
32
33 namespace Dali
34 {
35 class Adaptor;
36 class Window;
37
38 namespace Internal
39 {
40
41 namespace Adaptor
42 {
43
44 namespace Launchpad
45 {
46
47 /**
48  * @brief Launchpad is used to improve application launch performance.
49  * When an application is pre-initialized, so files are preloaded, some functions are initialized and a window is made in advance.
50  */
51 enum State
52 {
53   NONE,              ///< The default state
54   PRE_INITIALIZED    ///< Application is pre-initialized.
55 };
56
57 } // namespace Launchpad
58
59 class CommandLineOptions;
60 class EventLoop;
61
62 typedef Dali::Rect<int> PositionSize;
63
64 class Application;
65 typedef IntrusivePtr<Application> ApplicationPtr;
66
67 /**
68  * Implementation of the Application class.
69  */
70 class Application : public BaseObject, public Framework::Observer
71 {
72 public:
73
74   typedef Dali::Application::AppSignalType AppSignalType;
75   typedef Dali::Application::AppControlSignalType AppControlSignalType;
76   typedef Dali::Application::WINDOW_MODE WINDOW_MODE;
77
78   /**
79    * Create a new application
80    * @param[in]  argc         A pointer to the number of arguments
81    * @param[in]  argv         A pointer to the argument list
82    * @param[in]  stylesheet   The path to user defined theme file
83    * @param[in]  windowMode   A member of Dali::Application::WINDOW_MODE
84    * @param[in]  positionSize A position and a size of the window
85    * @param[in]  applicationType  A member of Dali::Framework::Type
86    */
87   static ApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet,
88     WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
89
90   /**
91    * @copydoc Dali::DevelApplication::PreInitialize()
92    */
93   static void PreInitialize( int* argc, char** argv[] );
94
95 public:
96
97   /**
98    * @copydoc Dali::Application::MainLoop()
99    */
100   void MainLoop(Dali::Configuration::ContextLoss configuration);
101
102   /**
103    * @copydoc Dali::Application::Lower()
104    */
105   void Lower();
106
107   /**
108    * @copydoc Dali::Application::Quit()
109    */
110   void Quit();
111
112   /**
113    * @copydoc Dali::Application::AddIdle()
114    */
115   bool AddIdle( CallbackBase* callback );
116
117   /**
118    * @copydoc Dali::Application::GetAdaptor();
119    */
120   Dali::Adaptor& GetAdaptor();
121
122   /**
123    * @copydoc Dali::Application::GetWindow();
124    */
125   Dali::Window GetWindow();
126
127   /**
128    * @copydoc Dali::Application::ReplaceWindow();
129    */
130   void ReplaceWindow( const PositionSize& positionSize, const std::string& name);
131
132   /**
133    * @copydoc Dali::Application::GetResourcePath();
134    */
135   static std::string GetResourcePath();
136
137   /**
138    * Retrieves the pre-initialized application.
139    *
140    * @return A pointer to the pre-initialized application
141    */
142   static ApplicationPtr GetPreInitializedApplication();
143
144 public: // Stereoscopy
145
146   /**
147    * @copydoc Dali::Application::SetViewMode()
148    */
149   void SetViewMode( ViewMode viewMode );
150
151   /**
152    * @copydoc Dali::Application::GetViewMode()
153    */
154   ViewMode GetViewMode() const;
155
156   /**
157    * @copydoc Dali::Application::SetStereoBase()
158    */
159   void SetStereoBase( float stereoBase );
160
161   /**
162    * @copydoc Dali::Application::GetStereoBase()
163    */
164   float GetStereoBase() const;
165
166 public: // Lifecycle functionality
167
168   /**
169    * Called when OnInit is called or the framework is initialised.
170    */
171   void DoInit();
172
173   /**
174    * Called after OnInit is called or the framework is started.
175    */
176   void DoStart();
177
178   /**
179    * Called when OnTerminate is called or the framework is terminated.
180    */
181   void DoTerminate();
182
183   /**
184    * Called when OnPause is called or the framework is paused.
185    */
186   void DoPause();
187
188   /**
189    * Called when OnResume is called or the framework resumes from a paused state.
190    */
191   void DoResume();
192
193   /**
194    * Called when OnLanguageChanged is called or the framework informs the application that the language of the device has changed.
195    */
196   void DoLanguageChange();
197
198 public: // From Framework::Observer
199
200   /**
201    * Called when the framework is initialised.
202    */
203   virtual void OnInit();
204
205   /**
206    * Called when the framework is terminated.
207    */
208   virtual void OnTerminate();
209
210   /**
211    * Called when the framework is paused.
212    */
213   virtual void OnPause();
214
215   /**
216    * Called when the framework resumes from a paused state.
217    */
218   virtual void OnResume();
219
220   /**
221   * Called when the framework received AppControlSignal.
222   * @param[in] The bundle data of AppControl event.
223   */
224   virtual void OnAppControl(void *data);
225
226   /**
227    * Called when the framework informs the application that it should reset itself.
228    */
229   virtual void OnReset();
230
231   /**
232    * Called when the framework informs the application that the language of the device has changed.
233    */
234   virtual void OnLanguageChanged();
235
236   /**
237   * Called when the framework informs the application that the region of the device has changed.
238   */
239   virtual void OnRegionChanged();
240
241   /**
242   * Called when the framework informs the application that the battery level of the device is low.
243   */
244   virtual void OnBatteryLow();
245
246   /**
247   * Called when the framework informs the application that the memory level of the device is low.
248   */
249   virtual void OnMemoryLow();
250
251 public:
252
253   /**
254    * Signal handler when the adaptor's window resizes itself.
255    * @param[in]  adaptor  The adaptor
256    */
257   void OnResize(Dali::Adaptor& adaptor);
258
259   /**
260    * Sets a user defined theme file.
261    * This should be called before initialization.
262    * @param[in] stylesheet The path to user defined theme file
263    */
264   void SetStyleSheet( const std::string& stylesheet );
265
266 public:  // Signals
267
268   /**
269    * @copydoc Dali::Application::InitSignal()
270    */
271   Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
272
273   /**
274    * @copydoc Dali::Application::TerminateSignal()
275    */
276   Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
277
278   /**
279    * @copydoc Dali::Application::PauseSignal()
280    */
281   Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
282
283   /**
284    * @copydoc Dali::Application::ResumeSignal()
285    */
286   Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
287
288   /**
289    * @copydoc Dali::Application::ResetSignal()
290    */
291   Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
292
293   /**
294   * @copydoc Dali::Application::AppControlSignal()
295   */
296   Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
297
298   /**
299    * @copydoc Dali::Application::ResizeSignal()
300    */
301   Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
302
303   /**
304    * @copydoc Dali::Application::LanguageChangedSignal()
305    */
306   Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
307
308   /**
309   * @copydoc Dali::Application::RegionChangedSignal()
310   */
311   Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
312
313   /**
314   * @copydoc Dali::Application::BatteryLowSignal()
315   */
316   Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
317
318   /**
319   * @copydoc Dali::Application::MemoryLowSignal()
320   */
321   Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
322
323 protected:
324
325   /**
326    * Private Constructor
327    * @param[in]  argc         A pointer to the number of arguments
328    * @param[in]  argv         A pointer to the argument list
329    * @param[in]  stylesheet   The path to user defined theme file
330    * @param[in]  windowMode   A member of Dali::Application::WINDOW_MODE
331    * @param[in]  positionSize A position and a size of the window
332    * @param[in]  applicationType  A member of Dali::Framework::Type
333    */
334   Application( int* argc, char **argv[], const std::string& stylesheet,
335       WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
336
337   /**
338    * Destructor
339    */
340   virtual ~Application();
341
342   // Undefined
343   Application(const Application&);
344   Application& operator=(Application&);
345
346   /**
347    * Creates the window
348    */
349   void CreateWindow();
350
351   /**
352    * Creates the adaptor
353    */
354   void CreateAdaptor();
355
356   /**
357    * Quits from the main loop
358    */
359   void QuitFromMainLoop();
360
361 private:
362
363   AppSignalType                           mInitSignal;
364   AppSignalType                           mTerminateSignal;
365   AppSignalType                           mPauseSignal;
366   AppSignalType                           mResumeSignal;
367   AppSignalType                           mResetSignal;
368   AppSignalType                           mResizeSignal;
369   AppControlSignalType                    mAppControlSignal;
370   AppSignalType                           mLanguageChangedSignal;
371   AppSignalType                           mRegionChangedSignal;
372   AppSignalType                           mBatteryLowSignal;
373   AppSignalType                           mMemoryLowSignal;
374
375   EventLoop*                            mEventLoop;
376   Framework*                            mFramework;
377
378   Dali::Configuration::ContextLoss      mContextLossConfiguration;
379   CommandLineOptions*                   mCommandLineOptions;
380
381   Dali::SingletonService                mSingletonService;
382   Dali::Adaptor*                        mAdaptor;
383   Dali::Window                          mWindow;
384   Dali::Application::WINDOW_MODE        mWindowMode;
385   std::string                           mName;
386   std::string                           mStylesheet;
387   EnvironmentOptions                    mEnvironmentOptions;
388   PositionSize                          mWindowPositionSize;
389   Launchpad::State                      mLaunchpadState;
390   bool                                  mUseRemoteSurface;
391
392   SlotDelegate< Application >           mSlotDelegate;
393
394   static ApplicationPtr                 gPreInitializedApplication;
395 };
396
397 inline Application& GetImplementation(Dali::Application& application)
398 {
399   DALI_ASSERT_ALWAYS(application && "application handle is empty");
400
401   BaseObject& handle = application.GetBaseObject();
402
403   return static_cast<Internal::Adaptor::Application&>(handle);
404 }
405
406 inline const Application& GetImplementation(const Dali::Application& application)
407 {
408   DALI_ASSERT_ALWAYS(application && "Timre handle is empty");
409
410   const BaseObject& handle = application.GetBaseObject();
411
412   return static_cast<const Internal::Adaptor::Application&>(handle);
413 }
414
415
416 } // namespace Adaptor
417
418 } // namespace Internal
419
420 } // namespace Dali
421
422 #endif // __DALI_INTERNAL_APPLICATION_H__