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/devel-api/adaptor-framework/text-clipboard.h>
32 #include <dali/integration-api/adaptor-framework/adaptor.h>
33 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
34 #include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
35 #include <dali/integration-api/scene.h>
36 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
37 #include <dali/internal/graphics/common/graphics-interface.h>
38 #include <dali/internal/legacy/common/tizen-platform-abstraction.h>
39 #include <dali/internal/network/common/socket-factory.h>
40 #include <dali/internal/system/common/core-event-interface.h>
41 #include <dali/internal/system/common/environment-options.h>
42 #include <dali/internal/system/common/kernel-trace.h>
43 #include <dali/internal/system/common/system-trace.h>
44 #include <dali/internal/window-system/common/damage-observer.h>
45 #include <dali/internal/window-system/common/window-visibility-observer.h>
46 #include <dali/public-api/adaptor-framework/tts-player.h>
52 class RenderSurfaceInterface;
54 namespace Accessibility
65 } // namespace Integration
71 class DisplayConnection;
72 class GraphicsFactory;
73 class GlImplementation;
74 class GlSyncImplementation;
75 class ThreadController;
77 class CallbackManager;
78 class FeedbackPluginProxy;
79 class FeedbackController;
81 class PerformanceInterface;
82 class LifeCycleObserver;
85 class ConfigurationManager;
86 enum class ThreadMode;
89 * Implementation of the Adaptor class.
91 class Adaptor : public Integration::RenderController,
92 public AdaptorInternalServices,
93 public CoreEventInterface,
94 public DamageObserver,
95 public WindowVisibilityObserver
98 using AdaptorSignalType = Dali::Adaptor::AdaptorSignalType;
99 using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType;
101 using SurfaceSize = Uint16Pair; ///< Surface size type
104 * Creates a New Adaptor
105 * @param[in] window The window handle
106 * @param[in] surface A render surface can be one of the following
107 * - Pixmap, adaptor will use existing Pixmap to draw on to
108 * - Window, adaptor will use existing Window to draw on to
109 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
110 * @param[in] threadMode The thread mode
112 static Dali::Adaptor* New(Dali::Integration::SceneHolder window,
113 Dali::RenderSurfaceInterface* surface,
114 EnvironmentOptions* environmentOptions,
115 ThreadMode threadMode);
118 * Creates a New Adaptor
119 * @param[in] window The window handle
120 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
122 static Dali::Adaptor* New(Dali::Integration::SceneHolder window,
123 EnvironmentOptions* environmentOptions);
126 * Creates a New Adaptor
127 * @param[in] graphicsFactory A factory that creates the graphics interface
128 * @param[in] window The window handle
129 * @param[in] surface A render surface can be one of the following
130 * - Pixmap, adaptor will use existing Pixmap to draw on to
131 * - Window, adaptor will use existing Window to draw on to
132 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
133 * @param[in] threadMode The thread mode
135 static Dali::Adaptor* New(GraphicsFactory& graphicsFactory,
136 Dali::Integration::SceneHolder window,
137 Dali::RenderSurfaceInterface* surface,
138 EnvironmentOptions* environmentOptions,
139 ThreadMode threadMode);
142 * Creates a New Adaptor
143 * @param[in] graphicsFactory A factory that creates the graphics interface
144 * @param[in] window The window handle
145 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
147 static Dali::Adaptor* New(GraphicsFactory& graphicsFactory,
148 Dali::Integration::SceneHolder window,
149 EnvironmentOptions* environmentOptions);
152 * 2-step initialisation, this should be called after creating an adaptor instance.
153 * @param[in] graphicsFactory A factory that creates the graphics interface
155 void Initialize(GraphicsFactory& graphicsFactory);
158 * Virtual destructor.
163 * @copydoc Dali::Adaptor::Get()
165 static Dali::Adaptor& Get();
168 * @copydoc Dali::Adaptor::IsAvailable()
170 static bool IsAvailable();
173 * @copydoc Dali::Core::SceneCreated();
178 * Get the application package name
180 static std::string GetApplicationPackageName();
182 public: // AdaptorInternalServices implementation
184 * @copydoc Dali::Adaptor::Start()
186 virtual void Start();
189 * @copydoc Dali::Adaptor::Pause()
191 virtual void Pause();
194 * @copydoc Dali::Adaptor::Resume()
196 virtual void Resume();
199 * @copydoc Dali::Adaptor::Stop()
204 * @copydoc Dali::Adaptor::ContextLost()
206 virtual void ContextLost();
209 * @copydoc Dali::Adaptor::ContextRegained()
211 virtual void ContextRegained();
214 * @copydoc Dali::EventFeeder::FeedTouchPoint()
216 virtual void FeedTouchPoint(TouchPoint& point, int timeStamp);
219 * @copydoc Dali::EventFeeder::FeedWheelEvent()
221 virtual void FeedWheelEvent(Dali::WheelEvent& wheelEvent);
224 * @copydoc Dali::EventFeeder::FeedKeyEvent()
226 virtual void FeedKeyEvent(Dali::KeyEvent& keyEvent);
229 * @copydoc Dali::Adaptor::ReplaceSurface()
231 virtual void ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface);
234 * @copydoc Dali::Adaptor::GetSurface()
236 virtual Dali::RenderSurfaceInterface& GetSurface() const;
239 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
241 virtual void ReleaseSurfaceLock();
244 * Retrieve the TtsPlayer.
245 * @param[in] mode The mode of TtsPlayer
246 * @return A handle to the TtsPlayer.
248 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
251 * @copydoc Dali::Adaptor::AddIdle()
253 virtual bool AddIdle(CallbackBase* callback, bool hasReturnValue, bool forceAdd);
256 * Adds a new Window instance to the Adaptor
257 * @param[in] childWindow The child window instance
259 virtual bool AddWindow(Dali::Integration::SceneHolder childWindow);
262 * Removes an existing Window instance from the Adaptor
263 * @param[in] window The Window instance
265 virtual bool RemoveWindow(Dali::Integration::SceneHolder* childWindow);
268 * Removes an existing Window instance from the Adaptor
269 * @param[in] windowName The Window name
270 * @note If two Windows have the same name, the first one that matches will be removed
272 virtual bool RemoveWindow(std::string childWindowName);
275 * @copydoc Dali::Adaptor::RemoveIdle()
277 virtual void RemoveIdle(CallbackBase* callback);
280 * @copydoc Dali::Adaptor::ProcessIdle()
282 virtual void ProcessIdle();
285 * Sets a pre-render callback.
287 void SetPreRenderCallback(CallbackBase* callback);
290 * Removes an existing Window instance from the Adaptor
291 * @param[in] childWindow The Window instance
293 bool RemoveWindow(Dali::Internal::Adaptor::SceneHolder* childWindow);
296 * @brief Deletes the rendering surface
297 * @param[in] surface to delete
299 void DeleteSurface(Dali::RenderSurfaceInterface& surface);
302 * @brief Retrieve the window that the given actor is added to.
304 * @param[in] actor The actor
305 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
307 Dali::Internal::Adaptor::SceneHolder* GetWindow(Dali::Actor& actor);
310 * @copydoc Dali::Adaptor::GetWindows()
312 Dali::WindowContainer GetWindows() const;
315 * @copydoc Dali::Adaptor::GetSceneHolders()
317 Dali::SceneHolderList GetSceneHolders() const;
320 * @copydoc Dali::Adaptor::GetObjectRegistry()
322 Dali::ObjectRegistry GetObjectRegistry() const;
326 * @return the Core instance
328 Dali::Integration::Core& GetCore() override;
331 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
333 void SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender);
336 * Return the PlatformAbstraction.
337 * @return The PlatformAbstraction.
339 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
342 * Destroy the TtsPlayer of specific mode.
343 * @param[in] mode The mode of TtsPlayer to destroy
345 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
348 * Gets native window handle
350 * @return native window handle
352 Any GetNativeWindowHandle();
355 * @brief Retrieve native window handle that the given actor is added to.
357 * @param[in] actor The actor
358 * @return native window handle
360 Any GetNativeWindowHandle(Dali::Actor actor);
363 * Get the native display associated with the graphics backend
365 * @return A handle to the native display
367 Any GetGraphicsDisplay();
370 * Sets use remote surface for Surface output
371 * @param[in] useRemoteSurface True if the remote surface is used
373 void SetUseRemoteSurface(bool useRemoteSurface);
377 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
378 * @param[in] observer The observer.
379 * @note Observers should remove themselves when they are destroyed.
381 void AddObserver(LifeCycleObserver& observer);
384 * Removes the observer from the adaptor.
385 * @param[in] observer The observer to remove.
386 * @note Observers should remove themselves when they are destroyed.
388 void RemoveObserver(LifeCycleObserver& observer);
391 * Emits the Notification event to the Dali core.
393 void SendNotificationEvent();
396 * Request adaptor to update once
398 void RequestUpdateOnce();
401 * @copydoc Dali::Adaptor::NotifySceneCreated()
403 void NotifySceneCreated();
406 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
408 void NotifyLanguageChanged();
411 * Gets AppId of current application
413 void GetAppId(std::string& appId);
416 * Gets path for resource storage.
417 * @param[out] path Path for resource storage
419 void GetResourceStoragePath(std::string& path);
422 * @copydoc Dali::Adaptor::SurfaceResizePrepare
424 void SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize);
427 * @copydoc Dali::Adaptor::SurfaceResizeComplete
429 void SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize);
432 * Sets layout direction of root by system language
433 * @param[in] locale System locale
435 void SetRootLayoutDirection(std::string locale);
438 * @copydoc Dali::Adaptor::RenderOnce
443 * @copydoc Dali::Adaptor::GetLogFactory
445 const LogFactoryInterface& GetLogFactory();
448 * @copydoc Dali::Adaptor::RegisterProcessor
450 void RegisterProcessor(Integration::Processor& processor, bool postProcessor);
453 * @coydoc Dali::Adaptor::UnregisterProcessor
455 void UnregisterProcessor(Integration::Processor& processor, bool postProcessor);
458 * Check MultipleWindow is supported
460 bool IsMultipleWindowSupported() const;
463 * @brief Gets the render thread id of DALi.
464 * @note If render thread id getter doesn't supported, it will return 0 as default.
465 * @return The render thread id.
467 int32_t GetRenderThreadId() const;
469 public: //AdaptorInternalServices
471 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
473 Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface() override;
476 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
478 Dali::DisplayConnection& GetDisplayConnectionInterface() override;
481 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
483 GraphicsInterface& GetGraphicsInterface() override;
486 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
488 TriggerEventInterface& GetProcessCoreEventsTrigger() override;
491 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
493 SocketFactoryInterface& GetSocketFactoryInterface() override;
496 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
498 Dali::RenderSurfaceInterface* GetRenderSurfaceInterface() override;
501 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
503 PerformanceInterface* GetPerformanceInterface() override;
506 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
508 TraceInterface& GetKernelTraceInterface() override;
511 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
513 TraceInterface& GetSystemTraceInterface() override;
516 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
518 void GetWindowContainerInterface(WindowContainer& windows) override;
521 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTextureUploadManager()
523 Devel::TextureUploadManager& GetTextureUploadManager() override;
526 * @brief Get the configuration manager
527 * @return The configuration manager, or null if it hasn't been created yet
529 const ConfigurationManager* GetConfigurationManager() const
531 return mConfigurationManager.get();
536 * @copydoc Dali::Adaptor::SignalResized
538 AdaptorSignalType& ResizedSignal()
540 return mResizedSignal;
544 * @copydoc Dali::Adaptor::LanguageChangedSignal
546 AdaptorSignalType& LanguageChangedSignal()
548 return mLanguageChangedSignal;
552 * @copydoc Dali::Adaptor::WindowCreatedSignal
554 WindowCreatedSignalType& WindowCreatedSignal()
556 return mWindowCreatedSignal;
559 public: // From Dali::Internal::Adaptor::CoreEventInterface
561 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
563 void ProcessCoreEvents() override;
565 private: // From Dali::Internal::Adaptor::CoreEventInterface
567 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
569 void QueueCoreEvent(const Dali::Integration::Event& event) override;
571 private: // From Dali::Integration::RenderController
573 * @copydoc Dali::Integration::RenderController::RequestUpdate()
575 void RequestUpdate() override;
578 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
580 void RequestProcessEventsOnIdle() override;
582 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
584 * Called when the window becomes fully or partially visible.
586 void OnWindowShown() override;
589 * Called when the window is fully hidden.
591 void OnWindowHidden() override;
593 private: // From Dali::Internal::Adaptor::DamageObserver
595 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
597 void OnDamaged(const DamageArea& area) override;
601 Adaptor(const Adaptor&) = delete;
602 Adaptor& operator=(Adaptor&) = delete;
606 * Assigns the render surface to the adaptor
609 void SetSurface(Dali::RenderSurfaceInterface* surface);
612 * called after surface is created
614 void SurfaceInitialized();
617 * Sends an notification message from main loop idle handler
619 bool ProcessCoreEventsFromIdle();
622 * Gets path for data/resource storage.
623 * @param[out] path Path for data/resource storage
625 void GetDataStoragePath(std::string& path);
628 * Sets up system information if needs
630 void SetupSystemInformation();
633 * Adds a callback to be run when entering an idle state.
635 * A callback of the following type should be used:
639 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
641 bool AddIdleEnterer(CallbackBase* callback, bool forceAdd);
644 * Removes a previously added the idle enterer callback.
646 void RemoveIdleEnterer(CallbackBase* callback);
649 * Trigger to log the memory pools from Core and Adaptor
651 bool MemoryPoolTimeout();
656 * @param[in] window window handle
657 * @param[in] adaptor The public adaptor
658 * @param[in] surface A render surface can be one of the following
659 * - Pixmap, adaptor will use existing Pixmap to draw on to
660 * - Window, adaptor will use existing Window to draw on to
661 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
662 * @param[in] threadMode The ThreadMode of the Adaptor
664 Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode);
669 READY, ///< Initial state before Adaptor::Start is called.
670 RUNNING, ///< Adaptor is running.
671 PAUSED, ///< Adaptor has been paused.
672 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
673 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
674 STOPPED, ///< Adaptor has been stopped.
677 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
678 // so we have to store the raw pointer.
679 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
680 using ObserverContainer = std::vector<LifeCycleObserver*>;
683 AdaptorSignalType mResizedSignal; ///< Resized signal.
684 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
685 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
687 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
688 State mState; ///< Current state of the adaptor
689 Dali::Integration::Core* mCore; ///< Dali Core
690 ThreadController* mThreadController; ///< Controls the threads
692 std::unique_ptr<GraphicsInterface> mGraphics; ///< Graphics interface
693 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
694 WindowContainer mWindows; ///< A container of all the Windows that are currently created
696 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
698 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
700 std::unique_ptr<CallbackManager> mCallbackManager; ///< Used to install callbacks
701 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
702 bool mRequiredIdleRepeat; ///< whether we need to repeat installed notification event in idle handler
703 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
704 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
705 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
706 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
707 ObserverContainer mObservers; ///< A list of adaptor observer pointers
708 EnvironmentOptions* mEnvironmentOptions; ///< environment options
709 PerformanceInterface* mPerformanceInterface; ///< Performance interface
710 KernelTrace mKernelTracer; ///< Kernel tracer
711 SystemTrace mSystemTracer; ///< System tracer
712 Devel::TextureUploadManager mTextureUploadManager; ///< TextureUploadManager
713 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
714 Dali::Timer mMemoryPoolTimer; ///< Logs memory pool capacity
715 SlotDelegate<Adaptor> mMemoryPoolTimerSlotDelegate;
716 SocketFactory mSocketFactory; ///< Socket factory
717 Mutex mMutex; ///< Mutex
718 ThreadMode mThreadMode; ///< The thread mode
719 const bool mEnvironmentOptionsOwned : 1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
720 bool mUseRemoteSurface : 1; ///< whether the remoteSurface is used or not
721 Dali::LayoutDirection::Type mRootLayoutDirection; ///< LayoutDirection of window
723 std::unique_ptr<Integration::AddOnManager> mAddOnManager; ///< Pointer to the addon manager
725 class AccessibilityObserver : public ConnectionTracker
728 void OnAccessibleKeyEvent(const Dali::KeyEvent& event);
730 AccessibilityObserver mAccessibilityObserver;
733 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor)
735 return *adaptor.mImpl;
739 } // namespace Adaptor
741 } // namespace Internal
745 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H