[dali_2.3.42] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-scene-holder.cpp
1 /*
2  * Copyright (c) 2024 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali/integration-api/adaptor-framework/scene-holder.h>
19 #include <dali/integration-api/events/touch-event-integ.h>
20
21 #include <toolkit-scene-holder-impl.h>
22
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/object/base-object.h>
26
27 #include <dali/integration-api/adaptor-framework/adaptor.h>
28 #include <dali/public-api/render-tasks/render-task-list.h>
29 #include <toolkit-adaptor-impl.h>
30 #include "test-render-surface.h"
31
32 using AdaptorImpl = Dali::Internal::Adaptor::Adaptor;
33
34 namespace Dali
35 {
36 ///////////////////////////////////////////////////////////////////////////////
37 //
38 // Dali::Internal::Adaptor::SceneHolder Stub
39 //
40 ///////////////////////////////////////////////////////////////////////////////
41
42 namespace Internal
43 {
44 namespace Adaptor
45 {
46 class SceneHolder::SceneHolderLifeCycleObserver
47 {
48 public:
49   SceneHolderLifeCycleObserver(Adaptor*& adaptor, bool& adaptorStarted)
50   : mAdaptor(adaptor),
51     mAdaptorStarted(adaptorStarted)
52   {
53   }
54
55 private: // Adaptor::LifeCycleObserver interface
56   virtual void OnStart()
57   {
58     mAdaptorStarted = true;
59   };
60   virtual void OnPause(){};
61   virtual void OnResume(){};
62   virtual void OnStop()
63   {
64     // Mark adaptor as stopped;
65     mAdaptorStarted = false;
66   };
67   virtual void OnDestroy()
68   {
69     mAdaptor = nullptr;
70   };
71
72 private:
73   Adaptor*& mAdaptor;
74   bool&     mAdaptorStarted;
75 };
76
77 SceneHolder::SceneHolder(const Dali::Rect<int>& positionSize)
78 : mId(0),
79   mScene(Dali::Integration::Scene::New(Dali::Size(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height)))),
80   mRenderSurface(new TestRenderSurface(positionSize))
81 {
82 }
83
84 SceneHolder::~SceneHolder()
85 {
86   if(Dali::Adaptor::IsAvailable())
87   {
88     AdaptorImpl::GetImpl(AdaptorImpl::Get()).RemoveWindow(this);
89   }
90 }
91
92 void SceneHolder::Add(Dali::Actor actor)
93 {
94   mScene.Add(actor);
95 }
96
97 void SceneHolder::Remove(Dali::Actor actor)
98 {
99   mScene.Remove(actor);
100 }
101
102 Dali::Layer SceneHolder::GetRootLayer() const
103 {
104   return mScene.GetRootLayer();
105 }
106
107 void SceneHolder::SetBackgroundColor(Vector4 color)
108 {
109   return mScene.SetBackgroundColor(color);
110 }
111
112 Vector4 SceneHolder::GetBackgroundColor() const
113 {
114   return mScene.GetBackgroundColor();
115 }
116
117 void SceneHolder::FeedTouchPoint(Dali::TouchPoint& point, int timeStamp)
118 {
119 }
120
121 void SceneHolder::FeedWheelEvent(Dali::WheelEvent& wheelEvent)
122 {
123 }
124
125 void SceneHolder::FeedKeyEvent(Dali::KeyEvent& keyEvent)
126 {
127 }
128
129 Dali::Integration::SceneHolder::KeyEventSignalType& SceneHolder::KeyEventSignal()
130 {
131   return mScene.KeyEventSignal();
132 }
133
134 Dali::Integration::SceneHolder::KeyEventGeneratedSignalType& SceneHolder::KeyEventGeneratedSignal()
135 {
136   return mScene.KeyEventGeneratedSignal();
137 }
138
139 Dali::Integration::SceneHolder::TouchEventSignalType& SceneHolder::TouchedSignal()
140 {
141   return mScene.TouchedSignal();
142 }
143
144 Dali::Integration::SceneHolder::WheelEventSignalType& SceneHolder::WheelEventSignal()
145 {
146   return mScene.WheelEventSignal();
147 }
148
149 Dali::Integration::SceneHolder::WheelEventGeneratedSignalType& SceneHolder::WheelEventGeneratedSignal()
150 {
151   return mScene.WheelEventGeneratedSignal();
152 }
153
154 Integration::Scene SceneHolder::GetScene()
155 {
156   return mScene;
157 }
158
159 Dali::Integration::RenderSurfaceInterface& SceneHolder::GetRenderSurface()
160 {
161   return *mRenderSurface;
162 }
163
164 Dali::RenderTaskList SceneHolder::GetRenderTaskList()
165 {
166   return mScene.GetRenderTaskList();
167 }
168
169 } // namespace Adaptor
170
171 } // namespace Internal
172
173 ///////////////////////////////////////////////////////////////////////////////
174 //
175 // Dali::Integration::SceneHolder Stub
176 //
177 ///////////////////////////////////////////////////////////////////////////////
178
179 namespace Integration
180 {
181 SceneHolder::SceneHolder()
182 {
183   // Dali::Internal::Adaptor::Adaptor::Get().WindowCreatedSignal().Emit( *this );
184 }
185
186 SceneHolder::~SceneHolder()
187 {
188 }
189
190 SceneHolder::SceneHolder(const SceneHolder& handle)
191 : BaseHandle(handle)
192 {
193 }
194
195 SceneHolder::SceneHolder(Internal::Adaptor::SceneHolder* internal)
196 : BaseHandle(internal)
197 {
198 }
199
200 SceneHolder& SceneHolder::operator=(const SceneHolder& rhs)
201 {
202   BaseHandle::operator=(rhs);
203   return *this;
204 }
205
206 Dali::Integration::SceneHolder SceneHolder::Get(Dali::Actor actor)
207 {
208   Internal::Adaptor::SceneHolder* sceneHolderImpl = nullptr;
209
210   if(Dali::Adaptor::IsAvailable())
211   {
212     sceneHolderImpl = AdaptorImpl::GetImpl(AdaptorImpl::Get()).GetWindow(actor);
213   }
214
215   return Dali::Integration::SceneHolder(sceneHolderImpl);
216 }
217
218 void SceneHolder::Add(Actor actor)
219 {
220   GetImplementation(*this).Add(actor);
221 }
222
223 void SceneHolder::Remove(Actor actor)
224 {
225   GetImplementation(*this).Remove(actor);
226 }
227
228 Dali::Layer SceneHolder::GetRootLayer() const
229 {
230   return GetImplementation(*this).GetRootLayer();
231 }
232
233 void SceneHolder::SetBackgroundColor(Vector4 color)
234 {
235   GetImplementation(*this).SetBackgroundColor(color);
236 }
237
238 Vector4 SceneHolder::GetBackgroundColor() const
239 {
240   return GetImplementation(*this).GetBackgroundColor();
241 }
242
243 void SceneHolder::FeedTouchPoint(Dali::TouchPoint& point, int timeStamp)
244 {
245   GetImplementation(*this).FeedTouchPoint(point, timeStamp);
246 }
247
248 void SceneHolder::FeedWheelEvent(Dali::WheelEvent& wheelEvent)
249 {
250   GetImplementation(*this).FeedWheelEvent(wheelEvent);
251 }
252
253 void SceneHolder::FeedKeyEvent(Dali::KeyEvent& keyEvent)
254 {
255   GetImplementation(*this).FeedKeyEvent(keyEvent);
256 }
257
258 RenderTaskList SceneHolder::GetRenderTaskList()
259 {
260   return GetImplementation(*this).GetRenderTaskList();
261 }
262
263 SceneHolder::KeyEventSignalType& SceneHolder::KeyEventSignal()
264 {
265   return GetImplementation(*this).KeyEventSignal();
266 }
267
268 SceneHolder::KeyEventGeneratedSignalType& SceneHolder::KeyEventGeneratedSignal()
269 {
270   return GetImplementation(*this).KeyEventGeneratedSignal();
271 }
272
273 SceneHolder::TouchEventSignalType& SceneHolder::TouchedSignal()
274 {
275   return GetImplementation(*this).TouchedSignal();
276 }
277
278 SceneHolder::WheelEventSignalType& SceneHolder::WheelEventSignal()
279 {
280   return GetImplementation(*this).WheelEventSignal();
281 }
282
283 SceneHolder::WheelEventGeneratedSignalType& SceneHolder::WheelEventGeneratedSignal()
284 {
285   return GetImplementation(*this).WheelEventGeneratedSignal();
286 }
287
288 } // namespace Integration
289
290 } // namespace Dali