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 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
186 if( 0u < timeInterval )
188 mObjectProfiler = new ObjectProfiler( timeInterval );
191 mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
193 mVSyncMonitor = new VSyncMonitor;
195 mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow->GetSurface()->GetSurfaceType() );
197 mThreadController = new ThreadController( *this, *mEnvironmentOptions );
199 // Should be called after Core creation
200 if( mEnvironmentOptions->GetPanGestureLoggingLevel() )
202 Integration::EnableProfiling( Dali::Integration::PROFILING_TYPE_PAN_GESTURE );
204 if( mEnvironmentOptions->GetPanGesturePredictionMode() >= 0 )
206 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
208 if( mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0 )
210 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
212 if( mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0 )
214 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
216 if( mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0 )
218 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
220 if( mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0 )
222 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
224 if( mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0 )
226 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
228 if( mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f )
230 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
232 if( mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0 )
234 Integration::SetPanGestureUseActualTimes( mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false );
236 if( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0 )
238 Integration::SetPanGestureInterpolationTimeRange( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() );
240 if( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0 )
242 Integration::SetPanGestureScalarOnlyPredictionEnabled( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false );
244 if( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0 )
246 Integration::SetPanGestureTwoPointPredictionEnabled( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false );
248 if( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0 )
250 Integration::SetPanGestureTwoPointInterpolatePastTime( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() );
252 if( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f )
254 Integration::SetPanGestureTwoPointVelocityBias( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() );
256 if( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f )
258 Integration::SetPanGestureTwoPointAccelerationBias( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() );
260 if( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0 )
262 Integration::SetPanGestureMultitapSmoothingRange( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() );
264 if( mEnvironmentOptions->GetMinimumPanDistance() >= 0 )
266 Integration::SetPanGestureMinimumDistance( mEnvironmentOptions->GetMinimumPanDistance() );
268 if( mEnvironmentOptions->GetMinimumPanEvents() >= 0 )
270 Integration::SetPanGestureMinimumPanEvents( mEnvironmentOptions->GetMinimumPanEvents() );
272 if( mEnvironmentOptions->GetMinimumPinchDistance() >= 0 )
274 Integration::SetPinchGestureMinimumDistance( mEnvironmentOptions->GetMinimumPinchDistance() );
277 // Set max texture size
278 if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
280 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
286 // Ensure stop status
289 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
290 gThreadLocalAdaptor = NULL;
292 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
294 (*iter)->OnDestroy();
297 // Clear out all the handles to Windows
300 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
301 delete mVSyncMonitor;
302 delete mObjectProfiler;
306 delete mDisplayConnection;
307 delete mPlatformAbstraction;
308 delete mCallbackManager;
309 delete mPerformanceInterface;
311 mGraphics->Destroy();
313 // uninstall it on this thread (main actor thread)
314 Dali::Integration::Log::UninstallLogFunction();
316 // Delete environment options if we own it
317 if( mEnvironmentOptionsOwned )
319 delete mEnvironmentOptions;
323 void Adaptor::Start()
325 // It doesn't support restart after stop at this moment to support restarting, need more testing
326 if( READY != mState )
333 SetupSystemInformation();
335 // Start the callback manager
336 mCallbackManager->Start();
338 SceneHolderPtr defaultWindow = mWindows.front();
340 unsigned int dpiHor, dpiVer;
343 defaultWindow->GetSurface()->GetDpi( dpiHor, dpiVer );
345 // set the DPI value for font rendering
346 FontClient fontClient = FontClient::Get();
347 fontClient.SetDpi( dpiHor, dpiVer );
349 // Tell the core the size of the surface just before we start the render-thread
350 mCore->SurfaceResized( defaultWindow->GetSurface() );
352 // Initialize the thread controller
353 mThreadController->Initialize();
355 ProcessCoreEvents(); // Ensure any startup messages are processed.
357 // Initialize the image loader plugin
358 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
360 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
366 // Dali::Internal::Adaptor::Adaptor::Pause
367 void Adaptor::Pause()
369 // Only pause the adaptor if we're actually running.
370 if( RUNNING == mState )
372 // Inform observers that we are about to be paused.
373 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
378 // Pause all windows event handlers when adaptor paused
379 for( SceneHolderPtr window : mWindows )
384 mThreadController->Pause();
387 // Ensure any messages queued during pause callbacks are processed by doing another update.
390 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Paused\n" );
394 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Not paused [%d]\n", mState );
398 // Dali::Internal::Adaptor::Adaptor::Resume
399 void Adaptor::Resume()
401 // Only resume the adaptor if we are in the suspended state.
402 if( PAUSED == mState )
406 // Reset the event handlers when adaptor resumed
407 for( SceneHolderPtr window : mWindows )
412 // Inform observers that we have resumed.
413 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
418 // Trigger processing of events queued up while paused
419 mCore->ProcessEvents();
421 // Do at end to ensure our first update/render after resumption includes the processed messages as well
422 mThreadController->Resume();
424 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Resumed\n");
428 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Not resumed [%d]\n", mState );
434 if( RUNNING == mState ||
436 PAUSED_WHILE_HIDDEN == mState )
438 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
443 mThreadController->Stop();
445 // Delete the TTS player
446 for( int i =0; i < Dali::TtsPlayer::MODE_NUM; i++ )
450 mTtsPlayers[i].Reset();
454 // Destroy the image loader plugin
455 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
457 delete mNotificationTrigger;
458 mNotificationTrigger = NULL;
460 mCallbackManager->Stop();
464 DALI_LOG_RELEASE_INFO( "Adaptor::Stop\n" );
468 void Adaptor::ContextLost()
470 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
473 void Adaptor::ContextRegained()
475 // Inform core, so that texture resources can be reloaded
476 mCore->RecoverFromContextLoss();
478 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
481 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
483 Integration::Point convertedPoint( point );
484 mWindows.front()->FeedTouchPoint( convertedPoint, timeStamp );
487 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
489 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
490 mWindows.front()->FeedWheelEvent( event );
493 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
495 Integration::KeyEvent convertedEvent( keyEvent );
496 mWindows.front()->FeedKeyEvent( convertedEvent );
499 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface )
501 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation( window );
502 for( SceneHolderPtr windowPtr : mWindows )
504 if( windowPtr.Get() == windowImpl ) // the window is not deleted
506 // Let the core know the surface size has changed
507 mCore->SurfaceResized( &newSurface );
509 mResizedSignal.Emit( mAdaptor );
511 windowImpl->SetSurface( &newSurface );
513 // Flush the event queue to give the update-render thread chance
514 // to start processing messages for new camera setup etc as soon as possible
517 // This method blocks until the render thread has completed the replace.
518 mThreadController->ReplaceSurface( &newSurface );
524 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
526 return *mWindows.front()->GetSurface();
529 void Adaptor::ReleaseSurfaceLock()
531 mWindows.front()->GetSurface()->ReleaseLock();
534 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
536 if( !mTtsPlayers[mode] )
538 // Create the TTS player when it needed, because it can reduce launching time.
539 mTtsPlayers[mode] = TtsPlayer::New(mode);
542 return mTtsPlayers[mode];
545 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
547 bool idleAdded(false);
549 // Only add an idle if the Adaptor is actually running
550 if( RUNNING == mState || READY == mState || forceAdd )
552 idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
558 void Adaptor::RemoveIdle( CallbackBase* callback )
560 mCallbackManager->RemoveIdleCallback( callback );
563 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
565 mThreadController->SetPreRenderCallback( callback );
568 bool Adaptor::AddWindow( Dali::Integration::SceneHolder* childWindow, const std::string& childWindowName, const std::string& childWindowClassName, const bool& childWindowMode )
570 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( *childWindow );
571 windowImpl.SetAdaptor( Get() );
573 // Add the new Window to the container - the order is not important
574 mWindows.push_back( SceneHolderPtr( &windowImpl ) );
578 bool Adaptor::RemoveWindow( Dali::Integration::SceneHolder* childWindow )
580 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( *childWindow );
581 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
583 if( *iter == &windowImpl )
585 mWindows.erase( iter );
593 bool Adaptor::RemoveWindow( std::string childWindowName )
595 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
597 if( ( *iter )->GetName() == childWindowName )
599 mWindows.erase( iter );
607 bool Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* childWindow )
609 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
611 if( ( *iter )->GetId() == childWindow->GetId() )
613 mWindows.erase( iter );
621 Dali::Adaptor& Adaptor::Get()
623 DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
624 return gThreadLocalAdaptor->mAdaptor;
627 bool Adaptor::IsAvailable()
629 return gThreadLocalAdaptor != NULL;
632 void Adaptor::SceneCreated()
634 mCore->SceneCreated();
637 Dali::Integration::Core& Adaptor::GetCore()
642 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
644 mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
647 void Adaptor::SetUseHardwareVSync( bool useHardware )
649 mVSyncMonitor->SetUseHardwareVSync( useHardware );
652 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
654 DALI_ASSERT_DEBUG( mDisplayConnection && "Display connection not created" );
655 return *mDisplayConnection;
658 GraphicsInterface& Adaptor::GetGraphicsInterface()
660 DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
664 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
666 return *mPlatformAbstraction;
669 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
671 return *mNotificationTrigger;
674 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
676 return mTriggerEventFactory;
679 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
681 return mSocketFactory;
684 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
686 if( !mWindows.empty() )
688 return mWindows.front()->GetSurface();
694 VSyncMonitorInterface* Adaptor::GetVSyncMonitorInterface()
696 return mVSyncMonitor;
699 TraceInterface& Adaptor::GetKernelTraceInterface()
701 return mKernelTracer;
704 TraceInterface& Adaptor::GetSystemTraceInterface()
706 return mSystemTracer;
709 PerformanceInterface* Adaptor::GetPerformanceInterface()
711 return mPerformanceInterface;
714 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
716 DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
717 return *mPlatformAbstraction;
720 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
722 if( mTtsPlayers[mode] )
724 mTtsPlayers[mode].Reset();
728 Any Adaptor::GetNativeWindowHandle()
730 return mWindows.front()->GetNativeHandle();
733 Any Adaptor::GetGraphicsDisplay()
739 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
741 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
742 display = eglImpl.GetDisplay();
748 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
750 mUseRemoteSurface = useRemoteSurface;
753 void Adaptor::AddObserver( LifeCycleObserver& observer )
755 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
757 if ( match == mObservers.end() )
759 mObservers.push_back( &observer );
763 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
765 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
767 if ( match != mObservers.end() )
769 mObservers.erase( match );
773 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
777 mCore->QueueEvent(event);
781 void Adaptor::ProcessCoreEvents()
785 if( mPerformanceInterface )
787 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
790 mCore->ProcessEvents();
792 if( mPerformanceInterface )
794 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
799 void Adaptor::RequestUpdate( bool forceUpdate )
805 mThreadController->RequestUpdate();
809 case PAUSED_WHILE_HIDDEN:
811 // When Dali applications are partially visible behind the lock-screen,
812 // the indicator must be updated (therefore allow updates in the PAUSED state)
815 mThreadController->RequestUpdateOnce();
827 void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
829 // Only request a notification if the Adaptor is actually running
830 // and we haven't installed the idle notification
831 if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
833 mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
837 void Adaptor::OnWindowShown()
839 if( PAUSED_WHILE_HIDDEN == mState )
841 // Adaptor can now be resumed
846 // Force a render task
851 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState );
855 void Adaptor::OnWindowHidden()
857 if( RUNNING == mState || READY == mState )
859 bool allWindowsHidden = true;
861 for( SceneHolderPtr window : mWindows )
863 if ( window->IsVisible() )
865 allWindowsHidden = false;
870 // Only pause the adaptor when all the windows are hidden
871 if( allWindowsHidden )
873 if( mState == RUNNING )
877 // Adaptor cannot be resumed until any window is shown
878 mState = PAUSED_WHILE_HIDDEN;
880 else // mState is READY
882 // Pause the adaptor after the state gets RUNNING
883 mState = PAUSED_WHILE_INITIALIZING;
888 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Some windows are shown. Don't pause adaptor.\n" );
893 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState );
897 // Dali::Internal::Adaptor::Adaptor::OnDamaged
898 void Adaptor::OnDamaged( const DamageArea& area )
900 // This is needed for the case where Dali window is partially obscured
901 RequestUpdate( false );
904 void Adaptor::SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
906 // Let the core know the surface size has changed
907 mCore->SurfaceResized( surface );
909 mResizedSignal.Emit( mAdaptor );
912 void Adaptor::SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
914 // Flush the event queue to give the update-render thread chance
915 // to start processing messages for new camera setup etc as soon as possible
918 mThreadController->ResizeSurface();
921 void Adaptor::NotifySceneCreated()
923 GetCore().SceneCreated();
925 // Flush the event queue to give the update-render thread chance
926 // to start processing messages for new camera setup etc as soon as possible
929 // Start thread controller after the scene has been created
930 mThreadController->Start();
932 // Process after surface is created (registering to remote surface provider if required)
933 SurfaceInitialized();
935 if( mState != PAUSED_WHILE_INITIALIZING )
939 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated: Adaptor is running\n" );
947 mState = PAUSED_WHILE_HIDDEN;
949 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated: Adaptor is paused\n" );
953 void Adaptor::NotifyLanguageChanged()
955 mLanguageChangedSignal.Emit( mAdaptor );
958 void Adaptor::RenderOnce()
963 const LogFactoryInterface& Adaptor::GetLogFactory()
965 return *mEnvironmentOptions;
968 void Adaptor::RegisterProcessor( Integration::Processor& processor )
970 GetCore().RegisterProcessor(processor);
973 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
975 GetCore().UnregisterProcessor(processor);
978 void Adaptor::RequestUpdateOnce()
980 if( mThreadController )
982 mThreadController->RequestUpdateOnce();
986 bool Adaptor::ProcessCoreEventsFromIdle()
990 // the idle handle automatically un-installs itself
991 mNotificationOnIdleInstalled = false;
996 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
998 Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
1000 for( auto window : mWindows )
1002 if ( scene == window->GetScene() )
1004 return window.Get();
1011 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions)
1013 mLanguageChangedSignal(),
1014 mAdaptor( adaptor ),
1017 mThreadController( nullptr ),
1018 mVSyncMonitor( nullptr ),
1019 mGraphics( nullptr ),
1020 mDisplayConnection( nullptr ),
1022 mPlatformAbstraction( nullptr ),
1023 mCallbackManager( nullptr ),
1024 mNotificationOnIdleInstalled( false ),
1025 mNotificationTrigger( nullptr ),
1026 mDaliFeedbackPlugin(),
1027 mFeedbackController( nullptr ),
1030 mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1031 mPerformanceInterface( nullptr ),
1034 mTriggerEventFactory(),
1035 mObjectProfiler( nullptr ),
1037 mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
1038 mUseRemoteSurface( false )
1040 DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
1041 mWindows.insert( mWindows.begin(), SceneHolderPtr( &Dali::GetImplementation( window ) ) );
1043 gThreadLocalAdaptor = this;
1046 void Adaptor::SetRootLayoutDirection( std::string locale )
1048 Dali::Stage stage = Dali::Stage::GetCurrent();
1050 stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
1051 static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
1054 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
1056 bool idleAdded( false );
1058 // Only add an idle if the Adaptor is actually running
1059 if( RUNNING == mState || READY == mState || forceAdd )
1061 idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
1067 void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
1069 mCallbackManager->RemoveIdleEntererCallback( callback );
1072 } // namespace Adaptor
1074 } // namespace Internal