2 * Copyright (c) 2019 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/adaptors/adaptor.h>
26 #include <dali/integration-api/adaptors/scene-holder.h>
27 #include <toolkit-scene-holder-impl.h>
29 #include <toolkit-adaptor-impl.h>
30 #include <dali/integration-api/debug.h>
31 #include <dali/integration-api/scene.h>
32 #include <test-application.h>
33 #include <test-render-surface.h>
41 ///////////////////////////////////////////////////////////////////////////////
45 ///////////////////////////////////////////////////////////////////////////////
47 class LogFactory : public LogFactoryInterface
50 LogFactory() = default;
51 virtual ~LogFactory() = default;
54 void InstallLogFunction() const override
56 Dali::Integration::Log::InstallLogFunction( &TestApplication::LogMessage );
59 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.
67 ///////////////////////////////////////////////////////////////////////////////
69 // Dali::Internal::Adaptor::Adaptor Stub
71 ///////////////////////////////////////////////////////////////////////////////
73 Dali::Adaptor* gAdaptor = nullptr;
75 Dali::Adaptor& Adaptor::New()
77 DALI_ASSERT_ALWAYS( ! gAdaptor );
78 gAdaptor = new Dali::Adaptor;
82 Dali::Adaptor& Adaptor::Get()
84 DALI_ASSERT_ALWAYS( gAdaptor );
97 void Adaptor::Start( Dali::Window window )
99 AddWindow( &GetImplementation( window ) );
102 Integration::Scene Adaptor::GetScene( Dali::Window window )
104 return window.GetScene();
107 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
109 mCallbacks.PushBack( callback );
113 void Adaptor::RemoveIdle( CallbackBase* callback )
115 mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
116 [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
119 void Adaptor::RunIdles()
121 for( auto& callback : mCallbacks )
123 CallbackBase::Execute( *callback );
129 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
131 DALI_ASSERT_ALWAYS( ! mWindows.empty() );
133 return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
136 Dali::WindowContainer Adaptor::GetWindows()
138 Dali::WindowContainer windows;
140 for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
142 // Downcast to Dali::Window
143 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
146 windows.push_back( window );
153 Dali::SceneHolderList Adaptor::GetSceneHolders()
155 Dali::SceneHolderList sceneHolderList;
157 for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
159 sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
162 return sceneHolderList;
165 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
167 Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
169 for( auto window : mWindows )
171 if ( scene == window->GetScene() )
180 void Adaptor::AddWindow( Internal::Adaptor::SceneHolder* window )
184 mWindows.push_back( window );
186 Dali::Integration::SceneHolder newWindow( window );
187 mWindowCreatedSignal.Emit( newWindow );
191 void Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* window )
193 auto iter = std::find( mWindows.begin(), mWindows.end(), window );
194 if( iter != mWindows.end() )
196 mWindows.erase( iter );
200 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
202 return mResizedSignal;
205 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
207 return mLanguageChangedSignal;
210 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
212 return mWindowCreatedSignal;
215 } // namespace Adaptor
216 } // namespace Internal
218 ///////////////////////////////////////////////////////////////////////////////
220 // Dali::Adaptor Stub
222 ///////////////////////////////////////////////////////////////////////////////
225 : mImpl( new Internal::Adaptor::Adaptor )
231 Internal::Adaptor::gAdaptor = nullptr;
235 void Adaptor::Start()
239 void Adaptor::Pause()
243 void Adaptor::Resume()
251 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
253 return mImpl->AddIdle( callback, hasReturnValue );
256 void Adaptor::RemoveIdle( CallbackBase* callback )
258 mImpl->RemoveIdle( callback );
261 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
265 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
269 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
271 return mImpl->ResizedSignal();
274 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
276 return mImpl->LanguageChangedSignal();
279 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
281 return mImpl->WindowCreatedSignal();
284 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
286 return mImpl->GetSurface();
289 Dali::WindowContainer Adaptor::GetWindows() const
291 return mImpl->GetWindows();
294 Dali::SceneHolderList Adaptor::GetSceneHolders() const
296 return mImpl->GetSceneHolders();
299 Any Adaptor::GetNativeWindowHandle()
305 Any Adaptor::GetNativeWindowHandle( Actor actor )
307 return GetNativeWindowHandle();
310 void Adaptor::ReleaseSurfaceLock()
314 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
318 Adaptor& Adaptor::Get()
320 return Internal::Adaptor::Adaptor::Get();
323 bool Adaptor::IsAvailable()
325 return Internal::Adaptor::gAdaptor;
328 void Adaptor::NotifySceneCreated()
332 void Adaptor::NotifyLanguageChanged()
336 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
340 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
344 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
348 void Adaptor::SceneCreated()
352 const LogFactoryInterface& Adaptor::GetLogFactory()
354 if( gLogFactory == NULL )
356 gLogFactory = new LogFactory;