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>
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>
33 #include <toolkit-test-application.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 );
102 mWindowCreatedSignal.Emit( window );
106 Integration::Scene Adaptor::GetScene( Dali::Window window )
108 return window.GetScene();
111 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
113 mCallbacks.PushBack( callback );
117 void Adaptor::RemoveIdle( CallbackBase* callback )
119 mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
120 [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
123 void Adaptor::RunIdles()
125 for( auto& callback : mCallbacks )
127 CallbackBase::Execute( *callback );
133 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
135 DALI_ASSERT_ALWAYS( ! mWindows.empty() );
137 return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front()->GetRenderSurface() );
140 Dali::WindowContainer Adaptor::GetWindows()
142 Dali::WindowContainer windows;
144 for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
146 // Downcast to Dali::Window
147 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
150 windows.push_back( window );
157 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
159 return mResizedSignal;
162 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
164 return mLanguageChangedSignal;
167 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
169 return mWindowCreatedSignal;
172 } // namespace Adaptor
173 } // namespace Internal
175 ///////////////////////////////////////////////////////////////////////////////
177 // Dali::Adaptor Stub
179 ///////////////////////////////////////////////////////////////////////////////
182 : mImpl( new Internal::Adaptor::Adaptor )
188 Internal::Adaptor::gAdaptor = nullptr;
192 void Adaptor::Start()
196 void Adaptor::Pause()
200 void Adaptor::Resume()
208 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
210 return mImpl->AddIdle( callback, hasReturnValue );
213 void Adaptor::RemoveIdle( CallbackBase* callback )
215 mImpl->RemoveIdle( callback );
218 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
222 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
226 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
228 return mImpl->ResizedSignal();
231 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
233 return mImpl->LanguageChangedSignal();
236 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
238 return mImpl->WindowCreatedSignal();
241 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
243 return mImpl->GetSurface();
246 Dali::WindowContainer Adaptor::GetWindows() const
248 return mImpl->GetWindows();
251 Any Adaptor::GetNativeWindowHandle()
257 Any Adaptor::GetNativeWindowHandle( Actor actor )
259 return GetNativeWindowHandle();
262 void Adaptor::ReleaseSurfaceLock()
266 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
270 Adaptor& Adaptor::Get()
272 return Internal::Adaptor::Adaptor::Get();
275 bool Adaptor::IsAvailable()
277 return Internal::Adaptor::gAdaptor;
280 void Adaptor::NotifySceneCreated()
284 void Adaptor::NotifyLanguageChanged()
288 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
292 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
296 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
300 void Adaptor::SceneCreated()
304 class LogFactory : public LogFactoryInterface
307 virtual void InstallLogFunction() const
309 Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
310 Dali::Integration::Log::InstallLogFunction(logFunction);
316 virtual ~LogFactory()
321 LogFactory* gLogFactory = NULL;
322 const LogFactoryInterface& Adaptor::GetLogFactory()
324 if( gLogFactory == NULL )
326 gLogFactory = new LogFactory;