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/touch-event-integ.h>
33 #include <dali/integration-api/processor-interface.h>
36 #include <dali/public-api/dali-adaptor-common.h>
37 #include <dali/internal/system/common/thread-controller.h>
38 #include <dali/internal/system/common/performance-interface-factory.h>
39 #include <dali/internal/adaptor/common/lifecycle-observer.h>
41 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
42 #include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
44 #include <dali/devel-api/text-abstraction/font-client.h>
46 #include <dali/internal/system/common/callback-manager.h>
47 #include <dali/internal/accessibility/common/tts-player-impl.h>
48 #include <dali/internal/accessibility/common/accessibility-adaptor-impl.h>
49 #include <dali/internal/input/common/gesture-manager.h>
50 #include <dali/internal/window-system/common/event-handler.h>
51 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
52 #include <dali/internal/graphics/gles/gl-implementation.h>
53 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
54 #include <dali/internal/graphics/common/egl-image-extensions.h>
55 #include <dali/internal/clipboard/common/clipboard-impl.h>
56 #include <dali/internal/graphics/common/vsync-monitor.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::Window 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::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
102 Window& 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::Window 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::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
121 Window& 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 WindowPtr defaultWindow = mWindows.front();
160 DALI_ASSERT_DEBUG( defaultWindow->GetSurface() && "Surface not initialized" );
162 PositionSize size = defaultWindow->GetSurface()->GetPositionSize();
164 mGestureManager = new GestureManager(*this, Vector2(size.width, size.height), mCallbackManager, *mEnvironmentOptions);
166 mGraphics = &( graphicsFactory.Create() );
167 mGraphics->Initialize( mEnvironmentOptions );
169 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
171 // This will only be created once
172 eglGraphics->Create();
174 GlImplementation& mGLES = eglGraphics->GetGlesInterface();
175 EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
177 mCore = Integration::Core::New( *this,
178 *mPlatformAbstraction,
182 dataRetentionPolicy ,
183 ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
184 mGraphics->GetDepthBufferRequired(),
185 mGraphics->GetStencilBufferRequired() );
187 defaultWindow->SetAdaptor( *this );
189 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
190 if( 0u < timeInterval )
192 mObjectProfiler = new ObjectProfiler( timeInterval );
195 mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
197 mVSyncMonitor = new VSyncMonitor;
199 mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow->GetSurface()->GetSurfaceType() );
201 mThreadController = new ThreadController( *this, *mEnvironmentOptions );
203 // Should be called after Core creation
204 if( mEnvironmentOptions->GetPanGestureLoggingLevel() )
206 Integration::EnableProfiling( Dali::Integration::PROFILING_TYPE_PAN_GESTURE );
208 if( mEnvironmentOptions->GetPanGesturePredictionMode() >= 0 )
210 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
212 if( mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0 )
214 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
216 if( mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0 )
218 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
220 if( mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0 )
222 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
224 if( mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0 )
226 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
228 if( mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0 )
230 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
232 if( mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f )
234 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
236 if( mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0 )
238 Integration::SetPanGestureUseActualTimes( mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false );
240 if( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0 )
242 Integration::SetPanGestureInterpolationTimeRange( mEnvironmentOptions->GetPanGestureInterpolationTimeRange() );
244 if( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0 )
246 Integration::SetPanGestureScalarOnlyPredictionEnabled( mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false );
248 if( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0 )
250 Integration::SetPanGestureTwoPointPredictionEnabled( mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false );
252 if( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0 )
254 Integration::SetPanGestureTwoPointInterpolatePastTime( mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() );
256 if( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f )
258 Integration::SetPanGestureTwoPointVelocityBias( mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() );
260 if( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f )
262 Integration::SetPanGestureTwoPointAccelerationBias( mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() );
264 if( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0 )
266 Integration::SetPanGestureMultitapSmoothingRange( mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() );
269 // Set max texture size
270 if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
272 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
278 // Ensure stop status
281 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
282 gThreadLocalAdaptor = NULL;
284 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
286 (*iter)->OnDestroy();
289 // Clear out all the handles to Windows
292 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
293 delete mVSyncMonitor;
294 delete mObjectProfiler;
298 delete mGestureManager;
299 delete mDisplayConnection;
300 delete mPlatformAbstraction;
301 delete mCallbackManager;
302 delete mPerformanceInterface;
304 mGraphics->Destroy();
306 // uninstall it on this thread (main actor thread)
307 Dali::Integration::Log::UninstallLogFunction();
309 // Delete environment options if we own it
310 if( mEnvironmentOptionsOwned )
312 delete mEnvironmentOptions;
316 void Adaptor::Start()
318 // It doesn't support restart after stop at this moment to support restarting, need more testing
319 if( READY != mState )
326 SetupSystemInformation();
328 // Start the callback manager
329 mCallbackManager->Start();
331 WindowPtr defaultWindow = mWindows.front();
333 if( mDeferredRotationObserver != NULL )
335 defaultWindow->SetRotationObserver( mDeferredRotationObserver );
336 mDeferredRotationObserver = NULL;
339 unsigned int dpiHor, dpiVer;
342 defaultWindow->GetSurface()->GetDpi( dpiHor, dpiVer );
344 // set the DPI value for font rendering
345 FontClient fontClient = FontClient::Get();
346 fontClient.SetDpi( dpiHor, dpiVer );
348 // Tell the core the size of the surface just before we start the render-thread
349 mCore->SurfaceResized( defaultWindow->GetSurface() );
351 // Initialize the thread controller
352 mThreadController->Initialize();
354 ProcessCoreEvents(); // Ensure any startup messages are processed.
356 // Initialize the image loader plugin
357 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
359 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
365 // Dali::Internal::Adaptor::Adaptor::Pause
366 void Adaptor::Pause()
368 // Only pause the adaptor if we're actually running.
369 if( RUNNING == mState )
371 // Inform observers that we are about to be paused.
372 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
377 // Pause all windows event handlers when adaptor paused
378 for( WindowPtr window : mWindows )
383 mThreadController->Pause();
386 // Ensure any messages queued during pause callbacks are processed by doing another update.
389 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Paused\n" );
393 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Not paused [%d]\n", mState );
397 // Dali::Internal::Adaptor::Adaptor::Resume
398 void Adaptor::Resume()
400 // Only resume the adaptor if we are in the suspended state.
401 if( PAUSED == mState )
405 // Reset the event handlers when adaptor resumed
406 for( WindowPtr window : mWindows )
411 // Inform observers that we have resumed.
412 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
417 // Trigger processing of events queued up while paused
418 mCore->ProcessEvents();
420 // Do at end to ensure our first update/render after resumption includes the processed messages as well
421 mThreadController->Resume();
423 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Resumed\n");
427 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Not resumed [%d]\n", mState );
433 if( RUNNING == mState ||
435 PAUSED_WHILE_HIDDEN == mState )
437 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
442 mThreadController->Stop();
444 // Delete the TTS player
445 for( int i =0; i < Dali::TtsPlayer::MODE_NUM; i++ )
449 mTtsPlayers[i].Reset();
453 // Destroy the image loader plugin
454 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
456 delete mNotificationTrigger;
457 mNotificationTrigger = NULL;
459 mCallbackManager->Stop();
463 DALI_LOG_RELEASE_INFO( "Adaptor::Stop\n" );
467 void Adaptor::ContextLost()
469 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
472 void Adaptor::ContextRegained()
474 // Inform core, so that texture resources can be reloaded
475 mCore->RecoverFromContextLoss();
477 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
480 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
482 mWindows.front()->FeedTouchPoint( point, timeStamp );
485 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
487 mWindows.front()->FeedWheelEvent( wheelEvent );
490 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
492 mWindows.front()->FeedKeyEvent( keyEvent );
495 void Adaptor::ReplaceSurface( Dali::Window window, Dali::RenderSurfaceInterface& newSurface )
497 Window* windowImpl = &Dali::GetImplementation( window );
498 for( WindowPtr windowPtr : mWindows )
500 if( windowPtr.Get() == windowImpl ) // the window is not deleted
502 // Let the core know the surface size has changed
503 mCore->SurfaceResized( &newSurface );
505 mResizedSignal.Emit( mAdaptor );
507 windowImpl->SetSurface( static_cast<WindowRenderSurface*>( &newSurface ) );
509 // Flush the event queue to give the update-render thread chance
510 // to start processing messages for new camera setup etc as soon as possible
513 // This method blocks until the render thread has completed the replace.
514 mThreadController->ReplaceSurface( &newSurface );
520 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
522 return *mWindows.front()->GetSurface();
525 void Adaptor::ReleaseSurfaceLock()
527 mWindows.front()->GetSurface()->ReleaseLock();
530 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
532 if( !mTtsPlayers[mode] )
534 // Create the TTS player when it needed, because it can reduce launching time.
535 mTtsPlayers[mode] = TtsPlayer::New(mode);
538 return mTtsPlayers[mode];
541 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
543 bool idleAdded(false);
545 // Only add an idle if the Adaptor is actually running
546 if( RUNNING == mState || READY == mState || forceAdd )
548 idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
554 void Adaptor::RemoveIdle( CallbackBase* callback )
556 mCallbackManager->RemoveIdleCallback( callback );
559 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
561 mThreadController->SetPreRenderCallback( callback );
564 bool Adaptor::AddWindow( Dali::Window* childWindow, const std::string& childWindowName, const std::string& childWindowClassName, const bool& childWindowMode )
566 Window& windowImpl = Dali::GetImplementation( *childWindow );
567 windowImpl.SetAdaptor( Get() );
569 // Add the new Window to the container - the order is not important
570 mWindows.push_back( WindowPtr( &windowImpl ) );
574 bool Adaptor::RemoveWindow( Dali::Window* childWindow )
576 Window& windowImpl = Dali::GetImplementation( *childWindow );
577 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
579 if( *iter == &windowImpl )
581 mWindows.erase( iter );
589 bool Adaptor::RemoveWindow( std::string childWindowName )
591 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
593 if( ( *iter )->GetName() == childWindowName )
595 mWindows.erase( iter );
603 bool Adaptor::RemoveWindow( Window* childWindow )
605 for ( WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter )
607 if( ( *iter )->GetId() == childWindow->GetId() )
609 mWindows.erase( iter );
617 Dali::Adaptor& Adaptor::Get()
619 DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
620 return gThreadLocalAdaptor->mAdaptor;
623 bool Adaptor::IsAvailable()
625 return gThreadLocalAdaptor != NULL;
628 void Adaptor::SceneCreated()
630 mCore->SceneCreated();
633 Dali::Integration::Core& Adaptor::GetCore()
638 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
640 mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
643 void Adaptor::SetUseHardwareVSync( bool useHardware )
645 mVSyncMonitor->SetUseHardwareVSync( useHardware );
648 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
650 DALI_ASSERT_DEBUG( mDisplayConnection && "Display connection not created" );
651 return *mDisplayConnection;
654 GraphicsInterface& Adaptor::GetGraphicsInterface()
656 DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
660 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
662 return *mPlatformAbstraction;
665 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
667 return *mNotificationTrigger;
670 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
672 return mTriggerEventFactory;
675 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
677 return mSocketFactory;
680 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
682 if( !mWindows.empty() )
684 return mWindows.front()->GetSurface();
690 VSyncMonitorInterface* Adaptor::GetVSyncMonitorInterface()
692 return mVSyncMonitor;
695 TraceInterface& Adaptor::GetKernelTraceInterface()
697 return mKernelTracer;
700 TraceInterface& Adaptor::GetSystemTraceInterface()
702 return mSystemTracer;
705 PerformanceInterface* Adaptor::GetPerformanceInterface()
707 return mPerformanceInterface;
710 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
712 DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
713 return *mPlatformAbstraction;
716 void Adaptor::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
718 mDragAndDropDetector = detector;
721 void Adaptor::SetRotationObserver( RotationObserver* observer )
723 WindowPtr defaultWindow = mWindows.front();
724 if( !defaultWindow->SetRotationObserver( observer ) && mState == READY )
726 // Set once event handler exists
727 mDeferredRotationObserver = observer;
731 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
733 if( mTtsPlayers[mode] )
735 mTtsPlayers[mode].Reset();
739 void Adaptor::SetMinimumPinchDistance(float distance)
741 if( mGestureManager )
743 mGestureManager->SetMinimumPinchDistance(distance);
747 Any Adaptor::GetNativeWindowHandle()
749 return mWindows.front()->GetNativeHandle();
752 Any Adaptor::GetGraphicsDisplay()
758 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
760 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
761 display = eglImpl.GetDisplay();
767 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
769 mUseRemoteSurface = useRemoteSurface;
772 void Adaptor::AddObserver( LifeCycleObserver& observer )
774 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
776 if ( match == mObservers.end() )
778 mObservers.push_back( &observer );
782 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
784 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
786 if ( match != mObservers.end() )
788 mObservers.erase( match );
792 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
796 mCore->QueueEvent(event);
800 void Adaptor::ProcessCoreEvents()
804 if( mPerformanceInterface )
806 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
809 mCore->ProcessEvents();
811 if( mPerformanceInterface )
813 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
818 void Adaptor::RequestUpdate( bool forceUpdate )
824 mThreadController->RequestUpdate();
828 case PAUSED_WHILE_HIDDEN:
830 // When Dali applications are partially visible behind the lock-screen,
831 // the indicator must be updated (therefore allow updates in the PAUSED state)
834 mThreadController->RequestUpdateOnce();
846 void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
848 // Only request a notification if the Adaptor is actually running
849 // and we haven't installed the idle notification
850 if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
852 mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
856 void Adaptor::OnWindowShown()
858 if ( PAUSED_WHILE_HIDDEN == mState )
860 // Adaptor can now be resumed
865 // Force a render task
870 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Not shown [%d]\n", mState );
874 void Adaptor::OnWindowHidden()
876 if ( RUNNING == mState )
880 // Adaptor cannot be resumed until the window is shown
881 mState = PAUSED_WHILE_HIDDEN;
885 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Not hidden [%d]\n", mState );
889 // Dali::Internal::Adaptor::Adaptor::OnDamaged
890 void Adaptor::OnDamaged( const DamageArea& area )
892 // This is needed for the case where Dali window is partially obscured
893 RequestUpdate( false );
896 void Adaptor::SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
898 // Let the core know the surface size has changed
899 mCore->SurfaceResized( surface );
901 mResizedSignal.Emit( mAdaptor );
904 void Adaptor::SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
906 // Flush the event queue to give the update-render thread chance
907 // to start processing messages for new camera setup etc as soon as possible
910 mThreadController->ResizeSurface();
913 void Adaptor::NotifySceneCreated()
915 GetCore().SceneCreated();
917 // Flush the event queue to give the update-render thread chance
918 // to start processing messages for new camera setup etc as soon as possible
921 // Start thread controller after the scene has been created
922 mThreadController->Start();
924 // Process after surface is created (registering to remote surface provider if required)
925 SurfaceInitialized();
929 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated\n" );
932 void Adaptor::NotifyLanguageChanged()
934 mLanguageChangedSignal.Emit( mAdaptor );
937 void Adaptor::RenderOnce()
942 const LogFactoryInterface& Adaptor::GetLogFactory()
944 return *mEnvironmentOptions;
947 void Adaptor::RegisterProcessor( Integration::Processor& processor )
949 GetCore().RegisterProcessor(processor);
952 void Adaptor::UnregisterProcessor( Integration::Processor& processor )
954 GetCore().UnregisterProcessor(processor);
957 void Adaptor::RequestUpdateOnce()
959 if( mThreadController )
961 mThreadController->RequestUpdateOnce();
965 bool Adaptor::ProcessCoreEventsFromIdle()
969 // the idle handle automatically un-installs itself
970 mNotificationOnIdleInstalled = false;
975 Adaptor::Adaptor(Dali::Window window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions)
977 mLanguageChangedSignal(),
981 mThreadController( nullptr ),
982 mVSyncMonitor( nullptr ),
983 mGraphics( nullptr ),
984 mDisplayConnection( nullptr ),
986 mPlatformAbstraction( nullptr ),
987 mCallbackManager( nullptr ),
988 mNotificationOnIdleInstalled( false ),
989 mNotificationTrigger( nullptr ),
990 mGestureManager( nullptr ),
991 mDaliFeedbackPlugin(),
992 mFeedbackController( nullptr ),
995 mDragAndDropDetector(),
996 mDeferredRotationObserver( nullptr ),
997 mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
998 mPerformanceInterface( nullptr ),
1001 mTriggerEventFactory(),
1002 mObjectProfiler( nullptr ),
1004 mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
1005 mUseRemoteSurface( false )
1007 DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
1008 mWindows.insert( mWindows.begin(), WindowPtr( &Dali::GetImplementation( window ) ) );
1010 gThreadLocalAdaptor = this;
1013 void Adaptor::SetRootLayoutDirection( std::string locale )
1015 Dali::Stage stage = Dali::Stage::GetCurrent();
1017 stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
1018 static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
1021 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
1023 bool idleAdded( false );
1025 // Only add an idle if the Adaptor is actually running
1026 if( RUNNING == mState || READY == mState || forceAdd )
1028 idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
1034 void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
1036 mCallbackManager->RemoveIdleEntererCallback( callback );
1039 } // namespace Adaptor
1041 } // namespace Internal