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)
82 mCallbacks.PushBack(callback);
86 void Adaptor::RemoveIdle(CallbackBase* callback)
88 mCallbacks.Erase(std::find_if(mCallbacks.Begin(), mCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }));
91 void Adaptor::RunIdles()
93 for(auto& callback : mCallbacks)
95 CallbackBase::Execute(*callback);
101 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
103 DALI_ASSERT_ALWAYS(!mWindows.empty());
105 return reinterpret_cast<Dali::RenderSurfaceInterface&>(mWindows.front()->GetRenderSurface());
108 Dali::WindowContainer Adaptor::GetWindows()
110 Dali::WindowContainer windows;
112 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
114 // Downcast to Dali::Window
115 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
118 windows.push_back(window);
125 Dali::SceneHolderList Adaptor::GetSceneHolders()
127 Dali::SceneHolderList sceneHolderList;
129 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
131 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
134 return sceneHolderList;
137 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
139 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
141 for(auto window : mWindows)
143 if(scene == window->GetScene())
152 void Adaptor::AddWindow(Internal::Adaptor::SceneHolder* window)
156 mWindows.push_back(window);
158 Dali::Integration::SceneHolder newWindow(window);
159 mWindowCreatedSignal.Emit(newWindow);
163 void Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* window)
165 auto iter = std::find(mWindows.begin(), mWindows.end(), window);
166 if(iter != mWindows.end())
168 mWindows.erase(iter);
172 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
174 Integration::Core& core = mTestApplication->GetCore();
175 core.RegisterProcessor(processor, postProcessor);
178 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
180 Integration::Core& core = mTestApplication->GetCore();
181 core.UnregisterProcessor(processor, postProcessor);
184 void Adaptor::SetApplication(Dali::TestApplication& testApplication)
186 mTestApplication = &testApplication;
189 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
191 return mResizedSignal;
194 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
196 return mLanguageChangedSignal;
199 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
201 return mWindowCreatedSignal;
204 } // namespace Adaptor
205 } // namespace Internal
207 ///////////////////////////////////////////////////////////////////////////////
209 // Dali::Adaptor Stub
211 ///////////////////////////////////////////////////////////////////////////////
214 : mImpl(new Internal::Adaptor::Adaptor)
220 Internal::Adaptor::gAdaptor = nullptr;
224 void Adaptor::Start()
228 void Adaptor::Pause()
232 void Adaptor::Resume()
240 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
242 return mImpl->AddIdle(callback, hasReturnValue);
245 void Adaptor::RemoveIdle(CallbackBase* callback)
247 mImpl->RemoveIdle(callback);
250 void Adaptor::ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface)
254 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface)
258 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
260 return mImpl->ResizedSignal();
263 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
265 return mImpl->LanguageChangedSignal();
268 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
270 return mImpl->WindowCreatedSignal();
273 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
275 return mImpl->GetSurface();
278 Dali::WindowContainer Adaptor::GetWindows() const
280 return mImpl->GetWindows();
283 Dali::SceneHolderList Adaptor::GetSceneHolders() const
285 return mImpl->GetSceneHolders();
288 Any Adaptor::GetNativeWindowHandle()
294 Any Adaptor::GetNativeWindowHandle(Actor actor)
296 return GetNativeWindowHandle();
299 void Adaptor::ReleaseSurfaceLock()
303 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
307 Adaptor& Adaptor::Get()
309 return Internal::Adaptor::Adaptor::Get();
312 bool Adaptor::IsAvailable()
314 return Internal::Adaptor::gAdaptor;
317 void Adaptor::NotifySceneCreated()
321 void Adaptor::NotifyLanguageChanged()
325 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
329 void Adaptor::FeedWheelEvent(WheelEvent& wheelEvent)
333 void Adaptor::FeedKeyEvent(KeyEvent& keyEvent)
337 void Adaptor::SceneCreated()
341 class LogFactory : public LogFactoryInterface
344 virtual void InstallLogFunction() const
346 Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
347 Dali::Integration::Log::InstallLogFunction(logFunction);
353 virtual ~LogFactory()
358 LogFactory* gLogFactory = NULL;
359 const LogFactoryInterface& Adaptor::GetLogFactory()
361 if(gLogFactory == NULL)
363 gLogFactory = new LogFactory;
368 class TraceFactory : public TraceFactoryInterface
371 virtual void InstallTraceFunction() const
373 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
374 Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
380 virtual ~TraceFactory()
385 TraceFactory* gTraceFactory = NULL;
386 const TraceFactoryInterface& Adaptor::GetTraceFactory()
388 if(gTraceFactory == NULL)
390 gTraceFactory = new TraceFactory;
392 return *gTraceFactory;
395 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
397 mImpl->RegisterProcessor(processor, postProcessor);
400 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
402 mImpl->UnregisterProcessor(processor, postProcessor);