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 * 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 );
453 * @coydoc Dali::Adaptor::UnregisterProcessor
455 void UnregisterProcessor( Integration::Processor& processor );
458 * Check MultipleWindow is supported
460 bool IsMultipleWindowSupported() const;
462 public: //AdaptorInternalServices
465 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
467 Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface() override;
470 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
472 Dali::DisplayConnection& GetDisplayConnectionInterface() override;
475 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
477 GraphicsInterface& GetGraphicsInterface() override;
480 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
482 TriggerEventInterface& GetProcessCoreEventsTrigger() override;
485 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
487 SocketFactoryInterface& GetSocketFactoryInterface() override;
490 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
492 Dali::RenderSurfaceInterface* GetRenderSurfaceInterface() override;
495 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
497 PerformanceInterface* GetPerformanceInterface() override;
500 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
502 TraceInterface& GetKernelTraceInterface() override;
505 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
507 TraceInterface& GetSystemTraceInterface() override;
510 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
512 void GetWindowContainerInterface( WindowContainer& windows ) override;
517 * @copydoc Dali::Adaptor::SignalResized
519 AdaptorSignalType& ResizedSignal()
521 return mResizedSignal;
525 * @copydoc Dali::Adaptor::LanguageChangedSignal
527 AdaptorSignalType& LanguageChangedSignal()
529 return mLanguageChangedSignal;
533 * @copydoc Dali::Adaptor::WindowCreatedSignal
535 WindowCreatedSignalType& WindowCreatedSignal()
537 return mWindowCreatedSignal;
540 public: // From Dali::Internal::Adaptor::CoreEventInterface
543 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
545 void ProcessCoreEvents() override;
547 private: // From Dali::Internal::Adaptor::CoreEventInterface
550 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
552 void QueueCoreEvent(const Dali::Integration::Event& event) override;
554 private: // From Dali::Integration::RenderController
557 * @copydoc Dali::Integration::RenderController::RequestUpdate()
559 void RequestUpdate( bool forceUpdate ) override;
562 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
564 void RequestProcessEventsOnIdle( bool forceProcess ) override;
566 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
569 * Called when the window becomes fully or partially visible.
571 void OnWindowShown() override;
574 * Called when the window is fully hidden.
576 void OnWindowHidden() override;
578 private: // From Dali::Internal::Adaptor::DamageObserver
581 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
583 void OnDamaged( const DamageArea& area ) override;
588 Adaptor(const Adaptor&) = delete;
589 Adaptor& operator=(Adaptor&) = delete;
594 * Assigns the render surface to the adaptor
597 void SetSurface(Dali::RenderSurfaceInterface *surface);
600 * called after surface is created
602 void SurfaceInitialized();
605 * Sends an notification message from main loop idle handler
607 bool ProcessCoreEventsFromIdle();
610 * Gets path for data/resource storage.
611 * @param[out] path Path for data/resource storage
613 void GetDataStoragePath(std::string& path);
616 * Sets up system information if needs
618 void SetupSystemInformation();
621 * Adds a callback to be run when entering an idle state.
623 * A callback of the following type should be used:
627 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
629 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
632 * Removes a previously added the idle enterer callback.
634 void RemoveIdleEnterer( CallbackBase* callback );
640 * @param[in] window window handle
641 * @param[in] adaptor The public adaptor
642 * @param[in] surface A render surface can be one of the following
643 * - Pixmap, adaptor will use existing Pixmap to draw on to
644 * - Window, adaptor will use existing Window to draw on to
645 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
646 * @param[in] threadMode The ThreadMode of the Adaptor
648 Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode );
654 READY, ///< Initial state before Adaptor::Start is called.
655 RUNNING, ///< Adaptor is running.
656 PAUSED, ///< Adaptor has been paused.
657 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
658 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
659 STOPPED, ///< Adaptor has been stopped.
662 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
663 // so we have to store the raw pointer.
664 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
665 using ObserverContainer = std::vector<LifeCycleObserver*>;
669 AdaptorSignalType mResizedSignal; ///< Resized signal.
670 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
671 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
673 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
674 State mState; ///< Current state of the adaptor
675 Dali::Integration::Core* mCore; ///< Dali Core
676 ThreadController* mThreadController; ///< Controls the threads
678 std::unique_ptr< GraphicsInterface > mGraphics; ///< Graphics interface
679 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
680 WindowContainer mWindows; ///< A container of all the Windows that are currently created
682 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
684 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
686 CallbackManager* mCallbackManager; ///< Used to install callbacks
687 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
688 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
689 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
690 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
691 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
692 ObserverContainer mObservers; ///< A list of adaptor observer pointers
693 EnvironmentOptions* mEnvironmentOptions; ///< environment options
694 PerformanceInterface* mPerformanceInterface; ///< Performance interface
695 KernelTrace mKernelTracer; ///< Kernel tracer
696 SystemTrace mSystemTracer; ///< System tracer
697 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
698 SocketFactory mSocketFactory; ///< Socket factory
699 ThreadMode mThreadMode; ///< The thread mode
700 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
701 bool mUseRemoteSurface:1; ///< whether the remoteSurface is used or not
702 Dali::LayoutDirection::Type mRootLayoutDirection; ///< LayoutDirection of window
704 std::unique_ptr<Integration::AddOnManager> mAddOnManager; ///< Pointer to the addon manager
706 class AccessibilityObserver : public ConnectionTracker
709 void OnAccessibleKeyEvent( const Dali::KeyEvent& event );
711 AccessibilityObserver accessibilityObserver;
714 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
717 } // namespace Internal
719 } // namespace Adaptor
723 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H