Merge "Changes after adaptor integration-api folder move" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-adaptor.cpp
1 /*
2  * Copyright (c) 2019 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 <algorithm>
19
20 #include <toolkit-window-impl.h>
21
22 // Don't want to include the actual window.h which otherwise will be indirectly included by adaptor.h.
23 #define DALI_WINDOW_H
24 #include <dali/integration-api/adaptor-framework/adaptor.h>
25 #include <dali/integration-api/adaptor-framework/scene-holder.h>
26
27 #include <toolkit-scene-holder-impl.h>
28 #include <toolkit-adaptor-impl.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/integration-api/scene.h>
31 #include <test-application.h>
32 #include <test-render-surface.h>
33
34 namespace Dali
35 {
36
37 namespace
38 {
39
40 ///////////////////////////////////////////////////////////////////////////////
41 //
42 // LogFactoryStub
43 //
44 ///////////////////////////////////////////////////////////////////////////////
45
46 class LogFactory : public LogFactoryInterface
47 {
48 public:
49   LogFactory() = default;
50   virtual ~LogFactory() = default;
51
52 private:
53   void InstallLogFunction() const override
54   {
55     Dali::Integration::Log::InstallLogFunction( &TestApplication::LogMessage );
56   }
57 };
58 LogFactory* gLogFactory = NULL; // For some reason, destroying this when the Adaptor is destroyed causes a crash in some test cases when running all of them.
59 } //unnamed namespace
60
61 namespace Internal
62 {
63 namespace Adaptor
64 {
65
66 ///////////////////////////////////////////////////////////////////////////////
67 //
68 // Dali::Internal::Adaptor::Adaptor Stub
69 //
70 ///////////////////////////////////////////////////////////////////////////////
71
72 Dali::Adaptor* gAdaptor = nullptr;
73
74 Dali::Adaptor& Adaptor::New()
75 {
76   DALI_ASSERT_ALWAYS( ! gAdaptor );
77   gAdaptor = new Dali::Adaptor;
78   return *gAdaptor;
79 }
80
81 Dali::Adaptor& Adaptor::Get()
82 {
83   DALI_ASSERT_ALWAYS( gAdaptor );
84   return *gAdaptor;
85 }
86
87 Adaptor::Adaptor()
88 {
89 }
90
91 Adaptor::~Adaptor()
92 {
93   gAdaptor = nullptr;
94 }
95
96 void Adaptor::Start( Dali::Window window )
97 {
98   AddWindow( &GetImplementation( window ) );
99 }
100
101 Integration::Scene Adaptor::GetScene( Dali::Window window )
102 {
103   return window.GetScene();
104 }
105
106 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
107 {
108   mCallbacks.PushBack( callback );
109   return true;
110 }
111
112 void Adaptor::RemoveIdle( CallbackBase* callback )
113 {
114   mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
115                                   [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
116 }
117
118 void Adaptor::RunIdles()
119 {
120   for( auto& callback : mCallbacks )
121   {
122     CallbackBase::Execute( *callback );
123   }
124
125   mCallbacks.Clear();
126 }
127
128 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
129 {
130   DALI_ASSERT_ALWAYS( ! mWindows.empty() );
131
132   return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
133 }
134
135 Dali::WindowContainer Adaptor::GetWindows()
136 {
137   Dali::WindowContainer windows;
138
139   for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
140   {
141     // Downcast to Dali::Window
142     Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
143     if ( window )
144     {
145       windows.push_back( window );
146     }
147   }
148
149   return windows;
150 }
151
152 Dali::SceneHolderList Adaptor::GetSceneHolders()
153 {
154   Dali::SceneHolderList sceneHolderList;
155
156   for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
157   {
158     sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
159   }
160
161   return sceneHolderList;
162 }
163
164 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
165 {
166   Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
167
168   for( auto window : mWindows )
169   {
170     if ( scene == window->GetScene() )
171     {
172       return window;
173     }
174   }
175
176   return nullptr;
177 }
178
179 void Adaptor::AddWindow( Internal::Adaptor::SceneHolder* window )
180 {
181   if ( window )
182   {
183     mWindows.push_back( window );
184
185     Dali::Integration::SceneHolder newWindow( window );
186     mWindowCreatedSignal.Emit( newWindow );
187   }
188 }
189
190 void Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* window )
191 {
192   auto iter = std::find( mWindows.begin(), mWindows.end(), window );
193   if( iter != mWindows.end() )
194   {
195     mWindows.erase( iter );
196   }
197 }
198
199 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
200 {
201   return mResizedSignal;
202 }
203
204 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
205 {
206   return mLanguageChangedSignal;
207 }
208
209 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
210 {
211   return mWindowCreatedSignal;
212 }
213
214 } // namespace Adaptor
215 } // namespace Internal
216
217 ///////////////////////////////////////////////////////////////////////////////
218 //
219 // Dali::Adaptor Stub
220 //
221 ///////////////////////////////////////////////////////////////////////////////
222
223 Adaptor::Adaptor()
224 : mImpl( new Internal::Adaptor::Adaptor )
225 {
226 }
227
228 Adaptor::~Adaptor()
229 {
230   Internal::Adaptor::gAdaptor = nullptr;
231   delete mImpl;
232 }
233
234 void Adaptor::Start()
235 {
236 }
237
238 void Adaptor::Pause()
239 {
240 }
241
242 void Adaptor::Resume()
243 {
244 }
245
246 void Adaptor::Stop()
247 {
248 }
249
250 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
251 {
252   return mImpl->AddIdle( callback, hasReturnValue );
253 }
254
255 void Adaptor::RemoveIdle( CallbackBase* callback )
256 {
257   mImpl->RemoveIdle( callback );
258 }
259
260 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
261 {
262 }
263
264 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
265 {
266 }
267
268 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
269 {
270   return mImpl->ResizedSignal();
271 }
272
273 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
274 {
275   return mImpl->LanguageChangedSignal();
276 }
277
278 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
279 {
280   return mImpl->WindowCreatedSignal();
281 }
282
283 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
284 {
285   return mImpl->GetSurface();
286 }
287
288 Dali::WindowContainer Adaptor::GetWindows() const
289 {
290   return mImpl->GetWindows();
291 }
292
293 Dali::SceneHolderList Adaptor::GetSceneHolders() const
294 {
295   return mImpl->GetSceneHolders();
296 }
297
298 Any Adaptor::GetNativeWindowHandle()
299 {
300   Any window;
301   return window;
302 }
303
304 Any Adaptor::GetNativeWindowHandle( Actor actor )
305 {
306   return GetNativeWindowHandle();
307 }
308
309 void Adaptor::ReleaseSurfaceLock()
310 {
311 }
312
313 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
314 {
315 }
316
317 Adaptor& Adaptor::Get()
318 {
319   return Internal::Adaptor::Adaptor::Get();
320 }
321
322 bool Adaptor::IsAvailable()
323 {
324   return Internal::Adaptor::gAdaptor;
325 }
326
327 void Adaptor::NotifySceneCreated()
328 {
329 }
330
331 void Adaptor::NotifyLanguageChanged()
332 {
333 }
334
335 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
336 {
337 }
338
339 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
340 {
341 }
342
343 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
344 {
345 }
346
347 void Adaptor::SceneCreated()
348 {
349 }
350
351 const LogFactoryInterface& Adaptor::GetLogFactory()
352 {
353   if( gLogFactory == NULL )
354   {
355     gLogFactory = new LogFactory;
356   }
357   return *gLogFactory;
358 }
359
360 } // namespace Dali