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/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 <test-render-surface.h>
40 ///////////////////////////////////////////////////////////////////////////////
44 ///////////////////////////////////////////////////////////////////////////////
46 class LogFactory : public LogFactoryInterface
49 LogFactory() = default;
50 virtual ~LogFactory() = default;
53 void InstallLogFunction() const override
55 Dali::Integration::Log::InstallLogFunction( &TestApplication::LogMessage );
58 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.
66 ///////////////////////////////////////////////////////////////////////////////
68 // Dali::Internal::Adaptor::Adaptor Stub
70 ///////////////////////////////////////////////////////////////////////////////
72 Dali::Adaptor* gAdaptor = nullptr;
74 Dali::Adaptor& Adaptor::New()
76 DALI_ASSERT_ALWAYS( ! gAdaptor );
77 gAdaptor = new Dali::Adaptor;
81 Dali::Adaptor& Adaptor::Get()
83 DALI_ASSERT_ALWAYS( gAdaptor );
96 void Adaptor::Start( Dali::Window window )
98 AddWindow( &GetImplementation( window ) );
101 Integration::Scene Adaptor::GetScene( Dali::Window window )
103 return window.GetScene();
106 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
108 mCallbacks.PushBack( callback );
112 void Adaptor::RemoveIdle( CallbackBase* callback )
114 mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
115 [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
118 void Adaptor::RunIdles()
120 for( auto& callback : mCallbacks )
122 CallbackBase::Execute( *callback );
128 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
130 DALI_ASSERT_ALWAYS( ! mWindows.empty() );
132 return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
135 Dali::WindowContainer Adaptor::GetWindows()
137 Dali::WindowContainer windows;
139 for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
141 // Downcast to Dali::Window
142 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
145 windows.push_back( window );
152 Dali::SceneHolderList Adaptor::GetSceneHolders()
154 Dali::SceneHolderList sceneHolderList;
156 for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
158 sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
161 return sceneHolderList;
164 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
166 Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
168 for( auto window : mWindows )
170 if ( scene == window->GetScene() )
179 void Adaptor::AddWindow( Internal::Adaptor::SceneHolder* window )
183 mWindows.push_back( window );
185 Dali::Integration::SceneHolder newWindow( window );
186 mWindowCreatedSignal.Emit( newWindow );
190 void Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* window )
192 auto iter = std::find( mWindows.begin(), mWindows.end(), window );
193 if( iter != mWindows.end() )
195 mWindows.erase( iter );
199 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
201 return mResizedSignal;
204 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
206 return mLanguageChangedSignal;
209 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
211 return mWindowCreatedSignal;
214 } // namespace Adaptor
215 } // namespace Internal
217 ///////////////////////////////////////////////////////////////////////////////
219 // Dali::Adaptor Stub
221 ///////////////////////////////////////////////////////////////////////////////
224 : mImpl( new Internal::Adaptor::Adaptor )
230 Internal::Adaptor::gAdaptor = nullptr;
234 void Adaptor::Start()
238 void Adaptor::Pause()
242 void Adaptor::Resume()
250 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
252 return mImpl->AddIdle( callback, hasReturnValue );
255 void Adaptor::RemoveIdle( CallbackBase* callback )
257 mImpl->RemoveIdle( callback );
260 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
264 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
268 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
270 return mImpl->ResizedSignal();
273 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
275 return mImpl->LanguageChangedSignal();
278 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
280 return mImpl->WindowCreatedSignal();
283 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
285 return mImpl->GetSurface();
288 Dali::WindowContainer Adaptor::GetWindows() const
290 return mImpl->GetWindows();
293 Dali::SceneHolderList Adaptor::GetSceneHolders() const
295 return mImpl->GetSceneHolders();
298 Any Adaptor::GetNativeWindowHandle()
304 Any Adaptor::GetNativeWindowHandle( Actor actor )
306 return GetNativeWindowHandle();
309 void Adaptor::ReleaseSurfaceLock()
313 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
317 Adaptor& Adaptor::Get()
319 return Internal::Adaptor::Adaptor::Get();
322 bool Adaptor::IsAvailable()
324 return Internal::Adaptor::gAdaptor;
327 void Adaptor::NotifySceneCreated()
331 void Adaptor::NotifyLanguageChanged()
335 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
339 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
343 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
347 void Adaptor::SceneCreated()
351 const LogFactoryInterface& Adaptor::GetLogFactory()
353 if( gLogFactory == NULL )
355 gLogFactory = new LogFactory;