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