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] configuration The context loss configuration ( to choose resource discard policy )
104 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
105 * @param[in] threadMode The mode of the Adaptor
107 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
108 Dali::RenderSurfaceInterface* surface,
109 Dali::Configuration::ContextLoss configuration,
110 EnvironmentOptions* environmentOptions,
111 ThreadMode threadMode );
114 * Creates a New Adaptor
115 * @param[in] window The window handle
116 * @param[in] surface A render surface can be one of the following
117 * - Pixmap, adaptor will use existing Pixmap to draw on to
118 * - Window, adaptor will use existing Window to draw on to
119 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
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 Dali::RenderSurfaceInterface* surface,
124 Dali::Configuration::ContextLoss configuration,
125 EnvironmentOptions* environmentOptions );
128 * Creates a New Adaptor
129 * @param[in] window The window handle
130 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
131 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
133 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
134 Dali::Configuration::ContextLoss configuration,
135 EnvironmentOptions* environmentOptions );
138 * Creates a New Adaptor
139 * @param[in] graphicsFactory A factory that creates the graphics interface
140 * @param[in] window The window handle
141 * @param[in] surface A render surface can be one of the following
142 * - Pixmap, adaptor will use existing Pixmap to draw on to
143 * - Window, adaptor will use existing Window to draw on to
144 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
145 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
146 * @param[in] threadMode The ThreadMode of the Adaptor
148 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
149 Dali::Integration::SceneHolder window,
150 Dali::RenderSurfaceInterface* surface,
151 Dali::Configuration::ContextLoss configuration,
152 EnvironmentOptions* environmentOptions,
153 ThreadMode threadMode );
156 * Creates a New Adaptor
157 * @param[in] graphicsFactory A factory that creates the graphics interface
158 * @param[in] window The window handle
159 * @param[in] surface A render surface can be one of the following
160 * - Pixmap, adaptor will use existing Pixmap to draw on to
161 * - Window, adaptor will use existing Window to draw on to
162 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
163 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
165 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
166 Dali::Integration::SceneHolder window,
167 Dali::RenderSurfaceInterface* surface,
168 Dali::Configuration::ContextLoss configuration,
169 EnvironmentOptions* environmentOptions );
172 * Creates a New Adaptor
173 * @param[in] graphicsFactory A factory that creates the graphics interface
174 * @param[in] window The window handle
175 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
176 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
178 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
179 Dali::Integration::SceneHolder window,
180 Dali::Configuration::ContextLoss configuration,
181 EnvironmentOptions* environmentOptions );
184 * 2-step initialisation, this should be called after creating an adaptor instance.
185 * @param[in] graphicsFactory A factory that creates the graphics interface
186 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
188 void Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration );
191 * Virtual destructor.
196 * @copydoc Dali::Adaptor::Get()
198 static Dali::Adaptor& Get();
201 * @copydoc Dali::Adaptor::IsAvailable()
203 static bool IsAvailable();
206 * @copydoc Dali::Core::SceneCreated();
210 public: // AdaptorInternalServices implementation
212 * @copydoc Dali::Adaptor::Start()
214 virtual void Start();
217 * @copydoc Dali::Adaptor::Pause()
219 virtual void Pause();
222 * @copydoc Dali::Adaptor::Resume()
224 virtual void Resume();
227 * @copydoc Dali::Adaptor::Stop()
232 * @copydoc Dali::Adaptor::ContextLost()
234 virtual void ContextLost();
237 * @copydoc Dali::Adaptor::ContextRegained()
239 virtual void ContextRegained();
242 * @copydoc Dali::EventFeeder::FeedTouchPoint()
244 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
247 * @copydoc Dali::EventFeeder::FeedWheelEvent()
249 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
252 * @copydoc Dali::EventFeeder::FeedKeyEvent()
254 virtual void FeedKeyEvent( KeyEvent& keyEvent );
257 * @copydoc Dali::Adaptor::ReplaceSurface()
259 virtual void ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface );
262 * @copydoc Dali::Adaptor::GetSurface()
264 virtual Dali::RenderSurfaceInterface& GetSurface() const;
267 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
269 virtual void ReleaseSurfaceLock();
272 * Retrieve the TtsPlayer.
273 * @param[in] mode The mode of TtsPlayer
274 * @return A handle to the TtsPlayer.
276 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
279 * @copydoc Dali::Adaptor::AddIdle()
281 virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
284 * Adds a new Window instance to the Adaptor
285 * @param[in] childWindow The child window instance
286 * @param[in] childWindowName The child window title/name
287 * @param[in] childWindowClassName The class name that the child window belongs to
288 * @param[in] childWindowMode The mode of the child window
290 virtual bool AddWindow( Dali::Integration::SceneHolder childWindow,
291 const std::string& childWindowName,
292 const std::string& childWindowClassName,
293 bool childWindowMode );
296 * Removes an existing Window instance from the Adaptor
297 * @param[in] window The Window instance
299 virtual bool RemoveWindow( Dali::Integration::SceneHolder* childWindow );
302 * Removes an existing Window instance from the Adaptor
303 * @param[in] windowName The Window name
304 * @note If two Windows have the same name, the first one that matches will be removed
306 virtual bool RemoveWindow( std::string childWindowName );
309 * @copydoc Dali::Adaptor::RemoveIdle()
311 virtual void RemoveIdle( CallbackBase* callback );
314 * @copydoc Dali::Adaptor::ProcessIdle()
316 virtual void ProcessIdle();
319 * Sets a pre-render callback.
321 void SetPreRenderCallback( CallbackBase* callback );
324 * Removes an existing Window instance from the Adaptor
325 * @param[in] childWindow The Window instance
327 bool RemoveWindow( Dali::Internal::Adaptor::SceneHolder* childWindow );
330 * @brief Deletes the rendering surface
331 * @param[in] surface to delete
333 void DeleteSurface( Dali::RenderSurfaceInterface& surface );
336 * @brief Retrieve the window that the given actor is added to.
338 * @param[in] actor The actor
339 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
341 Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
344 * @copydoc Dali::Adaptor::GetWindows()
346 Dali::WindowContainer GetWindows() const;
349 * @copydoc Dali::Adaptor::GetSceneHolders()
351 Dali::SceneHolderList GetSceneHolders() const;
354 * @copydoc Dali::Adaptor::GetObjectRegistry()
356 Dali::ObjectRegistry GetObjectRegistry() const;
361 * @return the Core instance
363 virtual Dali::Integration::Core& GetCore();
366 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
368 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
371 * Return the PlatformAbstraction.
372 * @return The PlatformAbstraction.
374 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
377 * Destroy the TtsPlayer of specific mode.
378 * @param[in] mode The mode of TtsPlayer to destroy
380 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
383 * Gets native window handle
385 * @return native window handle
387 Any GetNativeWindowHandle();
390 * @brief Retrieve native window handle that the given actor is added to.
392 * @param[in] actor The actor
393 * @return native window handle
395 Any GetNativeWindowHandle( Dali::Actor actor );
398 * Get the native display associated with the graphics backend
400 * @return A handle to the native display
402 Any GetGraphicsDisplay();
405 * Sets use remote surface for Surface output
406 * @param[in] useRemoteSurface True if the remote surface is used
408 void SetUseRemoteSurface(bool useRemoteSurface);
413 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
414 * @param[in] observer The observer.
415 * @note Observers should remove themselves when they are destroyed.
417 void AddObserver( LifeCycleObserver& observer );
420 * Removes the observer from the adaptor.
421 * @param[in] observer The observer to remove.
422 * @note Observers should remove themselves when they are destroyed.
424 void RemoveObserver( LifeCycleObserver& observer );
427 * Emits the Notification event to the Dali core.
429 void SendNotificationEvent();
432 * Request adaptor to update once
434 void RequestUpdateOnce();
437 * @copydoc Dali::Adaptor::NotifySceneCreated()
439 void NotifySceneCreated();
442 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
444 void NotifyLanguageChanged();
447 * Gets AppId of current application
449 void GetAppId( std::string& appId );
452 * @copydoc Dali::Adaptor::SurfaceResizePrepare
454 void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
457 * @copydoc Dali::Adaptor::SurfaceResizeComplete
459 void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
462 * Sets layout direction of root by system language
463 * @param[in] locale System locale
465 void SetRootLayoutDirection( std::string locale );
468 * @copydoc Dali::Adaptor::RenderOnce
473 * @copydoc Dali::Adaptor::GetLogFactory
475 const LogFactoryInterface& GetLogFactory();
478 * @copydoc Dali::Adaptor::RegisterProcessor
480 void RegisterProcessor( Integration::Processor& processor );
483 * @coydoc Dali::Adaptor::UnregisterProcessor
485 void UnregisterProcessor( Integration::Processor& processor );
488 * Check MultipleWindow is supported
490 bool IsMultipleWindowSupported() const;
492 public: //AdaptorInternalServices
495 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
497 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
500 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
502 virtual Dali::DisplayConnection& GetDisplayConnectionInterface();
505 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
507 virtual GraphicsInterface& GetGraphicsInterface();
510 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
512 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
515 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
517 virtual SocketFactoryInterface& GetSocketFactoryInterface();
520 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
522 virtual Dali::RenderSurfaceInterface* GetRenderSurfaceInterface();
525 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
527 virtual PerformanceInterface* GetPerformanceInterface();
530 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
532 virtual TraceInterface& GetKernelTraceInterface();
535 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
537 virtual TraceInterface& GetSystemTraceInterface();
540 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
542 virtual void GetWindowContainerInterface( WindowContainer& windows );
547 * @copydoc Dali::Adaptor::SignalResized
549 AdaptorSignalType& ResizedSignal()
551 return mResizedSignal;
555 * @copydoc Dali::Adaptor::LanguageChangedSignal
557 AdaptorSignalType& LanguageChangedSignal()
559 return mLanguageChangedSignal;
563 * @copydoc Dali::Adaptor::WindowCreatedSignal
565 WindowCreatedSignalType& WindowCreatedSignal()
567 return mWindowCreatedSignal;
570 public: // From Dali::Internal::Adaptor::CoreEventInterface
573 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
575 virtual void ProcessCoreEvents();
577 private: // From Dali::Internal::Adaptor::CoreEventInterface
580 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
582 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
584 private: // From Dali::Integration::RenderController
587 * @copydoc Dali::Integration::RenderController::RequestUpdate()
589 virtual void RequestUpdate( bool forceUpdate );
592 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
594 virtual void RequestProcessEventsOnIdle( bool forceProcess );
596 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
599 * Called when the window becomes fully or partially visible.
601 virtual void OnWindowShown();
604 * Called when the window is fully hidden.
606 virtual void OnWindowHidden();
608 private: // From Dali::Internal::Adaptor::DamageObserver
611 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
613 void OnDamaged( const DamageArea& area );
618 Adaptor(const Adaptor&) = delete;
619 Adaptor& operator=(Adaptor&) = delete;
624 * Assigns the render surface to the adaptor
627 void SetSurface(Dali::RenderSurfaceInterface *surface);
630 * called after surface is created
632 void SurfaceInitialized();
635 * Sends an notification message from main loop idle handler
637 bool ProcessCoreEventsFromIdle();
640 * Gets path for data/resource storage.
641 * @param[out] path Path for data/resource storage
643 void GetDataStoragePath(std::string& path);
646 * Sets up system information if needs
648 void SetupSystemInformation();
651 * Adds a callback to be run when entering an idle state.
653 * A callback of the following type should be used:
657 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
659 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
662 * Removes a previously added the idle enterer callback.
664 void RemoveIdleEnterer( CallbackBase* callback );
670 * @param[in] window window handle
671 * @param[in] adaptor The public adaptor
672 * @param[in] surface A render surface can be one of the following
673 * - Pixmap, adaptor will use existing Pixmap to draw on to
674 * - Window, adaptor will use existing Window to draw on to
675 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
676 * @param[in] threadMode The ThreadMode of the Adaptor
678 Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode );
684 READY, ///< Initial state before Adaptor::Start is called.
685 RUNNING, ///< Adaptor is running.
686 PAUSED, ///< Adaptor has been paused.
687 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
688 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
689 STOPPED, ///< Adaptor has been stopped.
692 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
693 // so we have to store the raw pointer.
694 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
695 using ObserverContainer = std::vector<LifeCycleObserver*>;
699 AdaptorSignalType mResizedSignal; ///< Resized signal.
700 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
701 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
703 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
704 State mState; ///< Current state of the adaptor
705 Dali::Integration::Core* mCore; ///< Dali Core
706 ThreadController* mThreadController; ///< Controls the threads
708 std::unique_ptr< GraphicsInterface > mGraphics; ///< Graphics interface
709 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
710 WindowContainer mWindows; ///< A container of all the Windows that are currently created
712 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
714 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
716 CallbackManager* mCallbackManager; ///< Used to install callbacks
717 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
718 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
719 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
720 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
721 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
722 ObserverContainer mObservers; ///< A list of adaptor observer pointers
723 EnvironmentOptions* mEnvironmentOptions; ///< environment options
724 PerformanceInterface* mPerformanceInterface; ///< Performance interface
725 KernelTrace mKernelTracer; ///< Kernel tracer
726 SystemTrace mSystemTracer; ///< System tracer
727 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
728 SocketFactory mSocketFactory; ///< Socket factory
729 ThreadMode mThreadMode; ///< The thread mode
730 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
731 bool mUseRemoteSurface:1; ///< whether the remoteSurface is used or not
733 std::unique_ptr<Integration::AddOnManager> mAddOnManager; ///< Pointer to the addon manager
736 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
739 } // namespace Internal
741 } // namespace Adaptor
745 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H