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>
49 class RenderSurfaceInterface;
64 class DisplayConnection;
65 class GraphicsFactory;
66 class GlImplementation;
67 class GlSyncImplementation;
68 class ThreadController;
70 class CallbackManager;
71 class FeedbackPluginProxy;
72 class FeedbackController;
74 class PerformanceInterface;
75 class LifeCycleObserver;
78 class ConfigurationManager;
79 enum class ThreadMode;
82 * Implementation of the Adaptor class.
84 class Adaptor : public Integration::RenderController,
85 public AdaptorInternalServices,
86 public CoreEventInterface,
87 public DamageObserver,
88 public WindowVisibilityObserver
92 using AdaptorSignalType = Dali::Adaptor::AdaptorSignalType;
93 using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType;
95 using SurfaceSize = Uint16Pair; ///< Surface size type
98 * Creates a New Adaptor
99 * @param[in] window The window handle
100 * @param[in] surface A render surface can be one of the following
101 * - Pixmap, adaptor will use existing Pixmap to draw on to
102 * - Window, adaptor will use existing Window to draw on to
103 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
105 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
106 Dali::RenderSurfaceInterface* surface,
107 EnvironmentOptions* environmentOptions );
110 * Creates a New Adaptor
111 * @param[in] window The window handle
112 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
114 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
115 EnvironmentOptions* environmentOptions );
118 * Creates a New Adaptor
119 * @param[in] graphicsFactory A factory that creates the graphics interface
120 * @param[in] window The window handle
121 * @param[in] surface A render surface can be one of the following
122 * - Pixmap, adaptor will use existing Pixmap to draw on to
123 * - Window, adaptor will use existing Window to draw on to
124 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
126 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
127 Dali::Integration::SceneHolder window,
128 Dali::RenderSurfaceInterface* surface,
129 EnvironmentOptions* environmentOptions );
132 * Creates a New Adaptor
133 * @param[in] graphicsFactory A factory that creates the graphics interface
134 * @param[in] window The window handle
135 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
137 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
138 Dali::Integration::SceneHolder window,
139 EnvironmentOptions* environmentOptions );
142 * 2-step initialisation, this should be called after creating an adaptor instance.
143 * @param[in] graphicsFactory A factory that creates the graphics interface
145 void Initialize( GraphicsFactory& graphicsFactory );
148 * Virtual destructor.
153 * @copydoc Dali::Adaptor::Get()
155 static Dali::Adaptor& Get();
158 * @copydoc Dali::Adaptor::IsAvailable()
160 static bool IsAvailable();
163 * @copydoc Dali::Core::SceneCreated();
167 public: // AdaptorInternalServices implementation
169 * @copydoc Dali::Adaptor::Start()
171 virtual void Start();
174 * @copydoc Dali::Adaptor::Pause()
176 virtual void Pause();
179 * @copydoc Dali::Adaptor::Resume()
181 virtual void Resume();
184 * @copydoc Dali::Adaptor::Stop()
189 * @copydoc Dali::Adaptor::ContextLost()
191 virtual void ContextLost();
194 * @copydoc Dali::Adaptor::ContextRegained()
196 virtual void ContextRegained();
199 * @copydoc Dali::EventFeeder::FeedTouchPoint()
201 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
204 * @copydoc Dali::EventFeeder::FeedWheelEvent()
206 virtual void FeedWheelEvent( Dali::WheelEvent& wheelEvent );
209 * @copydoc Dali::EventFeeder::FeedKeyEvent()
211 virtual void FeedKeyEvent( Dali::KeyEvent& keyEvent );
214 * @copydoc Dali::Adaptor::ReplaceSurface()
216 virtual void ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface );
219 * @copydoc Dali::Adaptor::GetSurface()
221 virtual Dali::RenderSurfaceInterface& GetSurface() const;
224 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
226 virtual void ReleaseSurfaceLock();
229 * Retrieve the TtsPlayer.
230 * @param[in] mode The mode of TtsPlayer
231 * @return A handle to the TtsPlayer.
233 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
236 * @copydoc Dali::Adaptor::AddIdle()
238 virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
241 * Adds a new Window instance to the Adaptor
242 * @param[in] childWindow The child window instance
244 virtual bool AddWindow( Dali::Integration::SceneHolder childWindow );
247 * Removes an existing Window instance from the Adaptor
248 * @param[in] window The Window instance
250 virtual bool RemoveWindow( Dali::Integration::SceneHolder* childWindow );
253 * Removes an existing Window instance from the Adaptor
254 * @param[in] windowName The Window name
255 * @note If two Windows have the same name, the first one that matches will be removed
257 virtual bool RemoveWindow( std::string childWindowName );
260 * @copydoc Dali::Adaptor::RemoveIdle()
262 virtual void RemoveIdle( CallbackBase* callback );
265 * @copydoc Dali::Adaptor::ProcessIdle()
267 virtual void ProcessIdle();
270 * Sets a pre-render callback.
272 void SetPreRenderCallback( CallbackBase* callback );
275 * Removes an existing Window instance from the Adaptor
276 * @param[in] childWindow The Window instance
278 bool RemoveWindow( Dali::Internal::Adaptor::SceneHolder* childWindow );
281 * @brief Deletes the rendering surface
282 * @param[in] surface to delete
284 void DeleteSurface( Dali::RenderSurfaceInterface& surface );
287 * @brief Retrieve the window that the given actor is added to.
289 * @param[in] actor The actor
290 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
292 Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
295 * @copydoc Dali::Adaptor::GetWindows()
297 Dali::WindowContainer GetWindows() const;
300 * @copydoc Dali::Adaptor::GetSceneHolders()
302 Dali::SceneHolderList GetSceneHolders() const;
305 * @copydoc Dali::Adaptor::GetObjectRegistry()
307 Dali::ObjectRegistry GetObjectRegistry() const;
312 * @return the Core instance
314 Dali::Integration::Core& GetCore() override;
317 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
319 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
322 * Return the PlatformAbstraction.
323 * @return The PlatformAbstraction.
325 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
328 * Destroy the TtsPlayer of specific mode.
329 * @param[in] mode The mode of TtsPlayer to destroy
331 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
334 * Gets native window handle
336 * @return native window handle
338 Any GetNativeWindowHandle();
341 * @brief Retrieve native window handle that the given actor is added to.
343 * @param[in] actor The actor
344 * @return native window handle
346 Any GetNativeWindowHandle( Dali::Actor actor );
349 * Get the native display associated with the graphics backend
351 * @return A handle to the native display
353 Any GetGraphicsDisplay();
356 * Sets use remote surface for Surface output
357 * @param[in] useRemoteSurface True if the remote surface is used
359 void SetUseRemoteSurface(bool useRemoteSurface);
364 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
365 * @param[in] observer The observer.
366 * @note Observers should remove themselves when they are destroyed.
368 void AddObserver( LifeCycleObserver& observer );
371 * Removes the observer from the adaptor.
372 * @param[in] observer The observer to remove.
373 * @note Observers should remove themselves when they are destroyed.
375 void RemoveObserver( LifeCycleObserver& observer );
378 * Emits the Notification event to the Dali core.
380 void SendNotificationEvent();
383 * Request adaptor to update once
385 void RequestUpdateOnce();
388 * @copydoc Dali::Adaptor::NotifySceneCreated()
390 void NotifySceneCreated();
393 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
395 void NotifyLanguageChanged();
398 * Gets AppId of current application
400 void GetAppId( std::string& appId );
403 * @copydoc Dali::Adaptor::SurfaceResizePrepare
405 void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
408 * @copydoc Dali::Adaptor::SurfaceResizeComplete
410 void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
413 * Sets layout direction of root by system language
414 * @param[in] locale System locale
416 void SetRootLayoutDirection( std::string locale );
419 * @copydoc Dali::Adaptor::RenderOnce
424 * @copydoc Dali::Adaptor::GetLogFactory
426 const LogFactoryInterface& GetLogFactory();
429 * @copydoc Dali::Adaptor::RegisterProcessor
431 void RegisterProcessor( Integration::Processor& processor );
434 * @coydoc Dali::Adaptor::UnregisterProcessor
436 void UnregisterProcessor( Integration::Processor& processor );
439 * Check MultipleWindow is supported
441 bool IsMultipleWindowSupported() const;
443 public: //AdaptorInternalServices
446 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
448 Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface() override;
451 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
453 Dali::DisplayConnection& GetDisplayConnectionInterface() override;
456 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
458 GraphicsInterface& GetGraphicsInterface() override;
461 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
463 TriggerEventInterface& GetProcessCoreEventsTrigger() override;
466 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
468 SocketFactoryInterface& GetSocketFactoryInterface() override;
471 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
473 Dali::RenderSurfaceInterface* GetRenderSurfaceInterface() override;
476 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
478 PerformanceInterface* GetPerformanceInterface() override;
481 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
483 TraceInterface& GetKernelTraceInterface() override;
486 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
488 TraceInterface& GetSystemTraceInterface() override;
491 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
493 void GetWindowContainerInterface( WindowContainer& windows ) override;
498 * @copydoc Dali::Adaptor::SignalResized
500 AdaptorSignalType& ResizedSignal()
502 return mResizedSignal;
506 * @copydoc Dali::Adaptor::LanguageChangedSignal
508 AdaptorSignalType& LanguageChangedSignal()
510 return mLanguageChangedSignal;
514 * @copydoc Dali::Adaptor::WindowCreatedSignal
516 WindowCreatedSignalType& WindowCreatedSignal()
518 return mWindowCreatedSignal;
521 public: // From Dali::Internal::Adaptor::CoreEventInterface
524 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
526 void ProcessCoreEvents() override;
528 private: // From Dali::Internal::Adaptor::CoreEventInterface
531 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
533 void QueueCoreEvent(const Dali::Integration::Event& event) override;
535 private: // From Dali::Integration::RenderController
538 * @copydoc Dali::Integration::RenderController::RequestUpdate()
540 void RequestUpdate( bool forceUpdate ) override;
543 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
545 void RequestProcessEventsOnIdle( bool forceProcess ) override;
547 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
550 * Called when the window becomes fully or partially visible.
552 void OnWindowShown() override;
555 * Called when the window is fully hidden.
557 void OnWindowHidden() override;
559 private: // From Dali::Internal::Adaptor::DamageObserver
562 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
564 void OnDamaged( const DamageArea& area ) override;
569 Adaptor(const Adaptor&) = delete;
570 Adaptor& operator=(Adaptor&) = delete;
575 * Assigns the render surface to the adaptor
578 void SetSurface(Dali::RenderSurfaceInterface *surface);
581 * called after surface is created
583 void SurfaceInitialized();
586 * Sends an notification message from main loop idle handler
588 bool ProcessCoreEventsFromIdle();
591 * Gets path for data/resource storage.
592 * @param[out] path Path for data/resource storage
594 void GetDataStoragePath(std::string& path);
597 * Sets up system information if needs
599 void SetupSystemInformation();
602 * Adds a callback to be run when entering an idle state.
604 * A callback of the following type should be used:
608 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
610 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
613 * Removes a previously added the idle enterer callback.
615 void RemoveIdleEnterer( CallbackBase* callback );
621 * @param[in] window window handle
622 * @param[in] adaptor The public adaptor
623 * @param[in] surface A render surface can be one of the following
624 * - Pixmap, adaptor will use existing Pixmap to draw on to
625 * - Window, adaptor will use existing Window to draw on to
626 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
628 Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions );
634 READY, ///< Initial state before Adaptor::Start is called.
635 RUNNING, ///< Adaptor is running.
636 PAUSED, ///< Adaptor has been paused.
637 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
638 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
639 STOPPED, ///< Adaptor has been stopped.
642 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
643 // so we have to store the raw pointer.
644 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
645 using ObserverContainer = std::vector<LifeCycleObserver*>;
649 AdaptorSignalType mResizedSignal; ///< Resized signal.
650 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
651 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
653 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
654 State mState; ///< Current state of the adaptor
655 Dali::Integration::Core* mCore; ///< Dali Core
656 ThreadController* mThreadController; ///< Controls the threads
658 std::unique_ptr< GraphicsInterface > mGraphics; ///< Graphics interface
659 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
660 WindowContainer mWindows; ///< A container of all the Windows that are currently created
662 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
664 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
666 CallbackManager* mCallbackManager; ///< Used to install callbacks
667 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
668 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
669 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
670 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
671 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
672 ObserverContainer mObservers; ///< A list of adaptor observer pointers
673 EnvironmentOptions* mEnvironmentOptions; ///< environment options
674 PerformanceInterface* mPerformanceInterface; ///< Performance interface
675 KernelTrace mKernelTracer; ///< Kernel tracer
676 SystemTrace mSystemTracer; ///< System tracer
677 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
678 SocketFactory mSocketFactory; ///< Socket factory
679 ThreadMode mThreadMode; ///< The thread mode
680 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
681 bool mUseRemoteSurface:1; ///< whether the remoteSurface is used or not
682 Dali::LayoutDirection::Type mRootLayoutDirection; ///< LayoutDirection of window
684 std::unique_ptr<Integration::AddOnManager> mAddOnManager; ///< Pointer to the addon manager
687 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
690 } // namespace Internal
692 } // namespace Adaptor
696 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H