1 #ifndef DALI_INTERNAL_ADAPTOR_IMPL_H
2 #define DALI_INTERNAL_ADAPTOR_IMPL_H
5 * Copyright (c) 2021 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/integration-api/render-controller.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/math/uint-16-pair.h>
26 #include <dali/public-api/signals/callback.h>
29 #include <dali/devel-api/adaptor-framework/clipboard.h>
30 #include <dali/integration-api/adaptor-framework/adaptor.h>
31 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
32 #include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
33 #include <dali/integration-api/scene.h>
34 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
35 #include <dali/internal/graphics/common/graphics-interface.h>
36 #include <dali/internal/legacy/common/tizen-platform-abstraction.h>
37 #include <dali/internal/network/common/socket-factory.h>
38 #include <dali/internal/system/common/core-event-interface.h>
39 #include <dali/internal/system/common/environment-options.h>
40 #include <dali/internal/system/common/kernel-trace.h>
41 #include <dali/internal/system/common/system-trace.h>
42 #include <dali/internal/window-system/common/damage-observer.h>
43 #include <dali/internal/window-system/common/window-visibility-observer.h>
44 #include <dali/public-api/adaptor-framework/tts-player.h>
50 class RenderSurfaceInterface;
52 namespace Accessibility
63 } // namespace Integration
69 class DisplayConnection;
70 class GraphicsFactory;
71 class GlImplementation;
72 class GlSyncImplementation;
73 class ThreadController;
75 class CallbackManager;
76 class FeedbackPluginProxy;
77 class FeedbackController;
79 class PerformanceInterface;
80 class LifeCycleObserver;
83 class ConfigurationManager;
84 enum class ThreadMode;
87 * Implementation of the Adaptor class.
89 class Adaptor : public Integration::RenderController,
90 public AdaptorInternalServices,
91 public CoreEventInterface,
92 public DamageObserver,
93 public WindowVisibilityObserver
96 using AdaptorSignalType = Dali::Adaptor::AdaptorSignalType;
97 using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType;
99 using SurfaceSize = Uint16Pair; ///< Surface size type
102 * Creates a New Adaptor
103 * @param[in] window The window handle
104 * @param[in] surface A render surface can be one of the following
105 * - Pixmap, adaptor will use existing Pixmap to draw on to
106 * - Window, adaptor will use existing Window to draw on to
107 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
108 * @param[in] threadMode The thread mode
110 static Dali::Adaptor* New(Dali::Integration::SceneHolder window,
111 Dali::RenderSurfaceInterface* surface,
112 EnvironmentOptions* environmentOptions,
113 ThreadMode threadMode);
116 * Creates a New Adaptor
117 * @param[in] window The window handle
118 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
120 static Dali::Adaptor* New(Dali::Integration::SceneHolder window,
121 EnvironmentOptions* environmentOptions);
124 * Creates a New Adaptor
125 * @param[in] graphicsFactory A factory that creates the graphics interface
126 * @param[in] window The window handle
127 * @param[in] surface A render surface can be one of the following
128 * - Pixmap, adaptor will use existing Pixmap to draw on to
129 * - Window, adaptor will use existing Window to draw on to
130 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
131 * @param[in] threadMode The thread mode
133 static Dali::Adaptor* New(GraphicsFactory& graphicsFactory,
134 Dali::Integration::SceneHolder window,
135 Dali::RenderSurfaceInterface* surface,
136 EnvironmentOptions* environmentOptions,
137 ThreadMode threadMode);
140 * Creates a New Adaptor
141 * @param[in] graphicsFactory A factory that creates the graphics interface
142 * @param[in] window The window handle
143 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
145 static Dali::Adaptor* New(GraphicsFactory& graphicsFactory,
146 Dali::Integration::SceneHolder window,
147 EnvironmentOptions* environmentOptions);
150 * 2-step initialisation, this should be called after creating an adaptor instance.
151 * @param[in] graphicsFactory A factory that creates the graphics interface
153 void Initialize(GraphicsFactory& graphicsFactory);
156 * Virtual destructor.
161 * @copydoc Dali::Adaptor::Get()
163 static Dali::Adaptor& Get();
166 * @copydoc Dali::Adaptor::IsAvailable()
168 static bool IsAvailable();
171 * @copydoc Dali::Core::SceneCreated();
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, bool forceAdd);
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 * Sets layout direction of root by system language
428 * @param[in] locale System locale
430 void SetRootLayoutDirection(std::string locale);
433 * @copydoc Dali::Adaptor::RenderOnce
438 * @copydoc Dali::Adaptor::GetLogFactory
440 const LogFactoryInterface& GetLogFactory();
443 * @copydoc Dali::Adaptor::RegisterProcessor
445 void RegisterProcessor(Integration::Processor& processor, bool postProcessor);
448 * @coydoc Dali::Adaptor::UnregisterProcessor
450 void UnregisterProcessor(Integration::Processor& processor, bool postProcessor);
453 * Check MultipleWindow is supported
455 bool IsMultipleWindowSupported() const;
457 public: //AdaptorInternalServices
459 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
461 Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface() override;
464 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
466 Dali::DisplayConnection& GetDisplayConnectionInterface() override;
469 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
471 GraphicsInterface& GetGraphicsInterface() override;
474 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
476 TriggerEventInterface& GetProcessCoreEventsTrigger() override;
479 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
481 SocketFactoryInterface& GetSocketFactoryInterface() override;
484 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
486 Dali::RenderSurfaceInterface* GetRenderSurfaceInterface() override;
489 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
491 PerformanceInterface* GetPerformanceInterface() override;
494 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
496 TraceInterface& GetKernelTraceInterface() override;
499 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
501 TraceInterface& GetSystemTraceInterface() override;
504 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
506 void GetWindowContainerInterface(WindowContainer& windows) override;
510 * @copydoc Dali::Adaptor::SignalResized
512 AdaptorSignalType& ResizedSignal()
514 return mResizedSignal;
518 * @copydoc Dali::Adaptor::LanguageChangedSignal
520 AdaptorSignalType& LanguageChangedSignal()
522 return mLanguageChangedSignal;
526 * @copydoc Dali::Adaptor::WindowCreatedSignal
528 WindowCreatedSignalType& WindowCreatedSignal()
530 return mWindowCreatedSignal;
533 public: // From Dali::Internal::Adaptor::CoreEventInterface
535 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
537 void ProcessCoreEvents() override;
539 private: // From Dali::Internal::Adaptor::CoreEventInterface
541 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
543 void QueueCoreEvent(const Dali::Integration::Event& event) override;
545 private: // From Dali::Integration::RenderController
547 * @copydoc Dali::Integration::RenderController::RequestUpdate()
549 void RequestUpdate(bool forceUpdate) override;
552 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
554 void RequestProcessEventsOnIdle(bool forceProcess) override;
556 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
558 * Called when the window becomes fully or partially visible.
560 void OnWindowShown() override;
563 * Called when the window is fully hidden.
565 void OnWindowHidden() override;
567 private: // From Dali::Internal::Adaptor::DamageObserver
569 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
571 void OnDamaged(const DamageArea& area) override;
575 Adaptor(const Adaptor&) = delete;
576 Adaptor& operator=(Adaptor&) = delete;
580 * Assigns the render surface to the adaptor
583 void SetSurface(Dali::RenderSurfaceInterface* surface);
586 * called after surface is created
588 void SurfaceInitialized();
591 * Sends an notification message from main loop idle handler
593 bool ProcessCoreEventsFromIdle();
596 * Gets path for data/resource storage.
597 * @param[out] path Path for data/resource storage
599 void GetDataStoragePath(std::string& path);
602 * Sets up system information if needs
604 void SetupSystemInformation();
607 * Adds a callback to be run when entering an idle state.
609 * A callback of the following type should be used:
613 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
615 bool AddIdleEnterer(CallbackBase* callback, bool forceAdd);
618 * Removes a previously added the idle enterer callback.
620 void RemoveIdleEnterer(CallbackBase* callback);
625 * @param[in] window window handle
626 * @param[in] adaptor The public adaptor
627 * @param[in] surface A render surface can be one of the following
628 * - Pixmap, adaptor will use existing Pixmap to draw on to
629 * - Window, adaptor will use existing Window to draw on to
630 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
631 * @param[in] threadMode The ThreadMode of the Adaptor
633 Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode);
638 READY, ///< Initial state before Adaptor::Start is called.
639 RUNNING, ///< Adaptor is running.
640 PAUSED, ///< Adaptor has been paused.
641 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
642 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
643 STOPPED, ///< Adaptor has been stopped.
646 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
647 // so we have to store the raw pointer.
648 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
649 using ObserverContainer = std::vector<LifeCycleObserver*>;
652 AdaptorSignalType mResizedSignal; ///< Resized signal.
653 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
654 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
656 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
657 State mState; ///< Current state of the adaptor
658 Dali::Integration::Core* mCore; ///< Dali Core
659 ThreadController* mThreadController; ///< Controls the threads
661 std::unique_ptr<GraphicsInterface> mGraphics; ///< Graphics interface
662 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
663 WindowContainer mWindows; ///< A container of all the Windows that are currently created
665 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
667 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
669 CallbackManager* mCallbackManager; ///< Used to install callbacks
670 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
671 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
672 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
673 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
674 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
675 ObserverContainer mObservers; ///< A list of adaptor observer pointers
676 EnvironmentOptions* mEnvironmentOptions; ///< environment options
677 PerformanceInterface* mPerformanceInterface; ///< Performance interface
678 KernelTrace mKernelTracer; ///< Kernel tracer
679 SystemTrace mSystemTracer; ///< System tracer
680 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
681 SocketFactory mSocketFactory; ///< Socket factory
682 ThreadMode mThreadMode; ///< The thread mode
683 const bool mEnvironmentOptionsOwned : 1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
684 bool mUseRemoteSurface : 1; ///< whether the remoteSurface is used or not
685 Dali::LayoutDirection::Type mRootLayoutDirection; ///< LayoutDirection of window
687 std::unique_ptr<Integration::AddOnManager> mAddOnManager; ///< Pointer to the addon manager
689 class AccessibilityObserver : public ConnectionTracker
692 void OnAccessibleKeyEvent(const Dali::KeyEvent& event);
694 AccessibilityObserver accessibilityObserver;
697 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor)
699 return *adaptor.mImpl;
703 } // namespace Adaptor
705 } // namespace Internal
709 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H