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/system/common/object-profiler.h>
58 #include <dali/internal/window-system/common/display-connection.h>
59 #include <dali/internal/window-system/common/window-impl.h>
60 #include <dali/internal/window-system/common/window-render-surface.h>
62 #include <dali/internal/system/common/logging.h>
64 #include <dali/internal/system/common/locale-utils.h>
65 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
66 #include <dali/internal/imaging/common/image-loader.h>
69 using Dali::TextAbstraction::FontClient;
82 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
83 } // unnamed namespace
85 Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
87 Dali::Adaptor* adaptor = new Dali::Adaptor;
88 Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions );
89 adaptor->mImpl = impl;
91 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder();
92 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
94 impl->Initialize( graphicsFactory, configuration );
95 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
100 Dali::Adaptor* Adaptor::New( Dali::Integration::SceneHolder window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
102 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( window );
103 Dali::Adaptor* adaptor = New( window, windowImpl.GetSurface(), configuration, environmentOptions );
104 windowImpl.SetAdaptor( *adaptor );
108 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
110 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
111 Adaptor* impl = new Adaptor( window, *adaptor, surface, environmentOptions ); // Impl adaptor
112 adaptor->mImpl = impl;
114 impl->Initialize( graphicsFactory, configuration );
119 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
121 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( window );
122 Dali::Adaptor* adaptor = New( graphicsFactory, window, windowImpl.GetSurface(), configuration, environmentOptions );
123 windowImpl.SetAdaptor( *adaptor );
127 void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration )
129 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
130 Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
131 mEnvironmentOptions->SetLogFunction( logFunction );
132 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
134 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
137 GetDataStoragePath( path );
138 mPlatformAbstraction->SetDataStoragePath( path );
140 ResourcePolicy::DataRetention dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
141 if( configuration == Dali::Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS )
143 dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
146 // Note, Tizen does not use DALI_RETAINS_ALL_DATA, as it can reload images from files automatically.
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 SceneHolderPtr 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();
173 mCore = Integration::Core::New( *this,
174 *mPlatformAbstraction,
177 dataRetentionPolicy ,
178 ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
179 mGraphics->GetDepthBufferRequired(),
180 mGraphics->GetStencilBufferRequired() );
182 defaultWindow->SetAdaptor( Get() );
184 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( ( &defaultWindow )->Get() ) );
187 mWindowCreatedSignal.Emit( window );
190 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
191 if( 0u < timeInterval )
193 mObjectProfiler = new ObjectProfiler( timeInterval );
196 mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
198 mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow->GetSurface()->GetSurfaceType() );
200 mThreadController = new ThreadController( *this, *mEnvironmentOptions );
202 // Should be called after Core creation
203 if( mEnvironmentOptions->GetPanGestureLoggingLevel() )
205 Integration::EnableProfiling( Dali::Integration::PROFILING_TYPE_PAN_GESTURE );
207 if( mEnvironmentOptions->GetPanGesturePredictionMode() >= 0 )
209 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
211 if( mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0 )
213 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
215 if( mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0 )
217 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
219 if( mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0 )
221 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
223 if( mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0 )
225 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
227 if( mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0 )
229 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
231 if( mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f )
233 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
235 if( mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0 )
237 Integration::SetPanGestureUseActualTimes( mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false );
239 if( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0 )
241 Integration::SetPanGestureInterpolationTimeRange( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() );
243 if( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0 )
245 Integration::SetPanGestureScalarOnlyPredictionEnabled( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false );
247 if( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0 )
249 Integration::SetPanGestureTwoPointPredictionEnabled( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false );
251 if( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0 )
253 Integration::SetPanGestureTwoPointInterpolatePastTime( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() );
255 if( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f )
257 Integration::SetPanGestureTwoPointVelocityBias( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() );
259 if( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f )
261 Integration::SetPanGestureTwoPointAccelerationBias( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() );
263 if( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0 )
265 Integration::SetPanGestureMultitapSmoothingRange( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() );
267 if( mEnvironmentOptions->GetMinimumPanDistance() >= 0 )
269 Integration::SetPanGestureMinimumDistance( mEnvironmentOptions->GetMinimumPanDistance() );
271 if( mEnvironmentOptions->GetMinimumPanEvents() >= 0 )
273 Integration::SetPanGestureMinimumPanEvents( mEnvironmentOptions->GetMinimumPanEvents() );
275 if( mEnvironmentOptions->GetMinimumPinchDistance() >= 0 )
277 Integration::SetPinchGestureMinimumDistance( mEnvironmentOptions->GetMinimumPinchDistance() );
280 // Set max texture size
281 if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
283 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
289 // Ensure stop status
292 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
293 gThreadLocalAdaptor = NULL;
295 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
297 (*iter)->OnDestroy();
300 // Clear out all the handles to Windows
303 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
304 delete mObjectProfiler;
308 delete mDisplayConnection;
309 delete mPlatformAbstraction;
310 delete mCallbackManager;
311 delete mPerformanceInterface;
313 mGraphics->Destroy();
315 // uninstall it on this thread (main actor thread)
316 Dali::Integration::Log::UninstallLogFunction();
318 // Delete environment options if we own it
319 if( mEnvironmentOptionsOwned )
321 delete mEnvironmentOptions;
325 void Adaptor::Start()
327 // It doesn't support restart after stop at this moment to support restarting, need more testing
328 if( READY != mState )
335 SetupSystemInformation();
337 // Start the callback manager
338 mCallbackManager->Start();
340 SceneHolderPtr defaultWindow = mWindows.front();
342 unsigned int dpiHor, dpiVer;
345 defaultWindow->GetSurface()->GetDpi( dpiHor, dpiVer );
347 // set the DPI value for font rendering
348 FontClient fontClient = FontClient::Get();
349 fontClient.SetDpi( dpiHor, dpiVer );
351 // Tell the core the size of the surface just before we start the render-thread
352 mCore->SurfaceResized( defaultWindow->GetSurface() );
354 // Initialize the thread controller
355 mThreadController->Initialize();
357 ProcessCoreEvents(); // Ensure any startup messages are processed.
359 // Initialize the image loader plugin
360 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
362 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
368 // Dali::Internal::Adaptor::Adaptor::Pause
369 void Adaptor::Pause()
371 // Only pause the adaptor if we're actually running.
372 if( RUNNING == mState )
374 // Inform observers that we are about to be paused.
375 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
380 // Pause all windows event handlers when adaptor paused
381 for( SceneHolderPtr window : mWindows )
386 mThreadController->Pause();
389 // Ensure any messages queued during pause callbacks are processed by doing another update.
392 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Paused\n" );
396 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Not paused [%d]\n", mState );
400 // Dali::Internal::Adaptor::Adaptor::Resume
401 void Adaptor::Resume()
403 // Only resume the adaptor if we are in the suspended state.
404 if( PAUSED == mState )
408 // Reset the event handlers when adaptor resumed
409 for( SceneHolderPtr window : mWindows )
414 // Inform observers that we have resumed.
415 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
420 // Trigger processing of events queued up while paused
421 mCore->ProcessEvents();
423 // Do at end to ensure our first update/render after resumption includes the processed messages as well
424 mThreadController->Resume();
426 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Resumed\n");
430 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Not resumed [%d]\n", mState );
436 if( RUNNING == mState ||
438 PAUSED_WHILE_HIDDEN == mState )
440 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
445 mThreadController->Stop();
447 // Delete the TTS player
448 for( int i =0; i < Dali::TtsPlayer::MODE_NUM; i++ )
452 mTtsPlayers[i].Reset();
456 // Destroy the image loader plugin
457 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
459 delete mNotificationTrigger;
460 mNotificationTrigger = NULL;
462 mCallbackManager->Stop();
466 DALI_LOG_RELEASE_INFO( "Adaptor::Stop\n" );
470 void Adaptor::ContextLost()
472 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
475 void Adaptor::ContextRegained()
477 // Inform core, so that texture resources can be reloaded
478 mCore->RecoverFromContextLoss();
480 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
483 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
485 Integration::Point convertedPoint( point );
486 mWindows.front()->FeedTouchPoint( convertedPoint, timeStamp );
489 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
491 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
492 mWindows.front()->FeedWheelEvent( event );
495 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
497 Integration::KeyEvent convertedEvent( keyEvent );
498 mWindows.front()->FeedKeyEvent( convertedEvent );
501 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface )
503 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation( window );
504 for( SceneHolderPtr windowPtr : mWindows )
506 if( windowPtr.Get() == windowImpl ) // the window is not deleted
508 // Let the core know the surface size has changed
509 mCore->SurfaceResized( &newSurface );
511 mResizedSignal.Emit( mAdaptor );
513 windowImpl->SetSurface( &newSurface );
515 // Flush the event queue to give the update-render thread chance
516 // to start processing messages for new camera setup etc as soon as possible
519 // This method blocks until the render thread has completed the replace.
520 mThreadController->ReplaceSurface( &newSurface );
526 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
528 return *mWindows.front()->GetSurface();
531 void Adaptor::ReleaseSurfaceLock()
533 mWindows.front()->GetSurface()->ReleaseLock();
536 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
538 if( !mTtsPlayers[mode] )
540 // Create the TTS player when it needed, because it can reduce launching time.
541 mTtsPlayers[mode] = TtsPlayer::New(mode);
544 return mTtsPlayers[mode];
547 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
549 bool idleAdded(false);
551 // Only add an idle if the Adaptor is actually running
552 if( RUNNING == mState || READY == mState || forceAdd )
554 idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
560 void Adaptor::RemoveIdle( CallbackBase* callback )
562 mCallbackManager->RemoveIdleCallback( callback );
565 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
567 mThreadController->SetPreRenderCallback( callback );
570 bool Adaptor::AddWindow( Dali::Integration::SceneHolder childWindow, const std::string& childWindowName, const std::string& childWindowClassName, bool childWindowMode )
572 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( childWindow );
573 windowImpl.SetAdaptor( Get() );
575 // Add the new Window to the container - the order is not important
576 mWindows.push_back( SceneHolderPtr( &windowImpl ) );
578 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( &windowImpl ) );
581 mWindowCreatedSignal.Emit( window );
587 bool Adaptor::RemoveWindow( Dali::Integration::SceneHolder* childWindow )
589 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation( *childWindow );
590 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
592 if( *iter == &windowImpl )
594 mWindows.erase( iter );
602 bool Adaptor::RemoveWindow( std::string childWindowName )
604 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
606 if( ( *iter )->GetName() == childWindowName )
608 mWindows.erase( iter );
616 bool Adaptor::RemoveWindow( Internal::Adaptor::SceneHolder* childWindow )
618 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
620 if( ( *iter )->GetId() == childWindow->GetId() )
622 mWindows.erase( iter );
630 Dali::Adaptor& Adaptor::Get()
632 DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
633 return gThreadLocalAdaptor->mAdaptor;
636 bool Adaptor::IsAvailable()
638 return gThreadLocalAdaptor != NULL;
641 void Adaptor::SceneCreated()
643 mCore->SceneCreated();
646 Dali::Integration::Core& Adaptor::GetCore()
651 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
653 mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
656 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
658 DALI_ASSERT_DEBUG( mDisplayConnection && "Display connection not created" );
659 return *mDisplayConnection;
662 GraphicsInterface& Adaptor::GetGraphicsInterface()
664 DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
668 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
670 return *mPlatformAbstraction;
673 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
675 return *mNotificationTrigger;
678 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
680 return mTriggerEventFactory;
683 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
685 return mSocketFactory;
688 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
690 if( !mWindows.empty() )
692 return mWindows.front()->GetSurface();
698 TraceInterface& Adaptor::GetKernelTraceInterface()
700 return mKernelTracer;
703 TraceInterface& Adaptor::GetSystemTraceInterface()
705 return mSystemTracer;
708 PerformanceInterface* Adaptor::GetPerformanceInterface()
710 return mPerformanceInterface;
713 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
715 DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
716 return *mPlatformAbstraction;
719 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
721 if( mTtsPlayers[mode] )
723 mTtsPlayers[mode].Reset();
727 Any Adaptor::GetNativeWindowHandle()
729 return mWindows.front()->GetNativeHandle();
732 Any Adaptor::GetGraphicsDisplay()
738 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
740 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
741 display = eglImpl.GetDisplay();
747 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
749 mUseRemoteSurface = useRemoteSurface;
752 void Adaptor::AddObserver( LifeCycleObserver& observer )
754 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
756 if ( match == mObservers.end() )
758 mObservers.push_back( &observer );
762 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
764 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
766 if ( match != mObservers.end() )
768 mObservers.erase( match );
772 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
776 mCore->QueueEvent(event);
780 void Adaptor::ProcessCoreEvents()
784 if( mPerformanceInterface )
786 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
789 mCore->ProcessEvents();
791 if( mPerformanceInterface )
793 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
798 void Adaptor::RequestUpdate( bool forceUpdate )
804 mThreadController->RequestUpdate();
808 case PAUSED_WHILE_HIDDEN:
810 // When Dali applications are partially visible behind the lock-screen,
811 // the indicator must be updated (therefore allow updates in the PAUSED state)
814 mThreadController->RequestUpdateOnce();
826 void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
828 // Only request a notification if the Adaptor is actually running
829 // and we haven't installed the idle notification
830 if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
832 mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
836 void Adaptor::OnWindowShown()
838 if( PAUSED_WHILE_HIDDEN == mState )
840 // Adaptor can now be resumed
845 // Force a render task
850 // Force a render task
853 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState );
857 void Adaptor::OnWindowHidden()
859 if( RUNNING == mState || READY == mState )
861 bool allWindowsHidden = true;
863 for( SceneHolderPtr window : mWindows )
865 if ( window->IsVisible() )
867 allWindowsHidden = false;
872 // Only pause the adaptor when all the windows are hidden
873 if( allWindowsHidden )
875 if( mState == RUNNING )
879 // Adaptor cannot be resumed until any window is shown
880 mState = PAUSED_WHILE_HIDDEN;
882 else // mState is READY
884 // Pause the adaptor after the state gets RUNNING
885 mState = PAUSED_WHILE_INITIALIZING;
890 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Some windows are shown. Don't pause adaptor.\n" );
895 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState );
899 // Dali::Internal::Adaptor::Adaptor::OnDamaged
900 void Adaptor::OnDamaged( const DamageArea& area )
902 // This is needed for the case where Dali window is partially obscured
903 RequestUpdate( false );
906 void Adaptor::SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
908 // Let the core know the surface size has changed
909 mCore->SurfaceResized( surface );
911 mResizedSignal.Emit( mAdaptor );
914 void Adaptor::SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
916 // Flush the event queue to give the update-render thread chance
917 // to start processing messages for new camera setup etc as soon as possible
920 mThreadController->ResizeSurface();
923 void Adaptor::NotifySceneCreated()
925 GetCore().SceneCreated();
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 // Start thread controller after the scene has been created
932 mThreadController->Start();
934 // Process after surface is created (registering to remote surface provider if required)
935 SurfaceInitialized();
937 if( mState != PAUSED_WHILE_INITIALIZING )
941 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated: Adaptor is running\n" );
949 mState = PAUSED_WHILE_HIDDEN;
951 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated: Adaptor is paused\n" );
955 void Adaptor::NotifyLanguageChanged()
957 mLanguageChangedSignal.Emit( mAdaptor );
960 void Adaptor::RenderOnce()
965 const LogFactoryInterface& Adaptor::GetLogFactory()
967 return *mEnvironmentOptions;
970 void Adaptor::RegisterProcessor( Integration::Processor& processor )
972 GetCore().RegisterProcessor(processor);
975 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
977 GetCore().UnregisterProcessor(processor);
980 void Adaptor::RequestUpdateOnce()
982 if( mThreadController )
984 mThreadController->RequestUpdateOnce();
988 bool Adaptor::ProcessCoreEventsFromIdle()
992 // the idle handle automatically un-installs itself
993 mNotificationOnIdleInstalled = false;
998 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow( Dali::Actor& actor )
1000 Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
1002 for( auto window : mWindows )
1004 if ( scene == window->GetScene() )
1006 return window.Get();
1013 Dali::WindowContainer Adaptor::GetWindows() const
1015 Dali::WindowContainer windows;
1017 for ( auto iter = mWindows.begin(); iter != mWindows.end(); ++iter )
1019 // Downcast to Dali::Window
1020 Dali::Window window( dynamic_cast<Dali::Internal::Adaptor::Window*>( iter->Get() ) );
1023 windows.push_back( window );
1030 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions)
1032 mLanguageChangedSignal(),
1033 mWindowCreatedSignal(),
1034 mAdaptor( adaptor ),
1037 mThreadController( nullptr ),
1038 mGraphics( nullptr ),
1039 mDisplayConnection( nullptr ),
1041 mPlatformAbstraction( nullptr ),
1042 mCallbackManager( nullptr ),
1043 mNotificationOnIdleInstalled( false ),
1044 mNotificationTrigger( nullptr ),
1045 mDaliFeedbackPlugin(),
1046 mFeedbackController( nullptr ),
1049 mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1050 mPerformanceInterface( nullptr ),
1053 mTriggerEventFactory(),
1054 mObjectProfiler( nullptr ),
1056 mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
1057 mUseRemoteSurface( false )
1059 DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
1060 mWindows.insert( mWindows.begin(), SceneHolderPtr( &Dali::GetImplementation( window ) ) );
1062 gThreadLocalAdaptor = this;
1065 void Adaptor::SetRootLayoutDirection( std::string locale )
1067 Dali::Stage stage = Dali::Stage::GetCurrent();
1069 stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
1070 static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
1073 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
1075 bool idleAdded( false );
1077 // Only add an idle if the Adaptor is actually running
1078 if( RUNNING == mState || READY == mState || forceAdd )
1080 idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
1086 void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
1088 mCallbackManager->RemoveIdleEntererCallback( callback );
1091 } // namespace Adaptor
1093 } // namespace Internal