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 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
200 return mResizedSignal;
203 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
205 return mLanguageChangedSignal;
208 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
210 return mWindowCreatedSignal;
213 } // namespace Adaptor
214 } // namespace Internal
216 ///////////////////////////////////////////////////////////////////////////////
218 // Dali::Adaptor Stub
220 ///////////////////////////////////////////////////////////////////////////////
223 : mImpl( new Internal::Adaptor::Adaptor )
229 Internal::Adaptor::gAdaptor = nullptr;
233 void Adaptor::Start()
237 void Adaptor::Pause()
241 void Adaptor::Resume()
249 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
251 return mImpl->AddIdle( callback, hasReturnValue );
254 void Adaptor::RemoveIdle( CallbackBase* callback )
256 mImpl->RemoveIdle( callback );
259 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
263 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
267 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
269 return mImpl->ResizedSignal();
272 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
274 return mImpl->LanguageChangedSignal();
277 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
279 return mImpl->WindowCreatedSignal();
282 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
284 return mImpl->GetSurface();
287 Dali::WindowContainer Adaptor::GetWindows() const
289 return mImpl->GetWindows();
292 Dali::SceneHolderList Adaptor::GetSceneHolders() const
294 return mImpl->GetSceneHolders();
297 Any Adaptor::GetNativeWindowHandle()
303 Any Adaptor::GetNativeWindowHandle( Actor actor )
305 return GetNativeWindowHandle();
308 void Adaptor::ReleaseSurfaceLock()
312 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
316 Adaptor& Adaptor::Get()
318 return Internal::Adaptor::Adaptor::Get();
321 bool Adaptor::IsAvailable()
323 return Internal::Adaptor::gAdaptor;
326 void Adaptor::NotifySceneCreated()
330 void Adaptor::NotifyLanguageChanged()
334 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
338 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
342 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
346 void Adaptor::SceneCreated()
350 const LogFactoryInterface& Adaptor::GetLogFactory()
352 if( gLogFactory == NULL )
354 gLogFactory = new LogFactory;