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.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 )
101 mWindows.push_back( window );
103 mSceneHolders.emplace_back( static_cast<SceneHolder*>( &window.GetBaseObject() ) );
107 Integration::Scene Adaptor::GetScene( Dali::Window window )
109 return window.GetScene();
112 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
114 mCallbacks.PushBack( callback );
118 void Adaptor::RemoveIdle( CallbackBase* callback )
120 mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
121 [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
124 void Adaptor::RunIdles()
126 for( auto& callback : mCallbacks )
128 CallbackBase::Execute( *callback );
134 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
136 DALI_ASSERT_ALWAYS( ! mWindows.empty() );
138 return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front().GetRenderSurface() );
141 Dali::WindowContainer Adaptor::GetWindows()
146 Dali::SceneHolderList Adaptor::GetSceneHolders()
148 return mSceneHolders;
151 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
153 return mResizedSignal;
156 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
158 return mLanguageChangedSignal;
161 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
163 return mWindowCreatedSignal;
166 } // namespace Adaptor
167 } // namespace Internal
169 ///////////////////////////////////////////////////////////////////////////////
171 // Dali::Adaptor Stub
173 ///////////////////////////////////////////////////////////////////////////////
176 : mImpl( new Internal::Adaptor::Adaptor )
182 Internal::Adaptor::gAdaptor = nullptr;
186 void Adaptor::Start()
190 void Adaptor::Pause()
194 void Adaptor::Resume()
202 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
204 return mImpl->AddIdle( callback, hasReturnValue );
207 void Adaptor::RemoveIdle( CallbackBase* callback )
209 mImpl->RemoveIdle( callback );
212 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
216 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
220 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
222 return mImpl->ResizedSignal();
225 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
227 return mImpl->LanguageChangedSignal();
230 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
232 return mImpl->WindowCreatedSignal();
235 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
237 return mImpl->GetSurface();
240 Dali::WindowContainer Adaptor::GetWindows() const
242 return mImpl->GetWindows();
245 Dali::SceneHolderList Adaptor::GetSceneHolders() const
247 return mImpl->GetSceneHolders();
250 Any Adaptor::GetNativeWindowHandle()
256 Any Adaptor::GetNativeWindowHandle( Actor actor )
258 return GetNativeWindowHandle();
261 void Adaptor::ReleaseSurfaceLock()
265 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
269 Adaptor& Adaptor::Get()
271 return Internal::Adaptor::Adaptor::Get();
274 bool Adaptor::IsAvailable()
276 return Internal::Adaptor::gAdaptor;
279 void Adaptor::NotifySceneCreated()
283 void Adaptor::NotifyLanguageChanged()
287 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
291 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
295 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
299 void Adaptor::SceneCreated()
303 const LogFactoryInterface& Adaptor::GetLogFactory()
305 if( gLogFactory == NULL )
307 gLogFactory = new LogFactory;