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.
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>
43 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
44 #include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
46 #include <dali/devel-api/text-abstraction/font-client.h>
48 #include <dali/internal/system/common/callback-manager.h>
49 #include <dali/internal/accessibility/common/tts-player-impl.h>
50 #include <dali/internal/accessibility/common/accessibility-adaptor-impl.h>
51 #include <dali/internal/window-system/common/event-handler.h>
52 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
53 #include <dali/internal/graphics/gles/gl-implementation.h>
54 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
55 #include <dali/internal/graphics/common/egl-image-extensions.h>
56 #include <dali/internal/clipboard/common/clipboard-impl.h>
57 #include <dali/internal/graphics/common/vsync-monitor.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/window-impl.h>
61 #include <dali/internal/window-system/common/window-render-surface.h>
63 #include <dali/internal/system/common/logging.h>
65 #include <dali/internal/system/common/locale-utils.h>
66 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
67 #include <dali/internal/imaging/common/image-loader.h>
70 using Dali::TextAbstraction::FontClient;
83 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
84 } // unnamed namespace
86 Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
88 Dali::Adaptor* adaptor = new Dali::Adaptor;
89 Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions );
90 adaptor->mImpl = impl;
92 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder();
93 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
95 impl->Initialize( graphicsFactory, configuration );
96 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
101 Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
103 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( window );
104 Dali::Adaptor* adaptor = New( window, windowImpl.GetSurface(), configuration, environmentOptions );
105 windowImpl.SetAdaptor( *adaptor );
109 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
111 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
112 Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions ); // Impl adaptor
113 adaptor->mImpl = impl;
115 impl->Initialize( graphicsFactory, configuration );
120 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
122 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( window );
123 Dali::Adaptor* adaptor = New( graphicsFactory, window, windowImpl.GetSurface(), configuration, environmentOptions );
124 windowImpl.SetAdaptor( *adaptor );
128 void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration )
130 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
131 Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
132 mEnvironmentOptions->SetLogFunction( logFunction );
133 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
135 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
138 GetDataStoragePath( path );
139 mPlatformAbstraction->SetDataStoragePath( path );
141 ResourcePolicy::DataRetention dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
142 if( configuration == Dali::Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS )
144 dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
147 // Note, Tizen does not use DALI_RETAINS_ALL_DATA, as it can reload images from files automatically.
149 if( mEnvironmentOptions->PerformanceServerRequired() )
151 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, *mEnvironmentOptions );
154 mEnvironmentOptions->CreateTraceManager( mPerformanceInterface );
155 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
157 mCallbackManager = CallbackManager::New();
159 SceneHolderPtr defaultWindow = mWindows.front();
161 DALI_ASSERT_DEBUG( defaultWindow->GetSurface() && "Surface not initialized" );
163 mGraphics = &( graphicsFactory.Create() );
164 mGraphics->Initialize( mEnvironmentOptions );
166 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
168 // This will only be created once
169 eglGraphics->Create();
171 GlImplementation& mGLES = eglGraphics->GetGlesInterface();
172 EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
174 mCore = Integration::Core::New( *this,
175 *mPlatformAbstraction,
178 dataRetentionPolicy ,
179 ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
180 mGraphics->GetDepthBufferRequired(),
181 mGraphics->GetStencilBufferRequired() );
183 defaultWindow->SetAdaptor( Get() );
185 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( ( &defaultWindow )->Get() ) );
188 mWindowCreatedSignal.Emit( window );
191 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
192 if( 0u < timeInterval )
194 mObjectProfiler = new ObjectProfiler( timeInterval );
197 mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
199 mVSyncMonitor = new VSyncMonitor;
201 mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow->GetSurface()->GetSurfaceType() );
203 mThreadController = new ThreadController( *this, *mEnvironmentOptions );
205 // Should be called after Core creation
206 if( mEnvironmentOptions->GetPanGestureLoggingLevel() )
208 Integration::EnableProfiling( Dali::Integration::PROFILING_TYPE_PAN_GESTURE );
210 if( mEnvironmentOptions->GetPanGesturePredictionMode() >= 0 )
212 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
214 if( mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0 )
216 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
218 if( mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0 )
220 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
222 if( mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0 )
224 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
226 if( mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0 )
228 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
230 if( mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0 )
232 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
234 if( mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f )
236 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
238 if( mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0 )
240 Integration::SetPanGestureUseActualTimes( mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false );
242 if( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0 )
244 Integration::SetPanGestureInterpolationTimeRange( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() );
246 if( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0 )
248 Integration::SetPanGestureScalarOnlyPredictionEnabled( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false );
250 if( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0 )
252 Integration::SetPanGestureTwoPointPredictionEnabled( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false );
254 if( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0 )
256 Integration::SetPanGestureTwoPointInterpolatePastTime( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() );
258 if( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f )
260 Integration::SetPanGestureTwoPointVelocityBias( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() );
262 if( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f )
264 Integration::SetPanGestureTwoPointAccelerationBias( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() );
266 if( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0 )
268 Integration::SetPanGestureMultitapSmoothingRange( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() );
270 if( mEnvironmentOptions->GetMinimumPanDistance() >= 0 )
272 Integration::SetPanGestureMinimumDistance( mEnvironmentOptions->GetMinimumPanDistance() );
274 if( mEnvironmentOptions->GetMinimumPanEvents() >= 0 )
276 Integration::SetPanGestureMinimumPanEvents( mEnvironmentOptions->GetMinimumPanEvents() );
278 if( mEnvironmentOptions->GetMinimumPinchDistance() >= 0 )
280 Integration::SetPinchGestureMinimumDistance( mEnvironmentOptions->GetMinimumPinchDistance() );
283 // Set max texture size
284 if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
286 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
292 // Ensure stop status
295 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
296 gThreadLocalAdaptor = NULL;
298 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
300 (*iter)->OnDestroy();
303 // Clear out all the handles to Windows
306 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
307 delete mVSyncMonitor;
308 delete mObjectProfiler;
312 delete mDisplayConnection;
313 delete mPlatformAbstraction;
314 delete mCallbackManager;
315 delete mPerformanceInterface;
317 mGraphics->Destroy();
319 // uninstall it on this thread (main actor thread)
320 Dali::Integration::Log::UninstallLogFunction();
322 // Delete environment options if we own it
323 if( mEnvironmentOptionsOwned )
325 delete mEnvironmentOptions;
329 void Adaptor::Start()
331 // It doesn't support restart after stop at this moment to support restarting, need more testing
332 if( READY != mState )
339 SetupSystemInformation();
341 // Start the callback manager
342 mCallbackManager->Start();
344 SceneHolderPtr defaultWindow = mWindows.front();
346 unsigned int dpiHor, dpiVer;
349 defaultWindow->GetSurface()->GetDpi( dpiHor, dpiVer );
351 // set the DPI value for font rendering
352 FontClient fontClient = FontClient::Get();
353 fontClient.SetDpi( dpiHor, dpiVer );
355 // Tell the core the size of the surface just before we start the render-thread
356 mCore->SurfaceResized( defaultWindow->GetSurface() );
358 // Initialize the thread controller
359 mThreadController->Initialize();
361 ProcessCoreEvents(); // Ensure any startup messages are processed.
363 // Initialize the image loader plugin
364 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
366 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
372 // Dali::Internal::Adaptor::Adaptor::Pause
373 void Adaptor::Pause()
375 // Only pause the adaptor if we're actually running.
376 if( RUNNING == mState )
378 // Inform observers that we are about to be paused.
379 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
384 // Pause all windows event handlers when adaptor paused
385 for( SceneHolderPtr window : mWindows )
390 mThreadController->Pause();
393 // Ensure any messages queued during pause callbacks are processed by doing another update.
396 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Paused\n" );
400 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Not paused [%d]\n", mState );
404 // Dali::Internal::Adaptor::Adaptor::Resume
405 void Adaptor::Resume()
407 // Only resume the adaptor if we are in the suspended state.
408 if( PAUSED == mState )
412 // Reset the event handlers when adaptor resumed
413 for( SceneHolderPtr window : mWindows )
418 // Inform observers that we have resumed.
419 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
424 // Trigger processing of events queued up while paused
425 mCore->ProcessEvents();
427 // Do at end to ensure our first update/render after resumption includes the processed messages as well
428 mThreadController->Resume();
430 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Resumed\n");
434 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Not resumed [%d]\n", mState );
440 if( RUNNING == mState ||
442 PAUSED_WHILE_HIDDEN == mState )
444 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
449 mThreadController->Stop();
451 // Delete the TTS player
452 for( int i =0; i < Dali::TtsPlayer::MODE_NUM; i++ )
456 mTtsPlayers[i].Reset();
460 // Destroy the image loader plugin
461 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
463 delete mNotificationTrigger;
464 mNotificationTrigger = NULL;
466 mCallbackManager->Stop();
470 DALI_LOG_RELEASE_INFO( "Adaptor::Stop\n" );
474 void Adaptor::ContextLost()
476 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
479 void Adaptor::ContextRegained()
481 // Inform core, so that texture resources can be reloaded
482 mCore->RecoverFromContextLoss();
484 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
487 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
489 Integration::Point convertedPoint( point );
490 mWindows.front()->FeedTouchPoint( convertedPoint, timeStamp );
493 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
495 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
496 mWindows.front()->FeedWheelEvent( event );
499 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
501 Integration::KeyEvent convertedEvent( keyEvent );
502 mWindows.front()->FeedKeyEvent( convertedEvent );
505 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface )
507 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation( window );
508 for( SceneHolderPtr windowPtr : mWindows )
510 if( windowPtr.Get() == windowImpl ) // the window is not deleted
512 // Let the core know the surface size has changed
513 mCore->SurfaceResized( &newSurface );
515 mResizedSignal.Emit( mAdaptor );
517 windowImpl->SetSurface( &newSurface );
519 // Flush the event queue to give the update-render thread chance
520 // to start processing messages for new camera setup etc as soon as possible
523 // This method blocks until the render thread has completed the replace.
524 mThreadController->ReplaceSurface( &newSurface );
530 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
532 return *mWindows.front()->GetSurface();
535 void Adaptor::ReleaseSurfaceLock()
537 mWindows.front()->GetSurface()->ReleaseLock();
540 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
542 if( !mTtsPlayers[mode] )
544 // Create the TTS player when it needed, because it can reduce launching time.
545 mTtsPlayers[mode] = TtsPlayer::New(mode);
548 return mTtsPlayers[mode];
551 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
553 bool idleAdded(false);
555 // Only add an idle if the Adaptor is actually running
556 if( RUNNING == mState || READY == mState || forceAdd )
558 idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
564 void Adaptor::RemoveIdle( CallbackBase* callback )
566 mCallbackManager->RemoveIdleCallback( callback );
569 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
571 mThreadController->SetPreRenderCallback( callback );
574 bool Adaptor::AddWindow( Dali::Integration::SceneHolder* childWindow, const std::string& childWindowName, const std::string& childWindowClassName, const bool& childWindowMode )
576 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( *childWindow );
577 windowImpl.SetAdaptor( Get() );
579 // Add the new Window to the container - the order is not important
580 mWindows.push_back( SceneHolderPtr( &windowImpl ) );
582 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( &windowImpl ) );
585 mWindowCreatedSignal.Emit( window );
591 bool Adaptor::RemoveWindow( Dali::Integration::SceneHolder* childWindow )
593 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( *childWindow );
594 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
596 if( *iter == &windowImpl )
598 mWindows.erase( iter );
606 bool Adaptor::RemoveWindow( std::string childWindowName )
608 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
610 if( ( *iter )->GetName() == childWindowName )
612 mWindows.erase( iter );
620 bool Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* childWindow )
622 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
624 if( ( *iter )->GetId() == childWindow->GetId() )
626 mWindows.erase( iter );
634 Dali::Adaptor& Adaptor::Get()
636 DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
637 return gThreadLocalAdaptor->mAdaptor;
640 bool Adaptor::IsAvailable()
642 return gThreadLocalAdaptor != NULL;
645 void Adaptor::SceneCreated()
647 mCore->SceneCreated();
650 Dali::Integration::Core& Adaptor::GetCore()
655 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
657 mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
660 void Adaptor::SetUseHardwareVSync( bool useHardware )
662 mVSyncMonitor->SetUseHardwareVSync( useHardware );
665 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
667 DALI_ASSERT_DEBUG( mDisplayConnection && "Display connection not created" );
668 return *mDisplayConnection;
671 GraphicsInterface& Adaptor::GetGraphicsInterface()
673 DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
677 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
679 return *mPlatformAbstraction;
682 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
684 return *mNotificationTrigger;
687 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
689 return mTriggerEventFactory;
692 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
694 return mSocketFactory;
697 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
699 if( !mWindows.empty() )
701 return mWindows.front()->GetSurface();
707 VSyncMonitorInterface* Adaptor::GetVSyncMonitorInterface()
709 return mVSyncMonitor;
712 TraceInterface& Adaptor::GetKernelTraceInterface()
714 return mKernelTracer;
717 TraceInterface& Adaptor::GetSystemTraceInterface()
719 return mSystemTracer;
722 PerformanceInterface* Adaptor::GetPerformanceInterface()
724 return mPerformanceInterface;
727 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
729 DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
730 return *mPlatformAbstraction;
733 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
735 if( mTtsPlayers[mode] )
737 mTtsPlayers[mode].Reset();
741 Any Adaptor::GetNativeWindowHandle()
743 return mWindows.front()->GetNativeHandle();
746 Any Adaptor::GetGraphicsDisplay()
752 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
754 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
755 display = eglImpl.GetDisplay();
761 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
763 mUseRemoteSurface = useRemoteSurface;
766 void Adaptor::AddObserver( LifeCycleObserver& observer )
768 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
770 if ( match == mObservers.end() )
772 mObservers.push_back( &observer );
776 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
778 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
780 if ( match != mObservers.end() )
782 mObservers.erase( match );
786 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
790 mCore->QueueEvent(event);
794 void Adaptor::ProcessCoreEvents()
798 if( mPerformanceInterface )
800 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
803 mCore->ProcessEvents();
805 if( mPerformanceInterface )
807 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
812 void Adaptor::RequestUpdate( bool forceUpdate )
818 mThreadController->RequestUpdate();
822 case PAUSED_WHILE_HIDDEN:
824 // When Dali applications are partially visible behind the lock-screen,
825 // the indicator must be updated (therefore allow updates in the PAUSED state)
828 mThreadController->RequestUpdateOnce();
840 void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
842 // Only request a notification if the Adaptor is actually running
843 // and we haven't installed the idle notification
844 if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
846 mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
850 void Adaptor::OnWindowShown()
852 if( PAUSED_WHILE_HIDDEN == mState )
854 // Adaptor can now be resumed
859 // Force a render task
864 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState );
868 void Adaptor::OnWindowHidden()
870 if( RUNNING == mState || READY == mState )
872 bool allWindowsHidden = true;
874 for( SceneHolderPtr window : mWindows )
876 if ( window->IsVisible() )
878 allWindowsHidden = false;
883 // Only pause the adaptor when all the windows are hidden
884 if( allWindowsHidden )
886 if( mState == RUNNING )
890 // Adaptor cannot be resumed until any window is shown
891 mState = PAUSED_WHILE_HIDDEN;
893 else // mState is READY
895 // Pause the adaptor after the state gets RUNNING
896 mState = PAUSED_WHILE_INITIALIZING;
901 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Some windows are shown. Don't pause adaptor.\n" );
906 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState );
910 // Dali::Internal::Adaptor::Adaptor::OnDamaged
911 void Adaptor::OnDamaged( const DamageArea& area )
913 // This is needed for the case where Dali window is partially obscured
914 RequestUpdate( false );
917 void Adaptor::SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
919 // Let the core know the surface size has changed
920 mCore->SurfaceResized( surface );
922 mResizedSignal.Emit( mAdaptor );
925 void Adaptor::SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
927 // Flush the event queue to give the update-render thread chance
928 // to start processing messages for new camera setup etc as soon as possible
931 mThreadController->ResizeSurface();
934 void Adaptor::NotifySceneCreated()
936 GetCore().SceneCreated();
938 // Flush the event queue to give the update-render thread chance
939 // to start processing messages for new camera setup etc as soon as possible
942 // Start thread controller after the scene has been created
943 mThreadController->Start();
945 // Process after surface is created (registering to remote surface provider if required)
946 SurfaceInitialized();
948 if( mState != PAUSED_WHILE_INITIALIZING )
952 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated: Adaptor is running\n" );
960 mState = PAUSED_WHILE_HIDDEN;
962 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated: Adaptor is paused\n" );
966 void Adaptor::NotifyLanguageChanged()
968 mLanguageChangedSignal.Emit( mAdaptor );
971 void Adaptor::RenderOnce()
976 const LogFactoryInterface& Adaptor::GetLogFactory()
978 return *mEnvironmentOptions;
981 void Adaptor::RegisterProcessor( Integration::Processor& processor )
983 GetCore().RegisterProcessor(processor);
986 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
988 GetCore().UnregisterProcessor(processor);
991 void Adaptor::RequestUpdateOnce()
993 if( mThreadController )
995 mThreadController->RequestUpdateOnce();
999 bool Adaptor::ProcessCoreEventsFromIdle()
1001 ProcessCoreEvents();
1003 // the idle handle automatically un-installs itself
1004 mNotificationOnIdleInstalled = false;
1009 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
1011 Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
1013 for( auto window : mWindows )
1015 if ( scene == window->GetScene() )
1017 return window.Get();
1024 Dali::WindowContainer Adaptor::GetWindows() const
1026 Dali::WindowContainer windows;
1028 for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
1030 // Downcast to Dali::Window
1031 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( iter->Get() ) );
1034 windows.push_back( window );
1041 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions)
1043 mLanguageChangedSignal(),
1044 mWindowCreatedSignal(),
1045 mAdaptor( adaptor ),
1048 mThreadController( nullptr ),
1049 mVSyncMonitor( nullptr ),
1050 mGraphics( nullptr ),
1051 mDisplayConnection( nullptr ),
1053 mPlatformAbstraction( nullptr ),
1054 mCallbackManager( nullptr ),
1055 mNotificationOnIdleInstalled( false ),
1056 mNotificationTrigger( nullptr ),
1057 mDaliFeedbackPlugin(),
1058 mFeedbackController( nullptr ),
1061 mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1062 mPerformanceInterface( nullptr ),
1065 mTriggerEventFactory(),
1066 mObjectProfiler( nullptr ),
1068 mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
1069 mUseRemoteSurface( false )
1071 DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
1072 mWindows.insert( mWindows.begin(), SceneHolderPtr( &Dali::GetImplementation( window ) ) );
1074 gThreadLocalAdaptor = this;
1077 void Adaptor::SetRootLayoutDirection( std::string locale )
1079 Dali::Stage stage = Dali::Stage::GetCurrent();
1081 stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
1082 static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
1085 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
1087 bool idleAdded( false );
1089 // Only add an idle if the Adaptor is actually running
1090 if( RUNNING == mState || READY == mState || forceAdd )
1092 idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
1098 void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
1100 mCallbackManager->RemoveIdleEntererCallback( callback );
1103 } // namespace Adaptor
1105 } // namespace Internal