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>
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 )
100 mWindows.push_back( window );
101 mWindowCreatedSignal.Emit( window );
105 Integration::Scene Adaptor::GetScene( Dali::Window window )
107 return window.GetScene();
110 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
112 mCallbacks.PushBack( callback );
116 void Adaptor::RemoveIdle( CallbackBase* callback )
118 mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
119 [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
122 void Adaptor::RunIdles()
124 for( auto& callback : mCallbacks )
126 CallbackBase::Execute( *callback );
132 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
134 DALI_ASSERT_ALWAYS( ! mWindows.empty() );
136 return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front().GetRenderSurface() );
139 Dali::WindowContainer Adaptor::GetWindows()
144 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
146 return mResizedSignal;
149 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
151 return mLanguageChangedSignal;
154 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
156 return mWindowCreatedSignal;
159 } // namespace Adaptor
160 } // namespace Internal
162 ///////////////////////////////////////////////////////////////////////////////
164 // Dali::Adaptor Stub
166 ///////////////////////////////////////////////////////////////////////////////
169 : mImpl( new Internal::Adaptor::Adaptor )
175 Internal::Adaptor::gAdaptor = nullptr;
179 void Adaptor::Start()
183 void Adaptor::Pause()
187 void Adaptor::Resume()
195 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
197 return mImpl->AddIdle( callback, hasReturnValue );
200 void Adaptor::RemoveIdle( CallbackBase* callback )
202 mImpl->RemoveIdle( callback );
205 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
209 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
213 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
215 return mImpl->ResizedSignal();
218 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
220 return mImpl->LanguageChangedSignal();
223 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
225 return mImpl->WindowCreatedSignal();
228 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
230 return mImpl->GetSurface();
233 Dali::WindowContainer Adaptor::GetWindows() const
235 return mImpl->GetWindows();
238 Any Adaptor::GetNativeWindowHandle()
244 void Adaptor::ReleaseSurfaceLock()
248 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
252 Adaptor& Adaptor::Get()
254 return Internal::Adaptor::Adaptor::Get();
257 bool Adaptor::IsAvailable()
259 return Internal::Adaptor::gAdaptor;
262 void Adaptor::NotifySceneCreated()
266 void Adaptor::NotifyLanguageChanged()
270 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
274 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
278 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
282 void Adaptor::SceneCreated()
286 const LogFactoryInterface& Adaptor::GetLogFactory()
288 if( gLogFactory == NULL )
290 gLogFactory = new LogFactory;