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>
41 ///////////////////////////////////////////////////////////////////////////////
43 // Dali::Internal::Adaptor::Adaptor Stub
45 ///////////////////////////////////////////////////////////////////////////////
47 Dali::Adaptor* gAdaptor = nullptr;
49 Dali::Adaptor& Adaptor::New()
51 DALI_ASSERT_ALWAYS(!gAdaptor);
52 gAdaptor = new Dali::Adaptor;
56 Dali::Adaptor& Adaptor::Get()
58 DALI_ASSERT_ALWAYS(gAdaptor);
70 // Ensure all threads and not-excuted tasks are destroyed.
71 // TODO : we'd better make some singletone service for toolkit UTC in future.
72 Test::AsyncTaskManager::DestroyAsyncTaskManager();
75 void Adaptor::Start(Dali::Window window)
77 AddWindow(&GetImplementation(window));
80 Integration::Scene Adaptor::GetScene(Dali::Window window)
82 return window.GetScene();
85 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
89 mReturnCallbacks.PushBack(callback);
93 mCallbacks.PushBack(callback);
98 void Adaptor::RemoveIdle(CallbackBase* callback)
100 mCallbacks.Erase(std::remove_if(mCallbacks.Begin(), mCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mCallbacks.End());
101 mReturnCallbacks.Erase(std::remove_if(mReturnCallbacks.Begin(), mReturnCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mReturnCallbacks.End());
104 void Adaptor::RunIdles()
106 Dali::Vector<CallbackBase*> reusedCallbacks;
107 for(auto& callback : mReturnCallbacks)
109 bool retValue = CallbackBase::ExecuteReturn<bool>(*callback);
112 reusedCallbacks.PushBack(callback);
115 for(auto& callback : mCallbacks)
117 CallbackBase::Execute(*callback);
121 mReturnCallbacks.Clear();
122 mReturnCallbacks.Swap(reusedCallbacks);
125 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
127 DALI_ASSERT_ALWAYS(!mWindows.empty());
129 return reinterpret_cast<Dali::RenderSurfaceInterface&>(mWindows.front()->GetRenderSurface());
132 Dali::WindowContainer Adaptor::GetWindows()
134 Dali::WindowContainer windows;
136 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
138 // Downcast to Dali::Window
139 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
142 windows.push_back(window);
149 Dali::SceneHolderList Adaptor::GetSceneHolders()
151 Dali::SceneHolderList sceneHolderList;
153 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
155 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
158 return sceneHolderList;
161 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
163 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
165 for(auto window : mWindows)
167 if(scene == window->GetScene())
176 void Adaptor::AddWindow(Internal::Adaptor::SceneHolder* window)
180 mWindows.push_back(window);
182 Dali::Integration::SceneHolder newWindow(window);
183 mWindowCreatedSignal.Emit(newWindow);
187 void Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* window)
189 auto iter = std::find(mWindows.begin(), mWindows.end(), window);
190 if(iter != mWindows.end())
192 mWindows.erase(iter);
196 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
198 Integration::Core& core = mTestApplication->GetCore();
199 core.RegisterProcessor(processor, postProcessor);
202 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
204 Integration::Core& core = mTestApplication->GetCore();
205 core.UnregisterProcessor(processor, postProcessor);
208 void Adaptor::SetApplication(Dali::TestApplication& testApplication)
210 mTestApplication = &testApplication;
213 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
215 return mResizedSignal;
218 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
220 return mLanguageChangedSignal;
223 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
225 return mWindowCreatedSignal;
228 } // namespace Adaptor
229 } // namespace Internal
231 ///////////////////////////////////////////////////////////////////////////////
233 // Dali::Adaptor Stub
235 ///////////////////////////////////////////////////////////////////////////////
238 : mImpl(new Internal::Adaptor::Adaptor)
244 Internal::Adaptor::gAdaptor = nullptr;
248 void Adaptor::Start()
252 void Adaptor::Pause()
256 void Adaptor::Resume()
264 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
266 return mImpl->AddIdle(callback, hasReturnValue);
269 void Adaptor::RemoveIdle(CallbackBase* callback)
271 mImpl->RemoveIdle(callback);
274 void Adaptor::ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface)
278 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface)
282 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
284 return mImpl->ResizedSignal();
287 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
289 return mImpl->LanguageChangedSignal();
292 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
294 return mImpl->WindowCreatedSignal();
297 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
299 return mImpl->GetSurface();
302 Dali::WindowContainer Adaptor::GetWindows() const
304 return mImpl->GetWindows();
307 Dali::SceneHolderList Adaptor::GetSceneHolders() const
309 return mImpl->GetSceneHolders();
312 Any Adaptor::GetNativeWindowHandle()
318 Any Adaptor::GetNativeWindowHandle(Actor actor)
320 return GetNativeWindowHandle();
323 void Adaptor::ReleaseSurfaceLock()
327 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
331 Adaptor& Adaptor::Get()
333 return Internal::Adaptor::Adaptor::Get();
336 bool Adaptor::IsAvailable()
338 return Internal::Adaptor::gAdaptor;
341 void Adaptor::NotifySceneCreated()
345 void Adaptor::NotifyLanguageChanged()
349 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
353 void Adaptor::FeedWheelEvent(WheelEvent& wheelEvent)
357 void Adaptor::FeedKeyEvent(KeyEvent& keyEvent)
361 void Adaptor::SceneCreated()
365 class LogFactory : public LogFactoryInterface
368 virtual void InstallLogFunction() const
370 Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
371 Dali::Integration::Log::InstallLogFunction(logFunction);
377 virtual ~LogFactory()
382 LogFactory* gLogFactory = NULL;
383 const LogFactoryInterface& Adaptor::GetLogFactory()
385 if(gLogFactory == NULL)
387 gLogFactory = new LogFactory;
392 class TraceFactory : public TraceFactoryInterface
395 virtual void InstallTraceFunction() const
397 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
398 Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
404 virtual ~TraceFactory()
409 TraceFactory* gTraceFactory = NULL;
410 const TraceFactoryInterface& Adaptor::GetTraceFactory()
412 if(gTraceFactory == NULL)
414 gTraceFactory = new TraceFactory;
416 return *gTraceFactory;
419 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
421 mImpl->RegisterProcessor(processor, postProcessor);
424 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
426 mImpl->UnregisterProcessor(processor, postProcessor);