2 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <toolkit-window-impl.h>
22 // Don't want to include the actual window.h which otherwise will be indirectly included by adaptor.h.
24 #include <dali/integration-api/adaptor-framework/adaptor.h>
25 #include <dali/integration-api/adaptor-framework/scene-holder.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/integration-api/scene.h>
29 #include <test-application.h>
30 #include <toolkit-adaptor-impl.h>
31 #include <toolkit-application.h>
32 #include <toolkit-async-task-manager.h>
33 #include <toolkit-scene-holder-impl.h>
34 #include <toolkit-test-application.h>
35 #include "dali-test-suite-utils.h"
43 ///////////////////////////////////////////////////////////////////////////////
45 // Dali::Internal::Adaptor::Adaptor Stub
47 ///////////////////////////////////////////////////////////////////////////////
49 Dali::Adaptor* gAdaptor = nullptr;
51 Dali::Adaptor& Adaptor::New()
53 DALI_ASSERT_ALWAYS(!gAdaptor);
54 gAdaptor = new Dali::Adaptor;
58 Dali::Adaptor& Adaptor::Get()
60 DALI_ASSERT_ALWAYS(gAdaptor);
72 // Ensure all threads and not-excuted tasks are destroyed.
73 // TODO : we'd better make some singletone service for toolkit UTC in future.
74 Test::AsyncTaskManager::DestroyAsyncTaskManager();
77 void Adaptor::Start(Dali::Window window)
79 AddWindow(&GetImplementation(window));
86 Integration::Core& core = mTestApplication->GetCore();
87 tet_printf("Adaptor::UnregisterProcessors\n");
88 core.UnregisterProcessors();
94 Integration::Scene Adaptor::GetScene(Dali::Window window)
96 return window.GetScene();
99 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
101 if(ToolkitApplication::ADD_IDLE_SUCCESS)
105 mReturnCallbacks.PushBack(callback);
109 mCallbacks.PushBack(callback);
112 return ToolkitApplication::ADD_IDLE_SUCCESS;
115 void Adaptor::RemoveIdle(CallbackBase* callback)
117 mCallbacks.Erase(std::remove_if(mCallbacks.Begin(), mCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mCallbacks.End());
118 mReturnCallbacks.Erase(std::remove_if(mReturnCallbacks.Begin(), mReturnCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mReturnCallbacks.End());
121 void Adaptor::RunIdles()
123 Dali::Vector<CallbackBase*> reusedCallbacks;
124 for(auto& callback : mReturnCallbacks)
126 bool retValue = CallbackBase::ExecuteReturn<bool>(*callback);
129 reusedCallbacks.PushBack(callback);
132 for(auto& callback : mCallbacks)
134 CallbackBase::Execute(*callback);
138 mReturnCallbacks.Clear();
139 mReturnCallbacks.Swap(reusedCallbacks);
142 void Adaptor::RequestUpdateOnce()
146 auto scene = mTestApplication->GetScene();
149 tet_printf("Adaptor::RequestUpdateOnce()\n");
150 scene.KeepRendering(0.0f);
155 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
157 DALI_ASSERT_ALWAYS(!mWindows.empty());
159 return reinterpret_cast<Dali::RenderSurfaceInterface&>(mWindows.front()->GetRenderSurface());
162 Dali::WindowContainer Adaptor::GetWindows()
164 Dali::WindowContainer windows;
166 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
168 // Downcast to Dali::Window
169 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
172 windows.push_back(window);
179 Dali::SceneHolderList Adaptor::GetSceneHolders()
181 Dali::SceneHolderList sceneHolderList;
183 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
185 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
188 return sceneHolderList;
191 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
193 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
195 for(auto window : mWindows)
197 if(scene == window->GetScene())
206 void Adaptor::AddWindow(Internal::Adaptor::SceneHolder* window)
210 mWindows.push_back(window);
212 Dali::Integration::SceneHolder newWindow(window);
213 mWindowCreatedSignal.Emit(newWindow);
217 void Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* window)
219 auto iter = std::find(mWindows.begin(), mWindows.end(), window);
220 if(iter != mWindows.end())
222 mWindows.erase(iter);
226 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
228 Integration::Core& core = mTestApplication->GetCore();
229 tet_printf("Adaptor::RegisterProcessor : %s\n", processor.GetProcessorName().data());
230 core.RegisterProcessor(processor, postProcessor);
233 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
235 Integration::Core& core = mTestApplication->GetCore();
236 tet_printf("Adaptor::UnregisterProcessor : %s\n", processor.GetProcessorName().data());
237 core.UnregisterProcessor(processor, postProcessor);
240 void Adaptor::RegisterProcessorOnce(Integration::Processor& processor, bool postProcessor)
242 Integration::Core& core = mTestApplication->GetCore();
243 tet_printf("Adaptor::RegisterProcessorOnce : %s\n", processor.GetProcessorName().data());
244 core.RegisterProcessorOnce(processor, postProcessor);
247 void Adaptor::UnregisterProcessorOnce(Integration::Processor& processor, bool postProcessor)
249 Integration::Core& core = mTestApplication->GetCore();
250 tet_printf("Adaptor::UnregisterProcessorOnce : %s\n", processor.GetProcessorName().data());
251 core.UnregisterProcessorOnce(processor, postProcessor);
254 void Adaptor::SetApplication(Dali::TestApplication& testApplication)
256 mTestApplication = &testApplication;
259 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
261 return mResizedSignal;
264 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
266 return mLanguageChangedSignal;
269 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
271 return mWindowCreatedSignal;
274 } // namespace Adaptor
275 } // namespace Internal
277 ///////////////////////////////////////////////////////////////////////////////
279 // Dali::Adaptor Stub
281 ///////////////////////////////////////////////////////////////////////////////
284 : mImpl(new Internal::Adaptor::Adaptor)
290 Internal::Adaptor::gAdaptor = nullptr;
294 void Adaptor::Start()
298 void Adaptor::Pause()
302 void Adaptor::Resume()
311 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
313 return mImpl->AddIdle(callback, hasReturnValue);
316 void Adaptor::RemoveIdle(CallbackBase* callback)
318 mImpl->RemoveIdle(callback);
321 void Adaptor::ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface)
325 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface)
329 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
331 return mImpl->ResizedSignal();
334 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
336 return mImpl->LanguageChangedSignal();
339 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
341 return mImpl->WindowCreatedSignal();
344 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
346 return mImpl->GetSurface();
349 Dali::WindowContainer Adaptor::GetWindows() const
351 return mImpl->GetWindows();
354 Dali::SceneHolderList Adaptor::GetSceneHolders() const
356 return mImpl->GetSceneHolders();
359 Any Adaptor::GetNativeWindowHandle()
365 Any Adaptor::GetNativeWindowHandle(Actor actor)
367 return GetNativeWindowHandle();
370 void Adaptor::ReleaseSurfaceLock()
374 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
378 Adaptor& Adaptor::Get()
380 return Internal::Adaptor::Adaptor::Get();
383 bool Adaptor::IsAvailable()
385 return Internal::Adaptor::gAdaptor && (!Internal::Adaptor::Adaptor::GetImpl(*Internal::Adaptor::gAdaptor).IsStopped());
388 void Adaptor::NotifySceneCreated()
392 void Adaptor::NotifyLanguageChanged()
396 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
400 void Adaptor::FeedWheelEvent(WheelEvent& wheelEvent)
404 void Adaptor::FeedKeyEvent(KeyEvent& keyEvent)
408 void Adaptor::SceneCreated()
412 class LogFactory : public LogFactoryInterface
415 virtual void InstallLogFunction() const
417 Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
418 Dali::Integration::Log::InstallLogFunction(logFunction);
424 virtual ~LogFactory()
429 LogFactory* gLogFactory = NULL;
430 const LogFactoryInterface& Adaptor::GetLogFactory()
432 if(gLogFactory == NULL)
434 gLogFactory = new LogFactory;
439 class TraceFactory : public TraceFactoryInterface
442 virtual void InstallTraceFunction() const
444 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
445 Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
451 virtual ~TraceFactory()
456 TraceFactory* gTraceFactory = NULL;
457 const TraceFactoryInterface& Adaptor::GetTraceFactory()
459 if(gTraceFactory == NULL)
461 gTraceFactory = new TraceFactory;
463 return *gTraceFactory;
466 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
468 mImpl->RegisterProcessor(processor, postProcessor);
471 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
473 mImpl->UnregisterProcessor(processor, postProcessor);
476 void Adaptor::RegisterProcessorOnce(Integration::Processor& processor, bool postProcessor)
478 mImpl->RegisterProcessorOnce(processor, postProcessor);
481 void Adaptor::UnregisterProcessorOnce(Integration::Processor& processor, bool postProcessor)
483 mImpl->UnregisterProcessorOnce(processor, postProcessor);