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.
106 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
107 Dali::RenderSurfaceInterface* surface,
108 Dali::Configuration::ContextLoss configuration,
109 EnvironmentOptions* environmentOptions );
112 * Creates a New Adaptor
113 * @param[in] window The window handle
114 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
115 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
117 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
118 Dali::Configuration::ContextLoss configuration,
119 EnvironmentOptions* environmentOptions );
122 * Creates a New Adaptor
123 * @param[in] graphicsFactory A factory that creates the graphics interface
124 * @param[in] window The window handle
125 * @param[in] surface A render surface can be one of the following
126 * - Pixmap, adaptor will use existing Pixmap to draw on to
127 * - Window, adaptor will use existing Window to draw on to
128 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
129 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
131 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
132 Dali::Integration::SceneHolder window,
133 Dali::RenderSurfaceInterface* surface,
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] configuration The context loss configuration ( to choose resource discard policy )
142 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
144 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
145 Dali::Integration::SceneHolder window,
146 Dali::Configuration::ContextLoss configuration,
147 EnvironmentOptions* environmentOptions );
150 * 2-step initialisation, this should be called after creating an adaptor instance.
151 * @param[in] graphicsFactory A factory that creates the graphics interface
152 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
154 void Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration );
157 * Virtual destructor.
162 * @copydoc Dali::Adaptor::Get()
164 static Dali::Adaptor& Get();
167 * @copydoc Dali::Adaptor::IsAvailable()
169 static bool IsAvailable();
172 * @copydoc Dali::Core::SceneCreated();
176 public: // AdaptorInternalServices implementation
178 * @copydoc Dali::Adaptor::Start()
180 virtual void Start();
183 * @copydoc Dali::Adaptor::Pause()
185 virtual void Pause();
188 * @copydoc Dali::Adaptor::Resume()
190 virtual void Resume();
193 * @copydoc Dali::Adaptor::Stop()
198 * @copydoc Dali::Adaptor::ContextLost()
200 virtual void ContextLost();
203 * @copydoc Dali::Adaptor::ContextRegained()
205 virtual void ContextRegained();
208 * @copydoc Dali::EventFeeder::FeedTouchPoint()
210 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
213 * @copydoc Dali::EventFeeder::FeedWheelEvent()
215 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
218 * @copydoc Dali::EventFeeder::FeedKeyEvent()
220 virtual void FeedKeyEvent( KeyEvent& keyEvent );
223 * @copydoc Dali::Adaptor::ReplaceSurface()
225 virtual void ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface );
228 * @copydoc Dali::Adaptor::GetSurface()
230 virtual Dali::RenderSurfaceInterface& GetSurface() const;
233 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
235 virtual void ReleaseSurfaceLock();
238 * Retrieve the TtsPlayer.
239 * @param[in] mode The mode of TtsPlayer
240 * @return A handle to the TtsPlayer.
242 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
245 * @copydoc Dali::Adaptor::AddIdle()
247 virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
250 * Adds a new Window instance to the Adaptor
251 * @param[in] childWindow The child window instance
253 virtual bool AddWindow( Dali::Integration::SceneHolder childWindow );
256 * Removes an existing Window instance from the Adaptor
257 * @param[in] window The Window instance
259 virtual bool RemoveWindow( Dali::Integration::SceneHolder* childWindow );
262 * Removes an existing Window instance from the Adaptor
263 * @param[in] windowName The Window name
264 * @note If two Windows have the same name, the first one that matches will be removed
266 virtual bool RemoveWindow( std::string childWindowName );
269 * @copydoc Dali::Adaptor::RemoveIdle()
271 virtual void RemoveIdle( CallbackBase* callback );
274 * @copydoc Dali::Adaptor::ProcessIdle()
276 virtual void ProcessIdle();
279 * Sets a pre-render callback.
281 void SetPreRenderCallback( CallbackBase* callback );
284 * Removes an existing Window instance from the Adaptor
285 * @param[in] childWindow The Window instance
287 bool RemoveWindow( Dali::Internal::Adaptor::SceneHolder* childWindow );
290 * @brief Deletes the rendering surface
291 * @param[in] surface to delete
293 void DeleteSurface( Dali::RenderSurfaceInterface& surface );
296 * @brief Retrieve the window that the given actor is added to.
298 * @param[in] actor The actor
299 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
301 Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
304 * @copydoc Dali::Adaptor::GetWindows()
306 Dali::WindowContainer GetWindows() const;
309 * @copydoc Dali::Adaptor::GetSceneHolders()
311 Dali::SceneHolderList GetSceneHolders() const;
314 * @copydoc Dali::Adaptor::GetObjectRegistry()
316 Dali::ObjectRegistry GetObjectRegistry() const;
321 * @return the Core instance
323 virtual Dali::Integration::Core& GetCore();
326 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
328 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
331 * Return the PlatformAbstraction.
332 * @return The PlatformAbstraction.
334 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
337 * Destroy the TtsPlayer of specific mode.
338 * @param[in] mode The mode of TtsPlayer to destroy
340 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
343 * Gets native window handle
345 * @return native window handle
347 Any GetNativeWindowHandle();
350 * @brief Retrieve native window handle that the given actor is added to.
352 * @param[in] actor The actor
353 * @return native window handle
355 Any GetNativeWindowHandle( Dali::Actor actor );
358 * Get the native display associated with the graphics backend
360 * @return A handle to the native display
362 Any GetGraphicsDisplay();
365 * Sets use remote surface for Surface output
366 * @param[in] useRemoteSurface True if the remote surface is used
368 void SetUseRemoteSurface(bool useRemoteSurface);
373 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
374 * @param[in] observer The observer.
375 * @note Observers should remove themselves when they are destroyed.
377 void AddObserver( LifeCycleObserver& observer );
380 * Removes the observer from the adaptor.
381 * @param[in] observer The observer to remove.
382 * @note Observers should remove themselves when they are destroyed.
384 void RemoveObserver( LifeCycleObserver& observer );
387 * Emits the Notification event to the Dali core.
389 void SendNotificationEvent();
392 * Request adaptor to update once
394 void RequestUpdateOnce();
397 * @copydoc Dali::Adaptor::NotifySceneCreated()
399 void NotifySceneCreated();
402 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
404 void NotifyLanguageChanged();
407 * Gets AppId of current application
409 void GetAppId( std::string& appId );
412 * @copydoc Dali::Adaptor::SurfaceResizePrepare
414 void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
417 * @copydoc Dali::Adaptor::SurfaceResizeComplete
419 void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
422 * Sets layout direction of root by system language
423 * @param[in] locale System locale
425 void SetRootLayoutDirection( std::string locale );
428 * @copydoc Dali::Adaptor::RenderOnce
433 * @copydoc Dali::Adaptor::GetLogFactory
435 const LogFactoryInterface& GetLogFactory();
438 * @copydoc Dali::Adaptor::RegisterProcessor
440 void RegisterProcessor( Integration::Processor& processor );
443 * @coydoc Dali::Adaptor::UnregisterProcessor
445 void UnregisterProcessor( Integration::Processor& processor );
448 * Check MultipleWindow is supported
450 bool IsMultipleWindowSupported() const;
452 public: //AdaptorInternalServices
455 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
457 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
460 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
462 virtual Dali::DisplayConnection& GetDisplayConnectionInterface();
465 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
467 virtual GraphicsInterface& GetGraphicsInterface();
470 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
472 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
475 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
477 virtual SocketFactoryInterface& GetSocketFactoryInterface();
480 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
482 virtual Dali::RenderSurfaceInterface* GetRenderSurfaceInterface();
485 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
487 virtual PerformanceInterface* GetPerformanceInterface();
490 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
492 virtual TraceInterface& GetKernelTraceInterface();
495 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
497 virtual TraceInterface& GetSystemTraceInterface();
500 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
502 virtual void GetWindowContainerInterface( WindowContainer& windows );
507 * @copydoc Dali::Adaptor::SignalResized
509 AdaptorSignalType& ResizedSignal()
511 return mResizedSignal;
515 * @copydoc Dali::Adaptor::LanguageChangedSignal
517 AdaptorSignalType& LanguageChangedSignal()
519 return mLanguageChangedSignal;
523 * @copydoc Dali::Adaptor::WindowCreatedSignal
525 WindowCreatedSignalType& WindowCreatedSignal()
527 return mWindowCreatedSignal;
530 public: // From Dali::Internal::Adaptor::CoreEventInterface
533 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
535 virtual void ProcessCoreEvents();
537 private: // From Dali::Internal::Adaptor::CoreEventInterface
540 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
542 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
544 private: // From Dali::Integration::RenderController
547 * @copydoc Dali::Integration::RenderController::RequestUpdate()
549 virtual void RequestUpdate( bool forceUpdate );
552 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
554 virtual void RequestProcessEventsOnIdle( bool forceProcess );
556 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
559 * Called when the window becomes fully or partially visible.
561 virtual void OnWindowShown();
564 * Called when the window is fully hidden.
566 virtual void OnWindowHidden();
568 private: // From Dali::Internal::Adaptor::DamageObserver
571 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
573 void OnDamaged( const DamageArea& area );
578 Adaptor(const Adaptor&) = delete;
579 Adaptor& operator=(Adaptor&) = delete;
584 * Assigns the render surface to the adaptor
587 void SetSurface(Dali::RenderSurfaceInterface *surface);
590 * called after surface is created
592 void SurfaceInitialized();
595 * Sends an notification message from main loop idle handler
597 bool ProcessCoreEventsFromIdle();
600 * Gets path for data/resource storage.
601 * @param[out] path Path for data/resource storage
603 void GetDataStoragePath(std::string& path);
606 * Sets up system information if needs
608 void SetupSystemInformation();
611 * Adds a callback to be run when entering an idle state.
613 * A callback of the following type should be used:
617 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
619 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
622 * Removes a previously added the idle enterer callback.
624 void RemoveIdleEnterer( CallbackBase* callback );
630 * @param[in] window window handle
631 * @param[in] adaptor The public adaptor
632 * @param[in] surface A render surface can be one of the following
633 * - Pixmap, adaptor will use existing Pixmap to draw on to
634 * - Window, adaptor will use existing Window to draw on to
635 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
637 Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions );
643 READY, ///< Initial state before Adaptor::Start is called.
644 RUNNING, ///< Adaptor is running.
645 PAUSED, ///< Adaptor has been paused.
646 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
647 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
648 STOPPED, ///< Adaptor has been stopped.
651 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
652 // so we have to store the raw pointer.
653 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
654 using ObserverContainer = std::vector<LifeCycleObserver*>;
658 AdaptorSignalType mResizedSignal; ///< Resized signal.
659 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
660 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
662 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
663 State mState; ///< Current state of the adaptor
664 Dali::Integration::Core* mCore; ///< Dali Core
665 ThreadController* mThreadController; ///< Controls the threads
667 std::unique_ptr< GraphicsInterface > mGraphics; ///< Graphics interface
668 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
669 WindowContainer mWindows; ///< A container of all the Windows that are currently created
671 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
673 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
675 CallbackManager* mCallbackManager; ///< Used to install callbacks
676 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
677 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
678 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
679 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
680 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
681 ObserverContainer mObservers; ///< A list of adaptor observer pointers
682 EnvironmentOptions* mEnvironmentOptions; ///< environment options
683 PerformanceInterface* mPerformanceInterface; ///< Performance interface
684 KernelTrace mKernelTracer; ///< Kernel tracer
685 SystemTrace mSystemTracer; ///< System tracer
686 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
687 SocketFactory mSocketFactory; ///< Socket factory
688 ThreadMode mThreadMode; ///< The thread mode
689 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
690 bool mUseRemoteSurface:1; ///< whether the remoteSurface is used or not
691 Dali::LayoutDirection::Type mRootLayoutDirection; ///< LayoutDirection of window
693 std::unique_ptr<Integration::AddOnManager> mAddOnManager; ///< Pointer to the addon manager
696 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
699 } // namespace Internal
701 } // namespace Adaptor
705 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H