1 #ifndef DALI_INTERNAL_ADAPTOR_IMPL_H
2 #define DALI_INTERNAL_ADAPTOR_IMPL_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/devel-api/threading/mutex.h>
23 #include <dali/integration-api/render-controller.h>
24 #include <dali/public-api/adaptor-framework/timer.h>
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/public-api/math/rect.h>
27 #include <dali/public-api/math/uint-16-pair.h>
28 #include <dali/public-api/signals/callback.h>
31 #include <dali/integration-api/adaptor-framework/adaptor.h>
32 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
33 #include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
34 #include <dali/integration-api/scene.h>
35 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
36 #include <dali/internal/graphics/common/graphics-interface.h>
37 #include <dali/internal/legacy/common/tizen-platform-abstraction.h>
38 #include <dali/internal/network/common/socket-factory.h>
39 #include <dali/internal/system/common/core-event-interface.h>
40 #include <dali/internal/system/common/environment-options.h>
41 #include <dali/internal/system/common/kernel-trace.h>
42 #include <dali/internal/system/common/system-trace.h>
43 #include <dali/internal/window-system/common/damage-observer.h>
44 #include <dali/internal/window-system/common/window-visibility-observer.h>
45 #include <dali/public-api/adaptor-framework/tts-player.h>
51 class RenderSurfaceInterface;
59 } // namespace Integration
65 class DisplayConnection;
66 class GraphicsFactory;
67 class GlImplementation;
68 class GlSyncImplementation;
69 class ThreadController;
71 class CallbackManager;
72 class FeedbackPluginProxy;
73 class FeedbackController;
75 class PerformanceInterface;
76 class LifeCycleObserver;
79 class ConfigurationManager;
80 enum class ThreadMode;
83 * Implementation of the Adaptor class.
85 class Adaptor : public Integration::RenderController,
86 public AdaptorInternalServices,
87 public CoreEventInterface,
88 public DamageObserver,
89 public WindowVisibilityObserver
92 using AdaptorSignalType = Dali::Adaptor::AdaptorSignalType;
93 using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType;
94 using LocaleChangedSignalType = Dali::Adaptor::LocaleChangedSignalType;
96 using SurfaceSize = Uint16Pair; ///< Surface size type
99 * Creates a New Adaptor
100 * @param[in] window The window handle
101 * @param[in] surface A render surface can be one of the following
102 * - Pixmap, adaptor will use existing Pixmap to draw on to
103 * - Window, adaptor will use existing Window to draw on to
104 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
105 * @param[in] threadMode The thread mode
107 static Dali::Adaptor* New(Dali::Integration::SceneHolder window,
108 Dali::RenderSurfaceInterface* surface,
109 EnvironmentOptions* environmentOptions,
110 ThreadMode threadMode);
113 * Creates a New Adaptor
114 * @param[in] window The window handle
115 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
117 static Dali::Adaptor* New(Dali::Integration::SceneHolder window,
118 EnvironmentOptions* environmentOptions);
121 * Creates a New Adaptor
122 * @param[in] graphicsFactory A factory that creates the graphics interface
123 * @param[in] window The window handle
124 * @param[in] surface A render surface can be one of the following
125 * - Pixmap, adaptor will use existing Pixmap to draw on to
126 * - Window, adaptor will use existing Window to draw on to
127 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
128 * @param[in] threadMode The thread mode
130 static Dali::Adaptor* New(GraphicsFactory& graphicsFactory,
131 Dali::Integration::SceneHolder window,
132 Dali::RenderSurfaceInterface* surface,
133 EnvironmentOptions* environmentOptions,
134 ThreadMode threadMode);
137 * Creates a New Adaptor
138 * @param[in] graphicsFactory A factory that creates the graphics interface
139 * @param[in] window The window handle
140 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
142 static Dali::Adaptor* New(GraphicsFactory& graphicsFactory,
143 Dali::Integration::SceneHolder window,
144 EnvironmentOptions* environmentOptions);
147 * 2-step initialisation, this should be called after creating an adaptor instance.
148 * @param[in] graphicsFactory A factory that creates the graphics interface
150 void Initialize(GraphicsFactory& graphicsFactory);
153 * Virtual destructor.
158 * @copydoc Dali::Adaptor::Get()
160 static Dali::Adaptor& Get();
163 * @copydoc Dali::Adaptor::IsAvailable()
165 static bool IsAvailable();
168 * @copydoc Dali::Core::SceneCreated();
173 * Get the application package name
175 static std::string GetApplicationPackageName();
177 public: // AdaptorInternalServices implementation
179 * @copydoc Dali::Adaptor::Start()
181 virtual void Start();
184 * @copydoc Dali::Adaptor::Pause()
186 virtual void Pause();
189 * @copydoc Dali::Adaptor::Resume()
191 virtual void Resume();
194 * @copydoc Dali::Adaptor::Stop()
199 * @copydoc Dali::Adaptor::ContextLost()
201 virtual void ContextLost();
204 * @copydoc Dali::Adaptor::ContextRegained()
206 virtual void ContextRegained();
209 * @copydoc Dali::EventFeeder::FeedTouchPoint()
211 virtual void FeedTouchPoint(TouchPoint& point, int timeStamp);
214 * @copydoc Dali::EventFeeder::FeedWheelEvent()
216 virtual void FeedWheelEvent(Dali::WheelEvent& wheelEvent);
219 * @copydoc Dali::EventFeeder::FeedKeyEvent()
221 virtual void FeedKeyEvent(Dali::KeyEvent& keyEvent);
224 * @copydoc Dali::Adaptor::ReplaceSurface()
226 virtual void ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface);
229 * @copydoc Dali::Adaptor::GetSurface()
231 virtual Dali::RenderSurfaceInterface& GetSurface() const;
234 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
236 virtual void ReleaseSurfaceLock();
239 * Retrieve the TtsPlayer.
240 * @param[in] mode The mode of TtsPlayer
241 * @return A handle to the TtsPlayer.
243 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
246 * @copydoc Dali::Adaptor::AddIdle()
248 virtual bool AddIdle(CallbackBase* callback, bool hasReturnValue);
251 * Adds a new Window instance to the Adaptor
252 * @param[in] childWindow The child window instance
254 virtual bool AddWindow(Dali::Integration::SceneHolder childWindow);
257 * Removes an existing Window instance from the Adaptor
258 * @param[in] window The Window instance
260 virtual bool RemoveWindow(Dali::Integration::SceneHolder* childWindow);
263 * Removes an existing Window instance from the Adaptor
264 * @param[in] windowName The Window name
265 * @note If two Windows have the same name, the first one that matches will be removed
267 virtual bool RemoveWindow(std::string childWindowName);
270 * @copydoc Dali::Adaptor::RemoveIdle()
272 virtual void RemoveIdle(CallbackBase* callback);
275 * @copydoc Dali::Adaptor::ProcessIdle()
277 virtual void ProcessIdle();
280 * Sets a pre-render callback.
282 void SetPreRenderCallback(CallbackBase* callback);
285 * Removes an existing Window instance from the Adaptor
286 * @param[in] childWindow The Window instance
288 bool RemoveWindow(Dali::Internal::Adaptor::SceneHolder* childWindow);
291 * @brief Deletes the rendering surface
292 * @param[in] surface to delete
294 void DeleteSurface(Dali::RenderSurfaceInterface& surface);
297 * @brief Retrieve the window that the given actor is added to.
299 * @param[in] actor The actor
300 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
302 Dali::Internal::Adaptor::SceneHolder* GetWindow(Dali::Actor& actor);
305 * @copydoc Dali::Adaptor::GetWindows()
307 Dali::WindowContainer GetWindows() const;
310 * @copydoc Dali::Adaptor::GetSceneHolders()
312 Dali::SceneHolderList GetSceneHolders() const;
315 * @copydoc Dali::Adaptor::GetObjectRegistry()
317 Dali::ObjectRegistry GetObjectRegistry() const;
321 * @return the Core instance
323 Dali::Integration::Core& GetCore() override;
326 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
328 void SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender);
331 * Return the PlatformAbstraction.
332 * @return The PlatformAbstraction.
334 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
337 * Destroy the TtsPlayer of specific mode.
338 * @param[in] mode The mode of TtsPlayer to destroy
340 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
343 * Gets native window handle
345 * @return native window handle
347 Any GetNativeWindowHandle();
350 * @brief Retrieve native window handle that the given actor is added to.
352 * @param[in] actor The actor
353 * @return native window handle
355 Any GetNativeWindowHandle(Dali::Actor actor);
358 * Get the native display associated with the graphics backend
360 * @return A handle to the native display
362 Any GetGraphicsDisplay();
365 * Sets use remote surface for Surface output
366 * @param[in] useRemoteSurface True if the remote surface is used
368 void SetUseRemoteSurface(bool useRemoteSurface);
372 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
373 * @param[in] observer The observer.
374 * @note Observers should remove themselves when they are destroyed.
376 void AddObserver(LifeCycleObserver& observer);
379 * Removes the observer from the adaptor.
380 * @param[in] observer The observer to remove.
381 * @note Observers should remove themselves when they are destroyed.
383 void RemoveObserver(LifeCycleObserver& observer);
386 * Emits the Notification event to the Dali core.
388 void SendNotificationEvent();
391 * Request adaptor to update once
393 void RequestUpdateOnce();
396 * @copydoc Dali::Adaptor::NotifySceneCreated()
398 void NotifySceneCreated();
401 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
403 void NotifyLanguageChanged();
406 * Gets AppId of current application
408 void GetAppId(std::string& appId);
411 * Gets path for resource storage.
412 * @param[out] path Path for resource storage
414 void GetResourceStoragePath(std::string& path);
417 * @copydoc Dali::Adaptor::SurfaceResizePrepare
419 void SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize);
422 * @copydoc Dali::Adaptor::SurfaceResizeComplete
424 void SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize);
427 * @brief Increase surface resize completed counter.
428 * This API will be ignored if thread controller is not exist.
430 void IncreaseSurfaceResizeCounter();
433 * Sets layout direction of root by system language
434 * @param[in] locale System locale
436 void SetRootLayoutDirection(std::string locale);
439 * @copydoc Dali::Adaptor::RenderOnce
444 * @copydoc Dali::Adaptor::GetLogFactory
446 const LogFactoryInterface& GetLogFactory();
449 * @copydoc Dali::Adaptor::GetTraceFactory
451 const TraceFactoryInterface& GetTraceFactory();
454 * @copydoc Dali::Adaptor::RegisterProcessor
456 void RegisterProcessor(Integration::Processor& processor, bool postProcessor);
459 * @coydoc Dali::Adaptor::UnregisterProcessor
461 void UnregisterProcessor(Integration::Processor& processor, bool postProcessor);
464 * Check MultipleWindow is supported
466 bool IsMultipleWindowSupported() const;
469 * @brief Gets the render thread id of DALi.
470 * @note If render thread id getter doesn't supported, it will return 0 as default.
471 * @return The render thread id.
473 int32_t GetRenderThreadId() const;
475 public: //AdaptorInternalServices
477 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
479 Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface() override;
482 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
484 Dali::DisplayConnection& GetDisplayConnectionInterface() override;
487 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
489 GraphicsInterface& GetGraphicsInterface() override;
492 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
494 TriggerEventInterface& GetProcessCoreEventsTrigger() override;
497 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
499 SocketFactoryInterface& GetSocketFactoryInterface() override;
502 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
504 Dali::RenderSurfaceInterface* GetRenderSurfaceInterface() override;
507 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
509 PerformanceInterface* GetPerformanceInterface() override;
512 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
514 TraceInterface& GetKernelTraceInterface() override;
517 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
519 TraceInterface& GetSystemTraceInterface() override;
522 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
524 void GetWindowContainerInterface(WindowContainer& windows) override;
527 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTextureUploadManager()
529 Devel::TextureUploadManager& GetTextureUploadManager() override;
532 * @brief Get the configuration manager
533 * @return The configuration manager, or null if it hasn't been created yet
535 const ConfigurationManager* GetConfigurationManager() const
537 return mConfigurationManager.get();
542 * @copydoc Dali::Adaptor::SignalResized
544 AdaptorSignalType& ResizedSignal()
546 return mResizedSignal;
550 * @copydoc Dali::Adaptor::LanguageChangedSignal
552 AdaptorSignalType& LanguageChangedSignal()
554 return mLanguageChangedSignal;
558 * @copydoc Dali::Adaptor::WindowCreatedSignal
560 WindowCreatedSignalType& WindowCreatedSignal()
562 return mWindowCreatedSignal;
566 * @copydoc Dali::Adaptor::LocaleChangedSignal
568 LocaleChangedSignalType& LocaleChangedSignal()
570 return mLocaleChangedSignal;
573 public: // From Dali::Internal::Adaptor::CoreEventInterface
575 * @copydoc Dali::Internal::Adaptor::CoreEventInterface:::FlushUpdateMessages()
577 void FlushUpdateMessages() override;
580 * @copydoc Dali::Internal::Adaptor::CoreEventInterface:::ProcessCoreEvents()
582 void ProcessCoreEvents() override;
584 private: // From Dali::Internal::Adaptor::CoreEventInterface
586 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
588 void QueueCoreEvent(const Dali::Integration::Event& event) override;
590 public: // From Dali::Integration::RenderController
592 * @copydoc Dali::Integration::RenderController::RequestUpdate()
594 void RequestUpdate() override;
597 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
599 void RequestProcessEventsOnIdle() override;
601 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
603 * Called when the window becomes fully or partially visible.
605 void OnWindowShown() override;
608 * Called when the window is fully hidden.
610 void OnWindowHidden() override;
612 private: // From Dali::Internal::Adaptor::DamageObserver
614 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
616 void OnDamaged(const DamageArea& area) override;
620 Adaptor(const Adaptor&) = delete;
621 Adaptor& operator=(Adaptor&) = delete;
625 * Assigns the render surface to the adaptor
628 void SetSurface(Dali::RenderSurfaceInterface* surface);
631 * called after surface is created
633 void SurfaceInitialized();
636 * Sends an notification message from main loop idle handler
638 bool ProcessCoreEventsFromIdle();
641 * Gets path for data/resource storage.
642 * @param[out] path Path for data/resource storage
644 void GetDataStoragePath(std::string& path);
647 * Sets up system information if needs
649 void SetupSystemInformation();
652 * Remove system information if needs
654 void RemoveSystemInformation();
657 * Adds a callback to be run when entering an idle state.
659 * A callback of the following type should be used:
663 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
665 bool AddIdleEnterer(CallbackBase* callback);
668 * Removes a previously added the idle enterer callback.
670 void RemoveIdleEnterer(CallbackBase* callback);
673 * Trigger to log the memory pools from Core and Adaptor
675 bool MemoryPoolTimeout();
680 * @param[in] window window handle
681 * @param[in] adaptor The public adaptor
682 * @param[in] surface A render surface can be one of the following
683 * - Pixmap, adaptor will use existing Pixmap to draw on to
684 * - Window, adaptor will use existing Window to draw on to
685 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
686 * @param[in] threadMode The ThreadMode of the Adaptor
688 Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode);
693 READY, ///< Initial state before Adaptor::Start is called.
694 RUNNING, ///< Adaptor is running.
695 PAUSED, ///< Adaptor has been paused.
696 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
697 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
698 STOPPED, ///< Adaptor has been stopped.
701 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
702 // so we have to store the raw pointer.
703 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
704 using ObserverContainer = std::vector<LifeCycleObserver*>;
707 AdaptorSignalType mResizedSignal; ///< Resized signal.
708 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
709 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
710 LocaleChangedSignalType mLocaleChangedSignal; ///< Locale changed signal.
712 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
713 State mState; ///< Current state of the adaptor
714 Dali::Integration::Core* mCore; ///< Dali Core
715 ThreadController* mThreadController; ///< Controls the threads
717 std::unique_ptr<GraphicsInterface> mGraphics; ///< Graphics interface
718 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
719 WindowContainer mWindows; ///< A container of all the Windows that are currently created
721 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
723 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
725 std::unique_ptr<CallbackManager> mCallbackManager; ///< Used to install callbacks
726 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
727 bool mRequiredIdleRepeat; ///< whether we need to repeat installed notification event in idle handler
728 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
729 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
730 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
731 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
732 ObserverContainer mObservers; ///< A list of adaptor observer pointers
733 EnvironmentOptions* mEnvironmentOptions; ///< environment options
734 PerformanceInterface* mPerformanceInterface; ///< Performance interface
735 KernelTrace mKernelTracer; ///< Kernel tracer
736 SystemTrace mSystemTracer; ///< System tracer
737 Devel::TextureUploadManager mTextureUploadManager; ///< TextureUploadManager
738 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
739 Dali::Timer mMemoryPoolTimer; ///< Logs memory pool capacity
740 SlotDelegate<Adaptor> mMemoryPoolTimerSlotDelegate;
741 SocketFactory mSocketFactory; ///< Socket factory
742 Mutex mMutex; ///< Mutex
743 ThreadMode mThreadMode; ///< The thread mode
744 const bool mEnvironmentOptionsOwned : 1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
745 bool mUseRemoteSurface : 1; ///< whether the remoteSurface is used or not
746 Dali::LayoutDirection::Type mRootLayoutDirection; ///< LayoutDirection of window
748 std::unique_ptr<Integration::AddOnManager> mAddOnManager; ///< Pointer to the addon manager
751 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor)
753 return *adaptor.mImpl;
757 } // namespace Adaptor
759 } // namespace Internal
763 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H