2 * Copyright (c) 2023 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-async-task-manager.h>
32 #include <toolkit-scene-holder-impl.h>
33 #include <toolkit-test-application.h>
34 #include "dali-test-suite-utils.h"
42 ///////////////////////////////////////////////////////////////////////////////
44 // Dali::Internal::Adaptor::Adaptor Stub
46 ///////////////////////////////////////////////////////////////////////////////
48 Dali::Adaptor* gAdaptor = nullptr;
50 Dali::Adaptor& Adaptor::New()
52 DALI_ASSERT_ALWAYS(!gAdaptor);
53 gAdaptor = new Dali::Adaptor;
57 Dali::Adaptor& Adaptor::Get()
59 DALI_ASSERT_ALWAYS(gAdaptor);
71 // Ensure all threads and not-excuted tasks are destroyed.
72 // TODO : we'd better make some singletone service for toolkit UTC in future.
73 Test::AsyncTaskManager::DestroyAsyncTaskManager();
76 void Adaptor::Start(Dali::Window window)
78 AddWindow(&GetImplementation(window));
81 Integration::Scene Adaptor::GetScene(Dali::Window window)
83 return window.GetScene();
86 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
90 mReturnCallbacks.PushBack(callback);
94 mCallbacks.PushBack(callback);
99 void Adaptor::RemoveIdle(CallbackBase* callback)
101 mCallbacks.Erase(std::remove_if(mCallbacks.Begin(), mCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mCallbacks.End());
102 mReturnCallbacks.Erase(std::remove_if(mReturnCallbacks.Begin(), mReturnCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mReturnCallbacks.End());
105 void Adaptor::RunIdles()
107 Dali::Vector<CallbackBase*> reusedCallbacks;
108 for(auto& callback : mReturnCallbacks)
110 bool retValue = CallbackBase::ExecuteReturn<bool>(*callback);
113 reusedCallbacks.PushBack(callback);
116 for(auto& callback : mCallbacks)
118 CallbackBase::Execute(*callback);
122 mReturnCallbacks.Clear();
123 mReturnCallbacks.Swap(reusedCallbacks);
126 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
128 DALI_ASSERT_ALWAYS(!mWindows.empty());
130 return reinterpret_cast<Dali::RenderSurfaceInterface&>(mWindows.front()->GetRenderSurface());
133 Dali::WindowContainer Adaptor::GetWindows()
135 Dali::WindowContainer windows;
137 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
139 // Downcast to Dali::Window
140 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
143 windows.push_back(window);
150 Dali::SceneHolderList Adaptor::GetSceneHolders()
152 Dali::SceneHolderList sceneHolderList;
154 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
156 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
159 return sceneHolderList;
162 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
164 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
166 for(auto window : mWindows)
168 if(scene == window->GetScene())
177 void Adaptor::AddWindow(Internal::Adaptor::SceneHolder* window)
181 mWindows.push_back(window);
183 Dali::Integration::SceneHolder newWindow(window);
184 mWindowCreatedSignal.Emit(newWindow);
188 void Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* window)
190 auto iter = std::find(mWindows.begin(), mWindows.end(), window);
191 if(iter != mWindows.end())
193 mWindows.erase(iter);
197 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
199 Integration::Core& core = mTestApplication->GetCore();
200 tet_printf("Adaptor::RegisterProcessor : %s\n", processor.GetProcessorName().data());
201 core.RegisterProcessor(processor, postProcessor);
204 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
206 Integration::Core& core = mTestApplication->GetCore();
207 tet_printf("Adaptor::UnregisterProcessor : %s\n", processor.GetProcessorName().data());
208 core.UnregisterProcessor(processor, postProcessor);
211 void Adaptor::SetApplication(Dali::TestApplication& testApplication)
213 mTestApplication = &testApplication;
216 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
218 return mResizedSignal;
221 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
223 return mLanguageChangedSignal;
226 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
228 return mWindowCreatedSignal;
231 } // namespace Adaptor
232 } // namespace Internal
234 ///////////////////////////////////////////////////////////////////////////////
236 // Dali::Adaptor Stub
238 ///////////////////////////////////////////////////////////////////////////////
241 : mImpl(new Internal::Adaptor::Adaptor)
247 Internal::Adaptor::gAdaptor = nullptr;
251 void Adaptor::Start()
255 void Adaptor::Pause()
259 void Adaptor::Resume()
267 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
269 return mImpl->AddIdle(callback, hasReturnValue);
272 void Adaptor::RemoveIdle(CallbackBase* callback)
274 mImpl->RemoveIdle(callback);
277 void Adaptor::ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface)
281 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface)
285 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
287 return mImpl->ResizedSignal();
290 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
292 return mImpl->LanguageChangedSignal();
295 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
297 return mImpl->WindowCreatedSignal();
300 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
302 return mImpl->GetSurface();
305 Dali::WindowContainer Adaptor::GetWindows() const
307 return mImpl->GetWindows();
310 Dali::SceneHolderList Adaptor::GetSceneHolders() const
312 return mImpl->GetSceneHolders();
315 Any Adaptor::GetNativeWindowHandle()
321 Any Adaptor::GetNativeWindowHandle(Actor actor)
323 return GetNativeWindowHandle();
326 void Adaptor::ReleaseSurfaceLock()
330 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
334 Adaptor& Adaptor::Get()
336 return Internal::Adaptor::Adaptor::Get();
339 bool Adaptor::IsAvailable()
341 return Internal::Adaptor::gAdaptor;
344 void Adaptor::NotifySceneCreated()
348 void Adaptor::NotifyLanguageChanged()
352 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
356 void Adaptor::FeedWheelEvent(WheelEvent& wheelEvent)
360 void Adaptor::FeedKeyEvent(KeyEvent& keyEvent)
364 void Adaptor::SceneCreated()
368 class LogFactory : public LogFactoryInterface
371 virtual void InstallLogFunction() const
373 Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
374 Dali::Integration::Log::InstallLogFunction(logFunction);
380 virtual ~LogFactory()
385 LogFactory* gLogFactory = NULL;
386 const LogFactoryInterface& Adaptor::GetLogFactory()
388 if(gLogFactory == NULL)
390 gLogFactory = new LogFactory;
395 class TraceFactory : public TraceFactoryInterface
398 virtual void InstallTraceFunction() const
400 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
401 Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
407 virtual ~TraceFactory()
412 TraceFactory* gTraceFactory = NULL;
413 const TraceFactoryInterface& Adaptor::GetTraceFactory()
415 if(gTraceFactory == NULL)
417 gTraceFactory = new TraceFactory;
419 return *gTraceFactory;
422 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
424 mImpl->RegisterProcessor(processor, postProcessor);
427 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
429 mImpl->UnregisterProcessor(processor, postProcessor);