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>
35 #include <dali/public-api/dali-adaptor-common.h>
36 #include <dali/internal/system/common/thread-controller.h>
37 #include <dali/internal/system/common/performance-interface-factory.h>
38 #include <dali/internal/adaptor/common/lifecycle-observer.h>
40 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
41 #include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
43 #include <dali/devel-api/text-abstraction/font-client.h>
45 #include <dali/internal/system/common/callback-manager.h>
46 #include <dali/internal/accessibility/common/tts-player-impl.h>
47 #include <dali/internal/accessibility/common/accessibility-adaptor-impl.h>
48 #include <dali/internal/input/common/gesture-manager.h>
49 #include <dali/internal/window-system/common/event-handler.h>
50 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
51 #include <dali/internal/graphics/gles/gl-implementation.h>
52 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
53 #include <dali/internal/graphics/common/egl-image-extensions.h>
54 #include <dali/internal/clipboard/common/clipboard-impl.h>
55 #include <dali/internal/graphics/common/vsync-monitor.h>
56 #include <dali/internal/system/common/object-profiler.h>
57 #include <dali/internal/window-system/common/display-connection.h>
58 #include <dali/internal/window-system/common/window-impl.h>
59 #include <dali/internal/window-system/common/window-render-surface.h>
61 #include <dali/internal/system/common/logging.h>
63 #include <dali/internal/system/common/locale-utils.h>
64 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
65 #include <dali/internal/imaging/common/image-loader.h>
68 using Dali::TextAbstraction::FontClient;
81 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
82 } // unnamed namespace
85 Dali::Adaptor* Adaptor::New( Any nativeWindow, RenderSurface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
87 Dali::Adaptor* adaptor = new Dali::Adaptor;
88 Adaptor* impl = new Adaptor( nativeWindow, *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 Any winId = window.GetNativeHandle();
104 Window& windowImpl = Dali::GetImplementation( window );
105 Dali::Adaptor* adaptor = New( winId, windowImpl.GetSurface(), configuration, environmentOptions );
106 windowImpl.SetAdaptor( *adaptor );
110 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Any nativeWindow, RenderSurface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
112 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
113 Adaptor* impl = new Adaptor( nativeWindow, *adaptor, surface, environmentOptions ); // Impl adaptor
114 adaptor->mImpl = impl;
116 impl->Initialize( graphicsFactory, configuration );
121 Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
123 Any winId = window.GetNativeHandle();
125 Window& windowImpl = Dali::GetImplementation( window );
126 Dali::Adaptor* adaptor = New( graphicsFactory, winId, windowImpl.GetSurface(), configuration, environmentOptions );
127 windowImpl.SetAdaptor( *adaptor );
131 void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration )
133 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
134 Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
135 mEnvironmentOptions->SetLogFunction( logFunction );
136 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
138 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
141 GetDataStoragePath( path );
142 mPlatformAbstraction->SetDataStoragePath( path );
144 ResourcePolicy::DataRetention dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
145 if( configuration == Dali::Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS )
147 dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
150 // Note, Tizen does not use DALI_RETAINS_ALL_DATA, as it can reload images from files automatically.
152 if( mEnvironmentOptions->PerformanceServerRequired() )
154 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, *mEnvironmentOptions );
157 mEnvironmentOptions->CreateTraceManager( mPerformanceInterface );
158 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
160 mCallbackManager = CallbackManager::New();
162 WindowPane defaultWindow = mWindowFrame.front();
164 DALI_ASSERT_DEBUG( defaultWindow.surface && "Surface not initialized" );
166 PositionSize size = defaultWindow.surface->GetPositionSize();
168 mGestureManager = new GestureManager(*this, Vector2(size.width, size.height), mCallbackManager, *mEnvironmentOptions);
170 mGraphics = &( graphicsFactory.Create() );
171 mGraphics->Initialize( mEnvironmentOptions );
173 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
175 GlImplementation& mGLES = eglGraphics->GetGlesInterface();
176 EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
178 mCore = Integration::Core::New( *this,
179 *mPlatformAbstraction,
183 dataRetentionPolicy ,
184 ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
185 mGraphics->GetDepthBufferRequired(),
186 mGraphics->GetStencilBufferRequired() );
188 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
189 if( 0u < timeInterval )
191 mObjectProfiler = new ObjectProfiler( timeInterval );
194 mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
196 mVSyncMonitor = new VSyncMonitor;
198 mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow.surface->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() );
268 // Set max texture size
269 if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
271 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
274 SetupSystemInformation();
279 // Ensure stop status
282 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
283 gThreadLocalAdaptor = NULL;
285 for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
287 (*iter)->OnDestroy();
290 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
291 delete mVSyncMonitor;
292 delete mEventHandler;
293 delete mObjectProfiler;
297 delete mGestureManager;
298 delete mDisplayConnection;
299 delete mPlatformAbstraction;
300 delete mCallbackManager;
301 delete mPerformanceInterface;
303 mGraphics->Destroy();
305 // uninstall it on this thread (main actor thread)
306 Dali::Integration::Log::UninstallLogFunction();
308 // Delete environment options if we own it
309 if( mEnvironmentOptionsOwned )
311 delete mEnvironmentOptions;
315 void Adaptor::Start()
317 // It doesn't support restart after stop at this moment to support restarting, need more testing
318 if( READY != mState )
323 // Start the callback manager
324 mCallbackManager->Start();
326 WindowPane defaultWindow = mWindowFrame.front();
328 // Create event handler
329 mEventHandler = new EventHandler( defaultWindow.surface, *this, *mGestureManager, *this, mDragAndDropDetector );
331 if( mDeferredRotationObserver != NULL )
333 mEventHandler->SetRotationObserver(mDeferredRotationObserver);
334 mDeferredRotationObserver = NULL;
337 unsigned int dpiHor, dpiVer;
340 defaultWindow.surface->GetDpi( dpiHor, dpiVer );
342 // tell core about the DPI value
343 mCore->SetDpi(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 PositionSize size = defaultWindow.surface->GetPositionSize();
352 mCore->SurfaceResized( size.width, size.height );
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 // Reset the event handler when adaptor paused
383 mEventHandler->Pause();
386 mThreadController->Pause();
389 // Ensure any messages queued during pause callbacks are processed by doing another update.
394 // Dali::Internal::Adaptor::Adaptor::Resume
395 void Adaptor::Resume()
397 // Only resume the adaptor if we are in the suspended state.
398 if( PAUSED == mState )
402 // Reset the event handler when adaptor resumed
405 mEventHandler->Resume();
408 // Inform observers that we have resumed.
409 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
414 // Trigger processing of events queued up while paused
415 mCore->ProcessEvents();
417 // Do at end to ensure our first update/render after resumption includes the processed messages as well
418 mThreadController->Resume();
424 if( RUNNING == mState ||
426 PAUSED_WHILE_HIDDEN == mState )
428 for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
433 mThreadController->Stop();
435 // Clear out all the handles to Windows
436 mWindowFrame.clear();
438 // Delete the TTS player
439 for(int i =0; i < Dali::TtsPlayer::MODE_NUM; i++)
443 mTtsPlayers[i].Reset();
447 // Destroy the image loader plugin
448 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
450 delete mEventHandler;
451 mEventHandler = NULL;
453 delete mNotificationTrigger;
454 mNotificationTrigger = NULL;
456 mCallbackManager->Stop();
462 void Adaptor::ContextLost()
464 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
467 void Adaptor::ContextRegained()
469 // Inform core, so that texture resources can be reloaded
470 mCore->RecoverFromContextLoss();
472 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
475 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
477 mEventHandler->FeedTouchPoint( point, timeStamp );
480 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
482 mEventHandler->FeedWheelEvent( wheelEvent );
485 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
487 mEventHandler->FeedKeyEvent( keyEvent );
490 void Adaptor::ReplaceSurface( Any nativeWindow, RenderSurface& newSurface )
492 PositionSize positionSize = newSurface.GetPositionSize();
494 // Let the core know the surface size has changed
495 mCore->SurfaceResized( positionSize.width, positionSize.height );
497 mResizedSignal.Emit( mAdaptor );
499 WindowPane newDefaultWindow;
500 newDefaultWindow.nativeWindow = nativeWindow;
501 newDefaultWindow.surface = &newSurface;
503 WindowPane oldDefaultWindow = mWindowFrame.front();
505 // Update WindowFrame
506 std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
507 iter = mWindowFrame.insert( iter, newDefaultWindow );
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( newDefaultWindow.surface );
516 // Must delete the old Window only after the render thread has completed the replace
517 oldDefaultWindow.surface->DestroySurface();
520 RenderSurface& Adaptor::GetSurface() const
522 WindowPane defaultWindow = mWindowFrame.front();
523 return *(defaultWindow.surface);
526 void Adaptor::ReleaseSurfaceLock()
528 WindowPane defaultWindow = mWindowFrame.front();
529 defaultWindow.surface->ReleaseLock();
532 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
534 if(!mTtsPlayers[mode])
536 // Create the TTS player when it needed, because it can reduce launching time.
537 mTtsPlayers[mode] = TtsPlayer::New(mode);
540 return mTtsPlayers[mode];
543 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
545 bool idleAdded(false);
547 // Only add an idle if the Adaptor is actually running
548 if( RUNNING == mState || READY == mState || forceAdd )
550 idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
556 void Adaptor::RemoveIdle( CallbackBase* callback )
558 mCallbackManager->RemoveIdleCallback( callback );
561 void Adaptor::SetPreRenderCallback( CallbackBase* callback )
563 mThreadController->SetPreRenderCallback( callback );
566 bool Adaptor::AddWindow( Dali::Window* childWindow, const std::string& childWindowName, const std::string& childWindowClassName, const bool& childWindowMode )
568 // This is any Window that is not the main (default) one
569 WindowPane additionalWindow;
570 additionalWindow.instance = childWindow;
571 additionalWindow.window_name = childWindowName;
572 additionalWindow.class_name = childWindowClassName;
573 additionalWindow.window_mode = childWindowMode;
575 // Add the new Window to the Frame - the order is not important
576 mWindowFrame.push_back( additionalWindow );
578 Window& windowImpl = Dali::GetImplementation( *childWindow );
579 windowImpl.SetAdaptor( Get() );
584 bool Adaptor::RemoveWindow( Dali::Window* childWindow )
586 for ( WindowFrames::iterator iter = mWindowFrame.begin(); iter != mWindowFrame.end(); ++iter )
588 if( iter->instance == childWindow )
590 mWindowFrame.erase( iter );
598 bool Adaptor::RemoveWindow( std::string childWindowName )
600 for ( WindowFrames::iterator iter = mWindowFrame.begin(); iter != mWindowFrame.end(); ++iter )
602 if( iter->window_name == childWindowName )
604 mWindowFrame.erase( iter );
612 Dali::Adaptor& Adaptor::Get()
614 DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
615 return gThreadLocalAdaptor->mAdaptor;
618 bool Adaptor::IsAvailable()
620 return gThreadLocalAdaptor != NULL;
623 void Adaptor::SceneCreated()
625 mCore->SceneCreated();
628 Dali::Integration::Core& Adaptor::GetCore()
633 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
635 mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
638 void Adaptor::SetUseHardwareVSync( bool useHardware )
640 mVSyncMonitor->SetUseHardwareVSync( useHardware );
643 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
645 DALI_ASSERT_DEBUG( mDisplayConnection && "Display connection not created" );
646 return *mDisplayConnection;
649 GraphicsInterface& Adaptor::GetGraphicsInterface()
651 DALI_ASSERT_DEBUG( mGraphics && "Graphics interface not created" );
655 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
657 return *mPlatformAbstraction;
660 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
662 return *mNotificationTrigger;
665 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
667 return mTriggerEventFactory;
670 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
672 return mSocketFactory;
675 RenderSurface* Adaptor::GetRenderSurfaceInterface()
677 if( !mWindowFrame.empty())
679 WindowPane defaultWindow = mWindowFrame.front();
680 return defaultWindow.surface;
688 VSyncMonitorInterface* Adaptor::GetVSyncMonitorInterface()
690 return mVSyncMonitor;
693 TraceInterface& Adaptor::GetKernelTraceInterface()
695 return mKernelTracer;
698 TraceInterface& Adaptor::GetSystemTraceInterface()
700 return mSystemTracer;
703 PerformanceInterface* Adaptor::GetPerformanceInterface()
705 return mPerformanceInterface;
708 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
710 DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
711 return *mPlatformAbstraction;
714 void Adaptor::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
716 mDragAndDropDetector = detector;
720 mEventHandler->SetDragAndDropDetector( detector );
724 void Adaptor::SetRotationObserver( RotationObserver* observer )
728 mEventHandler->SetRotationObserver( observer );
730 else if( mState == READY )
732 // Set once event handler exists
733 mDeferredRotationObserver = observer;
737 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
739 if(mTtsPlayers[mode])
741 mTtsPlayers[mode].Reset();
745 void Adaptor::SetMinimumPinchDistance(float distance)
747 if( mGestureManager )
749 mGestureManager->SetMinimumPinchDistance(distance);
753 Any Adaptor::GetNativeWindowHandle()
755 WindowPane defaultWindow = mWindowFrame.front();
756 return defaultWindow.nativeWindow;
759 Any Adaptor::GetGraphicsDisplay()
765 auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
767 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
768 display = eglImpl.GetDisplay();
774 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
776 mUseRemoteSurface = useRemoteSurface;
779 void Adaptor::AddObserver( LifeCycleObserver& observer )
781 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
783 if ( match == mObservers.end() )
785 mObservers.push_back( &observer );
789 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
791 ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
793 if ( match != mObservers.end() )
795 mObservers.erase( match );
799 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
803 mCore->QueueEvent(event);
807 void Adaptor::ProcessCoreEvents()
811 if( mPerformanceInterface )
813 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
816 mCore->ProcessEvents();
818 if( mPerformanceInterface )
820 mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
825 void Adaptor::RequestUpdate( bool forceUpdate )
831 mThreadController->RequestUpdate();
835 case PAUSED_WHILE_HIDDEN:
837 // When Dali applications are partially visible behind the lock-screen,
838 // the indicator must be updated (therefore allow updates in the PAUSED state)
841 mThreadController->RequestUpdateOnce();
853 void Adaptor::RequestProcessEventsOnIdle( bool forceProcess )
855 // Only request a notification if the Adaptor is actually running
856 // and we haven't installed the idle notification
857 if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
859 mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
863 void Adaptor::OnWindowShown()
865 if ( PAUSED_WHILE_HIDDEN == mState )
867 // Adaptor can now be resumed
872 // Force a render task
877 void Adaptor::OnWindowHidden()
879 if ( RUNNING == mState )
883 // Adaptor cannot be resumed until the window is shown
884 mState = PAUSED_WHILE_HIDDEN;
888 // Dali::Internal::Adaptor::Adaptor::OnDamaged
889 void Adaptor::OnDamaged( const DamageArea& area )
891 // This is needed for the case where Dali window is partially obscured
892 RequestUpdate( false );
895 void Adaptor::SurfaceResizePrepare( SurfaceSize surfaceSize )
897 // Let the core know the surface size has changed
898 mCore->SurfaceResized( surfaceSize.GetWidth(), surfaceSize.GetHeight() );
900 mResizedSignal.Emit( mAdaptor );
903 void Adaptor::SurfaceResizeComplete( SurfaceSize surfaceSize )
905 // Flush the event queue to give the update-render thread chance
906 // to start processing messages for new camera setup etc as soon as possible
909 mThreadController->ResizeSurface();
912 void Adaptor::NotifySceneCreated()
914 GetCore().SceneCreated();
916 // Start thread controller after the scene has been created
917 mThreadController->Start();
919 // Process after surface is created (registering to remote surface provider if required)
920 SurfaceInitialized();
925 void Adaptor::NotifyLanguageChanged()
927 mLanguageChangedSignal.Emit( mAdaptor );
930 void Adaptor::RenderOnce()
935 const LogFactoryInterface& Adaptor::GetLogFactory()
937 return *mEnvironmentOptions;
940 void Adaptor::RequestUpdateOnce()
942 if( mThreadController )
944 mThreadController->RequestUpdateOnce();
948 void Adaptor::IndicatorSizeChanged(int height)
950 // Let the core know the indicator height is changed
951 mCore->SetTopMargin(height);
954 bool Adaptor::ProcessCoreEventsFromIdle()
958 // the idle handle automatically un-installs itself
959 mNotificationOnIdleInstalled = false;
964 Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions)
966 mLanguageChangedSignal(),
970 mThreadController( nullptr ),
971 mVSyncMonitor( nullptr ),
972 mGraphics( nullptr ),
973 mDisplayConnection( nullptr ),
975 mPlatformAbstraction( nullptr ),
976 mEventHandler( nullptr ),
977 mCallbackManager( nullptr ),
978 mNotificationOnIdleInstalled( false ),
979 mNotificationTrigger( nullptr ),
980 mGestureManager( nullptr ),
981 mDaliFeedbackPlugin(),
982 mFeedbackController( nullptr ),
985 mDragAndDropDetector(),
986 mDeferredRotationObserver( nullptr ),
987 mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
988 mPerformanceInterface( nullptr ),
991 mTriggerEventFactory(),
992 mObjectProfiler( nullptr ),
994 mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
995 mUseRemoteSurface( false )
997 DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
999 WindowPane defaultWindow;
1000 defaultWindow.nativeWindow = nativeWindow;
1001 defaultWindow.surface = surface;
1003 std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
1004 iter = mWindowFrame.insert( iter, defaultWindow );
1006 gThreadLocalAdaptor = this;
1009 void Adaptor::SetRootLayoutDirection( std::string locale )
1011 Dali::Stage stage = Dali::Stage::GetCurrent();
1013 stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
1014 static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
1017 bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
1019 bool idleAdded( false );
1021 // Only add an idle if the Adaptor is actually running
1022 if( RUNNING == mState || READY == mState || forceAdd )
1024 idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
1030 void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
1032 mCallbackManager->RemoveIdleEntererCallback( callback );
1035 } // namespace Adaptor
1037 } // namespace Internal