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