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;
53 namespace Accessibility
64 } // namespace Integration
70 class DisplayConnection;
71 class GraphicsFactory;
72 class GlImplementation;
73 class GlSyncImplementation;
74 class ThreadController;
76 class CallbackManager;
77 class FeedbackPluginProxy;
78 class FeedbackController;
80 class PerformanceInterface;
81 class LifeCycleObserver;
84 class ConfigurationManager;
85 enum class ThreadMode;
88 * Implementation of the Adaptor class.
90 class Adaptor : public Integration::RenderController,
91 public AdaptorInternalServices,
92 public CoreEventInterface,
93 public DamageObserver,
94 public WindowVisibilityObserver
97 using AdaptorSignalType = Dali::Adaptor::AdaptorSignalType;
98 using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType;
100 using SurfaceSize = Uint16Pair; ///< Surface size type
103 * Creates a New Adaptor
104 * @param[in] window The window handle
105 * @param[in] surface A render surface can be one of the following
106 * - Pixmap, adaptor will use existing Pixmap to draw on to
107 * - Window, adaptor will use existing Window to draw on to
108 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
109 * @param[in] threadMode The thread mode
111 static Dali::Adaptor* New(Dali::Integration::SceneHolder window,
112 Dali::RenderSurfaceInterface* surface,
113 EnvironmentOptions* environmentOptions,
114 ThreadMode threadMode);
117 * Creates a New Adaptor
118 * @param[in] window The window handle
119 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
121 static Dali::Adaptor* New(Dali::Integration::SceneHolder window,
122 EnvironmentOptions* environmentOptions);
125 * Creates a New Adaptor
126 * @param[in] graphicsFactory A factory that creates the graphics interface
127 * @param[in] window The window handle
128 * @param[in] surface A render surface can be one of the following
129 * - Pixmap, adaptor will use existing Pixmap to draw on to
130 * - Window, adaptor will use existing Window to draw on to
131 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
132 * @param[in] threadMode The thread mode
134 static Dali::Adaptor* New(GraphicsFactory& graphicsFactory,
135 Dali::Integration::SceneHolder window,
136 Dali::RenderSurfaceInterface* surface,
137 EnvironmentOptions* environmentOptions,
138 ThreadMode threadMode);
141 * Creates a New Adaptor
142 * @param[in] graphicsFactory A factory that creates the graphics interface
143 * @param[in] window The window handle
144 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
146 static Dali::Adaptor* New(GraphicsFactory& graphicsFactory,
147 Dali::Integration::SceneHolder window,
148 EnvironmentOptions* environmentOptions);
151 * 2-step initialisation, this should be called after creating an adaptor instance.
152 * @param[in] graphicsFactory A factory that creates the graphics interface
154 void Initialize(GraphicsFactory& graphicsFactory);
157 * Virtual destructor.
162 * @copydoc Dali::Adaptor::Get()
164 static Dali::Adaptor& Get();
167 * @copydoc Dali::Adaptor::IsAvailable()
169 static bool IsAvailable();
172 * @copydoc Dali::Core::SceneCreated();
177 * Get the application package name
179 static std::string GetApplicationPackageName();
181 public: // AdaptorInternalServices implementation
183 * @copydoc Dali::Adaptor::Start()
185 virtual void Start();
188 * @copydoc Dali::Adaptor::Pause()
190 virtual void Pause();
193 * @copydoc Dali::Adaptor::Resume()
195 virtual void Resume();
198 * @copydoc Dali::Adaptor::Stop()
203 * @copydoc Dali::Adaptor::ContextLost()
205 virtual void ContextLost();
208 * @copydoc Dali::Adaptor::ContextRegained()
210 virtual void ContextRegained();
213 * @copydoc Dali::EventFeeder::FeedTouchPoint()
215 virtual void FeedTouchPoint(TouchPoint& point, int timeStamp);
218 * @copydoc Dali::EventFeeder::FeedWheelEvent()
220 virtual void FeedWheelEvent(Dali::WheelEvent& wheelEvent);
223 * @copydoc Dali::EventFeeder::FeedKeyEvent()
225 virtual void FeedKeyEvent(Dali::KeyEvent& keyEvent);
228 * @copydoc Dali::Adaptor::ReplaceSurface()
230 virtual void ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface);
233 * @copydoc Dali::Adaptor::GetSurface()
235 virtual Dali::RenderSurfaceInterface& GetSurface() const;
238 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
240 virtual void ReleaseSurfaceLock();
243 * Retrieve the TtsPlayer.
244 * @param[in] mode The mode of TtsPlayer
245 * @return A handle to the TtsPlayer.
247 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
250 * @copydoc Dali::Adaptor::AddIdle()
252 virtual bool AddIdle(CallbackBase* callback, bool hasReturnValue, bool forceAdd);
255 * Adds a new Window instance to the Adaptor
256 * @param[in] childWindow The child window instance
258 virtual bool AddWindow(Dali::Integration::SceneHolder childWindow);
261 * Removes an existing Window instance from the Adaptor
262 * @param[in] window The Window instance
264 virtual bool RemoveWindow(Dali::Integration::SceneHolder* childWindow);
267 * Removes an existing Window instance from the Adaptor
268 * @param[in] windowName The Window name
269 * @note If two Windows have the same name, the first one that matches will be removed
271 virtual bool RemoveWindow(std::string childWindowName);
274 * @copydoc Dali::Adaptor::RemoveIdle()
276 virtual void RemoveIdle(CallbackBase* callback);
279 * @copydoc Dali::Adaptor::ProcessIdle()
281 virtual void ProcessIdle();
284 * Sets a pre-render callback.
286 void SetPreRenderCallback(CallbackBase* callback);
289 * Removes an existing Window instance from the Adaptor
290 * @param[in] childWindow The Window instance
292 bool RemoveWindow(Dali::Internal::Adaptor::SceneHolder* childWindow);
295 * @brief Deletes the rendering surface
296 * @param[in] surface to delete
298 void DeleteSurface(Dali::RenderSurfaceInterface& surface);
301 * @brief Retrieve the window that the given actor is added to.
303 * @param[in] actor The actor
304 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
306 Dali::Internal::Adaptor::SceneHolder* GetWindow(Dali::Actor& actor);
309 * @copydoc Dali::Adaptor::GetWindows()
311 Dali::WindowContainer GetWindows() const;
314 * @copydoc Dali::Adaptor::GetSceneHolders()
316 Dali::SceneHolderList GetSceneHolders() const;
319 * @copydoc Dali::Adaptor::GetObjectRegistry()
321 Dali::ObjectRegistry GetObjectRegistry() const;
325 * @return the Core instance
327 Dali::Integration::Core& GetCore() override;
330 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
332 void SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender);
335 * Return the PlatformAbstraction.
336 * @return The PlatformAbstraction.
338 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
341 * Destroy the TtsPlayer of specific mode.
342 * @param[in] mode The mode of TtsPlayer to destroy
344 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
347 * Gets native window handle
349 * @return native window handle
351 Any GetNativeWindowHandle();
354 * @brief Retrieve native window handle that the given actor is added to.
356 * @param[in] actor The actor
357 * @return native window handle
359 Any GetNativeWindowHandle(Dali::Actor actor);
362 * Get the native display associated with the graphics backend
364 * @return A handle to the native display
366 Any GetGraphicsDisplay();
369 * Sets use remote surface for Surface output
370 * @param[in] useRemoteSurface True if the remote surface is used
372 void SetUseRemoteSurface(bool useRemoteSurface);
376 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
377 * @param[in] observer The observer.
378 * @note Observers should remove themselves when they are destroyed.
380 void AddObserver(LifeCycleObserver& observer);
383 * Removes the observer from the adaptor.
384 * @param[in] observer The observer to remove.
385 * @note Observers should remove themselves when they are destroyed.
387 void RemoveObserver(LifeCycleObserver& observer);
390 * Emits the Notification event to the Dali core.
392 void SendNotificationEvent();
395 * Request adaptor to update once
397 void RequestUpdateOnce();
400 * @copydoc Dali::Adaptor::NotifySceneCreated()
402 void NotifySceneCreated();
405 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
407 void NotifyLanguageChanged();
410 * Gets AppId of current application
412 void GetAppId(std::string& appId);
415 * Gets path for resource storage.
416 * @param[out] path Path for resource storage
418 void GetResourceStoragePath(std::string& path);
421 * @copydoc Dali::Adaptor::SurfaceResizePrepare
423 void SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize);
426 * @copydoc Dali::Adaptor::SurfaceResizeComplete
428 void SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize);
431 * Sets layout direction of root by system language
432 * @param[in] locale System locale
434 void SetRootLayoutDirection(std::string locale);
437 * @copydoc Dali::Adaptor::RenderOnce
442 * @copydoc Dali::Adaptor::GetLogFactory
444 const LogFactoryInterface& GetLogFactory();
447 * @copydoc Dali::Adaptor::RegisterProcessor
449 void RegisterProcessor(Integration::Processor& processor, bool postProcessor);
452 * @coydoc Dali::Adaptor::UnregisterProcessor
454 void UnregisterProcessor(Integration::Processor& processor, bool postProcessor);
457 * Check MultipleWindow is supported
459 bool IsMultipleWindowSupported() const;
462 * @brief Gets the render thread id of DALi.
463 * @note If render thread id getter doesn't supported, it will return 0 as default.
464 * @return The render thread id.
466 int32_t GetRenderThreadId() const;
468 public: //AdaptorInternalServices
470 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
472 Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface() override;
475 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
477 Dali::DisplayConnection& GetDisplayConnectionInterface() override;
480 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
482 GraphicsInterface& GetGraphicsInterface() override;
485 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
487 TriggerEventInterface& GetProcessCoreEventsTrigger() override;
490 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
492 SocketFactoryInterface& GetSocketFactoryInterface() override;
495 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
497 Dali::RenderSurfaceInterface* GetRenderSurfaceInterface() override;
500 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
502 PerformanceInterface* GetPerformanceInterface() override;
505 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
507 TraceInterface& GetKernelTraceInterface() override;
510 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
512 TraceInterface& GetSystemTraceInterface() override;
515 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
517 void GetWindowContainerInterface(WindowContainer& windows) override;
520 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTextureUploadManager()
522 Devel::TextureUploadManager& GetTextureUploadManager() override;
525 * @brief Get the configuration manager
526 * @return The configuration manager, or null if it hasn't been created yet
528 const ConfigurationManager* GetConfigurationManager() const
530 return mConfigurationManager.get();
535 * @copydoc Dali::Adaptor::SignalResized
537 AdaptorSignalType& ResizedSignal()
539 return mResizedSignal;
543 * @copydoc Dali::Adaptor::LanguageChangedSignal
545 AdaptorSignalType& LanguageChangedSignal()
547 return mLanguageChangedSignal;
551 * @copydoc Dali::Adaptor::WindowCreatedSignal
553 WindowCreatedSignalType& WindowCreatedSignal()
555 return mWindowCreatedSignal;
558 public: // From Dali::Internal::Adaptor::CoreEventInterface
560 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
562 void ProcessCoreEvents() override;
564 private: // From Dali::Internal::Adaptor::CoreEventInterface
566 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
568 void QueueCoreEvent(const Dali::Integration::Event& event) override;
570 private: // From Dali::Integration::RenderController
572 * @copydoc Dali::Integration::RenderController::RequestUpdate()
574 void RequestUpdate() override;
577 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
579 void RequestProcessEventsOnIdle() override;
581 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
583 * Called when the window becomes fully or partially visible.
585 void OnWindowShown() override;
588 * Called when the window is fully hidden.
590 void OnWindowHidden() override;
592 private: // From Dali::Internal::Adaptor::DamageObserver
594 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
596 void OnDamaged(const DamageArea& area) override;
600 Adaptor(const Adaptor&) = delete;
601 Adaptor& operator=(Adaptor&) = delete;
605 * Assigns the render surface to the adaptor
608 void SetSurface(Dali::RenderSurfaceInterface* surface);
611 * called after surface is created
613 void SurfaceInitialized();
616 * Sends an notification message from main loop idle handler
618 bool ProcessCoreEventsFromIdle();
621 * Gets path for data/resource storage.
622 * @param[out] path Path for data/resource storage
624 void GetDataStoragePath(std::string& path);
627 * Sets up system information if needs
629 void SetupSystemInformation();
632 * Adds a callback to be run when entering an idle state.
634 * A callback of the following type should be used:
638 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
640 bool AddIdleEnterer(CallbackBase* callback, bool forceAdd);
643 * Removes a previously added the idle enterer callback.
645 void RemoveIdleEnterer(CallbackBase* callback);
648 * Trigger to log the memory pools from Core and Adaptor
650 bool MemoryPoolTimeout();
655 * @param[in] window window handle
656 * @param[in] adaptor The public adaptor
657 * @param[in] surface A render surface can be one of the following
658 * - Pixmap, adaptor will use existing Pixmap to draw on to
659 * - Window, adaptor will use existing Window to draw on to
660 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
661 * @param[in] threadMode The ThreadMode of the Adaptor
663 Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode);
668 READY, ///< Initial state before Adaptor::Start is called.
669 RUNNING, ///< Adaptor is running.
670 PAUSED, ///< Adaptor has been paused.
671 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
672 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
673 STOPPED, ///< Adaptor has been stopped.
676 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
677 // so we have to store the raw pointer.
678 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
679 using ObserverContainer = std::vector<LifeCycleObserver*>;
682 AdaptorSignalType mResizedSignal; ///< Resized signal.
683 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
684 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
686 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
687 State mState; ///< Current state of the adaptor
688 Dali::Integration::Core* mCore; ///< Dali Core
689 ThreadController* mThreadController; ///< Controls the threads
691 std::unique_ptr<GraphicsInterface> mGraphics; ///< Graphics interface
692 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
693 WindowContainer mWindows; ///< A container of all the Windows that are currently created
695 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
697 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
699 std::unique_ptr<CallbackManager> mCallbackManager; ///< Used to install callbacks
700 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
701 bool mRequiredIdleRepeat; ///< whether we need to repeat installed notification event in idle handler
702 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
703 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
704 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
705 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
706 ObserverContainer mObservers; ///< A list of adaptor observer pointers
707 EnvironmentOptions* mEnvironmentOptions; ///< environment options
708 PerformanceInterface* mPerformanceInterface; ///< Performance interface
709 KernelTrace mKernelTracer; ///< Kernel tracer
710 SystemTrace mSystemTracer; ///< System tracer
711 Devel::TextureUploadManager mTextureUploadManager; ///< TextureUploadManager
712 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
713 Dali::Timer mMemoryPoolTimer; ///< Logs memory pool capacity
714 SlotDelegate<Adaptor> mMemoryPoolTimerSlotDelegate;
715 SocketFactory mSocketFactory; ///< Socket factory
716 Mutex mMutex; ///< Mutex
717 ThreadMode mThreadMode; ///< The thread mode
718 const bool mEnvironmentOptionsOwned : 1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
719 bool mUseRemoteSurface : 1; ///< whether the remoteSurface is used or not
720 Dali::LayoutDirection::Type mRootLayoutDirection; ///< LayoutDirection of window
722 std::unique_ptr<Integration::AddOnManager> mAddOnManager; ///< Pointer to the addon manager
724 class AccessibilityObserver : public ConnectionTracker
727 void OnAccessibleKeyEvent(const Dali::KeyEvent& event);
729 AccessibilityObserver mAccessibilityObserver;
732 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor)
734 return *adaptor.mImpl;
738 } // namespace Adaptor
740 } // namespace Internal
744 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H