2 * Copyright (c) 2021 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 <toolkit-scene-holder-impl.h>
28 #include <toolkit-adaptor-impl.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/integration-api/scene.h>
31 #include <test-application.h>
32 #include <toolkit-test-application.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 );
72 void Adaptor::Start( Dali::Window window )
74 AddWindow( &GetImplementation( window ) );
77 Integration::Scene Adaptor::GetScene( Dali::Window window )
79 return window.GetScene();
82 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
84 mCallbacks.PushBack( callback );
88 void Adaptor::RemoveIdle( CallbackBase* callback )
90 mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
91 [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
94 void Adaptor::RunIdles()
96 for( auto& callback : mCallbacks )
98 CallbackBase::Execute( *callback );
104 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
106 DALI_ASSERT_ALWAYS( ! mWindows.empty() );
108 return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
111 Dali::WindowContainer Adaptor::GetWindows()
113 Dali::WindowContainer windows;
115 for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
117 // Downcast to Dali::Window
118 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
121 windows.push_back( window );
128 Dali::SceneHolderList Adaptor::GetSceneHolders()
130 Dali::SceneHolderList sceneHolderList;
132 for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
134 sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
137 return sceneHolderList;
140 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
142 Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
144 for( auto window : mWindows )
146 if ( scene == window->GetScene() )
155 void Adaptor::AddWindow( Internal::Adaptor::SceneHolder* window )
159 mWindows.push_back( window );
161 Dali::Integration::SceneHolder newWindow( window );
162 mWindowCreatedSignal.Emit( newWindow );
166 void Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* window )
168 auto iter = std::find( mWindows.begin(), mWindows.end(), window );
169 if( iter != mWindows.end() )
171 mWindows.erase( iter );
175 void Adaptor::RegisterProcessor( Integration::Processor& processor, bool postProcessor )
177 Integration::Core& core = mTestApplication->GetCore();
178 core.RegisterProcessor( processor, postProcessor );
181 void Adaptor::UnregisterProcessor( Integration::Processor& processor, bool postProcessor )
183 Integration::Core& core = mTestApplication->GetCore();
184 core.UnregisterProcessor( processor, postProcessor );
187 void Adaptor::SetApplication( Dali::TestApplication& testApplication )
189 mTestApplication = &testApplication;
192 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
194 return mResizedSignal;
197 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
199 return mLanguageChangedSignal;
202 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
204 return mWindowCreatedSignal;
207 } // namespace Adaptor
208 } // namespace Internal
210 ///////////////////////////////////////////////////////////////////////////////
212 // Dali::Adaptor Stub
214 ///////////////////////////////////////////////////////////////////////////////
217 : mImpl( new Internal::Adaptor::Adaptor )
223 Internal::Adaptor::gAdaptor = nullptr;
227 void Adaptor::Start()
231 void Adaptor::Pause()
235 void Adaptor::Resume()
243 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
245 return mImpl->AddIdle( callback, hasReturnValue );
248 void Adaptor::RemoveIdle( CallbackBase* callback )
250 mImpl->RemoveIdle( callback );
253 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
257 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
261 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
263 return mImpl->ResizedSignal();
266 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
268 return mImpl->LanguageChangedSignal();
271 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
273 return mImpl->WindowCreatedSignal();
276 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
278 return mImpl->GetSurface();
281 Dali::WindowContainer Adaptor::GetWindows() const
283 return mImpl->GetWindows();
286 Dali::SceneHolderList Adaptor::GetSceneHolders() const
288 return mImpl->GetSceneHolders();
291 Any Adaptor::GetNativeWindowHandle()
297 Any Adaptor::GetNativeWindowHandle( Actor actor )
299 return GetNativeWindowHandle();
302 void Adaptor::ReleaseSurfaceLock()
306 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
310 Adaptor& Adaptor::Get()
312 return Internal::Adaptor::Adaptor::Get();
315 bool Adaptor::IsAvailable()
317 return Internal::Adaptor::gAdaptor;
320 void Adaptor::NotifySceneCreated()
324 void Adaptor::NotifyLanguageChanged()
328 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
332 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
336 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
340 void Adaptor::SceneCreated()
344 class LogFactory : public LogFactoryInterface
347 virtual void InstallLogFunction() const
349 Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
350 Dali::Integration::Log::InstallLogFunction(logFunction);
356 virtual ~LogFactory()
361 LogFactory* gLogFactory = NULL;
362 const LogFactoryInterface& Adaptor::GetLogFactory()
364 if( gLogFactory == NULL )
366 gLogFactory = new LogFactory;
371 void Adaptor::RegisterProcessor( Integration::Processor& processor, bool postProcessor)
373 mImpl->RegisterProcessor( processor, postProcessor );
376 void Adaptor::UnregisterProcessor( Integration::Processor& processor, bool postProcessor)
378 mImpl->UnregisterProcessor( processor, postProcessor );