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
252 * @param[in] childWindowName The child window title/name
253 * @param[in] childWindowClassName The class name that the child window belongs to
254 * @param[in] childWindowMode The mode of the child window
256 virtual bool AddWindow( Dali::Integration::SceneHolder childWindow,
257 const std::string& childWindowName,
258 const std::string& childWindowClassName,
259 bool childWindowMode );
262 * Removes an existing Window instance from the Adaptor
263 * @param[in] window The Window instance
265 virtual bool RemoveWindow( Dali::Integration::SceneHolder* childWindow );
268 * Removes an existing Window instance from the Adaptor
269 * @param[in] windowName The Window name
270 * @note If two Windows have the same name, the first one that matches will be removed
272 virtual bool RemoveWindow( std::string childWindowName );
275 * @copydoc Dali::Adaptor::RemoveIdle()
277 virtual void RemoveIdle( CallbackBase* callback );
280 * @copydoc Dali::Adaptor::ProcessIdle()
282 virtual void ProcessIdle();
285 * Sets a pre-render callback.
287 void SetPreRenderCallback( CallbackBase* callback );
290 * Removes an existing Window instance from the Adaptor
291 * @param[in] childWindow The Window instance
293 bool RemoveWindow( Dali::Internal::Adaptor::SceneHolder* childWindow );
296 * @brief Deletes the rendering surface
297 * @param[in] surface to delete
299 void DeleteSurface( Dali::RenderSurfaceInterface& surface );
302 * @brief Retrieve the window that the given actor is added to.
304 * @param[in] actor The actor
305 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
307 Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
310 * @copydoc Dali::Adaptor::GetWindows()
312 Dali::WindowContainer GetWindows() const;
315 * @copydoc Dali::Adaptor::GetSceneHolders()
317 Dali::SceneHolderList GetSceneHolders() const;
320 * @copydoc Dali::Adaptor::GetObjectRegistry()
322 Dali::ObjectRegistry GetObjectRegistry() const;
327 * @return the Core instance
329 virtual Dali::Integration::Core& GetCore();
332 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
334 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
337 * Return the PlatformAbstraction.
338 * @return The PlatformAbstraction.
340 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
343 * Destroy the TtsPlayer of specific mode.
344 * @param[in] mode The mode of TtsPlayer to destroy
346 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
349 * Gets native window handle
351 * @return native window handle
353 Any GetNativeWindowHandle();
356 * @brief Retrieve native window handle that the given actor is added to.
358 * @param[in] actor The actor
359 * @return native window handle
361 Any GetNativeWindowHandle( Dali::Actor actor );
364 * Get the native display associated with the graphics backend
366 * @return A handle to the native display
368 Any GetGraphicsDisplay();
371 * Sets use remote surface for Surface output
372 * @param[in] useRemoteSurface True if the remote surface is used
374 void SetUseRemoteSurface(bool useRemoteSurface);
379 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
380 * @param[in] observer The observer.
381 * @note Observers should remove themselves when they are destroyed.
383 void AddObserver( LifeCycleObserver& observer );
386 * Removes the observer from the adaptor.
387 * @param[in] observer The observer to remove.
388 * @note Observers should remove themselves when they are destroyed.
390 void RemoveObserver( LifeCycleObserver& observer );
393 * Emits the Notification event to the Dali core.
395 void SendNotificationEvent();
398 * Request adaptor to update once
400 void RequestUpdateOnce();
403 * @copydoc Dali::Adaptor::NotifySceneCreated()
405 void NotifySceneCreated();
408 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
410 void NotifyLanguageChanged();
413 * Gets AppId of current application
415 void GetAppId( std::string& appId );
418 * @copydoc Dali::Adaptor::SurfaceResizePrepare
420 void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
423 * @copydoc Dali::Adaptor::SurfaceResizeComplete
425 void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
428 * Sets layout direction of root by system language
429 * @param[in] locale System locale
431 void SetRootLayoutDirection( std::string locale );
434 * @copydoc Dali::Adaptor::RenderOnce
439 * @copydoc Dali::Adaptor::GetLogFactory
441 const LogFactoryInterface& GetLogFactory();
444 * @copydoc Dali::Adaptor::RegisterProcessor
446 void RegisterProcessor( Integration::Processor& processor );
449 * @coydoc Dali::Adaptor::UnregisterProcessor
451 void UnregisterProcessor( Integration::Processor& processor );
454 * Check MultipleWindow is supported
456 bool IsMultipleWindowSupported() const;
458 public: //AdaptorInternalServices
461 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
463 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
466 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
468 virtual Dali::DisplayConnection& GetDisplayConnectionInterface();
471 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
473 virtual GraphicsInterface& GetGraphicsInterface();
476 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
478 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
481 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
483 virtual SocketFactoryInterface& GetSocketFactoryInterface();
486 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
488 virtual Dali::RenderSurfaceInterface* GetRenderSurfaceInterface();
491 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
493 virtual PerformanceInterface* GetPerformanceInterface();
496 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
498 virtual TraceInterface& GetKernelTraceInterface();
501 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
503 virtual TraceInterface& GetSystemTraceInterface();
506 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
508 virtual void GetWindowContainerInterface( WindowContainer& windows );
513 * @copydoc Dali::Adaptor::SignalResized
515 AdaptorSignalType& ResizedSignal()
517 return mResizedSignal;
521 * @copydoc Dali::Adaptor::LanguageChangedSignal
523 AdaptorSignalType& LanguageChangedSignal()
525 return mLanguageChangedSignal;
529 * @copydoc Dali::Adaptor::WindowCreatedSignal
531 WindowCreatedSignalType& WindowCreatedSignal()
533 return mWindowCreatedSignal;
536 public: // From Dali::Internal::Adaptor::CoreEventInterface
539 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
541 virtual void ProcessCoreEvents();
543 private: // From Dali::Internal::Adaptor::CoreEventInterface
546 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
548 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
550 private: // From Dali::Integration::RenderController
553 * @copydoc Dali::Integration::RenderController::RequestUpdate()
555 virtual void RequestUpdate( bool forceUpdate );
558 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
560 virtual void RequestProcessEventsOnIdle( bool forceProcess );
562 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
565 * Called when the window becomes fully or partially visible.
567 virtual void OnWindowShown();
570 * Called when the window is fully hidden.
572 virtual void OnWindowHidden();
574 private: // From Dali::Internal::Adaptor::DamageObserver
577 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
579 void OnDamaged( const DamageArea& area );
584 Adaptor(const Adaptor&) = delete;
585 Adaptor& operator=(Adaptor&) = delete;
590 * Assigns the render surface to the adaptor
593 void SetSurface(Dali::RenderSurfaceInterface *surface);
596 * called after surface is created
598 void SurfaceInitialized();
601 * Sends an notification message from main loop idle handler
603 bool ProcessCoreEventsFromIdle();
606 * Gets path for data/resource storage.
607 * @param[out] path Path for data/resource storage
609 void GetDataStoragePath(std::string& path);
612 * Sets up system information if needs
614 void SetupSystemInformation();
617 * Adds a callback to be run when entering an idle state.
619 * A callback of the following type should be used:
623 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
625 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
628 * Removes a previously added the idle enterer callback.
630 void RemoveIdleEnterer( CallbackBase* callback );
636 * @param[in] window window handle
637 * @param[in] adaptor The public adaptor
638 * @param[in] surface A render surface can be one of the following
639 * - Pixmap, adaptor will use existing Pixmap to draw on to
640 * - Window, adaptor will use existing Window to draw on to
641 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
643 Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions );
649 READY, ///< Initial state before Adaptor::Start is called.
650 RUNNING, ///< Adaptor is running.
651 PAUSED, ///< Adaptor has been paused.
652 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
653 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
654 STOPPED, ///< Adaptor has been stopped.
657 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
658 // so we have to store the raw pointer.
659 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
660 using ObserverContainer = std::vector<LifeCycleObserver*>;
664 AdaptorSignalType mResizedSignal; ///< Resized signal.
665 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
666 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
668 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
669 State mState; ///< Current state of the adaptor
670 Dali::Integration::Core* mCore; ///< Dali Core
671 ThreadController* mThreadController; ///< Controls the threads
673 std::unique_ptr< GraphicsInterface > mGraphics; ///< Graphics interface
674 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
675 WindowContainer mWindows; ///< A container of all the Windows that are currently created
677 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
679 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
681 CallbackManager* mCallbackManager; ///< Used to install callbacks
682 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
683 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
684 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
685 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
686 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
687 ObserverContainer mObservers; ///< A list of adaptor observer pointers
688 EnvironmentOptions* mEnvironmentOptions; ///< environment options
689 PerformanceInterface* mPerformanceInterface; ///< Performance interface
690 KernelTrace mKernelTracer; ///< Kernel tracer
691 SystemTrace mSystemTracer; ///< System tracer
692 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
693 SocketFactory mSocketFactory; ///< Socket factory
694 ThreadMode mThreadMode; ///< The thread mode
695 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
696 bool mUseRemoteSurface:1; ///< whether the remoteSurface is used or not
698 std::unique_ptr<Integration::AddOnManager> mAddOnManager; ///< Pointer to the addon manager
701 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
704 } // namespace Internal
706 } // namespace Adaptor
710 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H