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