[dali_1.4.26] Merge branch '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 <toolkit-window.h>
19
20 // Don't want to include the actual window.h which otherwise will be indirectly included by adaptor.h.
21 #define DALI_WINDOW_H
22 #include <dali/integration-api/adaptors/adaptor.h>
23
24 #include <dali/integration-api/adaptors/scene-holder.h>
25
26 #include <dali/public-api/object/base-object.h>
27
28 #include <toolkit-adaptor-impl.h>
29 #include <dali/integration-api/debug.h>
30 #include <test-application.h>
31 #include <test-render-surface.h>
32
33 namespace Dali
34 {
35
36 namespace Internal
37 {
38 namespace Adaptor
39 {
40
41 bool Adaptor::mAvailable = false;
42 Vector<CallbackBase*> Adaptor::mCallbacks = Vector<CallbackBase*>();
43 Dali::WindowContainer Adaptor::mWindows;
44 Dali::Adaptor::WindowCreatedSignalType* Adaptor::mWindowCreatedSignal = nullptr;
45
46 Dali::Adaptor& Adaptor::Get()
47 {
48   Dali::Adaptor* adaptor = new Dali::Adaptor;
49   Adaptor::mAvailable = true;
50   return *adaptor;
51 }
52
53 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
54 {
55   Dali::RenderSurfaceInterface* renderSurface = reinterpret_cast <Dali::RenderSurfaceInterface*>( new Dali::TestRenderSurface( Dali::PositionSize( 0, 0, 480, 800 ) ) );
56   return *renderSurface;
57 }
58
59 Dali::WindowContainer Adaptor::GetWindows()
60 {
61   return Adaptor::mWindows;
62 }
63
64 Dali::Adaptor::AdaptorSignalType& Adaptor::AdaptorSignal()
65 {
66   Dali::Adaptor::AdaptorSignalType* signal = new Dali::Adaptor::AdaptorSignalType;
67   return *signal;
68 }
69
70 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
71 {
72   if ( !Adaptor::mWindowCreatedSignal )
73   {
74     Adaptor::mWindowCreatedSignal = new Dali::Adaptor::WindowCreatedSignalType;
75   }
76
77   return *Adaptor::mWindowCreatedSignal;
78 }
79
80 } // namespace Adaptor
81 } // namespace Internal
82
83 Adaptor& Adaptor::New( Window window )
84 {
85   return Internal::Adaptor::Adaptor::Get();
86 }
87
88 Adaptor& Adaptor::New( Window window, Configuration::ContextLoss configuration )
89 {
90   return Internal::Adaptor::Adaptor::Get();
91 }
92
93 Adaptor& Adaptor::New( Window window, const Dali::RenderSurfaceInterface& surface )
94 {
95   return Internal::Adaptor::Adaptor::Get();
96 }
97
98 Adaptor& Adaptor::New( Window window, const Dali::RenderSurfaceInterface& surface, Configuration::ContextLoss configuration )
99 {
100   return Internal::Adaptor::Adaptor::Get();
101 }
102
103 Adaptor& Adaptor::New( Dali::Integration::SceneHolder window )
104 {
105   return Internal::Adaptor::Adaptor::Get();
106 }
107
108 Adaptor& Adaptor::New( Dali::Integration::SceneHolder window, Configuration::ContextLoss configuration )
109 {
110   return Internal::Adaptor::Adaptor::Get();
111 }
112
113 Adaptor& Adaptor::New( Dali::Integration::SceneHolder window, const Dali::RenderSurfaceInterface& surface )
114 {
115   return Internal::Adaptor::Adaptor::Get();
116 }
117
118 Adaptor& Adaptor::New( Dali::Integration::SceneHolder window, const Dali::RenderSurfaceInterface& surface, Configuration::ContextLoss configuration )
119 {
120   return Internal::Adaptor::Adaptor::Get();
121 }
122
123 Adaptor::~Adaptor()
124 {
125 }
126
127 void Adaptor::Start()
128 {
129 }
130
131 void Adaptor::Pause()
132 {
133 }
134
135 void Adaptor::Resume()
136 {
137 }
138
139 void Adaptor::Stop()
140 {
141 }
142
143 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
144 {
145   const bool isAvailable = IsAvailable();
146
147   if( isAvailable )
148   {
149     Internal::Adaptor::Adaptor::mCallbacks.PushBack( callback );
150   }
151
152   return isAvailable;
153 }
154
155 void Adaptor::RemoveIdle( CallbackBase* callback )
156 {
157   const bool isAvailable = IsAvailable();
158
159   if( isAvailable )
160   {
161     for( Vector<CallbackBase*>::Iterator it = Internal::Adaptor::Adaptor::mCallbacks.Begin(),
162            endIt = Internal::Adaptor::Adaptor::mCallbacks.End();
163          it != endIt;
164          ++it )
165     {
166       if( callback == *it )
167       {
168         Internal::Adaptor::Adaptor::mCallbacks.Remove( it );
169         return;
170       }
171     }
172   }
173 }
174
175 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
176 {
177 }
178
179 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
180 {
181 }
182
183 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
184 {
185   return Internal::Adaptor::Adaptor::AdaptorSignal();
186 }
187
188 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
189 {
190   return Internal::Adaptor::Adaptor::AdaptorSignal();
191 }
192
193 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
194 {
195   return Internal::Adaptor::Adaptor::WindowCreatedSignal();
196 }
197
198 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
199 {
200   return Internal::Adaptor::Adaptor::GetSurface();
201 }
202
203 Dali::WindowContainer Adaptor::GetWindows() const
204 {
205   return Internal::Adaptor::Adaptor::GetWindows();
206 }
207
208 Any Adaptor::GetNativeWindowHandle()
209 {
210   Any window;
211   return window;
212 }
213
214 void Adaptor::ReleaseSurfaceLock()
215 {
216 }
217
218 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
219 {
220 }
221
222 Adaptor& Adaptor::Get()
223 {
224   return Internal::Adaptor::Adaptor::Get();
225 }
226
227 bool Adaptor::IsAvailable()
228 {
229   return Internal::Adaptor::Adaptor::mAvailable;
230 }
231
232 void Adaptor::NotifySceneCreated()
233 {
234 }
235
236 void Adaptor::NotifyLanguageChanged()
237 {
238 }
239
240 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
241 {
242 }
243
244 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
245 {
246 }
247
248 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
249 {
250 }
251
252 void Adaptor::SceneCreated()
253 {
254 }
255
256 class LogFactory : public LogFactoryInterface
257 {
258 public:
259   virtual void InstallLogFunction() const
260   {
261     Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
262     Dali::Integration::Log::InstallLogFunction(logFunction);
263   }
264
265   LogFactory()
266   {
267   }
268   virtual ~LogFactory()
269   {
270   }
271 };
272
273 LogFactory* gLogFactory = NULL;
274 const LogFactoryInterface& Adaptor::GetLogFactory()
275 {
276   if( gLogFactory == NULL )
277   {
278     gLogFactory = new LogFactory;
279   }
280   return *gLogFactory;
281 }
282
283 Adaptor::Adaptor()
284 : mImpl( NULL )
285 {
286   Dali::PositionSize win_size;
287   win_size.width = 640;
288   win_size.height = 800;
289
290   Dali::Window window = Dali::Window::New( win_size, "" );
291   Internal::Adaptor::Adaptor::mWindows.push_back( window );
292 }
293
294 } // namespace Dali