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-scene-holder-impl.h>
32 #include <toolkit-test-application.h>
40 ///////////////////////////////////////////////////////////////////////////////
42 // Dali::Internal::Adaptor::Adaptor Stub
44 ///////////////////////////////////////////////////////////////////////////////
46 Dali::Adaptor* gAdaptor = nullptr;
48 Dali::Adaptor& Adaptor::New()
50 DALI_ASSERT_ALWAYS(!gAdaptor);
51 gAdaptor = new Dali::Adaptor;
55 Dali::Adaptor& Adaptor::Get()
57 DALI_ASSERT_ALWAYS(gAdaptor);
70 void Adaptor::Start(Dali::Window window)
72 AddWindow(&GetImplementation(window));
75 Integration::Scene Adaptor::GetScene(Dali::Window window)
77 return window.GetScene();
80 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
84 mReturnCallbacks.PushBack(callback);
88 mCallbacks.PushBack(callback);
93 void Adaptor::RemoveIdle(CallbackBase* callback)
95 mCallbacks.Erase(std::remove_if(mCallbacks.Begin(), mCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mCallbacks.End());
96 mReturnCallbacks.Erase(std::remove_if(mReturnCallbacks.Begin(), mReturnCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mReturnCallbacks.End());
99 void Adaptor::RunIdles()
101 Dali::Vector<CallbackBase*> reusedCallbacks;
102 for(auto& callback : mReturnCallbacks)
104 bool retValue = CallbackBase::ExecuteReturn<bool>(*callback);
107 reusedCallbacks.PushBack(callback);
110 for(auto& callback : mCallbacks)
112 CallbackBase::Execute(*callback);
116 mReturnCallbacks.Clear();
117 mReturnCallbacks.Swap(reusedCallbacks);
120 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
122 DALI_ASSERT_ALWAYS(!mWindows.empty());
124 return reinterpret_cast<Dali::RenderSurfaceInterface&>(mWindows.front()->GetRenderSurface());
127 Dali::WindowContainer Adaptor::GetWindows()
129 Dali::WindowContainer windows;
131 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
133 // Downcast to Dali::Window
134 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
137 windows.push_back(window);
144 Dali::SceneHolderList Adaptor::GetSceneHolders()
146 Dali::SceneHolderList sceneHolderList;
148 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
150 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
153 return sceneHolderList;
156 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
158 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
160 for(auto window : mWindows)
162 if(scene == window->GetScene())
171 void Adaptor::AddWindow(Internal::Adaptor::SceneHolder* window)
175 mWindows.push_back(window);
177 Dali::Integration::SceneHolder newWindow(window);
178 mWindowCreatedSignal.Emit(newWindow);
182 void Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* window)
184 auto iter = std::find(mWindows.begin(), mWindows.end(), window);
185 if(iter != mWindows.end())
187 mWindows.erase(iter);
191 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
193 Integration::Core& core = mTestApplication->GetCore();
194 core.RegisterProcessor(processor, postProcessor);
197 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
199 Integration::Core& core = mTestApplication->GetCore();
200 core.UnregisterProcessor(processor, postProcessor);
203 void Adaptor::SetApplication(Dali::TestApplication& testApplication)
205 mTestApplication = &testApplication;
208 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
210 return mResizedSignal;
213 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
215 return mLanguageChangedSignal;
218 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
220 return mWindowCreatedSignal;
223 } // namespace Adaptor
224 } // namespace Internal
226 ///////////////////////////////////////////////////////////////////////////////
228 // Dali::Adaptor Stub
230 ///////////////////////////////////////////////////////////////////////////////
233 : mImpl(new Internal::Adaptor::Adaptor)
239 Internal::Adaptor::gAdaptor = nullptr;
243 void Adaptor::Start()
247 void Adaptor::Pause()
251 void Adaptor::Resume()
259 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
261 return mImpl->AddIdle(callback, hasReturnValue);
264 void Adaptor::RemoveIdle(CallbackBase* callback)
266 mImpl->RemoveIdle(callback);
269 void Adaptor::ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface)
273 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface)
277 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
279 return mImpl->ResizedSignal();
282 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
284 return mImpl->LanguageChangedSignal();
287 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
289 return mImpl->WindowCreatedSignal();
292 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
294 return mImpl->GetSurface();
297 Dali::WindowContainer Adaptor::GetWindows() const
299 return mImpl->GetWindows();
302 Dali::SceneHolderList Adaptor::GetSceneHolders() const
304 return mImpl->GetSceneHolders();
307 Any Adaptor::GetNativeWindowHandle()
313 Any Adaptor::GetNativeWindowHandle(Actor actor)
315 return GetNativeWindowHandle();
318 void Adaptor::ReleaseSurfaceLock()
322 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
326 Adaptor& Adaptor::Get()
328 return Internal::Adaptor::Adaptor::Get();
331 bool Adaptor::IsAvailable()
333 return Internal::Adaptor::gAdaptor;
336 void Adaptor::NotifySceneCreated()
340 void Adaptor::NotifyLanguageChanged()
344 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
348 void Adaptor::FeedWheelEvent(WheelEvent& wheelEvent)
352 void Adaptor::FeedKeyEvent(KeyEvent& keyEvent)
356 void Adaptor::SceneCreated()
360 class LogFactory : public LogFactoryInterface
363 virtual void InstallLogFunction() const
365 Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
366 Dali::Integration::Log::InstallLogFunction(logFunction);
372 virtual ~LogFactory()
377 LogFactory* gLogFactory = NULL;
378 const LogFactoryInterface& Adaptor::GetLogFactory()
380 if(gLogFactory == NULL)
382 gLogFactory = new LogFactory;
387 class TraceFactory : public TraceFactoryInterface
390 virtual void InstallTraceFunction() const
392 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
393 Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
399 virtual ~TraceFactory()
404 TraceFactory* gTraceFactory = NULL;
405 const TraceFactoryInterface& Adaptor::GetTraceFactory()
407 if(gTraceFactory == NULL)
409 gTraceFactory = new TraceFactory;
411 return *gTraceFactory;
414 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
416 mImpl->RegisterProcessor(processor, postProcessor);
419 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
421 mImpl->UnregisterProcessor(processor, postProcessor);