1 #ifndef DALI_INTERNAL_ADAPTOR_IMPL_H
2 #define DALI_INTERNAL_ADAPTOR_IMPL_H
5 * Copyright (c) 2022 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/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();
177 static std::string GetApplicationPackageName();
179 public: // AdaptorInternalServices implementation
181 * @copydoc Dali::Adaptor::Start()
183 virtual void Start();
186 * @copydoc Dali::Adaptor::Pause()
188 virtual void Pause();
191 * @copydoc Dali::Adaptor::Resume()
193 virtual void Resume();
196 * @copydoc Dali::Adaptor::Stop()
201 * @copydoc Dali::Adaptor::ContextLost()
203 virtual void ContextLost();
206 * @copydoc Dali::Adaptor::ContextRegained()
208 virtual void ContextRegained();
211 * @copydoc Dali::EventFeeder::FeedTouchPoint()
213 virtual void FeedTouchPoint(TouchPoint& point, int timeStamp);
216 * @copydoc Dali::EventFeeder::FeedWheelEvent()
218 virtual void FeedWheelEvent(Dali::WheelEvent& wheelEvent);
221 * @copydoc Dali::EventFeeder::FeedKeyEvent()
223 virtual void FeedKeyEvent(Dali::KeyEvent& keyEvent);
226 * @copydoc Dali::Adaptor::ReplaceSurface()
228 virtual void ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface);
231 * @copydoc Dali::Adaptor::GetSurface()
233 virtual Dali::RenderSurfaceInterface& GetSurface() const;
236 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
238 virtual void ReleaseSurfaceLock();
241 * Retrieve the TtsPlayer.
242 * @param[in] mode The mode of TtsPlayer
243 * @return A handle to the TtsPlayer.
245 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
248 * @copydoc Dali::Adaptor::AddIdle()
250 virtual bool AddIdle(CallbackBase* callback, bool hasReturnValue, bool forceAdd);
253 * Adds a new Window instance to the Adaptor
254 * @param[in] childWindow The child window instance
256 virtual bool AddWindow(Dali::Integration::SceneHolder childWindow);
259 * Removes an existing Window instance from the Adaptor
260 * @param[in] window The Window instance
262 virtual bool RemoveWindow(Dali::Integration::SceneHolder* childWindow);
265 * Removes an existing Window instance from the Adaptor
266 * @param[in] windowName The Window name
267 * @note If two Windows have the same name, the first one that matches will be removed
269 virtual bool RemoveWindow(std::string childWindowName);
272 * @copydoc Dali::Adaptor::RemoveIdle()
274 virtual void RemoveIdle(CallbackBase* callback);
277 * @copydoc Dali::Adaptor::ProcessIdle()
279 virtual void ProcessIdle();
282 * Sets a pre-render callback.
284 void SetPreRenderCallback(CallbackBase* callback);
287 * Removes an existing Window instance from the Adaptor
288 * @param[in] childWindow The Window instance
290 bool RemoveWindow(Dali::Internal::Adaptor::SceneHolder* childWindow);
293 * @brief Deletes the rendering surface
294 * @param[in] surface to delete
296 void DeleteSurface(Dali::RenderSurfaceInterface& surface);
299 * @brief Retrieve the window that the given actor is added to.
301 * @param[in] actor The actor
302 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
304 Dali::Internal::Adaptor::SceneHolder* GetWindow(Dali::Actor& actor);
307 * @copydoc Dali::Adaptor::GetWindows()
309 Dali::WindowContainer GetWindows() const;
312 * @copydoc Dali::Adaptor::GetSceneHolders()
314 Dali::SceneHolderList GetSceneHolders() const;
317 * @copydoc Dali::Adaptor::GetObjectRegistry()
319 Dali::ObjectRegistry GetObjectRegistry() const;
323 * @return the Core instance
325 Dali::Integration::Core& GetCore() override;
328 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
330 void SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender);
333 * Return the PlatformAbstraction.
334 * @return The PlatformAbstraction.
336 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
339 * Destroy the TtsPlayer of specific mode.
340 * @param[in] mode The mode of TtsPlayer to destroy
342 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
345 * Gets native window handle
347 * @return native window handle
349 Any GetNativeWindowHandle();
352 * @brief Retrieve native window handle that the given actor is added to.
354 * @param[in] actor The actor
355 * @return native window handle
357 Any GetNativeWindowHandle(Dali::Actor actor);
360 * Get the native display associated with the graphics backend
362 * @return A handle to the native display
364 Any GetGraphicsDisplay();
367 * Sets use remote surface for Surface output
368 * @param[in] useRemoteSurface True if the remote surface is used
370 void SetUseRemoteSurface(bool useRemoteSurface);
374 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
375 * @param[in] observer The observer.
376 * @note Observers should remove themselves when they are destroyed.
378 void AddObserver(LifeCycleObserver& observer);
381 * Removes the observer from the adaptor.
382 * @param[in] observer The observer to remove.
383 * @note Observers should remove themselves when they are destroyed.
385 void RemoveObserver(LifeCycleObserver& observer);
388 * Emits the Notification event to the Dali core.
390 void SendNotificationEvent();
393 * Request adaptor to update once
395 void RequestUpdateOnce();
398 * @copydoc Dali::Adaptor::NotifySceneCreated()
400 void NotifySceneCreated();
403 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
405 void NotifyLanguageChanged();
408 * Gets AppId of current application
410 void GetAppId(std::string& appId);
413 * Gets path for resource storage.
414 * @param[out] path Path for resource storage
416 void GetResourceStoragePath(std::string& path);
419 * @copydoc Dali::Adaptor::SurfaceResizePrepare
421 void SurfaceResizePrepare(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize);
424 * @copydoc Dali::Adaptor::SurfaceResizeComplete
426 void SurfaceResizeComplete(Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize);
429 * Sets layout direction of root by system language
430 * @param[in] locale System locale
432 void SetRootLayoutDirection(std::string locale);
435 * @copydoc Dali::Adaptor::RenderOnce
440 * @copydoc Dali::Adaptor::GetLogFactory
442 const LogFactoryInterface& GetLogFactory();
445 * @copydoc Dali::Adaptor::RegisterProcessor
447 void RegisterProcessor(Integration::Processor& processor, bool postProcessor);
450 * @coydoc Dali::Adaptor::UnregisterProcessor
452 void UnregisterProcessor(Integration::Processor& processor, bool postProcessor);
455 * Check MultipleWindow is supported
457 bool IsMultipleWindowSupported() const;
459 public: //AdaptorInternalServices
461 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
463 Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface() override;
466 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
468 Dali::DisplayConnection& GetDisplayConnectionInterface() override;
471 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
473 GraphicsInterface& GetGraphicsInterface() override;
476 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
478 TriggerEventInterface& GetProcessCoreEventsTrigger() override;
481 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
483 SocketFactoryInterface& GetSocketFactoryInterface() override;
486 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
488 Dali::RenderSurfaceInterface* GetRenderSurfaceInterface() override;
491 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
493 PerformanceInterface* GetPerformanceInterface() override;
496 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
498 TraceInterface& GetKernelTraceInterface() override;
501 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
503 TraceInterface& GetSystemTraceInterface() override;
506 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
508 void GetWindowContainerInterface(WindowContainer& windows) override;
512 * @copydoc Dali::Adaptor::SignalResized
514 AdaptorSignalType& ResizedSignal()
516 return mResizedSignal;
520 * @copydoc Dali::Adaptor::LanguageChangedSignal
522 AdaptorSignalType& LanguageChangedSignal()
524 return mLanguageChangedSignal;
528 * @copydoc Dali::Adaptor::WindowCreatedSignal
530 WindowCreatedSignalType& WindowCreatedSignal()
532 return mWindowCreatedSignal;
535 public: // From Dali::Internal::Adaptor::CoreEventInterface
537 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
539 void ProcessCoreEvents() override;
541 private: // From Dali::Internal::Adaptor::CoreEventInterface
543 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
545 void QueueCoreEvent(const Dali::Integration::Event& event) override;
547 private: // From Dali::Integration::RenderController
549 * @copydoc Dali::Integration::RenderController::RequestUpdate()
551 void RequestUpdate(bool forceUpdate) override;
554 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
556 void RequestProcessEventsOnIdle(bool forceProcess) override;
558 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
560 * Called when the window becomes fully or partially visible.
562 void OnWindowShown() override;
565 * Called when the window is fully hidden.
567 void OnWindowHidden() override;
569 private: // From Dali::Internal::Adaptor::DamageObserver
571 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
573 void OnDamaged(const DamageArea& area) override;
577 Adaptor(const Adaptor&) = delete;
578 Adaptor& operator=(Adaptor&) = delete;
582 * Assigns the render surface to the adaptor
585 void SetSurface(Dali::RenderSurfaceInterface* surface);
588 * called after surface is created
590 void SurfaceInitialized();
593 * Sends an notification message from main loop idle handler
595 bool ProcessCoreEventsFromIdle();
598 * Gets path for data/resource storage.
599 * @param[out] path Path for data/resource storage
601 void GetDataStoragePath(std::string& path);
604 * Sets up system information if needs
606 void SetupSystemInformation();
609 * Adds a callback to be run when entering an idle state.
611 * A callback of the following type should be used:
615 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
617 bool AddIdleEnterer(CallbackBase* callback, bool forceAdd);
620 * Removes a previously added the idle enterer callback.
622 void RemoveIdleEnterer(CallbackBase* callback);
625 * Trigger to log the memory pools from Core and Adaptor
627 bool MemoryPoolTimeout();
632 * @param[in] window window handle
633 * @param[in] adaptor The public adaptor
634 * @param[in] surface A render surface can be one of the following
635 * - Pixmap, adaptor will use existing Pixmap to draw on to
636 * - Window, adaptor will use existing Window to draw on to
637 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
638 * @param[in] threadMode The ThreadMode of the Adaptor
640 Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode);
645 READY, ///< Initial state before Adaptor::Start is called.
646 RUNNING, ///< Adaptor is running.
647 PAUSED, ///< Adaptor has been paused.
648 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
649 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
650 STOPPED, ///< Adaptor has been stopped.
653 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
654 // so we have to store the raw pointer.
655 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
656 using ObserverContainer = std::vector<LifeCycleObserver*>;
659 AdaptorSignalType mResizedSignal; ///< Resized signal.
660 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
661 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
663 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
664 State mState; ///< Current state of the adaptor
665 Dali::Integration::Core* mCore; ///< Dali Core
666 ThreadController* mThreadController; ///< Controls the threads
668 std::unique_ptr<GraphicsInterface> mGraphics; ///< Graphics interface
669 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
670 WindowContainer mWindows; ///< A container of all the Windows that are currently created
672 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
674 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
676 CallbackManager* mCallbackManager; ///< Used to install callbacks
677 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
678 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
679 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
680 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
681 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
682 ObserverContainer mObservers; ///< A list of adaptor observer pointers
683 EnvironmentOptions* mEnvironmentOptions; ///< environment options
684 PerformanceInterface* mPerformanceInterface; ///< Performance interface
685 KernelTrace mKernelTracer; ///< Kernel tracer
686 SystemTrace mSystemTracer; ///< System tracer
687 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
688 Dali::Timer mMemoryPoolTimer; ///< Logs memory pool capacity
689 SlotDelegate<Adaptor> mMemoryPoolTimerSlotDelegate;
690 SocketFactory mSocketFactory; ///< Socket factory
691 Mutex mMutex; ///< Mutex
692 ThreadMode mThreadMode; ///< The thread mode
693 const bool mEnvironmentOptionsOwned : 1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
694 bool mUseRemoteSurface : 1; ///< whether the remoteSurface is used or not
695 Dali::LayoutDirection::Type mRootLayoutDirection; ///< LayoutDirection of window
697 std::unique_ptr<Integration::AddOnManager> mAddOnManager; ///< Pointer to the addon manager
699 class AccessibilityObserver : public ConnectionTracker
702 void OnAccessibleKeyEvent(const Dali::KeyEvent& event);
704 AccessibilityObserver mAccessibilityObserver;
707 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor)
709 return *adaptor.mImpl;
713 } // namespace Adaptor
715 } // namespace Internal
719 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H