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));
82 Integration::Scene Adaptor::GetScene(Dali::Window window)
84 return window.GetScene();
87 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
89 if(ToolkitApplication::ADD_IDLE_SUCCESS)
93 mReturnCallbacks.PushBack(callback);
97 mCallbacks.PushBack(callback);
100 return ToolkitApplication::ADD_IDLE_SUCCESS;
103 void Adaptor::RemoveIdle(CallbackBase* callback)
105 mCallbacks.Erase(std::remove_if(mCallbacks.Begin(), mCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mCallbacks.End());
106 mReturnCallbacks.Erase(std::remove_if(mReturnCallbacks.Begin(), mReturnCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mReturnCallbacks.End());
109 void Adaptor::RunIdles()
111 Dali::Vector<CallbackBase*> reusedCallbacks;
112 for(auto& callback : mReturnCallbacks)
114 bool retValue = CallbackBase::ExecuteReturn<bool>(*callback);
117 reusedCallbacks.PushBack(callback);
120 for(auto& callback : mCallbacks)
122 CallbackBase::Execute(*callback);
126 mReturnCallbacks.Clear();
127 mReturnCallbacks.Swap(reusedCallbacks);
130 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
132 DALI_ASSERT_ALWAYS(!mWindows.empty());
134 return reinterpret_cast<Dali::RenderSurfaceInterface&>(mWindows.front()->GetRenderSurface());
137 Dali::WindowContainer Adaptor::GetWindows()
139 Dali::WindowContainer windows;
141 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
143 // Downcast to Dali::Window
144 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
147 windows.push_back(window);
154 Dali::SceneHolderList Adaptor::GetSceneHolders()
156 Dali::SceneHolderList sceneHolderList;
158 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
160 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
163 return sceneHolderList;
166 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
168 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
170 for(auto window : mWindows)
172 if(scene == window->GetScene())
181 void Adaptor::AddWindow(Internal::Adaptor::SceneHolder* window)
185 mWindows.push_back(window);
187 Dali::Integration::SceneHolder newWindow(window);
188 mWindowCreatedSignal.Emit(newWindow);
192 void Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* window)
194 auto iter = std::find(mWindows.begin(), mWindows.end(), window);
195 if(iter != mWindows.end())
197 mWindows.erase(iter);
201 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
203 Integration::Core& core = mTestApplication->GetCore();
204 tet_printf("Adaptor::RegisterProcessor : %s\n", processor.GetProcessorName().data());
205 core.RegisterProcessor(processor, postProcessor);
208 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
210 Integration::Core& core = mTestApplication->GetCore();
211 tet_printf("Adaptor::UnregisterProcessor : %s\n", processor.GetProcessorName().data());
212 core.UnregisterProcessor(processor, postProcessor);
215 void Adaptor::SetApplication(Dali::TestApplication& testApplication)
217 mTestApplication = &testApplication;
220 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
222 return mResizedSignal;
225 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
227 return mLanguageChangedSignal;
230 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
232 return mWindowCreatedSignal;
235 } // namespace Adaptor
236 } // namespace Internal
238 ///////////////////////////////////////////////////////////////////////////////
240 // Dali::Adaptor Stub
242 ///////////////////////////////////////////////////////////////////////////////
245 : mImpl(new Internal::Adaptor::Adaptor)
251 Internal::Adaptor::gAdaptor = nullptr;
255 void Adaptor::Start()
259 void Adaptor::Pause()
263 void Adaptor::Resume()
271 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
273 return mImpl->AddIdle(callback, hasReturnValue);
276 void Adaptor::RemoveIdle(CallbackBase* callback)
278 mImpl->RemoveIdle(callback);
281 void Adaptor::ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface)
285 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface)
289 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
291 return mImpl->ResizedSignal();
294 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
296 return mImpl->LanguageChangedSignal();
299 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
301 return mImpl->WindowCreatedSignal();
304 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
306 return mImpl->GetSurface();
309 Dali::WindowContainer Adaptor::GetWindows() const
311 return mImpl->GetWindows();
314 Dali::SceneHolderList Adaptor::GetSceneHolders() const
316 return mImpl->GetSceneHolders();
319 Any Adaptor::GetNativeWindowHandle()
325 Any Adaptor::GetNativeWindowHandle(Actor actor)
327 return GetNativeWindowHandle();
330 void Adaptor::ReleaseSurfaceLock()
334 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
338 Adaptor& Adaptor::Get()
340 return Internal::Adaptor::Adaptor::Get();
343 bool Adaptor::IsAvailable()
345 return Internal::Adaptor::gAdaptor;
348 void Adaptor::NotifySceneCreated()
352 void Adaptor::NotifyLanguageChanged()
356 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
360 void Adaptor::FeedWheelEvent(WheelEvent& wheelEvent)
364 void Adaptor::FeedKeyEvent(KeyEvent& keyEvent)
368 void Adaptor::SceneCreated()
372 class LogFactory : public LogFactoryInterface
375 virtual void InstallLogFunction() const
377 Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
378 Dali::Integration::Log::InstallLogFunction(logFunction);
384 virtual ~LogFactory()
389 LogFactory* gLogFactory = NULL;
390 const LogFactoryInterface& Adaptor::GetLogFactory()
392 if(gLogFactory == NULL)
394 gLogFactory = new LogFactory;
399 class TraceFactory : public TraceFactoryInterface
402 virtual void InstallTraceFunction() const
404 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
405 Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
411 virtual ~TraceFactory()
416 TraceFactory* gTraceFactory = NULL;
417 const TraceFactoryInterface& Adaptor::GetTraceFactory()
419 if(gTraceFactory == NULL)
421 gTraceFactory = new TraceFactory;
423 return *gTraceFactory;
426 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
428 mImpl->RegisterProcessor(processor, postProcessor);
431 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
433 mImpl->UnregisterProcessor(processor, postProcessor);