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>
34 #include <toolkit-test-application.h>
42 ///////////////////////////////////////////////////////////////////////////////
46 ///////////////////////////////////////////////////////////////////////////////
48 class LogFactory : public LogFactoryInterface
51 LogFactory() = default;
52 virtual ~LogFactory() = default;
55 void InstallLogFunction() const override
57 Dali::Integration::Log::InstallLogFunction( &TestApplication::LogMessage );
60 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.
68 ///////////////////////////////////////////////////////////////////////////////
70 // Dali::Internal::Adaptor::Adaptor Stub
72 ///////////////////////////////////////////////////////////////////////////////
74 Dali::Adaptor* gAdaptor = nullptr;
76 Dali::Adaptor& Adaptor::New()
78 DALI_ASSERT_ALWAYS( ! gAdaptor );
79 gAdaptor = new Dali::Adaptor;
83 Dali::Adaptor& Adaptor::Get()
85 DALI_ASSERT_ALWAYS( gAdaptor );
98 void Adaptor::Start( Dali::Window window )
100 AddWindow( &GetImplementation( window ) );
103 Integration::Scene Adaptor::GetScene( Dali::Window window )
105 return window.GetScene();
108 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
110 mCallbacks.PushBack( callback );
114 void Adaptor::RemoveIdle( CallbackBase* callback )
116 mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
117 [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
120 void Adaptor::RunIdles()
122 for( auto& callback : mCallbacks )
124 CallbackBase::Execute( *callback );
130 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
132 DALI_ASSERT_ALWAYS( ! mWindows.empty() );
134 return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
137 Dali::WindowContainer Adaptor::GetWindows()
139 Dali::WindowContainer windows;
141 for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
143 // Downcast to Dali::Window
144 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
147 windows.push_back( window );
154 Dali::SceneHolderList Adaptor::GetSceneHolders()
156 Dali::SceneHolderList sceneHolderList;
158 for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
160 sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
163 return sceneHolderList;
166 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
168 Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
170 for( auto window : mWindows )
172 if ( scene == window->GetScene() )
181 void Adaptor::AddWindow( Internal::Adaptor::SceneHolder* window )
185 mWindows.push_back( window );
187 Dali::Integration::SceneHolder newWindow( window );
188 mWindowCreatedSignal.Emit( newWindow );
192 void Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* window )
194 auto iter = std::find( mWindows.begin(), mWindows.end(), window );
195 if( iter != mWindows.end() )
197 mWindows.erase( iter );
201 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
203 return mResizedSignal;
206 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
208 return mLanguageChangedSignal;
211 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
213 return mWindowCreatedSignal;
216 } // namespace Adaptor
217 } // namespace Internal
219 ///////////////////////////////////////////////////////////////////////////////
221 // Dali::Adaptor Stub
223 ///////////////////////////////////////////////////////////////////////////////
226 : mImpl( new Internal::Adaptor::Adaptor )
232 Internal::Adaptor::gAdaptor = nullptr;
236 void Adaptor::Start()
240 void Adaptor::Pause()
244 void Adaptor::Resume()
252 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
254 return mImpl->AddIdle( callback, hasReturnValue );
257 void Adaptor::RemoveIdle( CallbackBase* callback )
259 mImpl->RemoveIdle( callback );
262 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
266 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
270 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
272 return mImpl->ResizedSignal();
275 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
277 return mImpl->LanguageChangedSignal();
280 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
282 return mImpl->WindowCreatedSignal();
285 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
287 return mImpl->GetSurface();
290 Dali::WindowContainer Adaptor::GetWindows() const
292 return mImpl->GetWindows();
295 Dali::SceneHolderList Adaptor::GetSceneHolders() const
297 return mImpl->GetSceneHolders();
300 Any Adaptor::GetNativeWindowHandle()
306 Any Adaptor::GetNativeWindowHandle( Actor actor )
308 return GetNativeWindowHandle();
311 void Adaptor::ReleaseSurfaceLock()
315 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
319 Adaptor& Adaptor::Get()
321 return Internal::Adaptor::Adaptor::Get();
324 bool Adaptor::IsAvailable()
326 return Internal::Adaptor::gAdaptor;
329 void Adaptor::NotifySceneCreated()
333 void Adaptor::NotifyLanguageChanged()
337 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
341 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
345 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
349 void Adaptor::SceneCreated()
353 class LogFactory : public LogFactoryInterface
356 virtual void InstallLogFunction() const
358 Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
359 Dali::Integration::Log::InstallLogFunction(logFunction);
365 virtual ~LogFactory()
370 LogFactory* gLogFactory = NULL;
371 const LogFactoryInterface& Adaptor::GetLogFactory()
373 if( gLogFactory == NULL )
375 gLogFactory = new LogFactory;