1f8d21a4a0a23c34cb80ff16a39bb7b27a73e68b
[platform/core/uifw/dali-adaptor.git] / adaptors / common / adaptor-impl.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "adaptor-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/common/stage.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/devel-api/actors/actor-devel.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/integration-api/core.h>
28 #include <dali/integration-api/context-notifier.h>
29 #include <dali/integration-api/profiling.h>
30 #include <dali/integration-api/input-options.h>
31 #include <dali/integration-api/events/touch-event-integ.h>
32
33 // INTERNAL INCLUDES
34 #include <base/thread-controller.h>
35 #include <base/performance-logging/performance-interface-factory.h>
36 #include <base/lifecycle-observer.h>
37
38 #include <dali/devel-api/text-abstraction/font-client.h>
39
40 #include <callback-manager.h>
41 #include <render-surface.h>
42 #include <tts-player-impl.h>
43 #include <accessibility-adaptor-impl.h>
44 #include <events/gesture-manager.h>
45 #include <events/event-handler.h>
46 #include <gl/gl-proxy-implementation.h>
47 #include <gl/gl-implementation.h>
48 #include <gl/egl-sync-implementation.h>
49 #include <gl/egl-image-extensions.h>
50 #include <gl/egl-factory.h>
51 #include <imf-manager-impl.h>
52 #include <clipboard-impl.h>
53 #include <vsync-monitor.h>
54 #include <object-profiler.h>
55 #include <base/display-connection.h>
56 #include <window-impl.h>
57
58 #include <tizen-logging.h>
59 #include <image-loading.h>
60
61 #include <locale-utils.h>
62
63 using Dali::TextAbstraction::FontClient;
64
65 namespace Dali
66 {
67
68 namespace Internal
69 {
70
71 namespace Adaptor
72 {
73
74 namespace
75 {
76 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
77 } // unnamed namespace
78
79 Dali::Adaptor* Adaptor::New( Any nativeWindow, RenderSurface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
80 {
81   Dali::Adaptor* adaptor = new Dali::Adaptor;
82   Adaptor* impl = new Adaptor( nativeWindow, *adaptor, surface, environmentOptions );
83   adaptor->mImpl = impl;
84
85   impl->Initialize(configuration);
86
87   return adaptor;
88 }
89
90 Dali::Adaptor* Adaptor::New( Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
91 {
92   Any winId = window.GetNativeHandle();
93
94   Window& windowImpl = Dali::GetImplementation(window);
95   Dali::Adaptor* adaptor = New( winId, windowImpl.GetSurface(), configuration, environmentOptions );
96
97   Internal::Adaptor::Adaptor::GetImplementation( *adaptor ).SetWindow( window );
98   windowImpl.SetAdaptor(*adaptor);
99   return adaptor;
100 }
101
102 void Adaptor::Initialize( Dali::Configuration::ContextLoss configuration )
103 {
104   // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
105   Dali::Integration::Log::LogFunction logFunction( Dali::TizenPlatform::LogMessage );
106   mEnvironmentOptions->SetLogFunction( logFunction );
107   mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
108
109   mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
110
111   std::string path;
112   GetDataStoragePath( path );
113   mPlatformAbstraction->SetDataStoragePath( path );
114
115   ResourcePolicy::DataRetention dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
116   if( configuration == Dali::Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS )
117   {
118     dataRetentionPolicy = ResourcePolicy::DALI_DISCARDS_ALL_DATA;
119   }
120   // Note, Tizen does not use DALI_RETAINS_ALL_DATA, as it can reload images from
121   // files automatically.
122
123   if( mEnvironmentOptions->PerformanceServerRequired() )
124   {
125     mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface( *this, *mEnvironmentOptions );
126   }
127
128   mCallbackManager = CallbackManager::New();
129
130   PositionSize size = mSurface->GetPositionSize();
131
132   mGestureManager = new GestureManager(*this, Vector2(size.width, size.height), mCallbackManager, *mEnvironmentOptions);
133
134   if( mEnvironmentOptions->GetGlesCallTime() > 0 )
135   {
136     mGLES = new GlProxyImplementation( *mEnvironmentOptions );
137   }
138   else
139   {
140     mGLES = new GlImplementation();
141   }
142
143   mEglFactory = new EglFactory( mEnvironmentOptions->GetMultiSamplingLevel() );
144
145   EglSyncImplementation* eglSyncImpl = mEglFactory->GetSyncImplementation();
146
147   mCore = Integration::Core::New( *this, *mPlatformAbstraction, *mGLES, *eglSyncImpl, *mGestureManager, dataRetentionPolicy );
148
149   const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
150   if( 0u < timeInterval )
151   {
152     mObjectProfiler = new ObjectProfiler( timeInterval );
153   }
154
155   mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
156
157   mVSyncMonitor = new VSyncMonitor;
158
159   mThreadController = new ThreadController( *this, *mEnvironmentOptions );
160
161   // Should be called after Core creation
162   if( mEnvironmentOptions->GetPanGestureLoggingLevel() )
163   {
164     Integration::EnableProfiling( Dali::Integration::PROFILING_TYPE_PAN_GESTURE );
165   }
166   if( mEnvironmentOptions->GetPanGesturePredictionMode() >= 0 )
167   {
168     Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
169   }
170   if( mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0 )
171   {
172     Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
173   }
174   if( mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0 )
175   {
176     Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
177   }
178   if( mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0 )
179   {
180     Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
181   }
182   if( mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0 )
183   {
184     Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
185   }
186   if( mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0 )
187   {
188     Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
189   }
190   if( mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f )
191   {
192     Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
193   }
194
195   // Set max texture size
196   if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
197   {
198     Dali::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
199   }
200
201   SetupSystemInformation();
202 }
203
204 Adaptor::~Adaptor()
205 {
206   // Ensure stop status
207   Stop();
208
209   // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
210   gThreadLocalAdaptor = NULL;
211
212   for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
213   {
214     (*iter)->OnDestroy();
215   }
216
217   delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
218   delete mVSyncMonitor;
219   delete mEventHandler;
220   delete mObjectProfiler;
221
222   delete mCore;
223   delete mEglFactory;
224   delete mGLES;
225   delete mGestureManager;
226   delete mPlatformAbstraction;
227   delete mCallbackManager;
228   delete mPerformanceInterface;
229
230   // uninstall it on this thread (main actor thread)
231   Dali::Integration::Log::UninstallLogFunction();
232
233   // Delete environment options if we own it
234   if( mEnvironmentOptionsOwned )
235   {
236     delete mEnvironmentOptions;
237   }
238 }
239
240 void Adaptor::Start()
241 {
242   // it doesn't support restart after stop at this moment
243   // to support restarting, need more testing
244   if( READY != mState )
245   {
246     return;
247   }
248
249   // Start the callback manager
250   mCallbackManager->Start();
251
252   // create event handler
253   mEventHandler = new EventHandler( mSurface, *this, *mGestureManager, *this, mDragAndDropDetector );
254
255   if( mDeferredRotationObserver != NULL )
256   {
257     mEventHandler->SetRotationObserver(mDeferredRotationObserver);
258     mDeferredRotationObserver = NULL;
259   }
260
261   unsigned int dpiHor, dpiVer;
262   dpiHor = dpiVer = 0;
263   Dali::DisplayConnection::GetDpi(dpiHor, dpiVer);
264
265   // tell core about the DPI value
266   mCore->SetDpi(dpiHor, dpiVer);
267
268   // set the DPI value for font rendering
269   FontClient fontClient = FontClient::Get();
270   fontClient.SetDpi( dpiHor, dpiVer );
271
272   // Tell the core the size of the surface just before we start the render-thread
273   PositionSize size = mSurface->GetPositionSize();
274   mCore->SurfaceResized( size.width, size.height );
275
276   // Initialize the thread controller
277   mThreadController->Initialize();
278
279   mState = RUNNING;
280
281   ProcessCoreEvents(); // Ensure any startup messages are processed.
282
283   for ( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
284   {
285     (*iter)->OnStart();
286   }
287 }
288
289 // Dali::Internal::Adaptor::Adaptor::Pause
290 void Adaptor::Pause()
291 {
292   // Only pause the adaptor if we're actually running.
293   if( RUNNING == mState )
294   {
295     // Inform observers that we are about to be paused.
296     for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
297     {
298       (*iter)->OnPause();
299     }
300
301     // Reset the event handler when adaptor paused
302     if( mEventHandler )
303     {
304       mEventHandler->Pause();
305     }
306
307     mThreadController->Pause();
308     mCore->Suspend();
309     mState = PAUSED;
310
311     // Process remained events and rendering in the update thread
312     RequestUpdateOnce();
313   }
314 }
315
316 // Dali::Internal::Adaptor::Adaptor::Resume
317 void Adaptor::Resume()
318 {
319   // Only resume the adaptor if we are in the suspended state.
320   if( PAUSED == mState )
321   {
322     mState = RUNNING;
323
324     // Reset the event handler when adaptor resumed
325     if( mEventHandler )
326     {
327       mEventHandler->Resume();
328     }
329
330     // Inform observers that we have resumed.
331     for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
332     {
333       (*iter)->OnResume();
334     }
335
336     // Resume core so it processes any requests as well
337     mCore->Resume();
338
339     // Do at end to ensure our first update/render after resumption includes the processed messages as well
340     mThreadController->Resume();
341   }
342 }
343
344 void Adaptor::Stop()
345 {
346   if( RUNNING == mState ||
347       PAUSED  == mState ||
348       PAUSED_WHILE_HIDDEN == mState )
349   {
350     for( ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter )
351     {
352       (*iter)->OnStop();
353     }
354
355     mThreadController->Stop();
356     mCore->Suspend();
357
358     // Delete the TTS player
359     for(int i =0; i < Dali::TtsPlayer::MODE_NUM; i++)
360     {
361       if(mTtsPlayers[i])
362       {
363         mTtsPlayers[i].Reset();
364       }
365     }
366
367     delete mEventHandler;
368     mEventHandler = NULL;
369
370     delete mNotificationTrigger;
371     mNotificationTrigger = NULL;
372
373     mCallbackManager->Stop();
374
375     mState = STOPPED;
376   }
377 }
378
379 void Adaptor::ContextLost()
380 {
381   mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
382 }
383
384 void Adaptor::ContextRegained()
385 {
386   // Inform core, so that texture resources can be reloaded
387   mCore->RecoverFromContextLoss();
388
389   mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
390 }
391
392 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
393 {
394   mEventHandler->FeedTouchPoint( point, timeStamp );
395 }
396
397 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
398 {
399   mEventHandler->FeedWheelEvent( wheelEvent );
400 }
401
402 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
403 {
404   mEventHandler->FeedKeyEvent( keyEvent );
405 }
406
407 void Adaptor::ReplaceSurface( Any nativeWindow, RenderSurface& surface )
408 {
409   PositionSize positionSize = surface.GetPositionSize();
410
411   // let the core know the surface size has changed
412   mCore->SurfaceResized( positionSize.width, positionSize.height );
413
414   mResizedSignal.Emit( mAdaptor );
415
416   mNativeWindow = nativeWindow;
417   mSurface = &surface;
418
419   // flush the event queue to give the update-render thread chance
420   // to start processing messages for new camera setup etc as soon as possible
421   ProcessCoreEvents();
422
423   // this method blocks until the render thread has completed the replace.
424   mThreadController->ReplaceSurface(mSurface);
425 }
426
427 RenderSurface& Adaptor::GetSurface() const
428 {
429   return *mSurface;
430 }
431
432 void Adaptor::ReleaseSurfaceLock()
433 {
434   mSurface->ReleaseLock();
435 }
436
437 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
438 {
439   if(!mTtsPlayers[mode])
440   {
441     // Create the TTS player when it needed, because it can reduce launching time.
442     mTtsPlayers[mode] = TtsPlayer::New(mode);
443   }
444
445   return mTtsPlayers[mode];
446 }
447
448 bool Adaptor::AddIdle( CallbackBase* callback )
449 {
450   bool idleAdded(false);
451
452   // Only add an idle if the Adaptor is actually running
453   if( RUNNING == mState )
454   {
455     idleAdded = mCallbackManager->AddIdleCallback( callback );
456   }
457
458   return idleAdded;
459 }
460
461 void Adaptor::RemoveIdle( CallbackBase* callback )
462 {
463   mCallbackManager->RemoveIdleCallback( callback );
464 }
465
466 Dali::Adaptor& Adaptor::Get()
467 {
468   DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
469   return gThreadLocalAdaptor->mAdaptor;
470 }
471
472 bool Adaptor::IsAvailable()
473 {
474   return gThreadLocalAdaptor != NULL;
475 }
476
477 void Adaptor::SceneCreated()
478 {
479   mCore->SceneCreated();
480 }
481
482 Dali::Integration::Core& Adaptor::GetCore()
483 {
484   return *mCore;
485 }
486
487 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
488 {
489   mThreadController->SetRenderRefreshRate( numberOfVSyncsPerRender );
490 }
491
492 void Adaptor::SetUseHardwareVSync( bool useHardware )
493 {
494   mVSyncMonitor->SetUseHardwareVSync( useHardware );
495 }
496
497 EglFactory& Adaptor::GetEGLFactory() const
498 {
499   DALI_ASSERT_DEBUG( mEglFactory && "EGL Factory not created" );
500   return *mEglFactory;
501 }
502
503 EglFactoryInterface& Adaptor::GetEGLFactoryInterface() const
504 {
505   return *mEglFactory;
506 }
507
508 Integration::GlAbstraction& Adaptor::GetGlAbstraction() const
509 {
510   DALI_ASSERT_DEBUG( mGLES && "GLImplementation not created" );
511   return *mGLES;
512 }
513
514 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
515 {
516   return *mPlatformAbstraction;
517 }
518
519 Dali::Integration::GlAbstraction& Adaptor::GetGlesInterface()
520 {
521   return *mGLES;
522 }
523
524 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
525 {
526   return *mNotificationTrigger;
527 }
528
529 TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
530 {
531   return mTriggerEventFactory;
532 }
533
534 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
535 {
536   return mSocketFactory;
537 }
538
539 RenderSurface* Adaptor::GetRenderSurfaceInterface()
540 {
541   return mSurface;
542 }
543
544 VSyncMonitorInterface* Adaptor::GetVSyncMonitorInterface()
545 {
546   return mVSyncMonitor;
547 }
548
549 TraceInterface& Adaptor::GetKernelTraceInterface()
550 {
551   return mKernelTracer;
552 }
553
554 TraceInterface& Adaptor::GetSystemTraceInterface()
555 {
556   return mSystemTracer;
557 }
558
559 PerformanceInterface* Adaptor::GetPerformanceInterface()
560 {
561   return mPerformanceInterface;
562 }
563
564 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
565 {
566   DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" );
567   return *mPlatformAbstraction;
568 }
569
570 void Adaptor::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
571 {
572   mDragAndDropDetector = detector;
573
574   if ( mEventHandler )
575   {
576     mEventHandler->SetDragAndDropDetector( detector );
577   }
578 }
579
580 void Adaptor::SetRotationObserver( RotationObserver* observer )
581 {
582   if( mEventHandler )
583   {
584     mEventHandler->SetRotationObserver( observer );
585   }
586   else if( mState == READY )
587   {
588     // Set once event handler exists
589     mDeferredRotationObserver = observer;
590   }
591 }
592
593 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
594 {
595   if(mTtsPlayers[mode])
596   {
597     mTtsPlayers[mode].Reset();
598   }
599 }
600
601 void Adaptor::SetMinimumPinchDistance(float distance)
602 {
603   if( mGestureManager )
604   {
605     mGestureManager->SetMinimumPinchDistance(distance);
606   }
607 }
608
609 Any Adaptor::GetNativeWindowHandle()
610 {
611   return mNativeWindow;
612 }
613
614 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
615 {
616   mUseRemoteSurface = useRemoteSurface;
617 }
618
619 void Adaptor::AddObserver( LifeCycleObserver& observer )
620 {
621   ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
622
623   if ( match == mObservers.end() )
624   {
625     mObservers.push_back( &observer );
626   }
627 }
628
629 void Adaptor::RemoveObserver( LifeCycleObserver& observer )
630 {
631   ObserverContainer::iterator match ( find(mObservers.begin(), mObservers.end(), &observer) );
632
633   if ( match != mObservers.end() )
634   {
635     mObservers.erase( match );
636   }
637 }
638
639 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
640 {
641   if( mCore )
642   {
643     mCore->QueueEvent(event);
644   }
645 }
646
647 void Adaptor::ProcessCoreEvents()
648 {
649   if( mCore )
650   {
651     if( mPerformanceInterface )
652     {
653       mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_START );
654     }
655
656     mCore->ProcessEvents();
657
658     if( mPerformanceInterface )
659     {
660       mPerformanceInterface->AddMarker( PerformanceInterface::PROCESS_EVENTS_END );
661     }
662   }
663 }
664
665 void Adaptor::RequestUpdate()
666 {
667   // When Dali applications are partially visible behind the lock-screen,
668   // the indicator must be updated (therefore allow updates in the PAUSED state)
669   if ( PAUSED  == mState ||
670        RUNNING == mState )
671   {
672     mThreadController->RequestUpdate();
673   }
674 }
675
676 void Adaptor::RequestProcessEventsOnIdle()
677 {
678   // Only request a notification if the Adaptor is actually running
679   // and we haven't installed the idle notification
680   if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState ) )
681   {
682     mNotificationOnIdleInstalled = AddIdle( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ) );
683   }
684 }
685
686 void Adaptor::OnWindowShown()
687 {
688   if ( PAUSED_WHILE_HIDDEN == mState )
689   {
690     // Adaptor can now be resumed
691     mState = PAUSED;
692
693     Resume();
694
695     // Force a render task
696     RequestUpdateOnce();
697   }
698 }
699
700 void Adaptor::OnWindowHidden()
701 {
702   if ( STOPPED != mState )
703   {
704     Pause();
705
706     // Adaptor cannot be resumed until the window is shown
707     mState = PAUSED_WHILE_HIDDEN;
708   }
709 }
710
711 // Dali::Internal::Adaptor::Adaptor::OnDamaged
712 void Adaptor::OnDamaged( const DamageArea& area )
713 {
714   // This is needed for the case where Dali window is partially obscured
715   RequestUpdate();
716 }
717
718 void Adaptor::SurfaceResizePrepare( SurfaceSize surfaceSize )
719 {
720   // let the core know the surface size has changed
721   mCore->SurfaceResized( surfaceSize.GetWidth(), surfaceSize.GetHeight() );
722
723   mResizedSignal.Emit( mAdaptor );
724 }
725
726 void Adaptor::SurfaceResizeComplete( SurfaceSize surfaceSize )
727 {
728   // flush the event queue to give the update-render thread chance
729   // to start processing messages for new camera setup etc as soon as possible
730   ProcessCoreEvents();
731
732   // this method blocks until the render thread has completed the resizing.
733   mThreadController->ResizeSurface();
734 }
735
736 void Adaptor::NotifySceneCreated()
737 {
738   GetCore().SceneCreated();
739
740   // Start thread controller after the scene has been created
741   mThreadController->Start();
742
743   // process after surface is created (registering to remote surface provider if required)
744   SurfaceInitialized();
745 }
746
747 void Adaptor::NotifyLanguageChanged()
748 {
749   mLanguageChangedSignal.Emit( mAdaptor );
750 }
751
752 void Adaptor::RenderOnce()
753 {
754   RequestUpdateOnce();
755 }
756
757 void Adaptor::RequestUpdateOnce()
758 {
759   if( PAUSED_WHILE_HIDDEN != mState )
760   {
761     if( mThreadController )
762     {
763       mThreadController->RequestUpdateOnce();
764     }
765   }
766 }
767
768 void Adaptor::IndicatorSizeChanged(int height)
769 {
770   // let the core know the indicator height is changed
771   mCore->SetTopMargin(height);
772 }
773
774 void Adaptor::ProcessCoreEventsFromIdle()
775 {
776   ProcessCoreEvents();
777
778   // the idle handle automatically un-installs itself
779   mNotificationOnIdleInstalled = false;
780 }
781
782 Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions)
783 : mResizedSignal(),
784   mLanguageChangedSignal(),
785   mAdaptor( adaptor ),
786   mState( READY ),
787   mCore( NULL ),
788   mThreadController( NULL ),
789   mVSyncMonitor( NULL ),
790   mGLES( NULL ),
791   mGlSync( NULL ),
792   mEglFactory( NULL ),
793   mNativeWindow( nativeWindow ),
794   mSurface( surface ),
795   mPlatformAbstraction( NULL ),
796   mEventHandler( NULL ),
797   mCallbackManager( NULL ),
798   mNotificationOnIdleInstalled( false ),
799   mNotificationTrigger( NULL ),
800   mGestureManager( NULL ),
801   mDaliFeedbackPlugin(),
802   mFeedbackController( NULL ),
803   mTtsPlayers(),
804   mObservers(),
805   mDragAndDropDetector(),
806   mDeferredRotationObserver( NULL ),
807   mEnvironmentOptions( environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
808   mPerformanceInterface( NULL ),
809   mKernelTracer(),
810   mSystemTracer(),
811   mTriggerEventFactory(),
812   mObjectProfiler( NULL ),
813   mSocketFactory(),
814   mWindow(),
815   mEnvironmentOptionsOwned( environmentOptions ? false : true /* If not provided then we own the object */ ),
816   mUseRemoteSurface( false )
817 {
818   DALI_ASSERT_ALWAYS( !IsAvailable() && "Cannot create more than one Adaptor per thread" );
819   gThreadLocalAdaptor = this;
820 }
821
822 // Stereoscopy
823
824 void Adaptor::SetViewMode( ViewMode viewMode )
825 {
826   mSurface->SetViewMode( viewMode );
827   mCore->SetViewMode( viewMode );
828 }
829
830 ViewMode Adaptor::GetViewMode() const
831 {
832   return mCore->GetViewMode();
833 }
834
835 void Adaptor::SetStereoBase( float stereoBase )
836 {
837   mCore->SetStereoBase( stereoBase );
838 }
839
840 float Adaptor::GetStereoBase() const
841 {
842   return mCore->GetStereoBase();
843 }
844
845 void Adaptor::SetRootLayoutDirection( std::string locale )
846 {
847   Dali::Stage stage = Dali::Stage::GetCurrent();
848
849   stage.GetRootLayer().SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,
850                                     static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
851 }
852
853 void Adaptor::SetWindow( Dali::Window window )
854 {
855   mWindow = window;
856 }
857
858 Dali::Window Adaptor::GetWindow()
859 {
860   return mWindow;
861 }
862
863 } // namespace Adaptor
864
865 } // namespace Internal
866
867 } // namespace Dali