2 * Copyright (c) 2018 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
86 Dali::Adaptor* Adaptor::New( Any nativeWindow, RenderSurface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
88 Dali::Adaptor* adaptor = new Dali::Adaptor;
89 Adaptor* impl = new Adaptor( nativeWindow, *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::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
103 Any winId = window.GetNativeHandle();
105 Window& windowImpl = Dali::GetImplementation( window );
106 Dali::Adaptor* adaptor = New( winId, windowImpl.GetSurface(), configuration, environmentOptions );
107 windowImpl.SetAdaptor( *adaptor );
111 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Any nativeWindow, RenderSurface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
113 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
114 Adaptor* impl = new Adaptor( nativeWindow, *adaptor, surface, environmentOptions ); // Impl adaptor
115 adaptor->mImpl = impl;
117 impl->Initialize( graphicsFactory, configuration );
122 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
124 Any winId = window.GetNativeHandle();
126 Window& windowImpl = Dali::GetImplementation( window );
127 Dali::Adaptor* adaptor = New( graphicsFactory, winId, windowImpl.GetSurface(), configuration, environmentOptions );
128 windowImpl.SetAdaptor( *adaptor );
132 void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration )
134 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
135 Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
136 mEnvironmentOptions->SetLogFunction( logFunction );
137 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
139 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
142 GetDataStoragePath( path );
143 mPlatformAbstraction->SetDataStoragePath( path );
145 ResourcePolicy::DataRetention dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
146 if( configuration == Dali::Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS )
148 dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
151 // Note, Tizen does not use DALI_RETAINS_ALL_DATA, as it can reload images from files automatically.
153 if( mEnvironmentOptions->PerformanceServerRequired() )
155 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, *mEnvironmentOptions );
158 mEnvironmentOptions->CreateTraceManager( mPerformanceInterface );
159 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
161 mCallbackManager = CallbackManager::New();
163 WindowPane defaultWindow = mWindowFrame.front();
165 DALI_ASSERT_DEBUG( defaultWindow.surface && "Surface not initialized" );
167 PositionSize size = defaultWindow.surface->GetPositionSize();
169 mGestureManager = new GestureManager(*this, Vector2(size.width, size.height), mCallbackManager, *mEnvironmentOptions);
171 mGraphics = &( graphicsFactory.Create() );
172 mGraphics->Initialize( mEnvironmentOptions );
174 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
176 GlImplementation& mGLES = eglGraphics->GetGlesInterface();
177 EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
179 mCore = Integration::Core::New( *this,
180 *mPlatformAbstraction,
184 dataRetentionPolicy ,
185 ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
186 mGraphics->GetDepthBufferRequired(),
187 mGraphics->GetStencilBufferRequired() );
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.surface->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() );
275 SetupSystemInformation();
280 // Ensure stop status
283 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
284 gThreadLocalAdaptor = NULL;
286 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
288 (*iter)->OnDestroy();
291 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
292 delete mVSyncMonitor;
293 delete mEventHandler;
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 )
324 // Start the callback manager
325 mCallbackManager->Start();
327 WindowPane defaultWindow = mWindowFrame.front();
329 // Create event handler
330 mEventHandler = new EventHandler( defaultWindow.surface, *this, *mGestureManager, *this, mDragAndDropDetector );
332 if( mDeferredRotationObserver != NULL )
334 mEventHandler->SetRotationObserver(mDeferredRotationObserver);
335 mDeferredRotationObserver = NULL;
338 unsigned int dpiHor, dpiVer;
341 defaultWindow.surface->GetDpi( dpiHor, dpiVer );
343 // tell core about the DPI value
344 mCore->SetDpi(dpiHor, dpiVer);
346 // set the DPI value for font rendering
347 FontClient fontClient = FontClient::Get();
348 fontClient.SetDpi( dpiHor, dpiVer );
350 // Tell the core the size of the surface just before we start the render-thread
351 PositionSize size = defaultWindow.surface->GetPositionSize();
353 mCore->SurfaceResized( size.width, size.height );
355 // Initialize the thread controller
356 mThreadController->Initialize();
358 ProcessCoreEvents(); // Ensure any startup messages are processed.
360 // Initialize the image loader plugin
361 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
363 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
369 // Dali::Internal::Adaptor::Adaptor::Pause
370 void Adaptor::Pause()
372 // Only pause the adaptor if we're actually running.
373 if( RUNNING == mState )
375 // Inform observers that we are about to be paused.
376 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
381 // Reset the event handler when adaptor paused
384 mEventHandler->Pause();
387 mThreadController->Pause();
390 // Ensure any messages queued during pause callbacks are processed by doing another update.
393 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Paused\n" );
397 DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Not paused [%d]\n", mState );
401 // Dali::Internal::Adaptor::Adaptor::Resume
402 void Adaptor::Resume()
404 // Only resume the adaptor if we are in the suspended state.
405 if( PAUSED == mState )
409 // Reset the event handler when adaptor resumed
412 mEventHandler->Resume();
415 // Inform observers that we have resumed.
416 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
421 // Trigger processing of events queued up while paused
422 mCore->ProcessEvents();
424 // Do at end to ensure our first update/render after resumption includes the processed messages as well
425 mThreadController->Resume();
427 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Resumed\n");
431 DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Not resumed [%d]\n", mState );
437 if( RUNNING == mState ||
439 PAUSED_WHILE_HIDDEN == mState )
441 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
446 mThreadController->Stop();
448 // Clear out all the handles to Windows
449 mWindowFrame.clear();
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 mEventHandler;
464 mEventHandler = NULL;
466 delete mNotificationTrigger;
467 mNotificationTrigger = NULL;
469 mCallbackManager->Stop();
473 DALI_LOG_RELEASE_INFO( "Adaptor::Stop\n" );
477 void Adaptor::ContextLost()
479 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
482 void Adaptor::ContextRegained()
484 // Inform core, so that texture resources can be reloaded
485 mCore->RecoverFromContextLoss();
487 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
490 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
492 mEventHandler->FeedTouchPoint( point, timeStamp );
495 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
497 mEventHandler->FeedWheelEvent( wheelEvent );
500 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
502 mEventHandler->FeedKeyEvent( keyEvent );
505 void Adaptor::ReplaceSurface( Any nativeWindow, RenderSurface& newSurface )
507 PositionSize positionSize = newSurface.GetPositionSize();
509 // Let the core know the surface size has changed
510 mCore->SurfaceResized( positionSize.width, positionSize.height );
512 mResizedSignal.Emit( mAdaptor );
514 WindowPane newDefaultWindow;
515 newDefaultWindow.nativeWindow = nativeWindow;
516 newDefaultWindow.surface = &newSurface;
518 WindowPane oldDefaultWindow = mWindowFrame.front();
520 // Update WindowFrame
521 std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
522 iter = mWindowFrame.insert( iter, newDefaultWindow );
524 // Flush the event queue to give the update-render thread chance
525 // to start processing messages for new camera setup etc as soon as possible
528 // This method blocks until the render thread has completed the replace.
529 mThreadController->ReplaceSurface( newDefaultWindow.surface );
531 // Must delete the old Window only after the render thread has completed the replace
532 oldDefaultWindow.surface->DestroySurface();
533 oldDefaultWindow.surface = nullptr;
536 RenderSurface& Adaptor::GetSurface() const
538 WindowPane defaultWindow = mWindowFrame.front();
539 return *(defaultWindow.surface);
542 void Adaptor::ReleaseSurfaceLock()
544 WindowPane defaultWindow = mWindowFrame.front();
545 defaultWindow.surface->ReleaseLock();
548 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
550 if(!mTtsPlayers[mode])
552 // Create the TTS player when it needed, because it can reduce launching time.
553 mTtsPlayers[mode] = TtsPlayer::New(mode);
556 return mTtsPlayers[mode];
559 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
561 bool idleAdded(false);
563 // Only add an idle if the Adaptor is actually running
564 if( RUNNING == mState || READY == mState || forceAdd )
566 idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
572 void Adaptor::RemoveIdle( CallbackBase* callback )
574 mCallbackManager->RemoveIdleCallback( callback );
577 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
579 mThreadController->SetPreRenderCallback( callback );
582 bool Adaptor::AddWindow( Dali::Window* childWindow, const std::string& childWindowName, const std::string& childWindowClassName, const bool& childWindowMode )
584 // This is any Window that is not the main (default) one
585 WindowPane additionalWindow;
586 additionalWindow.instance = childWindow;
587 additionalWindow.window_name = childWindowName;
588 additionalWindow.class_name = childWindowClassName;
589 additionalWindow.window_mode = childWindowMode;
591 // Add the new Window to the Frame - the order is not important
592 mWindowFrame.push_back( additionalWindow );
594 Window& windowImpl = Dali::GetImplementation( *childWindow );
595 windowImpl.SetAdaptor( Get() );
600 bool Adaptor::RemoveWindow( Dali::Window* childWindow )
602 for ( WindowFrames::iterator iter = mWindowFrame.begin(); iter != mWindowFrame.end(); ++iter )
604 if( iter->instance == childWindow )
606 mWindowFrame.erase( iter );
614 bool Adaptor::RemoveWindow( std::string childWindowName )
616 for ( WindowFrames::iterator iter = mWindowFrame.begin(); iter != mWindowFrame.end(); ++iter )
618 if( iter->window_name == childWindowName )
620 mWindowFrame.erase( iter );
628 Dali::Adaptor& Adaptor::Get()
630 DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
631 return gThreadLocalAdaptor->mAdaptor;
634 bool Adaptor::IsAvailable()
636 return gThreadLocalAdaptor != NULL;
639 void Adaptor::SceneCreated()
641 mCore->SceneCreated();
644 Dali::Integration::Core& Adaptor::GetCore()
649 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
651 mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
654 void Adaptor::SetUseHardwareVSync( bool useHardware )
656 mVSyncMonitor->SetUseHardwareVSync( useHardware );
659 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
661 DALI_ASSERT_DEBUG( mDisplayConnection && "Display connection not created" );
662 return *mDisplayConnection;
665 GraphicsInterface& Adaptor::GetGraphicsInterface()
667 DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
671 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
673 return *mPlatformAbstraction;
676 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
678 return *mNotificationTrigger;
681 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
683 return mTriggerEventFactory;
686 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
688 return mSocketFactory;
691 RenderSurface* Adaptor::GetRenderSurfaceInterface()
693 if( !mWindowFrame.empty())
695 WindowPane defaultWindow = mWindowFrame.front();
696 return defaultWindow.surface;
704 VSyncMonitorInterface* Adaptor::GetVSyncMonitorInterface()
706 return mVSyncMonitor;
709 TraceInterface& Adaptor::GetKernelTraceInterface()
711 return mKernelTracer;
714 TraceInterface& Adaptor::GetSystemTraceInterface()
716 return mSystemTracer;
719 PerformanceInterface* Adaptor::GetPerformanceInterface()
721 return mPerformanceInterface;
724 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
726 DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
727 return *mPlatformAbstraction;
730 void Adaptor::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
732 mDragAndDropDetector = detector;
736 mEventHandler->SetDragAndDropDetector( detector );
740 void Adaptor::SetRotationObserver( RotationObserver* observer )
744 mEventHandler->SetRotationObserver( observer );
746 else if( mState == READY )
748 // Set once event handler exists
749 mDeferredRotationObserver = observer;
753 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
755 if(mTtsPlayers[mode])
757 mTtsPlayers[mode].Reset();
761 void Adaptor::SetMinimumPinchDistance(float distance)
763 if( mGestureManager )
765 mGestureManager->SetMinimumPinchDistance(distance);
769 Any Adaptor::GetNativeWindowHandle()
771 WindowPane defaultWindow = mWindowFrame.front();
772 return defaultWindow.nativeWindow;
775 Any Adaptor::GetGraphicsDisplay()
781 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
783 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
784 display = eglImpl.GetDisplay();
790 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
792 mUseRemoteSurface = useRemoteSurface;
795 void Adaptor::AddObserver( LifeCycleObserver& observer )
797 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
799 if ( match == mObservers.end() )
801 mObservers.push_back( &observer );
805 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
807 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
809 if ( match != mObservers.end() )
811 mObservers.erase( match );
815 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
819 mCore->QueueEvent(event);
823 void Adaptor::ProcessCoreEvents()
827 if( mPerformanceInterface )
829 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
832 mCore->ProcessEvents();
834 if( mPerformanceInterface )
836 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
841 void Adaptor::RequestUpdate( bool forceUpdate )
847 mThreadController->RequestUpdate();
851 case PAUSED_WHILE_HIDDEN:
853 // When Dali applications are partially visible behind the lock-screen,
854 // the indicator must be updated (therefore allow updates in the PAUSED state)
857 mThreadController->RequestUpdateOnce();
869 void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
871 // Only request a notification if the Adaptor is actually running
872 // and we haven't installed the idle notification
873 if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
875 mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
879 void Adaptor::OnWindowShown()
881 if ( PAUSED_WHILE_HIDDEN == mState )
883 // Adaptor can now be resumed
888 // Force a render task
893 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Not shown [%d]\n", mState );
897 void Adaptor::OnWindowHidden()
899 if ( RUNNING == mState )
903 // Adaptor cannot be resumed until the window is shown
904 mState = PAUSED_WHILE_HIDDEN;
908 DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Not hidden [%d]\n", mState );
912 // Dali::Internal::Adaptor::Adaptor::OnDamaged
913 void Adaptor::OnDamaged( const DamageArea& area )
915 // This is needed for the case where Dali window is partially obscured
916 RequestUpdate( false );
919 void Adaptor::SurfaceResizePrepare( SurfaceSize surfaceSize )
921 // Let the core know the surface size has changed
922 mCore->SurfaceResized( surfaceSize.GetWidth(), surfaceSize.GetHeight() );
924 mResizedSignal.Emit( mAdaptor );
927 void Adaptor::SurfaceResizeComplete( SurfaceSize surfaceSize )
929 // Flush the event queue to give the update-render thread chance
930 // to start processing messages for new camera setup etc as soon as possible
933 mThreadController->ResizeSurface();
936 void Adaptor::NotifySceneCreated()
938 GetCore().SceneCreated();
940 // Flush the event queue to give the update-render thread chance
941 // to start processing messages for new camera setup etc as soon as possible
944 // Start thread controller after the scene has been created
945 mThreadController->Start();
947 // Process after surface is created (registering to remote surface provider if required)
948 SurfaceInitialized();
952 DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated\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 void Adaptor::IndicatorSizeChanged(int height)
990 // Let the core know the indicator height is changed
991 mCore->SetTopMargin(height);
994 bool Adaptor::ProcessCoreEventsFromIdle()
998 // the idle handle automatically un-installs itself
999 mNotificationOnIdleInstalled = false;
1004 Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions)
1006 mLanguageChangedSignal(),
1007 mAdaptor( adaptor ),
1010 mThreadController( nullptr ),
1011 mVSyncMonitor( nullptr ),
1012 mGraphics( nullptr ),
1013 mDisplayConnection( nullptr ),
1015 mPlatformAbstraction( nullptr ),
1016 mEventHandler( nullptr ),
1017 mCallbackManager( nullptr ),
1018 mNotificationOnIdleInstalled( false ),
1019 mNotificationTrigger( nullptr ),
1020 mGestureManager( nullptr ),
1021 mDaliFeedbackPlugin(),
1022 mFeedbackController( nullptr ),
1025 mDragAndDropDetector(),
1026 mDeferredRotationObserver( nullptr ),
1027 mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1028 mPerformanceInterface( nullptr ),
1031 mTriggerEventFactory(),
1032 mObjectProfiler( nullptr ),
1034 mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
1035 mUseRemoteSurface( false )
1037 DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
1039 WindowPane defaultWindow;
1040 defaultWindow.nativeWindow = nativeWindow;
1041 defaultWindow.surface = surface;
1043 std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
1044 iter = mWindowFrame.insert( iter, defaultWindow );
1046 gThreadLocalAdaptor = this;
1049 void Adaptor::SetRootLayoutDirection( std::string locale )
1051 Dali::Stage stage = Dali::Stage::GetCurrent();
1053 stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
1054 static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
1057 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
1059 bool idleAdded( false );
1061 // Only add an idle if the Adaptor is actually running
1062 if( RUNNING == mState || READY == mState || forceAdd )
1064 idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
1070 void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
1072 mCallbackManager->RemoveIdleEntererCallback( callback );
1075 } // namespace Adaptor
1077 } // namespace Internal