[dali_2.3.26] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / offscreen / common / offscreen-application-impl.h
1 #ifndef DALI_INTERNAL_OFFSCREEN_APPLICATION_IMPL_H
2 #define DALI_INTERNAL_OFFSCREEN_APPLICATION_IMPL_H
3
4 /*
5  * Copyright (c) 2023 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/intrusive-ptr.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <memory>
25
26 // INTERNAL INCLUDES
27 #include <dali/devel-api/adaptor-framework/offscreen-application.h>
28 #include <dali/devel-api/adaptor-framework/offscreen-window.h>
29 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
30 #include <dali/internal/adaptor/common/framework.h>
31
32 namespace Dali
33 {
34 class Adaptor;
35
36 namespace Internal
37 {
38 namespace Adaptor
39 {
40 class FrameworkFactory;
41 } // namespace Adaptor
42
43 /**
44  * Implementation of the OffscreenApplication class.
45  */
46 class OffscreenApplication : public BaseObject, public Adaptor::Framework::Observer, public Adaptor::Framework::TaskObserver
47 {
48 public:
49   using OffscreenApplicationSignalType = Dali::OffscreenApplication::OffscreenApplicationSignalType;
50
51   /**
52    * @brief Create a new OffscreenApplication
53    * @param[in] width The width of the default OffscreenWindow
54    * @param[in] height The height of the default OffscreenWindow
55    * @param[in] surface The native surface handle to create the default OffscreenWindow
56    * @param[in] isTranslucent Whether the OffscreenWindow is translucent or not
57    * @param[in] renderMode The RenderMode of the OffscreenApplication
58    */
59   static IntrusivePtr<OffscreenApplication> New(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, Dali::OffscreenApplication::RenderMode renderMode);
60
61 public:
62   /**
63    * Destructor
64    */
65   virtual ~OffscreenApplication();
66
67   /**
68    * @copydoc Dali::OffscreenApplication::MainLoop()
69    */
70   void MainLoop();
71
72   /**
73    * @copydoc Dali::OffscreenApplication::Quit()
74    */
75   void Quit();
76
77   /**
78    * @copydoc Dali::OffscreenApplication::GetDefaultWindow()
79    */
80   Dali::OffscreenWindow GetWindow();
81
82   /**
83    * @copydoc Dali::OffscreenApplication::RenderOnce()
84    */
85   void RenderOnce();
86
87   /**
88    * @copydoc Dali::OffscreenApplication::GetFrameworkContext()
89    */
90   Any GetFrameworkContext() const;
91
92 public: // Signals
93   /**
94    * @copydoc Dali::OffscreenApplication::InitSignal()
95    */
96   OffscreenApplicationSignalType& InitSignal()
97   {
98     return mInitSignal;
99   }
100
101   /**
102    * @copydoc Dali::OffscreenApplication::TerminateSignal()
103    */
104   OffscreenApplicationSignalType& TerminateSignal()
105   {
106     return mTerminateSignal;
107   }
108
109   /**
110    * @copydoc Dali::OffscreenApplication::PauseSignal()
111    */
112   OffscreenApplicationSignalType& PauseSignal()
113   {
114     return mPauseSignal;
115   }
116
117   /**
118    * @copydoc Dali::OffscreenApplication::ResumeSignal()
119    */
120   OffscreenApplicationSignalType& ResumeSignal()
121   {
122     return mResumeSignal;
123   }
124
125   /**
126    * @copydoc Dali::OffscreenApplication::ResetSignal()
127    */
128   OffscreenApplicationSignalType& ResetSignal()
129   {
130     return mResetSignal;
131   }
132
133   /**
134    * @copydoc Dali::OffscreenApplication::LanguageChangedSignal()
135    */
136   OffscreenApplicationSignalType& LanguageChangedSignal()
137   {
138     return mLanguageChangedSignal;
139   }
140
141 public: // From Framework::Observer
142   /**
143    * Called when the framework is initialised.
144    */
145   void OnInit() override;
146
147   /**
148    * Called when the framework is terminated.
149    */
150   void OnTerminate() override;
151
152   /**
153    * Called when the framework is paused.
154    */
155   void OnPause() override;
156
157   /**
158    * Called when the framework resumes from a paused state.
159    */
160   void OnResume() override;
161
162   /**
163    * Called when the framework informs the application that it should reset itself.
164    */
165   void OnReset() override;
166
167   /**
168    * Called when the framework informs the application that the language of the device has changed.
169    */
170   void OnLanguageChanged() override;
171
172 private:
173   /**
174    * Private constructor
175    * @param[in] width The width of the OffscreenWindow
176    * @param[in] height The height of the OffscreenApplication
177    * @param[in] surface The native surface handle to create the default OffscreenWindow
178    * @param[in] isTranslucent Whether the OffscreenWindow is translucent or not
179    * @param[in] renderMode The RenderMode of the OffscreenApplication
180    */
181   OffscreenApplication(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, Dali::OffscreenApplication::RenderMode renderMode);
182
183   /**
184    * Quits from the main loop
185    */
186   void QuitFromMainLoop();
187
188   // Undefined
189   OffscreenApplication(const OffscreenApplication&) = delete;
190   OffscreenApplication& operator=(OffscreenApplication&) = delete;
191   OffscreenApplication& operator=(const OffscreenApplication&) = delete;
192   OffscreenApplication& operator=(OffscreenApplication&&) = delete;
193
194 private:
195   std::unique_ptr<Dali::Adaptor> mAdaptor;
196   Dali::OffscreenWindow          mDefaultWindow;
197
198   std::unique_ptr<Internal::Adaptor::Framework>        mFramework;
199   std::unique_ptr<Internal::Adaptor::FrameworkFactory> mFrameworkFactory;
200
201   OffscreenApplicationSignalType mInitSignal;
202   OffscreenApplicationSignalType mTerminateSignal;
203   OffscreenApplicationSignalType mPauseSignal;
204   OffscreenApplicationSignalType mResumeSignal;
205   OffscreenApplicationSignalType mResetSignal;
206   OffscreenApplicationSignalType mLanguageChangedSignal;
207 };
208
209 inline OffscreenApplication& GetImplementation(Dali::OffscreenApplication& offscreenApplication)
210 {
211   DALI_ASSERT_ALWAYS(offscreenApplication && "OffscreenApplication handle is empty");
212
213   BaseObject& handle = offscreenApplication.GetBaseObject();
214
215   return static_cast<OffscreenApplication&>(handle);
216 }
217
218 inline const OffscreenApplication& GetImplementation(const Dali::OffscreenApplication& offscreenApplication)
219 {
220   DALI_ASSERT_ALWAYS(offscreenApplication && "OffscreenApplication handle is empty");
221
222   const BaseObject& handle = offscreenApplication.GetBaseObject();
223
224   return static_cast<const OffscreenApplication&>(handle);
225 }
226
227 } // namespace Internal
228
229 } // namespace Dali
230
231 #endif // DALI_INTERNAL_OFFSCREEN_APPLICATION_IMPL_H