2 * Copyright (c) 2021 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/public-api/actors/layer.h>
38 #include <dali/public-api/events/wheel-event.h>
39 #include <dali/public-api/object/any.h>
40 #include <dali/public-api/object/object-registry.h>
45 #include <dali/internal/adaptor/common/lifecycle-observer.h>
46 #include <dali/internal/adaptor/common/thread-controller-interface.h>
47 #include <dali/internal/system/common/performance-interface-factory.h>
48 #include <dali/internal/system/common/thread-controller.h>
49 #include <dali/public-api/dali-adaptor-common.h>
51 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
52 #include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
54 #include <dali/devel-api/text-abstraction/font-client.h>
56 #include <dali/internal/accessibility/common/tts-player-impl.h>
57 #include <dali/internal/clipboard/common/clipboard-impl.h>
58 #include <dali/internal/graphics/common/egl-image-extensions.h>
59 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
60 #include <dali/internal/graphics/gles/gl-implementation.h>
61 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
62 #include <dali/internal/system/common/callback-manager.h>
63 #include <dali/internal/system/common/object-profiler.h>
64 #include <dali/internal/window-system/common/display-connection.h>
65 #include <dali/internal/window-system/common/display-utils.h> // For Utils::MakeUnique
66 #include <dali/internal/window-system/common/event-handler.h>
67 #include <dali/internal/window-system/common/window-impl.h>
68 #include <dali/internal/window-system/common/window-render-surface.h>
70 #include <dali/devel-api/adaptor-framework/accessibility-impl.h>
71 #include <dali/internal/system/common/logging.h>
73 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
74 #include <dali/internal/imaging/common/image-loader.h>
75 #include <dali/internal/system/common/locale-utils.h>
77 #include <dali/internal/system/common/configuration-manager.h>
78 #include <dali/internal/system/common/environment-variables.h>
80 using Dali::TextAbstraction::FontClient;
82 extern std::string GetSystemCachePath();
92 thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer to allow Adaptor::Get
94 } // unnamed namespace
96 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
98 Dali::Adaptor* adaptor = new Dali::Adaptor;
99 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode);
100 adaptor->mImpl = impl;
102 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder = new AdaptorBuilder(*(impl->mEnvironmentOptions));
103 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
105 impl->Initialize(graphicsFactory);
106 delete mAdaptorBuilder; // Not needed anymore as the graphics interface has now been created
111 Dali::Adaptor* Adaptor::New(Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
113 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
114 Dali::Adaptor* adaptor = New(window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
115 windowImpl.SetAdaptor(*adaptor);
119 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
121 Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
122 Adaptor* impl = new Adaptor(window, *adaptor, surface, environmentOptions, threadMode); // Impl adaptor
123 adaptor->mImpl = impl;
125 impl->Initialize(graphicsFactory);
130 Dali::Adaptor* Adaptor::New(GraphicsFactory& graphicsFactory, Dali::Integration::SceneHolder window, EnvironmentOptions* environmentOptions)
132 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(window);
133 Dali::Adaptor* adaptor = New(graphicsFactory, window, windowImpl.GetSurface(), environmentOptions, ThreadMode::NORMAL);
134 windowImpl.SetAdaptor(*adaptor);
138 void Adaptor::Initialize(GraphicsFactory& graphicsFactory)
140 // all threads here (event, update, and render) will send their logs to TIZEN Platform's LogMessage handler.
141 Dali::Integration::Log::LogFunction logFunction(Dali::TizenPlatform::LogMessage);
142 mEnvironmentOptions->SetLogFunction(logFunction);
143 mEnvironmentOptions->InstallLogFunction(); // install logging for main thread
145 mPlatformAbstraction = new TizenPlatform::TizenPlatformAbstraction;
148 GetDataStoragePath(path);
149 mPlatformAbstraction->SetDataStoragePath(path);
151 if(mEnvironmentOptions->PerformanceServerRequired())
153 mPerformanceInterface = PerformanceInterfaceFactory::CreateInterface(*this, *mEnvironmentOptions);
156 mEnvironmentOptions->CreateTraceManager(mPerformanceInterface);
157 mEnvironmentOptions->InstallTraceFunction(); // install tracing for main thread
159 mCallbackManager = CallbackManager::New();
161 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
163 DALI_ASSERT_DEBUG(defaultWindow->GetSurface() && "Surface not initialized");
165 mGraphics = std::unique_ptr<GraphicsInterface>(&graphicsFactory.Create());
167 // Create the AddOnManager
168 mAddOnManager.reset(Dali::Internal::AddOnManagerFactory::CreateAddOnManager());
170 mCore = Integration::Core::New(*this,
171 *mPlatformAbstraction,
172 mGraphics->GetController(),
173 (0u != mEnvironmentOptions->GetRenderToFboInterval()) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
174 mGraphics->GetDepthBufferRequired(),
175 mGraphics->GetStencilBufferRequired(),
176 mGraphics->GetPartialUpdateRequired());
178 defaultWindow->SetAdaptor(Get());
180 Dali::Integration::SceneHolder defaultSceneHolder(defaultWindow);
182 mWindowCreatedSignal.Emit(defaultSceneHolder);
184 const unsigned int timeInterval = mEnvironmentOptions->GetObjectProfilerInterval();
185 if(0u < timeInterval)
187 mObjectProfiler = new ObjectProfiler(mCore->GetObjectRegistry(), timeInterval);
190 mNotificationTrigger = TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &Adaptor::ProcessCoreEvents), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
192 mDisplayConnection = Dali::DisplayConnection::New(*mGraphics, defaultWindow->GetSurface()->GetSurfaceType());
194 mThreadController = new ThreadController(*this, *mEnvironmentOptions, mThreadMode);
196 // Should be called after Core creation
197 if(mEnvironmentOptions->GetPanGestureLoggingLevel())
199 Integration::EnableProfiling(Dali::Integration::PROFILING_TYPE_PAN_GESTURE);
201 if(mEnvironmentOptions->GetPanGesturePredictionMode() >= 0)
203 Integration::SetPanGesturePredictionMode(mEnvironmentOptions->GetPanGesturePredictionMode());
205 if(mEnvironmentOptions->GetPanGesturePredictionAmount() >= 0)
207 Integration::SetPanGesturePredictionAmount(mEnvironmentOptions->GetPanGesturePredictionAmount());
209 if(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount() >= 0)
211 Integration::SetPanGestureMaximumPredictionAmount(mEnvironmentOptions->GetPanGestureMaximumPredictionAmount());
213 if(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount() >= 0)
215 Integration::SetPanGestureMinimumPredictionAmount(mEnvironmentOptions->GetPanGestureMinimumPredictionAmount());
217 if(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment() >= 0)
219 Integration::SetPanGesturePredictionAmountAdjustment(mEnvironmentOptions->GetPanGesturePredictionAmountAdjustment());
221 if(mEnvironmentOptions->GetPanGestureSmoothingMode() >= 0)
223 Integration::SetPanGestureSmoothingMode(mEnvironmentOptions->GetPanGestureSmoothingMode());
225 if(mEnvironmentOptions->GetPanGestureSmoothingAmount() >= 0.0f)
227 Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
229 if(mEnvironmentOptions->GetPanGestureUseActualTimes() >= 0)
231 Integration::SetPanGestureUseActualTimes(mEnvironmentOptions->GetPanGestureUseActualTimes() == 0 ? true : false);
233 if(mEnvironmentOptions->GetPanGestureInterpolationTimeRange() >= 0)
235 Integration::SetPanGestureInterpolationTimeRange(mEnvironmentOptions->GetPanGestureInterpolationTimeRange());
237 if(mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() >= 0)
239 Integration::SetPanGestureScalarOnlyPredictionEnabled(mEnvironmentOptions->GetPanGestureScalarOnlyPredictionEnabled() == 0 ? true : false);
241 if(mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() >= 0)
243 Integration::SetPanGestureTwoPointPredictionEnabled(mEnvironmentOptions->GetPanGestureTwoPointPredictionEnabled() == 0 ? true : false);
245 if(mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime() >= 0)
247 Integration::SetPanGestureTwoPointInterpolatePastTime(mEnvironmentOptions->GetPanGestureTwoPointInterpolatePastTime());
249 if(mEnvironmentOptions->GetPanGestureTwoPointVelocityBias() >= 0.0f)
251 Integration::SetPanGestureTwoPointVelocityBias(mEnvironmentOptions->GetPanGestureTwoPointVelocityBias());
253 if(mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias() >= 0.0f)
255 Integration::SetPanGestureTwoPointAccelerationBias(mEnvironmentOptions->GetPanGestureTwoPointAccelerationBias());
257 if(mEnvironmentOptions->GetPanGestureMultitapSmoothingRange() >= 0)
259 Integration::SetPanGestureMultitapSmoothingRange(mEnvironmentOptions->GetPanGestureMultitapSmoothingRange());
261 if(mEnvironmentOptions->GetMinimumPanDistance() >= 0)
263 Integration::SetPanGestureMinimumDistance(mEnvironmentOptions->GetMinimumPanDistance());
265 if(mEnvironmentOptions->GetMinimumPanEvents() >= 0)
267 Integration::SetPanGestureMinimumPanEvents(mEnvironmentOptions->GetMinimumPanEvents());
269 if(mEnvironmentOptions->GetMinimumPinchDistance() >= 0)
271 Integration::SetPinchGestureMinimumDistance(mEnvironmentOptions->GetMinimumPinchDistance());
273 if(mEnvironmentOptions->GetMinimumPinchTouchEvents() >= 0)
275 Integration::SetPinchGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumPinchTouchEvents());
277 if(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart() >= 0)
279 Integration::SetPinchGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumPinchTouchEventsAfterStart());
281 if(mEnvironmentOptions->GetMinimumRotationTouchEvents() >= 0)
283 Integration::SetRotationGestureMinimumTouchEvents(mEnvironmentOptions->GetMinimumRotationTouchEvents());
285 if(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart() >= 0)
287 Integration::SetRotationGestureMinimumTouchEventsAfterStart(mEnvironmentOptions->GetMinimumRotationTouchEventsAfterStart());
289 if(mEnvironmentOptions->GetLongPressMinimumHoldingTime() >= 0)
291 Integration::SetLongPressMinimumHoldingTime(mEnvironmentOptions->GetLongPressMinimumHoldingTime());
293 if(mEnvironmentOptions->GetTapMaximumAllowedTime() > 0)
295 Integration::SetTapMaximumAllowedTime(mEnvironmentOptions->GetTapMaximumAllowedTime());
298 std::string systemCachePath = GetSystemCachePath();
299 if(!systemCachePath.empty())
301 const int dir_err = mkdir(systemCachePath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
302 if(0 != dir_err && errno != EEXIST)
304 DALI_LOG_ERROR("Error creating system cache directory: %s!\n", systemCachePath.c_str());
309 mConfigurationManager = Utils::MakeUnique<ConfigurationManager>(systemCachePath, mGraphics.get(), mThreadController);
312 void Adaptor::AccessibilityObserver::OnAccessibleKeyEvent(const Dali::KeyEvent& event)
314 Accessibility::KeyEventType type;
315 if(event.GetState() == Dali::KeyEvent::DOWN)
317 type = Accessibility::KeyEventType::KEY_PRESSED;
319 else if(event.GetState() == Dali::KeyEvent::UP)
321 type = Accessibility::KeyEventType::KEY_RELEASED;
327 Dali::Accessibility::Bridge::GetCurrentBridge()->Emit(type, event.GetKeyCode(), event.GetKeyName(), event.GetTime(), !event.GetKeyString().empty());
332 Accessibility::Bridge::GetCurrentBridge()->Terminate();
334 // Ensure stop status
337 // set to NULL first as we do not want any access to Adaptor as it is being destroyed.
338 gThreadLocalAdaptor = NULL;
340 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
342 (*iter)->OnDestroy();
345 // Clear out all the handles to Windows
348 delete mThreadController; // this will shutdown render thread, which will call Core::ContextDestroyed before exit
349 delete mObjectProfiler;
353 delete mDisplayConnection;
354 delete mPlatformAbstraction;
355 delete mCallbackManager;
356 delete mPerformanceInterface;
358 mGraphics->Destroy();
360 // uninstall it on this thread (main actor thread)
361 Dali::Integration::Log::UninstallLogFunction();
363 // Delete environment options if we own it
364 if(mEnvironmentOptionsOwned)
366 delete mEnvironmentOptions;
370 void Adaptor::Start()
372 // It doesn't support restart after stop at this moment to support restarting, need more testing
380 SetupSystemInformation();
382 // Start the callback manager
383 mCallbackManager->Start();
385 // Initialize accessibility bridge after callback manager is started to use Idler callback
386 auto appName = GetApplicationPackageName();
387 auto bridge = Accessibility::Bridge::GetCurrentBridge();
388 bridge->SetApplicationName(appName);
389 bridge->Initialize();
390 Dali::Stage::GetCurrent().KeyEventSignal().Connect(&mAccessibilityObserver, &AccessibilityObserver::OnAccessibleKeyEvent);
392 Dali::Internal::Adaptor::SceneHolder* defaultWindow = mWindows.front();
394 unsigned int dpiHor, dpiVer;
397 defaultWindow->GetSurface()->GetDpi(dpiHor, dpiVer);
399 // set the DPI value for font rendering
400 FontClient fontClient = FontClient::Get();
401 fontClient.SetDpi(dpiHor, dpiVer);
403 // Initialize the thread controller
404 mThreadController->Initialize();
406 // Set max texture size
407 if(mEnvironmentOptions->GetMaxTextureSize() > 0)
409 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(mEnvironmentOptions->GetMaxTextureSize());
413 unsigned int maxTextureSize = mConfigurationManager->GetMaxTextureSize();
414 Dali::TizenPlatform::ImageLoader::SetMaxTextureSize(maxTextureSize);
417 // cache advanced blending and shader language version
418 mGraphics->CacheConfigurations(*mConfigurationManager.get());
420 ProcessCoreEvents(); // Ensure any startup messages are processed.
422 // Initialize the image loader plugin
423 Internal::Adaptor::ImageLoaderPluginProxy::Initialize();
425 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
432 mAddOnManager->Start();
436 // Dali::Internal::Adaptor::Adaptor::Pause
437 void Adaptor::Pause()
439 // Only pause the adaptor if we're actually running.
440 if(RUNNING == mState)
442 // Inform observers that we are about to be paused.
443 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
451 mAddOnManager->Pause();
454 // Pause all windows event handlers when adaptor paused
455 for(auto window : mWindows)
460 mThreadController->Pause();
463 // Ensure any messages queued during pause callbacks are processed by doing another update.
466 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Paused\n");
470 DALI_LOG_RELEASE_INFO("Adaptor::Pause: Not paused [%d]\n", mState);
474 // Dali::Internal::Adaptor::Adaptor::Resume
475 void Adaptor::Resume()
477 // Only resume the adaptor if we are in the suspended state.
482 // Reset the event handlers when adaptor resumed
483 for(auto window : mWindows)
488 // Resume AddOnManager
491 mAddOnManager->Resume();
494 // Inform observers that we have resumed.
495 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
500 // Trigger processing of events queued up while paused
501 mCore->ProcessEvents();
503 // Do at end to ensure our first update/render after resumption includes the processed messages as well
504 mThreadController->Resume();
506 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Resumed\n");
510 DALI_LOG_RELEASE_INFO("Adaptor::Resume: Not resumed [%d]\n", mState);
516 if(RUNNING == mState ||
518 PAUSED_WHILE_HIDDEN == mState)
520 for(ObserverContainer::iterator iter = mObservers.begin(), endIter = mObservers.end(); iter != endIter; ++iter)
527 mAddOnManager->Stop();
530 mThreadController->Stop();
532 // Delete the TTS player
533 for(int i = 0; i < Dali::TtsPlayer::MODE_NUM; i++)
537 mTtsPlayers[i].Reset();
541 // Destroy the image loader plugin
542 Internal::Adaptor::ImageLoaderPluginProxy::Destroy();
544 delete mNotificationTrigger;
545 mNotificationTrigger = NULL;
547 mCallbackManager->Stop();
551 DALI_LOG_RELEASE_INFO("Adaptor::Stop\n");
555 void Adaptor::ContextLost()
557 mCore->GetContextNotifier()->NotifyContextLost(); // Inform stage
560 void Adaptor::ContextRegained()
562 // Inform core, so that texture resources can be reloaded
563 mCore->RecoverFromContextLoss();
565 mCore->GetContextNotifier()->NotifyContextRegained(); // Inform stage
568 void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
570 Integration::Point convertedPoint(point);
571 mWindows.front()->FeedTouchPoint(convertedPoint, timeStamp);
574 void Adaptor::FeedWheelEvent(Dali::WheelEvent& wheelEvent)
576 Integration::WheelEvent event(static_cast<Integration::WheelEvent::Type>(wheelEvent.GetType()), wheelEvent.GetDirection(), wheelEvent.GetModifiers(), wheelEvent.GetPoint(), wheelEvent.GetDelta(), wheelEvent.GetTime());
577 mWindows.front()->FeedWheelEvent(event);
580 void Adaptor::FeedKeyEvent(Dali::KeyEvent& keyEvent)
582 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());
583 mWindows.front()->FeedKeyEvent(convertedEvent);
586 void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& newSurface)
588 Internal::Adaptor::SceneHolder* windowImpl = &Dali::GetImplementation(window);
589 for(auto windowPtr : mWindows)
591 if(windowPtr == windowImpl) // the window is not deleted
593 mResizedSignal.Emit(mAdaptor);
595 windowImpl->SetSurface(&newSurface);
597 // Flush the event queue to give the update-render thread chance
598 // to start processing messages for new camera setup etc as soon as possible
601 // This method blocks until the render thread has completed the replace.
602 mThreadController->ReplaceSurface(&newSurface);
608 void Adaptor::DeleteSurface(Dali::RenderSurfaceInterface& surface)
610 // Flush the event queue to give the update-render thread chance
611 // to start processing messages for new camera setup etc as soon as possible
614 // This method blocks until the render thread has finished rendering the current surface.
615 mThreadController->DeleteSurface(&surface);
618 Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
620 return *mWindows.front()->GetSurface();
623 void Adaptor::ReleaseSurfaceLock()
625 mWindows.front()->GetSurface()->ReleaseLock();
628 Dali::TtsPlayer Adaptor::GetTtsPlayer(Dali::TtsPlayer::Mode mode)
630 if(!mTtsPlayers[mode])
632 // Create the TTS player when it needed, because it can reduce launching time.
633 mTtsPlayers[mode] = TtsPlayer::New(mode);
636 return mTtsPlayers[mode];
639 bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue, bool forceAdd)
641 bool idleAdded(false);
643 // Only add an idle if the Adaptor is actually running
644 if(RUNNING == mState || READY == mState || forceAdd)
646 idleAdded = mCallbackManager->AddIdleCallback(callback, hasReturnValue);
652 void Adaptor::RemoveIdle(CallbackBase* callback)
654 mCallbackManager->RemoveIdleCallback(callback);
657 void Adaptor::ProcessIdle()
659 bool idleProcessed = mCallbackManager->ProcessIdle();
660 mNotificationOnIdleInstalled = mNotificationOnIdleInstalled && !idleProcessed;
663 void Adaptor::SetPreRenderCallback(CallbackBase* callback)
665 mThreadController->SetPreRenderCallback(callback);
668 bool Adaptor::AddWindow(Dali::Integration::SceneHolder childWindow)
670 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(childWindow);
671 windowImpl.SetAdaptor(Get());
673 // ChildWindow is set to the layout direction of the default window.
674 windowImpl.GetRootLayer().SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
676 // Add the new Window to the container - the order is not important
678 Dali::Mutex::ScopedLock lock(mMutex);
679 mWindows.push_back(&windowImpl);
682 Dali::RenderSurfaceInterface* surface = windowImpl.GetSurface();
684 mThreadController->AddSurface(surface);
686 mWindowCreatedSignal.Emit(childWindow);
691 bool Adaptor::RemoveWindow(Dali::Integration::SceneHolder* childWindow)
693 Internal::Adaptor::SceneHolder& windowImpl = Dali::GetImplementation(*childWindow);
694 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
696 if(*iter == &windowImpl)
698 Dali::Mutex::ScopedLock lock(mMutex);
699 mWindows.erase(iter);
707 bool Adaptor::RemoveWindow(std::string childWindowName)
709 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
711 if((*iter)->GetName() == childWindowName)
713 Dali::Mutex::ScopedLock lock(mMutex);
714 mWindows.erase(iter);
722 bool Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* childWindow)
724 for(WindowContainer::iterator iter = mWindows.begin(); iter != mWindows.end(); ++iter)
726 if((*iter)->GetId() == childWindow->GetId())
728 Dali::Mutex::ScopedLock lock(mMutex);
729 mWindows.erase(iter);
737 Dali::Adaptor& Adaptor::Get()
739 DALI_ASSERT_ALWAYS(IsAvailable() && "Adaptor not instantiated");
740 return gThreadLocalAdaptor->mAdaptor;
743 bool Adaptor::IsAvailable()
745 return gThreadLocalAdaptor != NULL;
748 void Adaptor::SceneCreated()
750 mCore->SceneCreated();
753 Dali::Integration::Core& Adaptor::GetCore()
758 void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
760 mThreadController->SetRenderRefreshRate(numberOfVSyncsPerRender);
763 Dali::DisplayConnection& Adaptor::GetDisplayConnectionInterface()
765 DALI_ASSERT_DEBUG(mDisplayConnection && "Display connection not created");
766 return *mDisplayConnection;
769 GraphicsInterface& Adaptor::GetGraphicsInterface()
771 DALI_ASSERT_DEBUG(mGraphics && "Graphics interface not created");
772 return *(mGraphics.get());
775 Dali::Integration::PlatformAbstraction& Adaptor::GetPlatformAbstractionInterface()
777 return *mPlatformAbstraction;
780 TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
782 return *mNotificationTrigger;
785 SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
787 return mSocketFactory;
790 Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
792 if(!mWindows.empty())
794 return mWindows.front()->GetSurface();
800 TraceInterface& Adaptor::GetKernelTraceInterface()
802 return mKernelTracer;
805 TraceInterface& Adaptor::GetSystemTraceInterface()
807 return mSystemTracer;
810 PerformanceInterface* Adaptor::GetPerformanceInterface()
812 return mPerformanceInterface;
815 Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
817 DALI_ASSERT_DEBUG(mPlatformAbstraction && "PlatformAbstraction not created");
818 return *mPlatformAbstraction;
821 void Adaptor::GetWindowContainerInterface(WindowContainer& windows)
823 Dali::Mutex::ScopedLock lock(mMutex);
827 void Adaptor::DestroyTtsPlayer(Dali::TtsPlayer::Mode mode)
829 if(mTtsPlayers[mode])
831 mTtsPlayers[mode].Reset();
835 Any Adaptor::GetNativeWindowHandle()
837 return mWindows.front()->GetNativeHandle();
840 Any Adaptor::GetNativeWindowHandle(Dali::Actor actor)
842 Any nativeWindowHandle;
844 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
846 for(auto sceneHolder : mWindows)
848 if(scene == sceneHolder->GetScene())
850 nativeWindowHandle = sceneHolder->GetNativeHandle();
855 return nativeWindowHandle;
858 Any Adaptor::GetGraphicsDisplay()
864 GraphicsInterface* graphics = mGraphics.get(); // This interface is temporary until Core has been updated to match
865 auto eglGraphics = static_cast<EglGraphics*>(graphics);
867 EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
868 display = eglImpl.GetDisplay();
874 void Adaptor::SetUseRemoteSurface(bool useRemoteSurface)
876 mUseRemoteSurface = useRemoteSurface;
879 void Adaptor::AddObserver(LifeCycleObserver& observer)
881 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
883 if(match == mObservers.end())
885 mObservers.push_back(&observer);
889 void Adaptor::RemoveObserver(LifeCycleObserver& observer)
891 ObserverContainer::iterator match(find(mObservers.begin(), mObservers.end(), &observer));
893 if(match != mObservers.end())
895 mObservers.erase(match);
899 void Adaptor::QueueCoreEvent(const Dali::Integration::Event& event)
903 mCore->QueueEvent(event);
907 void Adaptor::ProcessCoreEvents()
911 if(mPerformanceInterface)
913 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_START);
916 mCore->ProcessEvents();
918 if(mPerformanceInterface)
920 mPerformanceInterface->AddMarker(PerformanceInterface::PROCESS_EVENTS_END);
925 void Adaptor::RequestUpdate(bool forceUpdate)
931 mThreadController->RequestUpdate();
935 case PAUSED_WHILE_HIDDEN:
939 // Update (and resource upload) without rendering
940 mThreadController->RequestUpdateOnce(UpdateMode::SKIP_RENDER);
952 void Adaptor::RequestProcessEventsOnIdle(bool forceProcess)
954 // Only request a notification if the Adaptor is actually running
955 // and we haven't installed the idle notification
956 if((!mNotificationOnIdleInstalled) && (RUNNING == mState || READY == mState || forceProcess))
958 mNotificationOnIdleInstalled = AddIdleEnterer(MakeCallback(this, &Adaptor::ProcessCoreEventsFromIdle), forceProcess);
962 void Adaptor::OnWindowShown()
964 if(PAUSED_WHILE_HIDDEN == mState)
966 // Adaptor can now be resumed
971 // Force a render task
974 else if(RUNNING == mState)
976 // Force a render task
979 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Update requested.\n");
981 else if(PAUSED_WHILE_INITIALIZING == mState)
983 // Change the state to READY again. It will be changed to RUNNING after the adaptor is started.
988 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowShown: Adaptor is not paused state.[%d]\n", mState);
992 void Adaptor::OnWindowHidden()
994 if(RUNNING == mState || READY == mState)
996 bool allWindowsHidden = true;
998 for(auto window : mWindows)
1000 if(window->IsVisible())
1002 allWindowsHidden = false;
1007 // Only pause the adaptor when all the windows are hidden
1008 if(allWindowsHidden)
1010 if(mState == RUNNING)
1014 // Adaptor cannot be resumed until any window is shown
1015 mState = PAUSED_WHILE_HIDDEN;
1017 else // mState is READY
1019 // Pause the adaptor after the state gets RUNNING
1020 mState = PAUSED_WHILE_INITIALIZING;
1025 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Some windows are shown. Don't pause adaptor.\n");
1030 DALI_LOG_RELEASE_INFO("Adaptor::OnWindowHidden: Adaptor is not running state.[%d]\n", mState);
1034 // Dali::Internal::Adaptor::Adaptor::OnDamaged
1035 void Adaptor::OnDamaged(const DamageArea& area)
1037 // This is needed for the case where Dali window is partially obscured
1038 RequestUpdate(false);
1041 void Adaptor::SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1043 mResizedSignal.Emit(mAdaptor);
1046 void Adaptor::SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize)
1048 // Nofify surface resizing before flushing event queue
1049 mThreadController->ResizeSurface();
1051 // Flush the event queue to give the update-render thread chance
1052 // to start processing messages for new camera setup etc as soon as possible
1053 ProcessCoreEvents();
1056 void Adaptor::NotifySceneCreated()
1058 GetCore().SceneCreated();
1060 // Flush the event queue to give the update-render thread chance
1061 // to start processing messages for new camera setup etc as soon as possible
1062 ProcessCoreEvents();
1064 // Start thread controller after the scene has been created
1065 mThreadController->Start();
1067 // Process after surface is created (registering to remote surface provider if required)
1068 SurfaceInitialized();
1070 if(mState != PAUSED_WHILE_INITIALIZING)
1074 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is running\n");
1082 mState = PAUSED_WHILE_HIDDEN;
1084 DALI_LOG_RELEASE_INFO("Adaptor::NotifySceneCreated: Adaptor is paused\n");
1088 void Adaptor::NotifyLanguageChanged()
1090 mLanguageChangedSignal.Emit(mAdaptor);
1093 void Adaptor::RenderOnce()
1095 if(mThreadController)
1097 UpdateMode updateMode;
1098 if(mThreadMode == ThreadMode::NORMAL)
1100 updateMode = UpdateMode::NORMAL;
1104 updateMode = UpdateMode::FORCE_RENDER;
1106 ProcessCoreEvents();
1108 mThreadController->RequestUpdateOnce(updateMode);
1112 const LogFactoryInterface& Adaptor::GetLogFactory()
1114 return *mEnvironmentOptions;
1117 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
1119 GetCore().RegisterProcessor(processor, postProcessor);
1122 void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
1124 GetCore().UnregisterProcessor(processor, postProcessor);
1127 bool Adaptor::IsMultipleWindowSupported() const
1129 return mConfigurationManager->IsMultipleWindowSupported();
1132 void Adaptor::RequestUpdateOnce()
1134 if(mThreadController)
1136 mThreadController->RequestUpdateOnce(UpdateMode::NORMAL);
1140 bool Adaptor::ProcessCoreEventsFromIdle()
1142 ProcessCoreEvents();
1144 // the idle handle automatically un-installs itself
1145 mNotificationOnIdleInstalled = false;
1150 Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
1152 Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
1154 for(auto window : mWindows)
1156 if(scene == window->GetScene())
1165 Dali::WindowContainer Adaptor::GetWindows() const
1167 Dali::WindowContainer windows;
1169 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1171 // Downcast to Dali::Window
1172 Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
1175 windows.push_back(window);
1182 Dali::SceneHolderList Adaptor::GetSceneHolders() const
1184 Dali::SceneHolderList sceneHolderList;
1186 for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
1188 sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
1191 return sceneHolderList;
1194 Dali::ObjectRegistry Adaptor::GetObjectRegistry() const
1196 Dali::ObjectRegistry registry;
1199 registry = mCore->GetObjectRegistry();
1204 Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode)
1206 mLanguageChangedSignal(),
1207 mWindowCreatedSignal(),
1211 mThreadController(nullptr),
1213 mDisplayConnection(nullptr),
1215 mConfigurationManager(nullptr),
1216 mPlatformAbstraction(nullptr),
1217 mCallbackManager(nullptr),
1218 mNotificationOnIdleInstalled(false),
1219 mNotificationTrigger(nullptr),
1220 mDaliFeedbackPlugin(),
1221 mFeedbackController(nullptr),
1224 mEnvironmentOptions(environmentOptions ? environmentOptions : new EnvironmentOptions /* Create the options if not provided */),
1225 mPerformanceInterface(nullptr),
1228 mObjectProfiler(nullptr),
1231 mThreadMode(threadMode),
1232 mEnvironmentOptionsOwned(environmentOptions ? false : true /* If not provided then we own the object */),
1233 mUseRemoteSurface(false),
1234 mRootLayoutDirection(Dali::LayoutDirection::LEFT_TO_RIGHT)
1236 DALI_ASSERT_ALWAYS(!IsAvailable() && "Cannot create more than one Adaptor per thread");
1237 mWindows.insert(mWindows.begin(), &Dali::GetImplementation(window));
1239 gThreadLocalAdaptor = this;
1242 void Adaptor::SetRootLayoutDirection(std::string locale)
1244 mRootLayoutDirection = static_cast<LayoutDirection::Type>(Internal::Adaptor::Locale::GetDirection(std::string(locale)));
1245 for(auto& window : mWindows)
1247 Dali::Actor root = window->GetRootLayer();
1248 root.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
1252 bool Adaptor::AddIdleEnterer(CallbackBase* callback, bool forceAdd)
1254 bool idleAdded(false);
1256 // Only add an idle if the Adaptor is actually running
1257 if(RUNNING == mState || READY == mState || forceAdd)
1259 idleAdded = mCallbackManager->AddIdleEntererCallback(callback);
1271 void Adaptor::RemoveIdleEnterer(CallbackBase* callback)
1273 mCallbackManager->RemoveIdleEntererCallback(callback);
1276 } // namespace Adaptor
1278 } // namespace Internal