f12ce4d021647c8fdfbba193ed39bdf0e00792cc
[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 public: // From Framework::Observer
110   /**
111    * Called when the framework is initialised.
112    */
113   void OnInit() override;
114
115   /**
116    * Called when the framework is terminated.
117    */
118   void OnTerminate() override;
119
120 private:
121   /**
122    * Private constructor
123    * @param[in] width The width of the OffscreenWindow
124    * @param[in] height The height of the OffscreenApplication
125    * @param[in] surface The native surface handle to create the default OffscreenWindow
126    * @param[in] isTranslucent Whether the OffscreenWindow is translucent or not
127    * @param[in] renderMode The RenderMode of the OffscreenApplication
128    */
129   OffscreenApplication(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent, Dali::OffscreenApplication::RenderMode renderMode);
130
131   /**
132    * Quits from the main loop
133    */
134   void QuitFromMainLoop();
135
136   // Undefined
137   OffscreenApplication(const OffscreenApplication&) = delete;
138   OffscreenApplication& operator=(OffscreenApplication&) = delete;
139   OffscreenApplication& operator=(const OffscreenApplication&) = delete;
140   OffscreenApplication& operator=(OffscreenApplication&&) = delete;
141
142 private:
143   std::unique_ptr<Dali::Adaptor> mAdaptor;
144   Dali::OffscreenWindow          mDefaultWindow;
145
146   std::unique_ptr<Internal::Adaptor::Framework>        mFramework;
147   std::unique_ptr<Internal::Adaptor::FrameworkFactory> mFrameworkFactory;
148
149   OffscreenApplicationSignalType mInitSignal;
150   OffscreenApplicationSignalType mTerminateSignal;
151 };
152
153 inline OffscreenApplication& GetImplementation(Dali::OffscreenApplication& offscreenApplication)
154 {
155   DALI_ASSERT_ALWAYS(offscreenApplication && "OffscreenApplication handle is empty");
156
157   BaseObject& handle = offscreenApplication.GetBaseObject();
158
159   return static_cast<OffscreenApplication&>(handle);
160 }
161
162 inline const OffscreenApplication& GetImplementation(const Dali::OffscreenApplication& offscreenApplication)
163 {
164   DALI_ASSERT_ALWAYS(offscreenApplication && "OffscreenApplication handle is empty");
165
166   const BaseObject& handle = offscreenApplication.GetBaseObject();
167
168   return static_cast<const OffscreenApplication&>(handle);
169 }
170
171 } // namespace Internal
172
173 } // namespace Dali
174
175 #endif // DALI_INTERNAL_OFFSCREEN_APPLICATION_IMPL_H