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 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
144 DALI_ASSERT_ALWAYS(!mWindows.empty());
146 return reinterpret_cast<Dali::RenderSurfaceInterface&>(mWindows.front()->GetRenderSurface());
149 Dali::WindowContainer Adaptor::GetWindows()
151 Dali::WindowContainer windows;
153 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
155 // Downcast to Dali::Window
156 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
159 windows.push_back(window);
166 Dali::SceneHolderList Adaptor::GetSceneHolders()
168 Dali::SceneHolderList sceneHolderList;
170 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
172 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
175 return sceneHolderList;
178 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
180 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
182 for(auto window : mWindows)
184 if(scene == window->GetScene())
193 void Adaptor::AddWindow(Internal::Adaptor::SceneHolder* window)
197 mWindows.push_back(window);
199 Dali::Integration::SceneHolder newWindow(window);
200 mWindowCreatedSignal.Emit(newWindow);
204 void Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* window)
206 auto iter = std::find(mWindows.begin(), mWindows.end(), window);
207 if(iter != mWindows.end())
209 mWindows.erase(iter);
213 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
215 Integration::Core& core = mTestApplication->GetCore();
216 tet_printf("Adaptor::RegisterProcessor : %s\n", processor.GetProcessorName().data());
217 core.RegisterProcessor(processor, postProcessor);
220 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
222 Integration::Core& core = mTestApplication->GetCore();
223 tet_printf("Adaptor::UnregisterProcessor : %s\n", processor.GetProcessorName().data());
224 core.UnregisterProcessor(processor, postProcessor);
227 void Adaptor::SetApplication(Dali::TestApplication& testApplication)
229 mTestApplication = &testApplication;
232 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
234 return mResizedSignal;
237 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
239 return mLanguageChangedSignal;
242 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
244 return mWindowCreatedSignal;
247 } // namespace Adaptor
248 } // namespace Internal
250 ///////////////////////////////////////////////////////////////////////////////
252 // Dali::Adaptor Stub
254 ///////////////////////////////////////////////////////////////////////////////
257 : mImpl(new Internal::Adaptor::Adaptor)
263 Internal::Adaptor::gAdaptor = nullptr;
267 void Adaptor::Start()
271 void Adaptor::Pause()
275 void Adaptor::Resume()
284 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
286 return mImpl->AddIdle(callback, hasReturnValue);
289 void Adaptor::RemoveIdle(CallbackBase* callback)
291 mImpl->RemoveIdle(callback);
294 void Adaptor::ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface)
298 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface)
302 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
304 return mImpl->ResizedSignal();
307 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
309 return mImpl->LanguageChangedSignal();
312 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
314 return mImpl->WindowCreatedSignal();
317 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
319 return mImpl->GetSurface();
322 Dali::WindowContainer Adaptor::GetWindows() const
324 return mImpl->GetWindows();
327 Dali::SceneHolderList Adaptor::GetSceneHolders() const
329 return mImpl->GetSceneHolders();
332 Any Adaptor::GetNativeWindowHandle()
338 Any Adaptor::GetNativeWindowHandle(Actor actor)
340 return GetNativeWindowHandle();
343 void Adaptor::ReleaseSurfaceLock()
347 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
351 Adaptor& Adaptor::Get()
353 return Internal::Adaptor::Adaptor::Get();
356 bool Adaptor::IsAvailable()
358 return Internal::Adaptor::gAdaptor && (!Internal::Adaptor::Adaptor::GetImpl(*Internal::Adaptor::gAdaptor).IsStopped());
361 void Adaptor::NotifySceneCreated()
365 void Adaptor::NotifyLanguageChanged()
369 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
373 void Adaptor::FeedWheelEvent(WheelEvent& wheelEvent)
377 void Adaptor::FeedKeyEvent(KeyEvent& keyEvent)
381 void Adaptor::SceneCreated()
385 class LogFactory : public LogFactoryInterface
388 virtual void InstallLogFunction() const
390 Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
391 Dali::Integration::Log::InstallLogFunction(logFunction);
397 virtual ~LogFactory()
402 LogFactory* gLogFactory = NULL;
403 const LogFactoryInterface& Adaptor::GetLogFactory()
405 if(gLogFactory == NULL)
407 gLogFactory = new LogFactory;
412 class TraceFactory : public TraceFactoryInterface
415 virtual void InstallTraceFunction() const
417 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
418 Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
424 virtual ~TraceFactory()
429 TraceFactory* gTraceFactory = NULL;
430 const TraceFactoryInterface& Adaptor::GetTraceFactory()
432 if(gTraceFactory == NULL)
434 gTraceFactory = new TraceFactory;
436 return *gTraceFactory;
439 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
441 mImpl->RegisterProcessor(processor, postProcessor);
444 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
446 mImpl->UnregisterProcessor(processor, postProcessor);