2 * Copyright (c) 2020 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>
39 ///////////////////////////////////////////////////////////////////////////////
43 ///////////////////////////////////////////////////////////////////////////////
45 class LogFactory : public LogFactoryInterface
48 LogFactory() = default;
49 virtual ~LogFactory() = default;
52 void InstallLogFunction() const override
54 Dali::Integration::Log::InstallLogFunction( &TestApplication::LogMessage );
57 LogFactory* gLogFactory = NULL; // For some reason, destroying this when the Adaptor is destroyed causes a crash in some test cases when running all of them.
65 ///////////////////////////////////////////////////////////////////////////////
67 // Dali::Internal::Adaptor::Adaptor Stub
69 ///////////////////////////////////////////////////////////////////////////////
71 Dali::Adaptor* gAdaptor = nullptr;
73 Dali::Adaptor& Adaptor::New()
75 DALI_ASSERT_ALWAYS( ! gAdaptor );
76 gAdaptor = new Dali::Adaptor;
80 Dali::Adaptor& Adaptor::Get()
82 DALI_ASSERT_ALWAYS( gAdaptor );
95 void Adaptor::Start( Dali::Window window )
97 AddWindow( &GetImplementation( window ) );
100 Integration::Scene Adaptor::GetScene( Dali::Window window )
102 return window.GetScene();
105 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
107 mCallbacks.PushBack( callback );
111 void Adaptor::RemoveIdle( CallbackBase* callback )
113 mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
114 [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
117 void Adaptor::RunIdles()
119 for( auto& callback : mCallbacks )
121 CallbackBase::Execute( *callback );
127 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
129 DALI_ASSERT_ALWAYS( ! mWindows.empty() );
131 return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
134 Dali::WindowContainer Adaptor::GetWindows()
136 Dali::WindowContainer windows;
138 for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
140 // Downcast to Dali::Window
141 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
144 windows.push_back( window );
151 Dali::SceneHolderList Adaptor::GetSceneHolders()
153 Dali::SceneHolderList sceneHolderList;
155 for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
157 sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
160 return sceneHolderList;
163 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
165 Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
167 for( auto window : mWindows )
169 if ( scene == window->GetScene() )
178 void Adaptor::AddWindow( Internal::Adaptor::SceneHolder* window )
182 mWindows.push_back( window );
184 Dali::Integration::SceneHolder newWindow( window );
185 mWindowCreatedSignal.Emit( newWindow );
189 void Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* window )
191 auto iter = std::find( mWindows.begin(), mWindows.end(), window );
192 if( iter != mWindows.end() )
194 mWindows.erase( iter );
198 void Adaptor::RegisterProcessor( Integration::Processor& processor )
200 Integration::Core& core = mTestApplication->GetCore();
201 core.RegisterProcessor( processor );
204 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
206 Integration::Core& core = mTestApplication->GetCore();
207 core.UnregisterProcessor( processor );
210 void Adaptor::SetApplication( Dali::TestApplication& testApplication )
212 mTestApplication = &testApplication;
215 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
217 return mResizedSignal;
220 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
222 return mLanguageChangedSignal;
225 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
227 return mWindowCreatedSignal;
230 } // namespace Adaptor
231 } // namespace Internal
233 ///////////////////////////////////////////////////////////////////////////////
235 // Dali::Adaptor Stub
237 ///////////////////////////////////////////////////////////////////////////////
240 : mImpl( new Internal::Adaptor::Adaptor )
246 Internal::Adaptor::gAdaptor = nullptr;
250 void Adaptor::Start()
254 void Adaptor::Pause()
258 void Adaptor::Resume()
266 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
268 return mImpl->AddIdle( callback, hasReturnValue );
271 void Adaptor::RemoveIdle( CallbackBase* callback )
273 mImpl->RemoveIdle( callback );
276 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
280 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
284 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
286 return mImpl->ResizedSignal();
289 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
291 return mImpl->LanguageChangedSignal();
294 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
296 return mImpl->WindowCreatedSignal();
299 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
301 return mImpl->GetSurface();
304 Dali::WindowContainer Adaptor::GetWindows() const
306 return mImpl->GetWindows();
309 Dali::SceneHolderList Adaptor::GetSceneHolders() const
311 return mImpl->GetSceneHolders();
314 Any Adaptor::GetNativeWindowHandle()
320 Any Adaptor::GetNativeWindowHandle( Actor actor )
322 return GetNativeWindowHandle();
325 void Adaptor::ReleaseSurfaceLock()
329 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
333 Adaptor& Adaptor::Get()
335 return Internal::Adaptor::Adaptor::Get();
338 bool Adaptor::IsAvailable()
340 return Internal::Adaptor::gAdaptor;
343 void Adaptor::NotifySceneCreated()
347 void Adaptor::NotifyLanguageChanged()
351 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
355 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
359 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
363 void Adaptor::SceneCreated()
367 const LogFactoryInterface& Adaptor::GetLogFactory()
369 if( gLogFactory == NULL )
371 gLogFactory = new LogFactory;
376 void Adaptor::RegisterProcessor( Integration::Processor& processor )
378 mImpl->RegisterProcessor( processor );
381 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
383 mImpl->UnregisterProcessor( processor );