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::SetApplication(Dali::TestApplication& testApplication)
242 mTestApplication = &testApplication;
245 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
247 return mResizedSignal;
250 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
252 return mLanguageChangedSignal;
255 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
257 return mWindowCreatedSignal;
260 } // namespace Adaptor
261 } // namespace Internal
263 ///////////////////////////////////////////////////////////////////////////////
265 // Dali::Adaptor Stub
267 ///////////////////////////////////////////////////////////////////////////////
270 : mImpl(new Internal::Adaptor::Adaptor)
276 Internal::Adaptor::gAdaptor = nullptr;
280 void Adaptor::Start()
284 void Adaptor::Pause()
288 void Adaptor::Resume()
297 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
299 return mImpl->AddIdle(callback, hasReturnValue);
302 void Adaptor::RemoveIdle(CallbackBase* callback)
304 mImpl->RemoveIdle(callback);
307 void Adaptor::ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface)
311 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface)
315 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
317 return mImpl->ResizedSignal();
320 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
322 return mImpl->LanguageChangedSignal();
325 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
327 return mImpl->WindowCreatedSignal();
330 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
332 return mImpl->GetSurface();
335 Dali::WindowContainer Adaptor::GetWindows() const
337 return mImpl->GetWindows();
340 Dali::SceneHolderList Adaptor::GetSceneHolders() const
342 return mImpl->GetSceneHolders();
345 Any Adaptor::GetNativeWindowHandle()
351 Any Adaptor::GetNativeWindowHandle(Actor actor)
353 return GetNativeWindowHandle();
356 void Adaptor::ReleaseSurfaceLock()
360 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
364 Adaptor& Adaptor::Get()
366 return Internal::Adaptor::Adaptor::Get();
369 bool Adaptor::IsAvailable()
371 return Internal::Adaptor::gAdaptor && (!Internal::Adaptor::Adaptor::GetImpl(*Internal::Adaptor::gAdaptor).IsStopped());
374 void Adaptor::NotifySceneCreated()
378 void Adaptor::NotifyLanguageChanged()
382 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
386 void Adaptor::FeedWheelEvent(WheelEvent& wheelEvent)
390 void Adaptor::FeedKeyEvent(KeyEvent& keyEvent)
394 void Adaptor::SceneCreated()
398 class LogFactory : public LogFactoryInterface
401 virtual void InstallLogFunction() const
403 Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
404 Dali::Integration::Log::InstallLogFunction(logFunction);
410 virtual ~LogFactory()
415 LogFactory* gLogFactory = NULL;
416 const LogFactoryInterface& Adaptor::GetLogFactory()
418 if(gLogFactory == NULL)
420 gLogFactory = new LogFactory;
425 class TraceFactory : public TraceFactoryInterface
428 virtual void InstallTraceFunction() const
430 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
431 Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
437 virtual ~TraceFactory()
442 TraceFactory* gTraceFactory = NULL;
443 const TraceFactoryInterface& Adaptor::GetTraceFactory()
445 if(gTraceFactory == NULL)
447 gTraceFactory = new TraceFactory;
449 return *gTraceFactory;
452 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
454 mImpl->RegisterProcessor(processor, postProcessor);
457 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
459 mImpl->UnregisterProcessor(processor, postProcessor);