Revert "[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
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   if ( window )
99   {
100     mWindows.push_back( window );
101     mWindowCreatedSignal.Emit( window );
102   }
103 }
104
105 Integration::Scene Adaptor::GetScene( Dali::Window window )
106 {
107   return window.GetScene();
108 }
109
110 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
111 {
112   mCallbacks.PushBack( callback );
113   return true;
114 }
115
116 void Adaptor::RemoveIdle( CallbackBase* callback )
117 {
118   mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
119                                   [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
120 }
121
122 void Adaptor::RunIdles()
123 {
124   for( auto& callback : mCallbacks )
125   {
126     CallbackBase::Execute( *callback );
127   }
128
129   mCallbacks.Clear();
130 }
131
132 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
133 {
134   DALI_ASSERT_ALWAYS( ! mWindows.empty() );
135
136   return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
137 }
138
139 Dali::WindowContainer Adaptor::GetWindows()
140 {
141   Dali::WindowContainer windows;
142
143   for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
144   {
145     // Downcast to Dali::Window
146     Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
147     if ( window )
148     {
149       windows.push_back( window );
150     }
151   }
152
153   return windows;
154 }
155
156 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
157 {
158   return mResizedSignal;
159 }
160
161 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
162 {
163   return mLanguageChangedSignal;
164 }
165
166 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
167 {
168   return mWindowCreatedSignal;
169 }
170
171 } // namespace Adaptor
172 } // namespace Internal
173
174 ///////////////////////////////////////////////////////////////////////////////
175 //
176 // Dali::Adaptor Stub
177 //
178 ///////////////////////////////////////////////////////////////////////////////
179
180 Adaptor::Adaptor()
181 : mImpl( new Internal::Adaptor::Adaptor )
182 {
183 }
184
185 Adaptor::~Adaptor()
186 {
187   Internal::Adaptor::gAdaptor = nullptr;
188   delete mImpl;
189 }
190
191 void Adaptor::Start()
192 {
193 }
194
195 void Adaptor::Pause()
196 {
197 }
198
199 void Adaptor::Resume()
200 {
201 }
202
203 void Adaptor::Stop()
204 {
205 }
206
207 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
208 {
209   return mImpl->AddIdle( callback, hasReturnValue );
210 }
211
212 void Adaptor::RemoveIdle( CallbackBase* callback )
213 {
214   mImpl->RemoveIdle( callback );
215 }
216
217 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
218 {
219 }
220
221 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
222 {
223 }
224
225 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
226 {
227   return mImpl->ResizedSignal();
228 }
229
230 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
231 {
232   return mImpl->LanguageChangedSignal();
233 }
234
235 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
236 {
237   return mImpl->WindowCreatedSignal();
238 }
239
240 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
241 {
242   return mImpl->GetSurface();
243 }
244
245 Dali::WindowContainer Adaptor::GetWindows() const
246 {
247   return mImpl->GetWindows();
248 }
249
250 Any Adaptor::GetNativeWindowHandle()
251 {
252   Any window;
253   return window;
254 }
255
256 Any Adaptor::GetNativeWindowHandle( Actor actor )
257 {
258   return GetNativeWindowHandle();
259 }
260
261 void Adaptor::ReleaseSurfaceLock()
262 {
263 }
264
265 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
266 {
267 }
268
269 Adaptor& Adaptor::Get()
270 {
271   return Internal::Adaptor::Adaptor::Get();
272 }
273
274 bool Adaptor::IsAvailable()
275 {
276   return Internal::Adaptor::gAdaptor;
277 }
278
279 void Adaptor::NotifySceneCreated()
280 {
281 }
282
283 void Adaptor::NotifyLanguageChanged()
284 {
285 }
286
287 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
288 {
289 }
290
291 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
292 {
293 }
294
295 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
296 {
297 }
298
299 void Adaptor::SceneCreated()
300 {
301 }
302
303 const LogFactoryInterface& Adaptor::GetLogFactory()
304 {
305   if( gLogFactory == NULL )
306   {
307     gLogFactory = new LogFactory;
308   }
309   return *gLogFactory;
310 }
311
312 } // namespace Dali