2 * Copyright (c) 2023 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>
70 #include <dali/internal/window-system/common/window-system.h>
72 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
73 #include <dali/internal/system/common/logging.h>
75 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
76 #include <dali/internal/imaging/common/image-loader.h>
77 #include <dali/internal/system/common/locale-utils.h>
79 #include <dali/devel-api/adaptor-framework/environment-variable.h>
80 #include <dali/internal/system/common/configuration-manager.h>
81 #include <dali/internal/system/common/environment-variables.h>
83 using Dali::TextAbstraction::FontClient;
85 extern std::string GetSystemCachePath();
95 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
97 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false);
99 const char* ENABLE_IMAGE_LOADER_PLUGIN_ENV = "DALI_ENABLE_IMAGE_LOADER_PLUGIN";
100 } // unnamed namespace
102 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
104 Dali::Adaptor* adaptor = new Dali::Adaptor;
105 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode);
106 adaptor->mImpl = impl;
108 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder(*(impl->mEnvironmentOptions));
109 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
111 impl->Initialize(graphicsFactory);
112 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
117 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
119 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
120 Dali::Adaptor* adaptor = New(window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
121 windowImpl.SetAdaptor(*adaptor);
125 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
127 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
128 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode); // Impl adaptor
129 adaptor->mImpl = impl;
131 impl->Initialize(graphicsFactory);
136 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
138 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
139 Dali::Adaptor* adaptor = New(graphicsFactory, window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
140 windowImpl.SetAdaptor(*adaptor);
144 void Adaptor::Initialize(GraphicsFactory& graphicsFactory)
146 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
147 Dali::Integration::Log::LogFunction logFunction(Dali::TizenPlatform::LogMessage);
148 mEnvironmentOptions->SetLogFunction(logFunction);
149 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
151 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
154 GetDataStoragePath(path);
155 mPlatformAbstraction->SetDataStoragePath(path);
157 if(mEnvironmentOptions->PerformanceServerRequired())
159 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface(*this, *mEnvironmentOptions);
162 mEnvironmentOptions->CreateTraceManager(mPerformanceInterface);
163 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
165 mCallbackManager = CallbackManager::New();
167 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
169 DALI_ASSERT_DEBUG(defaultWindow->GetSurface() && "Surface not initialized");
171 mGraphics = std::unique_ptr<GraphicsInterface>(&graphicsFactory.Create());
173 // Create the AddOnManager
174 mAddOnManager.reset(Dali::Internal::AddOnManagerFactory::CreateAddOnManager());
176 mCore = Integration::Core::New(*this,
177 *mPlatformAbstraction,
178 mGraphics->GetController(),
179 (0u != mEnvironmentOptions->GetRenderToFboInterval()) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
180 mGraphics->GetDepthBufferRequired(),
181 mGraphics->GetStencilBufferRequired(),
182 mGraphics->GetPartialUpdateRequired());
184 defaultWindow->SetAdaptor(Get());
186 Dali::Integration::SceneHolder defaultSceneHolder(defaultWindow);
188 mWindowCreatedSignal.Emit(defaultSceneHolder);
190 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
191 if(0u < timeInterval)
193 mObjectProfiler = new ObjectProfiler(mCore->GetObjectRegistry(), timeInterval);
196 mNotificationTrigger = TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &Adaptor::ProcessCoreEvents), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
198 mDisplayConnection = Dali::DisplayConnection::New(*mGraphics, defaultWindow->GetSurface()->GetSurfaceType());
200 mThreadController = new ThreadController(*this, *mEnvironmentOptions, mThreadMode);
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());
267 if(mEnvironmentOptions->GetMinimumPanDistance() >= 0)
269 Integration::SetPanGestureMinimumDistance(mEnvironmentOptions->GetMinimumPanDistance());
271 if(mEnvironmentOptions->GetMinimumPanEvents() >= 0)
273 Integration::SetPanGestureMinimumPanEvents(mEnvironmentOptions->GetMinimumPanEvents());
275 if(mEnvironmentOptions->GetMinimumPinchDistance() >= 0)
277 Integration::SetPinchGestureMinimumDistance(mEnvironmentOptions->GetMinimumPinchDistance());
279 if(mEnvironmentOptions->GetMinimumPinchTouchEvents() >= 0)
281 Integration::SetPinchGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumPinchTouchEvents());
283 if(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart() >= 0)
285 Integration::SetPinchGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart());
287 if(mEnvironmentOptions->GetMinimumRotationTouchEvents() >= 0)
289 Integration::SetRotationGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumRotationTouchEvents());
291 if(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart() >= 0)
293 Integration::SetRotationGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart());
295 if(mEnvironmentOptions->GetLongPressMinimumHoldingTime() >= 0)
297 Integration::SetLongPressMinimumHoldingTime(mEnvironmentOptions->GetLongPressMinimumHoldingTime());
299 if(mEnvironmentOptions->GetTapMaximumAllowedTime() > 0)
301 Integration::SetTapMaximumAllowedTime(mEnvironmentOptions->GetTapMaximumAllowedTime());
304 std::string systemCachePath = GetSystemCachePath();
305 if(!systemCachePath.empty())
307 const int dir_err = mkdir(systemCachePath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
308 if(0 != dir_err && errno != EEXIST)
310 DALI_LOG_ERROR("Error creating system cache directory: %s!\n", systemCachePath.c_str());
314 mConfigurationManager = Utils::MakeUnique<ConfigurationManager>(systemCachePath, mGraphics.get(), mThreadController);
317 void Adaptor::AccessibilityObserver::OnAccessibleKeyEvent(const Dali::KeyEvent& event)
319 Accessibility::KeyEventType type;
320 if(event.GetState() == Dali::KeyEvent::DOWN)
322 type = Accessibility::KeyEventType::KEY_PRESSED;
324 else if(event.GetState() == Dali::KeyEvent::UP)
326 type = Accessibility::KeyEventType::KEY_RELEASED;
332 Dali::Accessibility::Bridge::GetCurrentBridge()->Emit(type, event.GetKeyCode(), event.GetKeyName(), event.GetTime(), !event.GetKeyString().empty());
337 Accessibility::Bridge::GetCurrentBridge()->Terminate();
339 // Ensure stop status
342 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
343 gThreadLocalAdaptor = NULL;
345 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
347 (*iter)->OnDestroy();
350 // Clear out all the handles to Windows
353 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
354 delete mObjectProfiler;
358 delete mDisplayConnection;
359 delete mPlatformAbstraction;
360 delete mCallbackManager;
361 delete mPerformanceInterface;
363 mGraphics->Destroy();
365 // uninstall it on this thread (main actor thread)
366 Dali::Integration::Log::UninstallLogFunction();
368 // Delete environment options if we own it
369 if(mEnvironmentOptionsOwned)
371 delete mEnvironmentOptions;
375 void Adaptor::Start()
377 // It doesn't support restart after stop at this moment to support restarting, need more testing
385 SetupSystemInformation();
387 // Start the callback manager
388 mCallbackManager->Start();
390 // Initialize accessibility bridge after callback manager is started to use Idler callback
391 auto appName = GetApplicationPackageName();
392 auto bridge = Accessibility::Bridge::GetCurrentBridge();
393 bridge->SetApplicationName(appName);
394 bridge->Initialize();
395 Dali::Stage::GetCurrent().KeyEventSignal().Connect(&mAccessibilityObserver, &AccessibilityObserver::OnAccessibleKeyEvent);
397 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
399 unsigned int dpiHor, dpiVer;
402 defaultWindow->GetSurface()->GetDpi(dpiHor, dpiVer);
403 Dali::Internal::Adaptor::WindowSystem::SetDpi(dpiHor, dpiVer);
405 // Initialize the thread controller
406 mThreadController->Initialize();
408 // Set max texture size
409 if(mEnvironmentOptions->GetMaxTextureSize() > 0)
411 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(mEnvironmentOptions->GetMaxTextureSize());
415 unsigned int maxTextureSize = mConfigurationManager->GetMaxTextureSize();
416 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(maxTextureSize);
419 // cache advanced blending and shader language version
420 mGraphics->CacheConfigurations(*mConfigurationManager.get());
422 ProcessCoreEvents(); // Ensure any startup messages are processed.
424 // Initialize the image loader plugin
425 auto enablePluginString = Dali::EnvironmentVariable::GetEnvironmentVariable(ENABLE_IMAGE_LOADER_PLUGIN_ENV);
426 bool enablePlugin = enablePluginString ? std::atoi(enablePluginString) : false;
429 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
432 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
439 mAddOnManager->Start();
443 // Dali::Internal::Adaptor::Adaptor::Pause
444 void Adaptor::Pause()
446 // Only pause the adaptor if we're actually running.
447 if(RUNNING == mState)
449 // Inform observers that we are about to be paused.
450 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
458 mAddOnManager->Pause();
461 // Pause all windows event handlers when adaptor paused
462 for(auto window : mWindows)
467 mThreadController->Pause();
470 // Ensure any messages queued during pause callbacks are processed by doing another update.
473 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Paused\n");
477 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Not paused [%d]\n", mState);
481 // Dali::Internal::Adaptor::Adaptor::Resume
482 void Adaptor::Resume()
484 // Only resume the adaptor if we are in the suspended state.
489 // Reset the event handlers when adaptor resumed
490 for(auto window : mWindows)
495 // Resume AddOnManager
498 mAddOnManager->Resume();
501 // Inform observers that we have resumed.
502 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
507 // Trigger processing of events queued up while paused
508 mCore->ProcessEvents();
510 // Do at end to ensure our first update/render after resumption includes the processed messages as well
511 mThreadController->Resume();
513 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Resumed\n");
517 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Not resumed [%d]\n", mState);
523 if(RUNNING == mState ||
525 PAUSED_WHILE_HIDDEN == mState)
527 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
534 mAddOnManager->Stop();
537 mThreadController->Stop();
539 // Delete the TTS player
540 for(int i = 0; i < Dali::TtsPlayer::MODE_NUM; i++)
544 mTtsPlayers[i].Reset();
548 // Destroy the image loader plugin
549 auto enablePluginString = Dali::EnvironmentVariable::GetEnvironmentVariable(ENABLE_IMAGE_LOADER_PLUGIN_ENV);
550 bool enablePlugin = enablePluginString ? std::atoi(enablePluginString) : false;
553 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
556 delete mNotificationTrigger;
557 mNotificationTrigger = NULL;
559 mCallbackManager->Stop();
563 DALI_LOG_RELEASE_INFO("Adaptor::Stop\n");
567 void Adaptor::ContextLost()
569 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
572 void Adaptor::ContextRegained()
574 // Inform core, so that texture resources can be reloaded
575 mCore->RecoverFromContextLoss();
577 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
580 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
582 Integration::Point convertedPoint(point);
583 mWindows.front()->FeedTouchPoint(convertedPoint, timeStamp);
586 void Adaptor::FeedWheelEvent(Dali::WheelEvent& wheelEvent)
588 Integration::WheelEvent event(static_cast<Integration::WheelEvent::Type>(wheelEvent.GetType()), wheelEvent.GetDirection(), wheelEvent.GetModifiers(), wheelEvent.GetPoint(), wheelEvent.GetDelta(), wheelEvent.GetTime());
589 mWindows.front()->FeedWheelEvent(event);
592 void Adaptor::FeedKeyEvent(Dali::KeyEvent& keyEvent)
594 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());
595 mWindows.front()->FeedKeyEvent(convertedEvent);
598 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface)
600 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation(window);
601 for(auto windowPtr : mWindows)
603 if(windowPtr == windowImpl) // the window is not deleted
605 mResizedSignal.Emit(mAdaptor);
607 windowImpl->SetSurface(&newSurface);
609 // Flush the event queue to give the update-render thread chance
610 // to start processing messages for new camera setup etc as soon as possible
613 // This method blocks until the render thread has completed the replace.
614 mThreadController->ReplaceSurface(&newSurface);
620 void Adaptor::DeleteSurface(Dali::RenderSurfaceInterface& surface)
622 // Flush the event queue to give the update-render thread chance
623 // to start processing messages for new camera setup etc as soon as possible
626 // This method blocks until the render thread has finished rendering the current surface.
627 mThreadController->DeleteSurface(&surface);
630 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
632 return *mWindows.front()->GetSurface();
635 void Adaptor::ReleaseSurfaceLock()
637 mWindows.front()->GetSurface()->ReleaseLock();
640 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
642 if(!mTtsPlayers[mode])
644 // Create the TTS player when it needed, because it can reduce launching time.
645 mTtsPlayers[mode] = TtsPlayer::New(mode);
648 return mTtsPlayers[mode];
651 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue, bool forceAdd)
653 bool idleAdded(false);
655 // Only add an idle if the Adaptor is actually running
656 if(RUNNING == mState || READY == mState || forceAdd)
658 idleAdded = mCallbackManager->AddIdleCallback(callback, hasReturnValue);
664 void Adaptor::RemoveIdle(CallbackBase* callback)
666 mCallbackManager->RemoveIdleCallback(callback);
669 void Adaptor::ProcessIdle()
671 bool idleProcessed = mCallbackManager->ProcessIdle();
672 mNotificationOnIdleInstalled = mNotificationOnIdleInstalled && !idleProcessed;
675 void Adaptor::SetPreRenderCallback(CallbackBase* callback)
677 mThreadController->SetPreRenderCallback(callback);
680 bool Adaptor::AddWindow(Dali::Integration::SceneHolder childWindow)
682 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(childWindow);
683 windowImpl.SetAdaptor(Get());
685 // ChildWindow is set to the layout direction of the default window.
686 windowImpl.GetRootLayer().SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
688 // Add the new Window to the container - the order is not important
690 Dali::Mutex::ScopedLock lock(mMutex);
691 mWindows.push_back(&windowImpl);
694 Dali::RenderSurfaceInterface* surface = windowImpl.GetSurface();
696 mThreadController->AddSurface(surface);
698 mWindowCreatedSignal.Emit(childWindow);
703 bool Adaptor::RemoveWindow(Dali::Integration::SceneHolder* childWindow)
705 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(*childWindow);
706 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
708 if(*iter == &windowImpl)
710 Dali::Mutex::ScopedLock lock(mMutex);
711 mWindows.erase(iter);
719 bool Adaptor::RemoveWindow(std::string childWindowName)
721 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
723 if((*iter)->GetName() == childWindowName)
725 Dali::Mutex::ScopedLock lock(mMutex);
726 mWindows.erase(iter);
734 bool Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* childWindow)
736 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
738 if((*iter)->GetId() == childWindow->GetId())
740 Dali::Mutex::ScopedLock lock(mMutex);
741 mWindows.erase(iter);
749 Dali::Adaptor& Adaptor::Get()
751 DALI_ASSERT_ALWAYS(IsAvailable() && "Adaptor not instantiated");
752 return gThreadLocalAdaptor->mAdaptor;
755 bool Adaptor::IsAvailable()
757 return gThreadLocalAdaptor != NULL;
760 void Adaptor::SceneCreated()
762 mCore->SceneCreated();
765 Dali::Integration::Core& Adaptor::GetCore()
770 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
772 mThreadController->SetRenderRefreshRate(numberOfVSyncsPerRender);
775 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
777 DALI_ASSERT_DEBUG(mDisplayConnection && "Display connection not created");
778 return *mDisplayConnection;
781 GraphicsInterface& Adaptor::GetGraphicsInterface()
783 DALI_ASSERT_DEBUG(mGraphics && "Graphics interface not created");
784 return *(mGraphics.get());
787 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
789 return *mPlatformAbstraction;
792 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
794 return *mNotificationTrigger;
797 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
799 return mSocketFactory;
802 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
804 if(!mWindows.empty())
806 return mWindows.front()->GetSurface();
812 TraceInterface& Adaptor::GetKernelTraceInterface()
814 return mKernelTracer;
817 TraceInterface& Adaptor::GetSystemTraceInterface()
819 return mSystemTracer;
822 PerformanceInterface* Adaptor::GetPerformanceInterface()
824 return mPerformanceInterface;
827 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
829 DALI_ASSERT_DEBUG(mPlatformAbstraction && "PlatformAbstraction not created");
830 return *mPlatformAbstraction;
833 void Adaptor::GetWindowContainerInterface(WindowContainer& windows)
835 Dali::Mutex::ScopedLock lock(mMutex);
839 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
841 if(mTtsPlayers[mode])
843 mTtsPlayers[mode].Reset();
847 Any Adaptor::GetNativeWindowHandle()
849 return mWindows.front()->GetNativeHandle();
852 Any Adaptor::GetNativeWindowHandle(Dali::Actor actor)
854 Any nativeWindowHandle;
856 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
858 for(auto sceneHolder : mWindows)
860 if(scene == sceneHolder->GetScene())
862 nativeWindowHandle = sceneHolder->GetNativeHandle();
867 return nativeWindowHandle;
870 Any Adaptor::GetGraphicsDisplay()
876 GraphicsInterface* graphics = mGraphics.get(); // This interface is temporary until Core has been updated to match
877 auto eglGraphics = static_cast<EglGraphics*>(graphics);
879 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
880 display = eglImpl.GetDisplay();
886 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
888 mUseRemoteSurface = useRemoteSurface;
891 void Adaptor::AddObserver(LifeCycleObserver& observer)
893 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
895 if(match == mObservers.end())
897 mObservers.push_back(&observer);
901 void Adaptor::RemoveObserver(LifeCycleObserver& observer)
903 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
905 if(match != mObservers.end())
907 mObservers.erase(match);
911 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
915 mCore->QueueEvent(event);
919 void Adaptor::ProcessCoreEvents()
923 if(mPerformanceInterface)
925 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_START);
928 DALI_TRACE_BEGIN(gTraceFilter, "DALI_PROCESS_CORE_EVENTS");
930 mCore->ProcessEvents();
932 DALI_TRACE_END(gTraceFilter, "DALI_PROCESS_CORE_EVENTS");
934 if(mPerformanceInterface)
936 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_END);
941 void Adaptor::RequestUpdate(bool forceUpdate)
947 mThreadController->RequestUpdate();
951 case PAUSED_WHILE_HIDDEN:
955 // Update (and resource upload) without rendering
956 mThreadController->RequestUpdateOnce(UpdateMode::SKIP_RENDER);
968 void Adaptor::RequestProcessEventsOnIdle(bool forceProcess)
970 // Only request a notification if the Adaptor is actually running
971 // and we haven't installed the idle notification
972 if((!mNotificationOnIdleInstalled) && (RUNNING == mState || READY == mState || forceProcess))
974 mNotificationOnIdleInstalled = AddIdleEnterer(MakeCallback(this, &Adaptor::ProcessCoreEventsFromIdle), forceProcess);
978 void Adaptor::OnWindowShown()
980 if(PAUSED_WHILE_HIDDEN == mState)
982 // Adaptor can now be resumed
987 // Force a render task
990 else if(RUNNING == mState)
992 // Force a render task
995 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Update requested.\n");
997 else if(PAUSED_WHILE_INITIALIZING == mState)
999 // Change the state to READY again. It will be changed to RUNNING after the adaptor is started.
1004 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState);
1008 void Adaptor::OnWindowHidden()
1010 if(RUNNING == mState || READY == mState)
1012 bool allWindowsHidden = true;
1014 for(auto window : mWindows)
1016 if(window->IsVisible())
1018 allWindowsHidden = false;
1023 // Only pause the adaptor when all the windows are hidden
1024 if(allWindowsHidden)
1026 if(mState == RUNNING)
1030 // Adaptor cannot be resumed until any window is shown
1031 mState = PAUSED_WHILE_HIDDEN;
1033 else // mState is READY
1035 // Pause the adaptor after the state gets RUNNING
1036 mState = PAUSED_WHILE_INITIALIZING;
1041 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Some windows are shown. Don't pause adaptor.\n");
1046 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState);
1050 // Dali::Internal::Adaptor::Adaptor::OnDamaged
1051 void Adaptor::OnDamaged(const DamageArea& area)
1053 // This is needed for the case where Dali window is partially obscured
1054 RequestUpdate(false);
1057 void Adaptor::SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1059 mResizedSignal.Emit(mAdaptor);
1062 void Adaptor::SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1064 // Nofify surface resizing before flushing event queue
1065 mThreadController->ResizeSurface();
1067 // Flush the event queue to give the update-render thread chance
1068 // to start processing messages for new camera setup etc as soon as possible
1069 ProcessCoreEvents();
1072 void Adaptor::NotifySceneCreated()
1074 GetCore().SceneCreated();
1076 // Flush the event queue to give the update-render thread chance
1077 // to start processing messages for new camera setup etc as soon as possible
1078 ProcessCoreEvents();
1080 // Start thread controller after the scene has been created
1081 mThreadController->Start();
1083 // Process after surface is created (registering to remote surface provider if required)
1084 SurfaceInitialized();
1086 if(mState != PAUSED_WHILE_INITIALIZING)
1090 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is running\n");
1098 mState = PAUSED_WHILE_HIDDEN;
1100 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is paused\n");
1104 void Adaptor::NotifyLanguageChanged()
1106 mLanguageChangedSignal.Emit(mAdaptor);
1109 void Adaptor::RenderOnce()
1111 if(mThreadController)
1113 UpdateMode updateMode;
1114 if(mThreadMode == ThreadMode::NORMAL)
1116 updateMode = UpdateMode::NORMAL;
1120 updateMode = UpdateMode::FORCE_RENDER;
1122 ProcessCoreEvents();
1124 mThreadController->RequestUpdateOnce(updateMode);
1128 const LogFactoryInterface& Adaptor::GetLogFactory()
1130 return *mEnvironmentOptions;
1133 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
1135 GetCore().RegisterProcessor(processor, postProcessor);
1138 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
1140 GetCore().UnregisterProcessor(processor, postProcessor);
1143 bool Adaptor::IsMultipleWindowSupported() const
1145 return mConfigurationManager->IsMultipleWindowSupported();
1148 int32_t Adaptor::GetRenderThreadId() const
1150 if(mThreadController)
1152 return mThreadController->GetThreadId();
1157 void Adaptor::RequestUpdateOnce()
1159 if(mThreadController)
1161 mThreadController->RequestUpdateOnce(UpdateMode::NORMAL);
1165 bool Adaptor::ProcessCoreEventsFromIdle()
1167 ProcessCoreEvents();
1169 // the idle handle automatically un-installs itself
1170 mNotificationOnIdleInstalled = false;
1175 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
1177 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
1179 for(auto window : mWindows)
1181 if(scene == window->GetScene())
1190 Dali::WindowContainer Adaptor::GetWindows() const
1192 Dali::WindowContainer windows;
1194 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1196 // Downcast to Dali::Window
1197 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
1200 windows.push_back(window);
1207 Dali::SceneHolderList Adaptor::GetSceneHolders() const
1209 Dali::SceneHolderList sceneHolderList;
1211 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1213 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
1216 return sceneHolderList;
1219 Dali::ObjectRegistry Adaptor::GetObjectRegistry() const
1221 Dali::ObjectRegistry registry;
1224 registry = mCore->GetObjectRegistry();
1229 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
1231 mLanguageChangedSignal(),
1232 mWindowCreatedSignal(),
1236 mThreadController(nullptr),
1238 mDisplayConnection(nullptr),
1240 mConfigurationManager(nullptr),
1241 mPlatformAbstraction(nullptr),
1242 mCallbackManager(nullptr),
1243 mNotificationOnIdleInstalled(false),
1244 mNotificationTrigger(nullptr),
1245 mDaliFeedbackPlugin(),
1246 mFeedbackController(nullptr),
1249 mEnvironmentOptions(environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1250 mPerformanceInterface(nullptr),
1253 mObjectProfiler(nullptr),
1256 mThreadMode(threadMode),
1257 mEnvironmentOptionsOwned(environmentOptions ? false : true /* If not provided then we own the object */),
1258 mUseRemoteSurface(false),
1259 mRootLayoutDirection(Dali::LayoutDirection::LEFT_TO_RIGHT)
1261 DALI_ASSERT_ALWAYS(!IsAvailable() && "Cannot create more than one Adaptor per thread");
1262 mWindows.insert(mWindows.begin(), &Dali::GetImplementation(window));
1264 gThreadLocalAdaptor = this;
1267 void Adaptor::SetRootLayoutDirection(std::string locale)
1269 mRootLayoutDirection = static_cast<LayoutDirection::Type>(Internal::Adaptor::Locale::GetDirection(std::string(locale)));
1270 for(auto& window : mWindows)
1272 Dali::Actor root = window->GetRootLayer();
1273 root.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
1277 bool Adaptor::AddIdleEnterer(CallbackBase* callback, bool forceAdd)
1279 bool idleAdded(false);
1281 // Only add an idle if the Adaptor is actually running
1282 if(RUNNING == mState || READY == mState || forceAdd)
1284 idleAdded = mCallbackManager->AddIdleEntererCallback(callback);
1296 void Adaptor::RemoveIdleEnterer(CallbackBase* callback)
1298 mCallbackManager->RemoveIdleEntererCallback(callback);
1301 } // namespace Adaptor
1303 } // namespace Internal