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