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;
63 class DisplayConnection;
64 class GraphicsFactory;
65 class GlImplementation;
66 class GlSyncImplementation;
67 class ThreadController;
69 class CallbackManager;
70 class FeedbackPluginProxy;
71 class FeedbackController;
73 class PerformanceInterface;
74 class LifeCycleObserver;
77 class ConfigurationManager;
78 enum class ThreadMode;
81 * Implementation of the Adaptor class.
83 class Adaptor : public Integration::RenderController,
84 public AdaptorInternalServices,
85 public CoreEventInterface,
86 public DamageObserver,
87 public WindowVisibilityObserver
91 using AdaptorSignalType = Dali::Adaptor::AdaptorSignalType;
92 using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType;
94 using SurfaceSize = Uint16Pair; ///< Surface size type
97 * Creates a New Adaptor
98 * @param[in] window The window handle
99 * @param[in] surface A render surface can be one of the following
100 * - Pixmap, adaptor will use existing Pixmap to draw on to
101 * - Window, adaptor will use existing Window to draw on to
102 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
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 Dali::Configuration::ContextLoss configuration,
108 EnvironmentOptions* environmentOptions );
111 * Creates a New Adaptor
112 * @param[in] window The window handle
113 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
114 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
116 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
117 Dali::Configuration::ContextLoss configuration,
118 EnvironmentOptions* environmentOptions );
121 * Creates a New Adaptor
122 * @param[in] graphicsFactory A factory that creates the graphics interface
123 * @param[in] window The window handle
124 * @param[in] surface A render surface can be one of the following
125 * - Pixmap, adaptor will use existing Pixmap to draw on to
126 * - Window, adaptor will use existing Window to draw on to
127 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
128 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
130 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
131 Dali::Integration::SceneHolder window,
132 Dali::RenderSurfaceInterface* surface,
133 Dali::Configuration::ContextLoss configuration,
134 EnvironmentOptions* environmentOptions );
137 * Creates a New Adaptor
138 * @param[in] graphicsFactory A factory that creates the graphics interface
139 * @param[in] window The window handle
140 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
141 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
143 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
144 Dali::Integration::SceneHolder window,
145 Dali::Configuration::ContextLoss configuration,
146 EnvironmentOptions* environmentOptions );
149 * 2-step initialisation, this should be called after creating an adaptor instance.
150 * @param[in] graphicsFactory A factory that creates the graphics interface
151 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
153 void Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration );
156 * Virtual destructor.
161 * @copydoc Dali::Adaptor::Get()
163 static Dali::Adaptor& Get();
166 * @copydoc Dali::Adaptor::IsAvailable()
168 static bool IsAvailable();
171 * @copydoc Dali::Core::SceneCreated();
175 public: // AdaptorInternalServices implementation
177 * @copydoc Dali::Adaptor::Start()
179 virtual void Start();
182 * @copydoc Dali::Adaptor::Pause()
184 virtual void Pause();
187 * @copydoc Dali::Adaptor::Resume()
189 virtual void Resume();
192 * @copydoc Dali::Adaptor::Stop()
197 * @copydoc Dali::Adaptor::ContextLost()
199 virtual void ContextLost();
202 * @copydoc Dali::Adaptor::ContextRegained()
204 virtual void ContextRegained();
207 * @copydoc Dali::EventFeeder::FeedTouchPoint()
209 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
212 * @copydoc Dali::EventFeeder::FeedWheelEvent()
214 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
217 * @copydoc Dali::EventFeeder::FeedKeyEvent()
219 virtual void FeedKeyEvent( KeyEvent& keyEvent );
222 * @copydoc Dali::Adaptor::ReplaceSurface()
224 virtual void ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface );
227 * @copydoc Dali::Adaptor::GetSurface()
229 virtual Dali::RenderSurfaceInterface& GetSurface() const;
232 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
234 virtual void ReleaseSurfaceLock();
237 * Retrieve the TtsPlayer.
238 * @param[in] mode The mode of TtsPlayer
239 * @return A handle to the TtsPlayer.
241 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
244 * @copydoc Dali::Adaptor::AddIdle()
246 virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
249 * Adds a new Window instance to the Adaptor
250 * @param[in] childWindow The child window instance
251 * @param[in] childWindowName The child window title/name
252 * @param[in] childWindowClassName The class name that the child window belongs to
253 * @param[in] childWindowMode The mode of the child window
255 virtual bool AddWindow( Dali::Integration::SceneHolder childWindow,
256 const std::string& childWindowName,
257 const std::string& childWindowClassName,
258 bool childWindowMode );
261 * Removes an existing Window instance from the Adaptor
262 * @param[in] window The Window instance
264 virtual bool RemoveWindow( Dali::Integration::SceneHolder* childWindow );
267 * Removes an existing Window instance from the Adaptor
268 * @param[in] windowName The Window name
269 * @note If two Windows have the same name, the first one that matches will be removed
271 virtual bool RemoveWindow( std::string childWindowName );
274 * @copydoc Dali::Adaptor::RemoveIdle()
276 virtual void RemoveIdle( CallbackBase* callback );
279 * @copydoc Dali::Adaptor::ProcessIdle()
281 virtual void ProcessIdle();
284 * Sets a pre-render callback.
286 void SetPreRenderCallback( CallbackBase* callback );
289 * Removes an existing Window instance from the Adaptor
290 * @param[in] childWindow The Window instance
292 bool RemoveWindow( Dali::Internal::Adaptor::SceneHolder* childWindow );
295 * @brief Deletes the rendering surface
296 * @param[in] surface to delete
298 void DeleteSurface( Dali::RenderSurfaceInterface& surface );
301 * @brief Retrieve the window that the given actor is added to.
303 * @param[in] actor The actor
304 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
306 Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
309 * @copydoc Dali::Adaptor::GetWindows()
311 Dali::WindowContainer GetWindows() const;
314 * @copydoc Dali::Adaptor::GetSceneHolders()
316 Dali::SceneHolderList GetSceneHolders() const;
319 * @copydoc Dali::Adaptor::GetObjectRegistry()
321 Dali::ObjectRegistry GetObjectRegistry() const;
326 * @return the Core instance
328 virtual Dali::Integration::Core& GetCore();
331 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
333 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
336 * Return the PlatformAbstraction.
337 * @return The PlatformAbstraction.
339 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
342 * Destroy the TtsPlayer of specific mode.
343 * @param[in] mode The mode of TtsPlayer to destroy
345 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
348 * Gets native window handle
350 * @return native window handle
352 Any GetNativeWindowHandle();
355 * @brief Retrieve native window handle that the given actor is added to.
357 * @param[in] actor The actor
358 * @return native window handle
360 Any GetNativeWindowHandle( Dali::Actor actor );
363 * Get the native display associated with the graphics backend
365 * @return A handle to the native display
367 Any GetGraphicsDisplay();
370 * Sets use remote surface for Surface output
371 * @param[in] useRemoteSurface True if the remote surface is used
373 void SetUseRemoteSurface(bool useRemoteSurface);
378 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
379 * @param[in] observer The observer.
380 * @note Observers should remove themselves when they are destroyed.
382 void AddObserver( LifeCycleObserver& observer );
385 * Removes the observer from the adaptor.
386 * @param[in] observer The observer to remove.
387 * @note Observers should remove themselves when they are destroyed.
389 void RemoveObserver( LifeCycleObserver& observer );
392 * Emits the Notification event to the Dali core.
394 void SendNotificationEvent();
397 * Request adaptor to update once
399 void RequestUpdateOnce();
402 * @copydoc Dali::Adaptor::NotifySceneCreated()
404 void NotifySceneCreated();
407 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
409 void NotifyLanguageChanged();
412 * Gets AppId of current application
414 void GetAppId( std::string& appId );
417 * @copydoc Dali::Adaptor::SurfaceResizePrepare
419 void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
422 * @copydoc Dali::Adaptor::SurfaceResizeComplete
424 void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
427 * Sets layout direction of root by system language
428 * @param[in] locale System locale
430 void SetRootLayoutDirection( std::string locale );
433 * @copydoc Dali::Adaptor::RenderOnce
438 * @copydoc Dali::Adaptor::GetLogFactory
440 const LogFactoryInterface& GetLogFactory();
443 * @copydoc Dali::Adaptor::RegisterProcessor
445 void RegisterProcessor( Integration::Processor& processor );
448 * @coydoc Dali::Adaptor::UnregisterProcessor
450 void UnregisterProcessor( Integration::Processor& processor );
453 * Check MultipleWindow is supported
455 bool IsMultipleWindowSupported() const;
457 public: //AdaptorInternalServices
460 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
462 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
465 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
467 virtual Dali::DisplayConnection& GetDisplayConnectionInterface();
470 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
472 virtual GraphicsInterface& GetGraphicsInterface();
475 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
477 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
480 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
482 virtual SocketFactoryInterface& GetSocketFactoryInterface();
485 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
487 virtual Dali::RenderSurfaceInterface* GetRenderSurfaceInterface();
490 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
492 virtual PerformanceInterface* GetPerformanceInterface();
495 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
497 virtual TraceInterface& GetKernelTraceInterface();
500 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
502 virtual TraceInterface& GetSystemTraceInterface();
505 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
507 virtual void GetWindowContainerInterface( WindowContainer& windows );
512 * @copydoc Dali::Adaptor::SignalResized
514 AdaptorSignalType& ResizedSignal()
516 return mResizedSignal;
520 * @copydoc Dali::Adaptor::LanguageChangedSignal
522 AdaptorSignalType& LanguageChangedSignal()
524 return mLanguageChangedSignal;
528 * @copydoc Dali::Adaptor::WindowCreatedSignal
530 WindowCreatedSignalType& WindowCreatedSignal()
532 return mWindowCreatedSignal;
535 public: // From Dali::Internal::Adaptor::CoreEventInterface
538 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
540 virtual void ProcessCoreEvents();
542 private: // From Dali::Internal::Adaptor::CoreEventInterface
545 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
547 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
549 private: // From Dali::Integration::RenderController
552 * @copydoc Dali::Integration::RenderController::RequestUpdate()
554 virtual void RequestUpdate( bool forceUpdate );
557 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
559 virtual void RequestProcessEventsOnIdle( bool forceProcess );
561 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
564 * Called when the window becomes fully or partially visible.
566 virtual void OnWindowShown();
569 * Called when the window is fully hidden.
571 virtual void OnWindowHidden();
573 private: // From Dali::Internal::Adaptor::DamageObserver
576 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
578 void OnDamaged( const DamageArea& area );
583 Adaptor(const Adaptor&) = delete;
584 Adaptor& operator=(Adaptor&) = delete;
589 * Assigns the render surface to the adaptor
592 void SetSurface(Dali::RenderSurfaceInterface *surface);
595 * called after surface is created
597 void SurfaceInitialized();
600 * Sends an notification message from main loop idle handler
602 bool ProcessCoreEventsFromIdle();
605 * Gets path for data/resource storage.
606 * @param[out] path Path for data/resource storage
608 void GetDataStoragePath(std::string& path);
611 * Sets up system information if needs
613 void SetupSystemInformation();
616 * Adds a callback to be run when entering an idle state.
618 * A callback of the following type should be used:
622 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
624 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
627 * Removes a previously added the idle enterer callback.
629 void RemoveIdleEnterer( CallbackBase* callback );
635 * @param[in] window window handle
636 * @param[in] adaptor The public adaptor
637 * @param[in] surface A render surface can be one of the following
638 * - Pixmap, adaptor will use existing Pixmap to draw on to
639 * - Window, adaptor will use existing Window to draw on to
640 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
642 Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions );
648 READY, ///< Initial state before Adaptor::Start is called.
649 RUNNING, ///< Adaptor is running.
650 PAUSED, ///< Adaptor has been paused.
651 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
652 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
653 STOPPED, ///< Adaptor has been stopped.
656 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
657 // so we have to store the raw pointer.
658 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
659 using ObserverContainer = std::vector<LifeCycleObserver*>;
663 AdaptorSignalType mResizedSignal; ///< Resized signal.
664 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
665 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
667 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
668 State mState; ///< Current state of the adaptor
669 Dali::Integration::Core* mCore; ///< Dali Core
670 ThreadController* mThreadController; ///< Controls the threads
672 std::unique_ptr< GraphicsInterface > mGraphics; ///< Graphics interface
673 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
674 WindowContainer mWindows; ///< A container of all the Windows that are currently created
676 std::unique_ptr<ConfigurationManager> mConfigurationManager; ///< Configuration manager
678 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
680 CallbackManager* mCallbackManager; ///< Used to install callbacks
681 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
682 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
683 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
684 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
685 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
686 ObserverContainer mObservers; ///< A list of adaptor observer pointers
687 EnvironmentOptions* mEnvironmentOptions; ///< environment options
688 PerformanceInterface* mPerformanceInterface; ///< Performance interface
689 KernelTrace mKernelTracer; ///< Kernel tracer
690 SystemTrace mSystemTracer; ///< System tracer
691 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
692 SocketFactory mSocketFactory; ///< Socket factory
693 ThreadMode mThreadMode; ///< The thread mode
694 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
695 bool mUseRemoteSurface:1; ///< whether the remoteSurface is used or not
698 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
701 } // namespace Internal
703 } // namespace Adaptor
707 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H