1 #ifndef DALI_INTERNAL_ADAPTOR_IMPL_H
2 #define DALI_INTERNAL_ADAPTOR_IMPL_H
5 * Copyright (c) 2020 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/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/signals/callback.h>
25 #include <dali/public-api/math/uint-16-pair.h>
26 #include <dali/integration-api/render-controller.h>
29 #include <dali/public-api/adaptor-framework/tts-player.h>
30 #include <dali/devel-api/adaptor-framework/clipboard.h>
31 #include <dali/integration-api/scene.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/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>
51 class RenderSurfaceInterface;
53 namespace Accessibility
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
99 using AdaptorSignalType = Dali::Adaptor::AdaptorSignalType;
100 using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType;
102 using SurfaceSize = Uint16Pair; ///< Surface size type
105 * Creates a New Adaptor
106 * @param[in] window The window handle
107 * @param[in] surface A render surface can be one of the following
108 * - Pixmap, adaptor will use existing Pixmap to draw on to
109 * - Window, adaptor will use existing Window to draw on to
110 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
111 * @param[in] threadMode The thread mode
113 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
114 Dali::RenderSurfaceInterface* surface,
115 EnvironmentOptions* environmentOptions,
116 ThreadMode threadMode );
119 * Creates a New Adaptor
120 * @param[in] window The window handle
121 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
123 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
124 EnvironmentOptions* environmentOptions );
127 * Creates a New Adaptor
128 * @param[in] graphicsFactory A factory that creates the graphics interface
129 * @param[in] window The window handle
130 * @param[in] surface A render surface can be one of the following
131 * - Pixmap, adaptor will use existing Pixmap to draw on to
132 * - Window, adaptor will use existing Window to draw on to
133 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
134 * @param[in] threadMode The thread mode
136 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
137 Dali::Integration::SceneHolder window,
138 Dali::RenderSurfaceInterface* surface,
139 EnvironmentOptions* environmentOptions,
140 ThreadMode threadMode );
143 * Creates a New Adaptor
144 * @param[in] graphicsFactory A factory that creates the graphics interface
145 * @param[in] window The window handle
146 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
148 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
149 Dali::Integration::SceneHolder window,
150 EnvironmentOptions* environmentOptions );
153 * 2-step initialisation, this should be called after creating an adaptor instance.
154 * @param[in] graphicsFactory A factory that creates the graphics interface
156 void Initialize( GraphicsFactory& graphicsFactory );
159 * Virtual destructor.
164 * @copydoc Dali::Adaptor::Get()
166 static Dali::Adaptor& Get();
169 * @copydoc Dali::Adaptor::IsAvailable()
171 static bool IsAvailable();
174 * @copydoc Dali::Core::SceneCreated();
178 static std::string GetApplicationPackageName();
180 public: // AdaptorInternalServices implementation
182 * @copydoc Dali::Adaptor::Start()
184 virtual void Start();
187 * @copydoc Dali::Adaptor::Pause()
189 virtual void Pause();
192 * @copydoc Dali::Adaptor::Resume()
194 virtual void Resume();
197 * @copydoc Dali::Adaptor::Stop()
202 * @copydoc Dali::Adaptor::ContextLost()
204 virtual void ContextLost();
207 * @copydoc Dali::Adaptor::ContextRegained()
209 virtual void ContextRegained();
212 * @copydoc Dali::EventFeeder::FeedTouchPoint()
214 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
217 * @copydoc Dali::EventFeeder::FeedWheelEvent()
219 virtual void FeedWheelEvent( Dali::WheelEvent& wheelEvent );
222 * @copydoc Dali::EventFeeder::FeedKeyEvent()
224 virtual void FeedKeyEvent( Dali::KeyEvent& keyEvent );
227 * @copydoc Dali::Adaptor::ReplaceSurface()
229 virtual void ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface );
232 * @copydoc Dali::Adaptor::GetSurface()
234 virtual Dali::RenderSurfaceInterface& GetSurface() const;
237 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
239 virtual void ReleaseSurfaceLock();
242 * Retrieve the TtsPlayer.
243 * @param[in] mode The mode of TtsPlayer
244 * @return A handle to the TtsPlayer.
246 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
249 * @copydoc Dali::Adaptor::AddIdle()
251 virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
254 * Adds a new Window instance to the Adaptor
255 * @param[in] childWindow The child window instance
257 virtual bool AddWindow( Dali::Integration::SceneHolder childWindow );
260 * Removes an existing Window instance from the Adaptor
261 * @param[in] window The Window instance
263 virtual bool RemoveWindow( Dali::Integration::SceneHolder* childWindow );
266 * Removes an existing Window instance from the Adaptor
267 * @param[in] windowName The Window name
268 * @note If two Windows have the same name, the first one that matches will be removed
270 virtual bool RemoveWindow( std::string childWindowName );
273 * @copydoc Dali::Adaptor::RemoveIdle()
275 virtual void RemoveIdle( CallbackBase* callback );
278 * @copydoc Dali::Adaptor::ProcessIdle()
280 virtual void ProcessIdle();
283 * Sets a pre-render callback.
285 void SetPreRenderCallback( CallbackBase* callback );
288 * Removes an existing Window instance from the Adaptor
289 * @param[in] childWindow The Window instance
291 bool RemoveWindow( Dali::Internal::Adaptor::SceneHolder* childWindow );
294 * @brief Deletes the rendering surface
295 * @param[in] surface to delete
297 void DeleteSurface( Dali::RenderSurfaceInterface& surface );
300 * @brief Retrieve the window that the given actor is added to.
302 * @param[in] actor The actor
303 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
305 Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
308 * @copydoc Dali::Adaptor::GetWindows()
310 Dali::WindowContainer GetWindows() const;
313 * @copydoc Dali::Adaptor::GetSceneHolders()
315 Dali::SceneHolderList GetSceneHolders() const;
318 * @copydoc Dali::Adaptor::GetObjectRegistry()
320 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);
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 * @copydoc Dali::Adaptor::SurfaceResizePrepare
418 void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
421 * @copydoc Dali::Adaptor::SurfaceResizeComplete
423 void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
426 * Sets layout direction of root by system language
427 * @param[in] locale System locale
429 void SetRootLayoutDirection( std::string locale );
432 * @copydoc Dali::Adaptor::RenderOnce
437 * @copydoc Dali::Adaptor::GetLogFactory
439 const LogFactoryInterface& GetLogFactory();
442 * @copydoc Dali::Adaptor::RegisterProcessor
444 void RegisterProcessor( Integration::Processor& processor );
447 * @coydoc Dali::Adaptor::UnregisterProcessor
449 void UnregisterProcessor( Integration::Processor& processor );
452 * Check MultipleWindow is supported
454 bool IsMultipleWindowSupported() const;
456 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;
511 * @copydoc Dali::Adaptor::SignalResized
513 AdaptorSignalType& ResizedSignal()
515 return mResizedSignal;
519 * @copydoc Dali::Adaptor::LanguageChangedSignal
521 AdaptorSignalType& LanguageChangedSignal()
523 return mLanguageChangedSignal;
527 * @copydoc Dali::Adaptor::WindowCreatedSignal
529 WindowCreatedSignalType& WindowCreatedSignal()
531 return mWindowCreatedSignal;
534 public: // From Dali::Internal::Adaptor::CoreEventInterface
537 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
539 void ProcessCoreEvents() override;
541 private: // From Dali::Internal::Adaptor::CoreEventInterface
544 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
546 void QueueCoreEvent(const Dali::Integration::Event& event) override;
548 private: // From Dali::Integration::RenderController
551 * @copydoc Dali::Integration::RenderController::RequestUpdate()
553 void RequestUpdate( bool forceUpdate ) override;
556 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
558 void RequestProcessEventsOnIdle( bool forceProcess ) override;
560 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
563 * Called when the window becomes fully or partially visible.
565 void OnWindowShown() override;
568 * Called when the window is fully hidden.
570 void OnWindowHidden() override;
572 private: // From Dali::Internal::Adaptor::DamageObserver
575 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
577 void OnDamaged( const DamageArea& area ) override;
582 Adaptor(const Adaptor&) = delete;
583 Adaptor& operator=(Adaptor&) = delete;
588 * Assigns the render surface to the adaptor
591 void SetSurface(Dali::RenderSurfaceInterface *surface);
594 * called after surface is created
596 void SurfaceInitialized();
599 * Sends an notification message from main loop idle handler
601 bool ProcessCoreEventsFromIdle();
604 * Gets path for data/resource storage.
605 * @param[out] path Path for data/resource storage
607 void GetDataStoragePath(std::string& path);
610 * Sets up system information if needs
612 void SetupSystemInformation();
615 * Adds a callback to be run when entering an idle state.
617 * A callback of the following type should be used:
621 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
623 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
626 * Removes a previously added the idle enterer callback.
628 void RemoveIdleEnterer( CallbackBase* callback );
634 * @param[in] window window handle
635 * @param[in] adaptor The public adaptor
636 * @param[in] surface A render surface can be one of the following
637 * - Pixmap, adaptor will use existing Pixmap to draw on to
638 * - Window, adaptor will use existing Window to draw on to
639 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
640 * @param[in] threadMode The ThreadMode of the Adaptor
642 Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode );
648 READY, ///< Initial state before Adaptor::Start is called.
649 RUNNING, ///< Adaptor is running.
650 PAUSED, ///< Adaptor has been paused.
651 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
652 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
653 STOPPED, ///< Adaptor has been stopped.
656 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
657 // so we have to store the raw pointer.
658 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
659 using ObserverContainer = std::vector<LifeCycleObserver*>;
663 AdaptorSignalType mResizedSignal; ///< Resized signal.
664 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
665 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
667 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
668 State mState; ///< Current state of the adaptor
669 Dali::Integration::Core* mCore; ///< Dali Core
670 ThreadController* mThreadController; ///< Controls the threads
672 std::unique_ptr< GraphicsInterface > mGraphics; ///< Graphics interface
673 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
674 WindowContainer mWindows; ///< A container of all the Windows that are currently created
676 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
678 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
680 CallbackManager* mCallbackManager; ///< Used to install callbacks
681 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
682 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
683 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
684 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
685 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
686 ObserverContainer mObservers; ///< A list of adaptor observer pointers
687 EnvironmentOptions* mEnvironmentOptions; ///< environment options
688 PerformanceInterface* mPerformanceInterface; ///< Performance interface
689 KernelTrace mKernelTracer; ///< Kernel tracer
690 SystemTrace mSystemTracer; ///< System tracer
691 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
692 SocketFactory mSocketFactory; ///< Socket factory
693 ThreadMode mThreadMode; ///< The thread mode
694 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
695 bool mUseRemoteSurface:1; ///< whether the remoteSurface is used or not
696 Dali::LayoutDirection::Type mRootLayoutDirection; ///< LayoutDirection of window
698 std::unique_ptr<Integration::AddOnManager> mAddOnManager; ///< Pointer to the addon manager
700 class AccessibilityObserver : public ConnectionTracker
703 void OnAccessibleKeyEvent( const Dali::KeyEvent& event );
705 AccessibilityObserver accessibilityObserver;
708 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
711 } // namespace Internal
713 } // namespace Adaptor
717 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H