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>
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()
141 Dali::WindowContainer windows;
143 for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
145 // Downcast to Dali::Window
146 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
149 windows.push_back( window );
156 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
158 return mResizedSignal;
161 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
163 return mLanguageChangedSignal;
166 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
168 return mWindowCreatedSignal;
171 } // namespace Adaptor
172 } // namespace Internal
174 ///////////////////////////////////////////////////////////////////////////////
176 // Dali::Adaptor Stub
178 ///////////////////////////////////////////////////////////////////////////////
181 : mImpl( new Internal::Adaptor::Adaptor )
187 Internal::Adaptor::gAdaptor = nullptr;
191 void Adaptor::Start()
195 void Adaptor::Pause()
199 void Adaptor::Resume()
207 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
209 return mImpl->AddIdle( callback, hasReturnValue );
212 void Adaptor::RemoveIdle( CallbackBase* callback )
214 mImpl->RemoveIdle( callback );
217 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
221 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
225 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
227 return mImpl->ResizedSignal();
230 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
232 return mImpl->LanguageChangedSignal();
235 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
237 return mImpl->WindowCreatedSignal();
240 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
242 return mImpl->GetSurface();
245 Dali::WindowContainer Adaptor::GetWindows() const
247 return mImpl->GetWindows();
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;