2 * Copyright (c) 2020 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.
19 #include <dali/internal/adaptor/common/adaptor-impl.h>
20 #include <dali/internal/adaptor/common/adaptor-builder-impl.h>
23 #include <dali/public-api/common/stage.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/object/any.h>
26 #include <dali/devel-api/actors/actor-devel.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/integration-api/core.h>
29 #include <dali/integration-api/context-notifier.h>
30 #include <dali/integration-api/profiling.h>
31 #include <dali/integration-api/input-options.h>
32 #include <dali/integration-api/events/key-event-integ.h>
33 #include <dali/integration-api/events/touch-event-integ.h>
34 #include <dali/integration-api/events/wheel-event-integ.h>
35 #include <dali/integration-api/processor-interface.h>
38 #include <dali/public-api/dali-adaptor-common.h>
39 #include <dali/internal/system/common/thread-controller.h>
40 #include <dali/internal/system/common/performance-interface-factory.h>
41 #include <dali/internal/adaptor/common/lifecycle-observer.h>
42 #include <dali/internal/adaptor/common/thread-controller-interface.h>
44 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
45 #include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
47 #include <dali/devel-api/text-abstraction/font-client.h>
49 #include <dali/internal/system/common/callback-manager.h>
50 #include <dali/internal/accessibility/common/tts-player-impl.h>
51 #include <dali/internal/accessibility/common/accessibility-adaptor-impl.h>
52 #include <dali/internal/window-system/common/event-handler.h>
53 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
54 #include <dali/internal/graphics/gles/gl-implementation.h>
55 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
56 #include <dali/internal/graphics/common/egl-image-extensions.h>
57 #include <dali/internal/clipboard/common/clipboard-impl.h>
58 #include <dali/internal/system/common/object-profiler.h>
59 #include <dali/internal/window-system/common/display-connection.h>
60 #include <dali/internal/window-system/common/display-utils.h> // For Utils::MakeUnique
61 #include <dali/internal/window-system/common/window-impl.h>
62 #include <dali/internal/window-system/common/window-render-surface.h>
64 #include <dali/internal/system/common/logging.h>
66 #include <dali/internal/system/common/locale-utils.h>
67 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
68 #include <dali/internal/imaging/common/image-loader.h>
70 #include <dali/internal/system/common/configuration-manager.h>
71 #include <dali/internal/system/common/environment-variables.h>
73 using Dali::TextAbstraction::FontClient;
75 extern std::string GetSystemCachePath();
89 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
91 } // unnamed namespace
93 Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
95 Dali::Adaptor* adaptor = new Dali::Adaptor;
96 Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions );
97 adaptor->mImpl = impl;
99 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder();
100 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
102 impl->Initialize( graphicsFactory, configuration );
103 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
108 Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
110 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( window );
111 Dali::Adaptor* adaptor = New( window, windowImpl.GetSurface(), configuration, environmentOptions );
112 windowImpl.SetAdaptor( *adaptor );
116 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
118 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
119 Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions ); // Impl adaptor
120 adaptor->mImpl = impl;
122 impl->Initialize( graphicsFactory, configuration );
127 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
129 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( window );
130 Dali::Adaptor* adaptor = New( graphicsFactory, window, windowImpl.GetSurface(), configuration, environmentOptions );
131 windowImpl.SetAdaptor( *adaptor );
135 void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration )
137 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
138 Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
139 mEnvironmentOptions->SetLogFunction( logFunction );
140 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
142 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
145 GetDataStoragePath( path );
146 mPlatformAbstraction->SetDataStoragePath( path );
148 if( mEnvironmentOptions->PerformanceServerRequired() )
150 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, *mEnvironmentOptions );
153 mEnvironmentOptions->CreateTraceManager( mPerformanceInterface );
154 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
156 mCallbackManager = CallbackManager::New();
158 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
160 DALI_ASSERT_DEBUG( defaultWindow->GetSurface() && "Surface not initialized" );
162 mGraphics = &( graphicsFactory.Create() );
163 mGraphics->Initialize( mEnvironmentOptions );
165 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
167 // This will only be created once
168 eglGraphics->Create();
170 GlImplementation& mGLES = eglGraphics->GetGlesInterface();
171 EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
172 EglContextHelperImplementation& eglContextHelperImpl = eglGraphics->GetContextHelperImplementation();
174 mCore = Integration::Core::New( *this,
175 *mPlatformAbstraction,
178 eglContextHelperImpl,
179 ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
180 mGraphics->GetDepthBufferRequired(),
181 mGraphics->GetStencilBufferRequired() );
183 defaultWindow->SetAdaptor( Get() );
185 Dali::Integration::SceneHolder defaultSceneHolder( defaultWindow );
187 mWindowCreatedSignal.Emit( defaultSceneHolder );
189 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
190 if( 0u < timeInterval )
192 mObjectProfiler = new ObjectProfiler( timeInterval );
195 mNotificationTrigger = TriggerEventFactory::CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
197 mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow->GetSurface()->GetSurfaceType() );
199 mThreadController = new ThreadController( *this, *mEnvironmentOptions );
201 // Should be called after Core creation
202 if( mEnvironmentOptions->GetPanGestureLoggingLevel() )
204 Integration::EnableProfiling( Dali::Integration::PROFILING_TYPE_PAN_GESTURE );
206 if( mEnvironmentOptions->GetPanGesturePredictionMode() >= 0 )
208 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
210 if( mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0 )
212 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
214 if( mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0 )
216 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
218 if( mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0 )
220 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
222 if( mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0 )
224 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
226 if( mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0 )
228 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
230 if( mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f )
232 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
234 if( mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0 )
236 Integration::SetPanGestureUseActualTimes( mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false );
238 if( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0 )
240 Integration::SetPanGestureInterpolationTimeRange( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() );
242 if( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0 )
244 Integration::SetPanGestureScalarOnlyPredictionEnabled( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false );
246 if( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0 )
248 Integration::SetPanGestureTwoPointPredictionEnabled( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false );
250 if( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0 )
252 Integration::SetPanGestureTwoPointInterpolatePastTime( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() );
254 if( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f )
256 Integration::SetPanGestureTwoPointVelocityBias( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() );
258 if( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f )
260 Integration::SetPanGestureTwoPointAccelerationBias( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() );
262 if( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0 )
264 Integration::SetPanGestureMultitapSmoothingRange( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() );
266 if( mEnvironmentOptions->GetMinimumPanDistance() >= 0 )
268 Integration::SetPanGestureMinimumDistance( mEnvironmentOptions->GetMinimumPanDistance() );
270 if( mEnvironmentOptions->GetMinimumPanEvents() >= 0 )
272 Integration::SetPanGestureMinimumPanEvents( mEnvironmentOptions->GetMinimumPanEvents() );
274 if( mEnvironmentOptions->GetMinimumPinchDistance() >= 0 )
276 Integration::SetPinchGestureMinimumDistance( mEnvironmentOptions->GetMinimumPinchDistance() );
278 if( mEnvironmentOptions->GetMinimumPinchTouchEvents() >= 0 )
280 Integration::SetPinchGestureMinimumTouchEvents( mEnvironmentOptions->GetMinimumPinchTouchEvents() );
282 if( mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart() >= 0 )
284 Integration::SetPinchGestureMinimumTouchEventsAfterStart( mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart() );
286 if( mEnvironmentOptions->GetMinimumRotationTouchEvents() >= 0 )
288 Integration::SetRotationGestureMinimumTouchEvents( mEnvironmentOptions->GetMinimumRotationTouchEvents() );
290 if( mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart() >= 0 )
292 Integration::SetRotationGestureMinimumTouchEventsAfterStart( mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart() );
294 if( mEnvironmentOptions->GetLongPressMinimumHoldingTime() >= 0 )
296 Integration::SetLongPressMinimumHoldingTime( mEnvironmentOptions->GetLongPressMinimumHoldingTime() );
299 std::string systemCachePath = GetSystemCachePath();
300 if( ! systemCachePath.empty() )
302 const int dir_err = system( std::string( "mkdir " + systemCachePath ).c_str() );
305 printf( "Error creating system cache directory: %s!\n", systemCachePath.c_str() );
310 mConfigurationManager = Utils::MakeUnique<ConfigurationManager>( systemCachePath, eglGraphics, mThreadController );
315 // Ensure stop status
318 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
319 gThreadLocalAdaptor = NULL;
321 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
323 (*iter)->OnDestroy();
326 // Clear out all the handles to Windows
329 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
330 delete mObjectProfiler;
334 delete mDisplayConnection;
335 delete mPlatformAbstraction;
336 delete mCallbackManager;
337 delete mPerformanceInterface;
339 mGraphics->Destroy();
341 // uninstall it on this thread (main actor thread)
342 Dali::Integration::Log::UninstallLogFunction();
344 // Delete environment options if we own it
345 if( mEnvironmentOptionsOwned )
347 delete mEnvironmentOptions;
351 void Adaptor::Start()
353 // It doesn't support restart after stop at this moment to support restarting, need more testing
354 if( READY != mState )
361 SetupSystemInformation();
363 // Start the callback manager
364 mCallbackManager->Start();
366 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
368 unsigned int dpiHor, dpiVer;
371 defaultWindow->GetSurface()->GetDpi( dpiHor, dpiVer );
373 // set the DPI value for font rendering
374 FontClient fontClient = FontClient::Get();
375 fontClient.SetDpi( dpiHor, dpiVer );
377 // Initialize the thread controller
378 mThreadController->Initialize();
380 // Set max texture size
381 if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
383 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
387 unsigned int maxTextureSize = mConfigurationManager->GetMaxTextureSize();
388 setenv( DALI_ENV_MAX_TEXTURE_SIZE, std::to_string( maxTextureSize ).c_str(), 1 );
389 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( maxTextureSize );
392 ProcessCoreEvents(); // Ensure any startup messages are processed.
394 // Initialize the image loader plugin
395 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
397 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
403 // Dali::Internal::Adaptor::Adaptor::Pause
404 void Adaptor::Pause()
406 // Only pause the adaptor if we're actually running.
407 if( RUNNING == mState )
409 // Inform observers that we are about to be paused.
410 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
415 // Pause all windows event handlers when adaptor paused
416 for( auto window : mWindows )
421 mThreadController->Pause();
424 // Ensure any messages queued during pause callbacks are processed by doing another update.
427 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Paused\n" );
431 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Not paused [%d]\n", mState );
435 // Dali::Internal::Adaptor::Adaptor::Resume
436 void Adaptor::Resume()
438 // Only resume the adaptor if we are in the suspended state.
439 if( PAUSED == mState )
443 // Reset the event handlers when adaptor resumed
444 for( auto window : mWindows )
449 // Inform observers that we have resumed.
450 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
455 // Trigger processing of events queued up while paused
456 mCore->ProcessEvents();
458 // Do at end to ensure our first update/render after resumption includes the processed messages as well
459 mThreadController->Resume();
461 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Resumed\n");
465 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Not resumed [%d]\n", mState );
471 if( RUNNING == mState ||
473 PAUSED_WHILE_HIDDEN == mState )
475 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
480 mThreadController->Stop();
482 // Delete the TTS player
483 for( int i =0; i < Dali::TtsPlayer::MODE_NUM; i++ )
487 mTtsPlayers[i].Reset();
491 // Destroy the image loader plugin
492 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
494 delete mNotificationTrigger;
495 mNotificationTrigger = NULL;
497 mCallbackManager->Stop();
501 DALI_LOG_RELEASE_INFO( "Adaptor::Stop\n" );
505 void Adaptor::ContextLost()
507 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
510 void Adaptor::ContextRegained()
512 // Inform core, so that texture resources can be reloaded
513 mCore->RecoverFromContextLoss();
515 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
518 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
520 Integration::Point convertedPoint( point );
521 mWindows.front()->FeedTouchPoint( convertedPoint, timeStamp );
524 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
526 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
527 mWindows.front()->FeedWheelEvent( event );
530 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
532 Integration::KeyEvent convertedEvent( keyEvent );
533 mWindows.front()->FeedKeyEvent( convertedEvent );
536 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface )
538 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation( window );
539 for( auto windowPtr : mWindows )
541 if( windowPtr == windowImpl ) // the window is not deleted
543 mResizedSignal.Emit( mAdaptor );
545 windowImpl->SetSurface( &newSurface );
547 // Flush the event queue to give the update-render thread chance
548 // to start processing messages for new camera setup etc as soon as possible
551 // This method blocks until the render thread has completed the replace.
552 mThreadController->ReplaceSurface( &newSurface );
558 void Adaptor::DeleteSurface( Dali::RenderSurfaceInterface& surface )
560 // Flush the event queue to give the update-render thread chance
561 // to start processing messages for new camera setup etc as soon as possible
564 // This method blocks until the render thread has finished rendering the current surface.
565 mThreadController->DeleteSurface( &surface );
568 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
570 return *mWindows.front()->GetSurface();
573 void Adaptor::ReleaseSurfaceLock()
575 mWindows.front()->GetSurface()->ReleaseLock();
578 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
580 if( !mTtsPlayers[mode] )
582 // Create the TTS player when it needed, because it can reduce launching time.
583 mTtsPlayers[mode] = TtsPlayer::New(mode);
586 return mTtsPlayers[mode];
589 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
591 bool idleAdded(false);
593 // Only add an idle if the Adaptor is actually running
594 if( RUNNING == mState || READY == mState || forceAdd )
596 idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
602 void Adaptor::RemoveIdle( CallbackBase* callback )
604 mCallbackManager->RemoveIdleCallback( callback );
607 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
609 mThreadController->SetPreRenderCallback( callback );
612 bool Adaptor::AddWindow( Dali::Integration::SceneHolder childWindow, const std::string& childWindowName, const std::string& childWindowClassName, bool childWindowMode )
614 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( childWindow );
615 windowImpl.SetAdaptor( Get() );
617 // Add the new Window to the container - the order is not important
618 mWindows.push_back( &windowImpl );
620 Dali::RenderSurfaceInterface* surface = windowImpl.GetSurface();
622 mThreadController->AddSurface( surface );
624 mWindowCreatedSignal.Emit( childWindow );
629 bool Adaptor::RemoveWindow( Dali::Integration::SceneHolder* childWindow )
631 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( *childWindow );
632 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
634 if( *iter == &windowImpl )
636 mWindows.erase( iter );
644 bool Adaptor::RemoveWindow( std::string childWindowName )
646 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
648 if( ( *iter )->GetName() == childWindowName )
650 mWindows.erase( iter );
658 bool Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* childWindow )
660 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
662 if( ( *iter )->GetId() == childWindow->GetId() )
664 mWindows.erase( iter );
672 Dali::Adaptor& Adaptor::Get()
674 DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
675 return gThreadLocalAdaptor->mAdaptor;
678 bool Adaptor::IsAvailable()
680 return gThreadLocalAdaptor != NULL;
683 void Adaptor::SceneCreated()
685 mCore->SceneCreated();
688 Dali::Integration::Core& Adaptor::GetCore()
693 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
695 mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
698 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
700 DALI_ASSERT_DEBUG( mDisplayConnection && "Display connection not created" );
701 return *mDisplayConnection;
704 GraphicsInterface& Adaptor::GetGraphicsInterface()
706 DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
710 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
712 return *mPlatformAbstraction;
715 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
717 return *mNotificationTrigger;
720 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
722 return mSocketFactory;
725 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
727 if( !mWindows.empty() )
729 return mWindows.front()->GetSurface();
735 TraceInterface& Adaptor::GetKernelTraceInterface()
737 return mKernelTracer;
740 TraceInterface& Adaptor::GetSystemTraceInterface()
742 return mSystemTracer;
745 PerformanceInterface* Adaptor::GetPerformanceInterface()
747 return mPerformanceInterface;
750 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
752 DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
753 return *mPlatformAbstraction;
756 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
758 if( mTtsPlayers[mode] )
760 mTtsPlayers[mode].Reset();
764 Any Adaptor::GetNativeWindowHandle()
766 return mWindows.front()->GetNativeHandle();
769 Any Adaptor::GetNativeWindowHandle( Dali::Actor actor )
771 Any nativeWindowHandle;
773 Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
775 for( auto sceneHolder : mWindows )
777 if ( scene == sceneHolder->GetScene() )
779 nativeWindowHandle = sceneHolder->GetNativeHandle();
784 return nativeWindowHandle;
787 Any Adaptor::GetGraphicsDisplay()
793 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
795 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
796 display = eglImpl.GetDisplay();
802 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
804 mUseRemoteSurface = useRemoteSurface;
807 void Adaptor::AddObserver( LifeCycleObserver& observer )
809 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
811 if ( match == mObservers.end() )
813 mObservers.push_back( &observer );
817 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
819 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
821 if ( match != mObservers.end() )
823 mObservers.erase( match );
827 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
831 mCore->QueueEvent(event);
835 void Adaptor::ProcessCoreEvents()
839 if( mPerformanceInterface )
841 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
844 mCore->ProcessEvents();
846 if( mPerformanceInterface )
848 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
853 void Adaptor::RequestUpdate( bool forceUpdate )
859 mThreadController->RequestUpdate();
863 case PAUSED_WHILE_HIDDEN:
867 // Update (and resource upload) without rendering
868 mThreadController->RequestUpdateOnce( UpdateMode::SKIP_RENDER );
880 void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
882 // Only request a notification if the Adaptor is actually running
883 // and we haven't installed the idle notification
884 if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
886 mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
890 void Adaptor::OnWindowShown()
892 if( PAUSED_WHILE_HIDDEN == mState )
894 // Adaptor can now be resumed
899 // Force a render task
902 else if( RUNNING == mState )
904 // Force a render task
907 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Update requested.\n" );
911 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState );
915 void Adaptor::OnWindowHidden()
917 if( RUNNING == mState || READY == mState )
919 bool allWindowsHidden = true;
921 for( auto window : mWindows )
923 if ( window->IsVisible() )
925 allWindowsHidden = false;
930 // Only pause the adaptor when all the windows are hidden
931 if( allWindowsHidden )
933 if( mState == RUNNING )
937 // Adaptor cannot be resumed until any window is shown
938 mState = PAUSED_WHILE_HIDDEN;
940 else // mState is READY
942 // Pause the adaptor after the state gets RUNNING
943 mState = PAUSED_WHILE_INITIALIZING;
948 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Some windows are shown. Don't pause adaptor.\n" );
953 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState );
957 // Dali::Internal::Adaptor::Adaptor::OnDamaged
958 void Adaptor::OnDamaged( const DamageArea& area )
960 // This is needed for the case where Dali window is partially obscured
961 RequestUpdate( false );
964 void Adaptor::SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
966 mResizedSignal.Emit( mAdaptor );
969 void Adaptor::SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
971 // Flush the event queue to give the update-render thread chance
972 // to start processing messages for new camera setup etc as soon as possible
975 mThreadController->ResizeSurface();
978 void Adaptor::NotifySceneCreated()
980 GetCore().SceneCreated();
982 // Flush the event queue to give the update-render thread chance
983 // to start processing messages for new camera setup etc as soon as possible
986 // Start thread controller after the scene has been created
987 mThreadController->Start();
989 // Process after surface is created (registering to remote surface provider if required)
990 SurfaceInitialized();
992 if( mState != PAUSED_WHILE_INITIALIZING )
996 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated: Adaptor is running\n" );
1004 mState = PAUSED_WHILE_HIDDEN;
1006 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated: Adaptor is paused\n" );
1010 void Adaptor::NotifyLanguageChanged()
1012 mLanguageChangedSignal.Emit( mAdaptor );
1015 void Adaptor::RenderOnce()
1017 RequestUpdateOnce();
1020 const LogFactoryInterface& Adaptor::GetLogFactory()
1022 return *mEnvironmentOptions;
1025 void Adaptor::RegisterProcessor( Integration::Processor& processor )
1027 GetCore().RegisterProcessor(processor);
1030 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
1032 GetCore().UnregisterProcessor(processor);
1035 bool Adaptor::IsMultipleWindowSupported() const
1037 return mConfigurationManager->IsMultipleWindowSupported();
1040 void Adaptor::RequestUpdateOnce()
1042 if( mThreadController )
1044 mThreadController->RequestUpdateOnce( UpdateMode::NORMAL );
1048 bool Adaptor::ProcessCoreEventsFromIdle()
1050 ProcessCoreEvents();
1052 // the idle handle automatically un-installs itself
1053 mNotificationOnIdleInstalled = false;
1058 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
1060 Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
1062 for( auto window : mWindows )
1064 if ( scene == window->GetScene() )
1073 Dali::WindowContainer Adaptor::GetWindows() const
1075 Dali::WindowContainer windows;
1077 for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
1079 // Downcast to Dali::Window
1080 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( *iter ) );
1083 windows.push_back( window );
1090 Dali::SceneHolderList Adaptor::GetSceneHolders() const
1092 Dali::SceneHolderList sceneHolderList;
1094 for( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
1096 sceneHolderList.push_back( Dali::Integration::SceneHolder( *iter ) );
1099 return sceneHolderList;
1102 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions)
1104 mLanguageChangedSignal(),
1105 mWindowCreatedSignal(),
1106 mAdaptor( adaptor ),
1109 mThreadController( nullptr ),
1110 mGraphics( nullptr ),
1111 mDisplayConnection( nullptr ),
1113 mConfigurationManager( nullptr ),
1114 mPlatformAbstraction( nullptr ),
1115 mCallbackManager( nullptr ),
1116 mNotificationOnIdleInstalled( false ),
1117 mNotificationTrigger( nullptr ),
1118 mDaliFeedbackPlugin(),
1119 mFeedbackController( nullptr ),
1122 mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1123 mPerformanceInterface( nullptr ),
1126 mObjectProfiler( nullptr ),
1128 mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
1129 mUseRemoteSurface( false )
1131 DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
1132 mWindows.insert( mWindows.begin(), &Dali::GetImplementation( window ) );
1134 gThreadLocalAdaptor = this;
1137 void Adaptor::SetRootLayoutDirection( std::string locale )
1139 Dali::Stage stage = Dali::Stage::GetCurrent();
1141 stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
1142 static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
1145 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
1147 bool idleAdded( false );
1149 // Only add an idle if the Adaptor is actually running
1150 if( RUNNING == mState || READY == mState || forceAdd )
1152 idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
1158 void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
1160 mCallbackManager->RemoveIdleEntererCallback( callback );
1163 } // namespace Adaptor
1165 } // namespace Internal