2 * Copyright (c) 2022 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-builder-impl.h>
20 #include <dali/internal/adaptor/common/adaptor-impl.h>
21 #include <dali/internal/addons/common/addon-manager-factory.h>
22 #include <dali/internal/addons/common/addon-manager-impl.h>
25 #include <dali/devel-api/actors/actor-devel.h>
26 #include <dali/devel-api/common/stage.h>
27 #include <dali/integration-api/addon-manager.h>
28 #include <dali/integration-api/context-notifier.h>
29 #include <dali/integration-api/core.h>
30 #include <dali/integration-api/debug.h>
31 #include <dali/integration-api/events/key-event-integ.h>
32 #include <dali/integration-api/events/touch-event-integ.h>
33 #include <dali/integration-api/events/wheel-event-integ.h>
34 #include <dali/integration-api/input-options.h>
35 #include <dali/integration-api/processor-interface.h>
36 #include <dali/integration-api/profiling.h>
37 #include <dali/integration-api/trace.h>
38 #include <dali/public-api/actors/layer.h>
39 #include <dali/public-api/events/wheel-event.h>
40 #include <dali/public-api/object/any.h>
41 #include <dali/public-api/object/object-registry.h>
46 #include <dali/internal/adaptor/common/lifecycle-observer.h>
47 #include <dali/internal/adaptor/common/thread-controller-interface.h>
48 #include <dali/internal/system/common/performance-interface-factory.h>
49 #include <dali/internal/system/common/thread-controller.h>
50 #include <dali/public-api/dali-adaptor-common.h>
52 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
53 #include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
55 #include <dali/devel-api/text-abstraction/font-client.h>
57 #include <dali/internal/accessibility/common/tts-player-impl.h>
58 #include <dali/internal/clipboard/common/clipboard-impl.h>
59 #include <dali/internal/graphics/common/egl-image-extensions.h>
60 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
61 #include <dali/internal/graphics/gles/gl-implementation.h>
62 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
63 #include <dali/internal/system/common/callback-manager.h>
64 #include <dali/internal/system/common/object-profiler.h>
65 #include <dali/internal/window-system/common/display-connection.h>
66 #include <dali/internal/window-system/common/display-utils.h> // For Utils::MakeUnique
67 #include <dali/internal/window-system/common/event-handler.h>
68 #include <dali/internal/window-system/common/window-impl.h>
69 #include <dali/internal/window-system/common/window-render-surface.h>
71 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
72 #include <dali/internal/system/common/logging.h>
74 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
75 #include <dali/internal/imaging/common/image-loader.h>
76 #include <dali/internal/system/common/locale-utils.h>
78 #include <dali/internal/system/common/configuration-manager.h>
79 #include <dali/internal/system/common/environment-variables.h>
81 using Dali::TextAbstraction::FontClient;
83 extern std::string GetSystemCachePath();
93 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
95 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false);
96 } // unnamed namespace
98 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
100 Dali::Adaptor* adaptor = new Dali::Adaptor;
101 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode);
102 adaptor->mImpl = impl;
104 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder(*(impl->mEnvironmentOptions));
105 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
107 impl->Initialize(graphicsFactory);
108 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
113 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
115 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
116 Dali::Adaptor* adaptor = New(window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
117 windowImpl.SetAdaptor(*adaptor);
121 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
123 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
124 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode); // Impl adaptor
125 adaptor->mImpl = impl;
127 impl->Initialize(graphicsFactory);
132 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
134 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
135 Dali::Adaptor* adaptor = New(graphicsFactory, window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
136 windowImpl.SetAdaptor(*adaptor);
140 void Adaptor::Initialize(GraphicsFactory& graphicsFactory)
142 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
143 Dali::Integration::Log::LogFunction logFunction(Dali::TizenPlatform::LogMessage);
144 mEnvironmentOptions->SetLogFunction(logFunction);
145 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
147 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
150 GetDataStoragePath(path);
151 mPlatformAbstraction->SetDataStoragePath(path);
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 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
165 DALI_ASSERT_DEBUG(defaultWindow->GetSurface() && "Surface not initialized");
167 mGraphics = std::unique_ptr<GraphicsInterface>(&graphicsFactory.Create());
169 // Create the AddOnManager
170 mAddOnManager.reset(Dali::Internal::AddOnManagerFactory::CreateAddOnManager());
172 mCore = Integration::Core::New(*this,
173 *mPlatformAbstraction,
174 mGraphics->GetController(),
175 (0u != mEnvironmentOptions->GetRenderToFboInterval()) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
176 mGraphics->GetDepthBufferRequired(),
177 mGraphics->GetStencilBufferRequired(),
178 mGraphics->GetPartialUpdateRequired());
180 defaultWindow->SetAdaptor(Get());
182 Dali::Integration::SceneHolder defaultSceneHolder(defaultWindow);
184 mWindowCreatedSignal.Emit(defaultSceneHolder);
186 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
187 if(0u < timeInterval)
189 mObjectProfiler = new ObjectProfiler(mCore->GetObjectRegistry(), timeInterval);
192 const uint32_t poolTimeInterval = mEnvironmentOptions->GetMemoryPoolInterval();
193 if(0u < poolTimeInterval)
195 mMemoryPoolTimer = Dali::Timer::New(poolTimeInterval * 1000);
196 mMemoryPoolTimer.TickSignal().Connect(mMemoryPoolTimerSlotDelegate, &Adaptor::MemoryPoolTimeout);
197 mMemoryPoolTimer.Start();
200 mNotificationTrigger = TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &Adaptor::ProcessCoreEvents), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
202 mDisplayConnection = Dali::DisplayConnection::New(*mGraphics, defaultWindow->GetSurface()->GetSurfaceType());
204 mThreadController = new ThreadController(*this, *mEnvironmentOptions, mThreadMode);
206 // Should be called after Core creation
207 if(mEnvironmentOptions->GetPanGestureLoggingLevel())
209 Integration::EnableProfiling(Dali::Integration::PROFILING_TYPE_PAN_GESTURE);
211 if(mEnvironmentOptions->GetPanGesturePredictionMode() >= 0)
213 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
215 if(mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0)
217 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
219 if(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0)
221 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
223 if(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0)
225 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
227 if(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0)
229 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
231 if(mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0)
233 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
235 if(mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f)
237 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
239 if(mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0)
241 Integration::SetPanGestureUseActualTimes(mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false);
243 if(mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0)
245 Integration::SetPanGestureInterpolationTimeRange(mEnvironmentOptions->GetPanGestureInterpolationTimeRange());
247 if(mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0)
249 Integration::SetPanGestureScalarOnlyPredictionEnabled(mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false);
251 if(mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0)
253 Integration::SetPanGestureTwoPointPredictionEnabled(mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false);
255 if(mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0)
257 Integration::SetPanGestureTwoPointInterpolatePastTime(mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime());
259 if(mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f)
261 Integration::SetPanGestureTwoPointVelocityBias(mEnvironmentOptions->GetPanGestureTwoPointVelocityBias());
263 if(mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f)
265 Integration::SetPanGestureTwoPointAccelerationBias(mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias());
267 if(mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0)
269 Integration::SetPanGestureMultitapSmoothingRange(mEnvironmentOptions->GetPanGestureMultitapSmoothingRange());
271 if(mEnvironmentOptions->GetMinimumPanDistance() >= 0)
273 Integration::SetPanGestureMinimumDistance(mEnvironmentOptions->GetMinimumPanDistance());
275 if(mEnvironmentOptions->GetMinimumPanEvents() >= 0)
277 Integration::SetPanGestureMinimumPanEvents(mEnvironmentOptions->GetMinimumPanEvents());
279 if(mEnvironmentOptions->GetMinimumPinchDistance() >= 0)
281 Integration::SetPinchGestureMinimumDistance(mEnvironmentOptions->GetMinimumPinchDistance());
283 if(mEnvironmentOptions->GetMinimumPinchTouchEvents() >= 0)
285 Integration::SetPinchGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumPinchTouchEvents());
287 if(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart() >= 0)
289 Integration::SetPinchGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart());
291 if(mEnvironmentOptions->GetMinimumRotationTouchEvents() >= 0)
293 Integration::SetRotationGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumRotationTouchEvents());
295 if(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart() >= 0)
297 Integration::SetRotationGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart());
299 if(mEnvironmentOptions->GetLongPressMinimumHoldingTime() >= 0)
301 Integration::SetLongPressMinimumHoldingTime(mEnvironmentOptions->GetLongPressMinimumHoldingTime());
303 if(mEnvironmentOptions->GetTapMaximumAllowedTime() > 0)
305 Integration::SetTapMaximumAllowedTime(mEnvironmentOptions->GetTapMaximumAllowedTime());
308 std::string systemCachePath = GetSystemCachePath();
309 if(!systemCachePath.empty())
311 const int dir_err = mkdir(systemCachePath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
312 if(0 != dir_err && errno != EEXIST)
314 DALI_LOG_ERROR("Error creating system cache directory: %s!\n", systemCachePath.c_str());
318 mConfigurationManager = Utils::MakeUnique<ConfigurationManager>(systemCachePath, mGraphics.get(), mThreadController);
321 void Adaptor::AccessibilityObserver::OnAccessibleKeyEvent(const Dali::KeyEvent& event)
323 Accessibility::KeyEventType type;
324 if(event.GetState() == Dali::KeyEvent::DOWN)
326 type = Accessibility::KeyEventType::KEY_PRESSED;
328 else if(event.GetState() == Dali::KeyEvent::UP)
330 type = Accessibility::KeyEventType::KEY_RELEASED;
336 Dali::Accessibility::Bridge::GetCurrentBridge()->Emit(type, event.GetKeyCode(), event.GetKeyName(), event.GetTime(), !event.GetKeyString().empty());
341 Accessibility::Bridge::GetCurrentBridge()->Terminate();
343 // Ensure stop status
346 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
347 gThreadLocalAdaptor = NULL;
349 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
351 (*iter)->OnDestroy();
354 // Clear out all the handles to Windows
357 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
358 delete mObjectProfiler;
362 delete mDisplayConnection;
363 delete mPlatformAbstraction;
364 delete mCallbackManager;
365 delete mPerformanceInterface;
367 mGraphics->Destroy();
369 // uninstall it on this thread (main actor thread)
370 Dali::Integration::Log::UninstallLogFunction();
372 // Delete environment options if we own it
373 if(mEnvironmentOptionsOwned)
375 delete mEnvironmentOptions;
379 void Adaptor::Start()
381 // It doesn't support restart after stop at this moment to support restarting, need more testing
389 SetupSystemInformation();
391 // Start the callback manager
392 mCallbackManager->Start();
394 // Initialize accessibility bridge after callback manager is started to use Idler callback
395 auto appName = GetApplicationPackageName();
396 auto bridge = Accessibility::Bridge::GetCurrentBridge();
397 bridge->SetApplicationName(appName);
398 bridge->Initialize();
399 Dali::Stage::GetCurrent().KeyEventSignal().Connect(&mAccessibilityObserver, &AccessibilityObserver::OnAccessibleKeyEvent);
401 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
403 unsigned int dpiHor, dpiVer;
406 defaultWindow->GetSurface()->GetDpi(dpiHor, dpiVer);
408 // set the DPI value for font rendering
409 FontClient fontClient = FontClient::Get();
410 fontClient.SetDpi(dpiHor, dpiVer);
412 // Initialize the thread controller
413 mThreadController->Initialize();
415 // Set max texture size
416 if(mEnvironmentOptions->GetMaxTextureSize() > 0)
418 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(mEnvironmentOptions->GetMaxTextureSize());
422 unsigned int maxTextureSize = mConfigurationManager->GetMaxTextureSize();
423 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(maxTextureSize);
426 // cache advanced blending and shader language version
427 mGraphics->CacheConfigurations(*mConfigurationManager.get());
429 ProcessCoreEvents(); // Ensure any startup messages are processed.
431 // Initialize the image loader plugin
432 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
434 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
441 mAddOnManager->Start();
445 // Dali::Internal::Adaptor::Adaptor::Pause
446 void Adaptor::Pause()
448 // Only pause the adaptor if we're actually running.
449 if(RUNNING == mState)
451 // Inform observers that we are about to be paused.
452 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
460 mAddOnManager->Pause();
463 // Pause all windows event handlers when adaptor paused
464 for(auto window : mWindows)
469 mThreadController->Pause();
472 // Ensure any messages queued during pause callbacks are processed by doing another update.
475 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Paused\n");
479 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Not paused [%d]\n", mState);
483 // Dali::Internal::Adaptor::Adaptor::Resume
484 void Adaptor::Resume()
486 // Only resume the adaptor if we are in the suspended state.
491 // Reset the event handlers when adaptor resumed
492 for(auto window : mWindows)
497 // Resume AddOnManager
500 mAddOnManager->Resume();
503 // Inform observers that we have resumed.
504 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
509 // Trigger processing of events queued up while paused
510 mCore->ProcessEvents();
512 // Do at end to ensure our first update/render after resumption includes the processed messages as well
513 mThreadController->Resume();
515 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Resumed\n");
519 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Not resumed [%d]\n", mState);
525 if(RUNNING == mState ||
527 PAUSED_WHILE_HIDDEN == mState)
529 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
536 mAddOnManager->Stop();
539 mThreadController->Stop();
541 // Delete the TTS player
542 for(int i = 0; i < Dali::TtsPlayer::MODE_NUM; i++)
546 mTtsPlayers[i].Reset();
550 // Destroy the image loader plugin
551 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
553 delete mNotificationTrigger;
554 mNotificationTrigger = NULL;
556 mCallbackManager->Stop();
560 DALI_LOG_RELEASE_INFO("Adaptor::Stop\n");
564 void Adaptor::ContextLost()
566 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
569 void Adaptor::ContextRegained()
571 // Inform core, so that texture resources can be reloaded
572 mCore->RecoverFromContextLoss();
574 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
577 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
579 Integration::Point convertedPoint(point);
580 mWindows.front()->FeedTouchPoint(convertedPoint, timeStamp);
583 void Adaptor::FeedWheelEvent(Dali::WheelEvent& wheelEvent)
585 Integration::WheelEvent event(static_cast<Integration::WheelEvent::Type>(wheelEvent.GetType()), wheelEvent.GetDirection(), wheelEvent.GetModifiers(), wheelEvent.GetPoint(), wheelEvent.GetDelta(), wheelEvent.GetTime());
586 mWindows.front()->FeedWheelEvent(event);
589 void Adaptor::FeedKeyEvent(Dali::KeyEvent& keyEvent)
591 Integration::KeyEvent convertedEvent(keyEvent.GetKeyName(), keyEvent.GetLogicalKey(), keyEvent.GetKeyString(), keyEvent.GetKeyCode(), keyEvent.GetKeyModifier(), keyEvent.GetTime(), static_cast<Integration::KeyEvent::State>(keyEvent.GetState()), keyEvent.GetCompose(), keyEvent.GetDeviceName(), keyEvent.GetDeviceClass(), keyEvent.GetDeviceSubclass());
592 mWindows.front()->FeedKeyEvent(convertedEvent);
595 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface)
597 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation(window);
598 for(auto windowPtr : mWindows)
600 if(windowPtr == windowImpl) // the window is not deleted
602 mResizedSignal.Emit(mAdaptor);
604 windowImpl->SetSurface(&newSurface);
606 // Flush the event queue to give the update-render thread chance
607 // to start processing messages for new camera setup etc as soon as possible
610 // This method blocks until the render thread has completed the replace.
611 mThreadController->ReplaceSurface(&newSurface);
617 void Adaptor::DeleteSurface(Dali::RenderSurfaceInterface& surface)
619 // Flush the event queue to give the update-render thread chance
620 // to start processing messages for new camera setup etc as soon as possible
623 // This method blocks until the render thread has finished rendering the current surface.
624 mThreadController->DeleteSurface(&surface);
627 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
629 return *mWindows.front()->GetSurface();
632 void Adaptor::ReleaseSurfaceLock()
634 mWindows.front()->GetSurface()->ReleaseLock();
637 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
639 if(!mTtsPlayers[mode])
641 // Create the TTS player when it needed, because it can reduce launching time.
642 mTtsPlayers[mode] = TtsPlayer::New(mode);
645 return mTtsPlayers[mode];
648 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue, bool forceAdd)
650 bool idleAdded(false);
652 // Only add an idle if the Adaptor is actually running
653 if(RUNNING == mState || READY == mState || forceAdd)
655 idleAdded = mCallbackManager->AddIdleCallback(callback, hasReturnValue);
661 void Adaptor::RemoveIdle(CallbackBase* callback)
663 mCallbackManager->RemoveIdleCallback(callback);
666 void Adaptor::ProcessIdle()
668 bool idleProcessed = mCallbackManager->ProcessIdle();
669 mNotificationOnIdleInstalled = mNotificationOnIdleInstalled && !idleProcessed;
672 void Adaptor::SetPreRenderCallback(CallbackBase* callback)
674 mThreadController->SetPreRenderCallback(callback);
677 bool Adaptor::AddWindow(Dali::Integration::SceneHolder childWindow)
679 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(childWindow);
680 windowImpl.SetAdaptor(Get());
682 // ChildWindow is set to the layout direction of the default window.
683 windowImpl.GetRootLayer().SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
685 // Add the new Window to the container - the order is not important
687 Dali::Mutex::ScopedLock lock(mMutex);
688 mWindows.push_back(&windowImpl);
691 Dali::RenderSurfaceInterface* surface = windowImpl.GetSurface();
693 mThreadController->AddSurface(surface);
695 mWindowCreatedSignal.Emit(childWindow);
700 bool Adaptor::RemoveWindow(Dali::Integration::SceneHolder* childWindow)
702 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(*childWindow);
703 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
705 if(*iter == &windowImpl)
707 Dali::Mutex::ScopedLock lock(mMutex);
708 mWindows.erase(iter);
716 bool Adaptor::RemoveWindow(std::string childWindowName)
718 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
720 if((*iter)->GetName() == childWindowName)
722 Dali::Mutex::ScopedLock lock(mMutex);
723 mWindows.erase(iter);
731 bool Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* childWindow)
733 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
735 if((*iter)->GetId() == childWindow->GetId())
737 Dali::Mutex::ScopedLock lock(mMutex);
738 mWindows.erase(iter);
746 Dali::Adaptor& Adaptor::Get()
748 DALI_ASSERT_ALWAYS(IsAvailable() && "Adaptor not instantiated");
749 return gThreadLocalAdaptor->mAdaptor;
752 bool Adaptor::IsAvailable()
754 return gThreadLocalAdaptor != NULL;
757 void Adaptor::SceneCreated()
759 mCore->SceneCreated();
762 Dali::Integration::Core& Adaptor::GetCore()
767 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
769 mThreadController->SetRenderRefreshRate(numberOfVSyncsPerRender);
772 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
774 DALI_ASSERT_DEBUG(mDisplayConnection && "Display connection not created");
775 return *mDisplayConnection;
778 GraphicsInterface& Adaptor::GetGraphicsInterface()
780 DALI_ASSERT_DEBUG(mGraphics && "Graphics interface not created");
781 return *(mGraphics.get());
784 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
786 return *mPlatformAbstraction;
789 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
791 return *mNotificationTrigger;
794 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
796 return mSocketFactory;
799 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
801 if(!mWindows.empty())
803 return mWindows.front()->GetSurface();
809 TraceInterface& Adaptor::GetKernelTraceInterface()
811 return mKernelTracer;
814 TraceInterface& Adaptor::GetSystemTraceInterface()
816 return mSystemTracer;
819 PerformanceInterface* Adaptor::GetPerformanceInterface()
821 return mPerformanceInterface;
824 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
826 DALI_ASSERT_DEBUG(mPlatformAbstraction && "PlatformAbstraction not created");
827 return *mPlatformAbstraction;
830 void Adaptor::GetWindowContainerInterface(WindowContainer& windows)
832 Dali::Mutex::ScopedLock lock(mMutex);
836 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
838 if(mTtsPlayers[mode])
840 mTtsPlayers[mode].Reset();
844 Any Adaptor::GetNativeWindowHandle()
846 return mWindows.front()->GetNativeHandle();
849 Any Adaptor::GetNativeWindowHandle(Dali::Actor actor)
851 Any nativeWindowHandle;
853 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
855 for(auto sceneHolder : mWindows)
857 if(scene == sceneHolder->GetScene())
859 nativeWindowHandle = sceneHolder->GetNativeHandle();
864 return nativeWindowHandle;
867 Any Adaptor::GetGraphicsDisplay()
873 GraphicsInterface* graphics = mGraphics.get(); // This interface is temporary until Core has been updated to match
874 auto eglGraphics = static_cast<EglGraphics*>(graphics);
876 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
877 display = eglImpl.GetDisplay();
883 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
885 mUseRemoteSurface = useRemoteSurface;
888 void Adaptor::AddObserver(LifeCycleObserver& observer)
890 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
892 if(match == mObservers.end())
894 mObservers.push_back(&observer);
898 void Adaptor::RemoveObserver(LifeCycleObserver& observer)
900 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
902 if(match != mObservers.end())
904 mObservers.erase(match);
908 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
912 mCore->QueueEvent(event);
916 void Adaptor::ProcessCoreEvents()
920 DALI_TRACE_SCOPE(gTraceFilter, "DALI_PROCESS_CORE_EVENTS");
922 if(mPerformanceInterface)
924 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_START);
927 mCore->ProcessEvents();
929 if(mPerformanceInterface)
931 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_END);
936 void Adaptor::RequestUpdate(bool forceUpdate)
942 mThreadController->RequestUpdate();
946 case PAUSED_WHILE_HIDDEN:
950 // Update (and resource upload) without rendering
951 mThreadController->RequestUpdateOnce(UpdateMode::SKIP_RENDER);
963 void Adaptor::RequestProcessEventsOnIdle(bool forceProcess)
965 // Only request a notification if the Adaptor is actually running
966 // and we haven't installed the idle notification
967 if((!mNotificationOnIdleInstalled) && (RUNNING == mState || READY == mState || forceProcess))
969 mNotificationOnIdleInstalled = AddIdleEnterer(MakeCallback(this, &Adaptor::ProcessCoreEventsFromIdle), forceProcess);
973 void Adaptor::OnWindowShown()
975 if(PAUSED_WHILE_HIDDEN == mState)
977 // Adaptor can now be resumed
982 // Force a render task
985 else if(RUNNING == mState)
987 // Force a render task
990 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Update requested.\n");
992 else if(PAUSED_WHILE_INITIALIZING == mState)
994 // Change the state to READY again. It will be changed to RUNNING after the adaptor is started.
999 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState);
1003 void Adaptor::OnWindowHidden()
1005 if(RUNNING == mState || READY == mState)
1007 bool allWindowsHidden = true;
1009 for(auto window : mWindows)
1011 if(window->IsVisible())
1013 allWindowsHidden = false;
1018 // Only pause the adaptor when all the windows are hidden
1019 if(allWindowsHidden)
1021 if(mState == RUNNING)
1025 // Adaptor cannot be resumed until any window is shown
1026 mState = PAUSED_WHILE_HIDDEN;
1028 else // mState is READY
1030 // Pause the adaptor after the state gets RUNNING
1031 mState = PAUSED_WHILE_INITIALIZING;
1036 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Some windows are shown. Don't pause adaptor.\n");
1041 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState);
1045 // Dali::Internal::Adaptor::Adaptor::OnDamaged
1046 void Adaptor::OnDamaged(const DamageArea& area)
1048 // This is needed for the case where Dali window is partially obscured
1049 RequestUpdate(false);
1052 void Adaptor::SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1054 mResizedSignal.Emit(mAdaptor);
1057 void Adaptor::SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1059 // Nofify surface resizing before flushing event queue
1060 mThreadController->ResizeSurface();
1062 // Flush the event queue to give the update-render thread chance
1063 // to start processing messages for new camera setup etc as soon as possible
1064 ProcessCoreEvents();
1067 void Adaptor::NotifySceneCreated()
1069 GetCore().SceneCreated();
1071 // Flush the event queue to give the update-render thread chance
1072 // to start processing messages for new camera setup etc as soon as possible
1073 ProcessCoreEvents();
1075 // Start thread controller after the scene has been created
1076 mThreadController->Start();
1078 // Process after surface is created (registering to remote surface provider if required)
1079 SurfaceInitialized();
1081 if(mState != PAUSED_WHILE_INITIALIZING)
1085 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is running\n");
1093 mState = PAUSED_WHILE_HIDDEN;
1095 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is paused\n");
1099 void Adaptor::NotifyLanguageChanged()
1101 mLanguageChangedSignal.Emit(mAdaptor);
1104 void Adaptor::RenderOnce()
1106 if(mThreadController)
1108 UpdateMode updateMode;
1109 if(mThreadMode == ThreadMode::NORMAL)
1111 updateMode = UpdateMode::NORMAL;
1115 updateMode = UpdateMode::FORCE_RENDER;
1117 ProcessCoreEvents();
1119 mThreadController->RequestUpdateOnce(updateMode);
1123 const LogFactoryInterface& Adaptor::GetLogFactory()
1125 return *mEnvironmentOptions;
1128 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
1130 GetCore().RegisterProcessor(processor, postProcessor);
1133 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
1135 GetCore().UnregisterProcessor(processor, postProcessor);
1138 bool Adaptor::IsMultipleWindowSupported() const
1140 return mConfigurationManager->IsMultipleWindowSupported();
1143 void Adaptor::RequestUpdateOnce()
1145 if(mThreadController)
1147 mThreadController->RequestUpdateOnce(UpdateMode::NORMAL);
1151 bool Adaptor::ProcessCoreEventsFromIdle()
1153 ProcessCoreEvents();
1155 // the idle handle automatically un-installs itself
1156 mNotificationOnIdleInstalled = false;
1161 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
1163 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
1165 for(auto window : mWindows)
1167 if(scene == window->GetScene())
1176 Dali::WindowContainer Adaptor::GetWindows() const
1178 Dali::WindowContainer windows;
1180 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1182 // Downcast to Dali::Window
1183 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
1186 windows.push_back(window);
1193 Dali::SceneHolderList Adaptor::GetSceneHolders() const
1195 Dali::SceneHolderList sceneHolderList;
1197 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1199 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
1202 return sceneHolderList;
1205 Dali::ObjectRegistry Adaptor::GetObjectRegistry() const
1207 Dali::ObjectRegistry registry;
1210 registry = mCore->GetObjectRegistry();
1215 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
1217 mLanguageChangedSignal(),
1218 mWindowCreatedSignal(),
1222 mThreadController(nullptr),
1224 mDisplayConnection(nullptr),
1226 mConfigurationManager(nullptr),
1227 mPlatformAbstraction(nullptr),
1228 mCallbackManager(nullptr),
1229 mNotificationOnIdleInstalled(false),
1230 mNotificationTrigger(nullptr),
1231 mDaliFeedbackPlugin(),
1232 mFeedbackController(nullptr),
1235 mEnvironmentOptions(environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1236 mPerformanceInterface(nullptr),
1239 mObjectProfiler(nullptr),
1240 mMemoryPoolTimerSlotDelegate(this),
1243 mThreadMode(threadMode),
1244 mEnvironmentOptionsOwned(environmentOptions ? false : true /* If not provided then we own the object */),
1245 mUseRemoteSurface(false),
1246 mRootLayoutDirection(Dali::LayoutDirection::LEFT_TO_RIGHT)
1248 DALI_ASSERT_ALWAYS(!IsAvailable() && "Cannot create more than one Adaptor per thread");
1249 mWindows.insert(mWindows.begin(), &Dali::GetImplementation(window));
1251 gThreadLocalAdaptor = this;
1254 void Adaptor::SetRootLayoutDirection(std::string locale)
1256 mRootLayoutDirection = static_cast<LayoutDirection::Type>(Internal::Adaptor::Locale::GetDirection(std::string(locale)));
1257 for(auto& window : mWindows)
1259 Dali::Actor root = window->GetRootLayer();
1260 root.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
1264 bool Adaptor::AddIdleEnterer(CallbackBase* callback, bool forceAdd)
1266 bool idleAdded(false);
1268 // Only add an idle if the Adaptor is actually running
1269 if(RUNNING == mState || READY == mState || forceAdd)
1271 idleAdded = mCallbackManager->AddIdleEntererCallback(callback);
1283 void Adaptor::RemoveIdleEnterer(CallbackBase* callback)
1285 mCallbackManager->RemoveIdleEntererCallback(callback);
1288 bool Adaptor::MemoryPoolTimeout()
1290 mCore->LogMemoryPools();
1291 return true; // Keep logging forever
1294 } // namespace Adaptor
1296 } // namespace Internal