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
287 virtual bool AddWindow( Dali::Integration::SceneHolder childWindow );
290 * Removes an existing Window instance from the Adaptor
291 * @param[in] window The Window instance
293 virtual bool RemoveWindow( Dali::Integration::SceneHolder* childWindow );
296 * Removes an existing Window instance from the Adaptor
297 * @param[in] windowName The Window name
298 * @note If two Windows have the same name, the first one that matches will be removed
300 virtual bool RemoveWindow( std::string childWindowName );
303 * @copydoc Dali::Adaptor::RemoveIdle()
305 virtual void RemoveIdle( CallbackBase* callback );
308 * @copydoc Dali::Adaptor::ProcessIdle()
310 virtual void ProcessIdle();
313 * Sets a pre-render callback.
315 void SetPreRenderCallback( CallbackBase* callback );
318 * Removes an existing Window instance from the Adaptor
319 * @param[in] childWindow The Window instance
321 bool RemoveWindow( Dali::Internal::Adaptor::SceneHolder* childWindow );
324 * @brief Deletes the rendering surface
325 * @param[in] surface to delete
327 void DeleteSurface( Dali::RenderSurfaceInterface& surface );
330 * @brief Retrieve the window that the given actor is added to.
332 * @param[in] actor The actor
333 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
335 Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
338 * @copydoc Dali::Adaptor::GetWindows()
340 Dali::WindowContainer GetWindows() const;
343 * @copydoc Dali::Adaptor::GetSceneHolders()
345 Dali::SceneHolderList GetSceneHolders() const;
348 * @copydoc Dali::Adaptor::GetObjectRegistry()
350 Dali::ObjectRegistry GetObjectRegistry() const;
355 * @return the Core instance
357 virtual Dali::Integration::Core& GetCore();
360 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
362 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
365 * Return the PlatformAbstraction.
366 * @return The PlatformAbstraction.
368 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
371 * Destroy the TtsPlayer of specific mode.
372 * @param[in] mode The mode of TtsPlayer to destroy
374 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
377 * Gets native window handle
379 * @return native window handle
381 Any GetNativeWindowHandle();
384 * @brief Retrieve native window handle that the given actor is added to.
386 * @param[in] actor The actor
387 * @return native window handle
389 Any GetNativeWindowHandle( Dali::Actor actor );
392 * Get the native display associated with the graphics backend
394 * @return A handle to the native display
396 Any GetGraphicsDisplay();
399 * Sets use remote surface for Surface output
400 * @param[in] useRemoteSurface True if the remote surface is used
402 void SetUseRemoteSurface(bool useRemoteSurface);
407 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
408 * @param[in] observer The observer.
409 * @note Observers should remove themselves when they are destroyed.
411 void AddObserver( LifeCycleObserver& observer );
414 * Removes the observer from the adaptor.
415 * @param[in] observer The observer to remove.
416 * @note Observers should remove themselves when they are destroyed.
418 void RemoveObserver( LifeCycleObserver& observer );
421 * Emits the Notification event to the Dali core.
423 void SendNotificationEvent();
426 * Request adaptor to update once
428 void RequestUpdateOnce();
431 * @copydoc Dali::Adaptor::NotifySceneCreated()
433 void NotifySceneCreated();
436 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
438 void NotifyLanguageChanged();
441 * Gets AppId of current application
443 void GetAppId( std::string& appId );
446 * @copydoc Dali::Adaptor::SurfaceResizePrepare
448 void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
451 * @copydoc Dali::Adaptor::SurfaceResizeComplete
453 void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
456 * Sets layout direction of root by system language
457 * @param[in] locale System locale
459 void SetRootLayoutDirection( std::string locale );
462 * @copydoc Dali::Adaptor::RenderOnce
467 * @copydoc Dali::Adaptor::GetLogFactory
469 const LogFactoryInterface& GetLogFactory();
472 * @copydoc Dali::Adaptor::RegisterProcessor
474 void RegisterProcessor( Integration::Processor& processor );
477 * @coydoc Dali::Adaptor::UnregisterProcessor
479 void UnregisterProcessor( Integration::Processor& processor );
482 * Check MultipleWindow is supported
484 bool IsMultipleWindowSupported() const;
486 public: //AdaptorInternalServices
489 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
491 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
494 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
496 virtual Dali::DisplayConnection& GetDisplayConnectionInterface();
499 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
501 virtual GraphicsInterface& GetGraphicsInterface();
504 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
506 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
509 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
511 virtual SocketFactoryInterface& GetSocketFactoryInterface();
514 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
516 virtual Dali::RenderSurfaceInterface* GetRenderSurfaceInterface();
519 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
521 virtual PerformanceInterface* GetPerformanceInterface();
524 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
526 virtual TraceInterface& GetKernelTraceInterface();
529 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
531 virtual TraceInterface& GetSystemTraceInterface();
534 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
536 virtual void GetWindowContainerInterface( WindowContainer& windows );
541 * @copydoc Dali::Adaptor::SignalResized
543 AdaptorSignalType& ResizedSignal()
545 return mResizedSignal;
549 * @copydoc Dali::Adaptor::LanguageChangedSignal
551 AdaptorSignalType& LanguageChangedSignal()
553 return mLanguageChangedSignal;
557 * @copydoc Dali::Adaptor::WindowCreatedSignal
559 WindowCreatedSignalType& WindowCreatedSignal()
561 return mWindowCreatedSignal;
564 public: // From Dali::Internal::Adaptor::CoreEventInterface
567 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
569 virtual void ProcessCoreEvents();
571 private: // From Dali::Internal::Adaptor::CoreEventInterface
574 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
576 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
578 private: // From Dali::Integration::RenderController
581 * @copydoc Dali::Integration::RenderController::RequestUpdate()
583 virtual void RequestUpdate( bool forceUpdate );
586 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
588 virtual void RequestProcessEventsOnIdle( bool forceProcess );
590 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
593 * Called when the window becomes fully or partially visible.
595 virtual void OnWindowShown();
598 * Called when the window is fully hidden.
600 virtual void OnWindowHidden();
602 private: // From Dali::Internal::Adaptor::DamageObserver
605 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
607 void OnDamaged( const DamageArea& area );
612 Adaptor(const Adaptor&) = delete;
613 Adaptor& operator=(Adaptor&) = delete;
618 * Assigns the render surface to the adaptor
621 void SetSurface(Dali::RenderSurfaceInterface *surface);
624 * called after surface is created
626 void SurfaceInitialized();
629 * Sends an notification message from main loop idle handler
631 bool ProcessCoreEventsFromIdle();
634 * Gets path for data/resource storage.
635 * @param[out] path Path for data/resource storage
637 void GetDataStoragePath(std::string& path);
640 * Sets up system information if needs
642 void SetupSystemInformation();
645 * Adds a callback to be run when entering an idle state.
647 * A callback of the following type should be used:
651 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
653 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
656 * Removes a previously added the idle enterer callback.
658 void RemoveIdleEnterer( CallbackBase* callback );
664 * @param[in] window window handle
665 * @param[in] adaptor The public adaptor
666 * @param[in] surface A render surface can be one of the following
667 * - Pixmap, adaptor will use existing Pixmap to draw on to
668 * - Window, adaptor will use existing Window to draw on to
669 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
670 * @param[in] threadMode The ThreadMode of the Adaptor
672 Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions, ThreadMode threadMode );
678 READY, ///< Initial state before Adaptor::Start is called.
679 RUNNING, ///< Adaptor is running.
680 PAUSED, ///< Adaptor has been paused.
681 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
682 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
683 STOPPED, ///< Adaptor has been stopped.
686 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
687 // so we have to store the raw pointer.
688 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
689 using ObserverContainer = std::vector<LifeCycleObserver*>;
693 AdaptorSignalType mResizedSignal; ///< Resized signal.
694 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
695 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
697 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
698 State mState; ///< Current state of the adaptor
699 Dali::Integration::Core* mCore; ///< Dali Core
700 ThreadController* mThreadController; ///< Controls the threads
702 std::unique_ptr< GraphicsInterface > mGraphics; ///< Graphics interface
703 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
704 WindowContainer mWindows; ///< A container of all the Windows that are currently created
706 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
708 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
710 CallbackManager* mCallbackManager; ///< Used to install callbacks
711 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
712 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
713 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
714 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
715 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
716 ObserverContainer mObservers; ///< A list of adaptor observer pointers
717 EnvironmentOptions* mEnvironmentOptions; ///< environment options
718 PerformanceInterface* mPerformanceInterface; ///< Performance interface
719 KernelTrace mKernelTracer; ///< Kernel tracer
720 SystemTrace mSystemTracer; ///< System tracer
721 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
722 SocketFactory mSocketFactory; ///< Socket factory
723 ThreadMode mThreadMode; ///< The thread mode
724 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
725 bool mUseRemoteSurface:1; ///< whether the remoteSurface is used or not
726 Dali::LayoutDirection::Type mRootLayoutDirection; ///< LayoutDirection of window
728 std::unique_ptr<Integration::AddOnManager> mAddOnManager; ///< Pointer to the addon manager
731 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
734 } // namespace Internal
736 } // namespace Adaptor
740 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H