1 #ifndef DALI_INTERNAL_ADAPTOR_IMPL_H
2 #define DALI_INTERNAL_ADAPTOR_IMPL_H
5 * Copyright (c) 2019 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/common/view-mode.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/signals/callback.h>
26 #include <dali/public-api/math/uint-16-pair.h>
27 #include <dali/integration-api/render-controller.h>
30 #include <dali/integration-api/adaptor.h>
31 #include <dali/integration-api/scene.h>
33 #ifdef DALI_ADAPTOR_COMPILATION
34 #include <dali/integration-api/scene-holder-impl.h>
36 #include <dali/integration-api/adaptors/scene-holder-impl.h>
39 #include <dali/public-api/adaptor-framework/tts-player.h>
40 #include <dali/devel-api/adaptor-framework/clipboard.h>
42 #include <dali/internal/graphics/common/graphics-interface.h>
44 #include <dali/internal/legacy/common/tizen-platform-abstraction.h>
45 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
46 #include <dali/internal/system/common/environment-options.h>
47 #include <dali/internal/system/common/core-event-interface.h>
48 #include <dali/internal/window-system/common/damage-observer.h>
49 #include <dali/internal/window-system/common/window-visibility-observer.h>
50 #include <dali/internal/system/common/kernel-trace.h>
51 #include <dali/internal/system/common/system-trace.h>
52 #include <dali/integration-api/trigger-event-factory.h>
53 #include <dali/internal/network/common/socket-factory.h>
59 class RenderSurfaceInterface;
73 class DisplayConnection;
74 class GraphicsFactory;
75 class GlImplementation;
76 class GlSyncImplementation;
77 class ThreadController;
79 class CallbackManager;
80 class FeedbackPluginProxy;
81 class FeedbackController;
83 class PerformanceInterface;
84 class LifeCycleObserver;
89 * Implementation of the Adaptor class.
91 class Adaptor : public Integration::RenderController,
92 public AdaptorInternalServices,
93 public CoreEventInterface,
94 public DamageObserver,
95 public WindowVisibilityObserver
99 using AdaptorSignalType = Dali::Adaptor::AdaptorSignalType;
100 using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType;
102 using SurfaceSize = Uint16Pair; ///< Surface size type
105 * Creates a New Adaptor
106 * @param[in] window The window handle
107 * @param[in] surface A render surface can be one of the following
108 * - Pixmap, adaptor will use existing Pixmap to draw on to
109 * - Window, adaptor will use existing Window to draw on to
110 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
111 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
113 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
114 Dali::RenderSurfaceInterface* surface,
115 Dali::Configuration::ContextLoss configuration,
116 EnvironmentOptions* environmentOptions );
119 * Creates a New Adaptor
120 * @param[in] window The window handle
121 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
122 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
124 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
125 Dali::Configuration::ContextLoss configuration,
126 EnvironmentOptions* environmentOptions );
129 * Creates a New Adaptor
130 * @param[in] graphicsFactory A factory that creates the graphics interface
131 * @param[in] window The window handle
132 * @param[in] surface A render surface can be one of the following
133 * - Pixmap, adaptor will use existing Pixmap to draw on to
134 * - Window, adaptor will use existing Window to draw on to
135 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
136 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
138 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
139 Dali::Integration::SceneHolder window,
140 Dali::RenderSurfaceInterface* surface,
141 Dali::Configuration::ContextLoss configuration,
142 EnvironmentOptions* environmentOptions );
145 * Creates a New Adaptor
146 * @param[in] graphicsFactory A factory that creates the graphics interface
147 * @param[in] window The window handle
148 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
149 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
151 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
152 Dali::Integration::SceneHolder window,
153 Dali::Configuration::ContextLoss configuration,
154 EnvironmentOptions* environmentOptions );
157 * 2-step initialisation, this should be called after creating an adaptor instance.
158 * @param[in] graphicsFactory A factory that creates the graphics interface
159 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
161 void Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration );
164 * Virtual destructor.
169 * @copydoc Dali::Adaptor::Get()
171 static Dali::Adaptor& Get();
174 * @copydoc Dali::Adaptor::IsAvailable()
176 static bool IsAvailable();
179 * @copydoc Dali::Core::SceneCreated();
183 public: // AdaptorInternalServices implementation
185 * @copydoc Dali::Adaptor::Start()
187 virtual void Start();
190 * @copydoc Dali::Adaptor::Pause()
192 virtual void Pause();
195 * @copydoc Dali::Adaptor::Resume()
197 virtual void Resume();
200 * @copydoc Dali::Adaptor::Stop()
205 * @copydoc Dali::Adaptor::ContextLost()
207 virtual void ContextLost();
210 * @copydoc Dali::Adaptor::ContextRegained()
212 virtual void ContextRegained();
215 * @copydoc Dali::EventFeeder::FeedTouchPoint()
217 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
220 * @copydoc Dali::EventFeeder::FeedWheelEvent()
222 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
225 * @copydoc Dali::EventFeeder::FeedKeyEvent()
227 virtual void FeedKeyEvent( KeyEvent& keyEvent );
230 * @copydoc Dali::Adaptor::ReplaceSurface()
232 virtual void ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface );
235 * @copydoc Dali::Adaptor::GetSurface()
237 virtual Dali::RenderSurfaceInterface& GetSurface() const;
240 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
242 virtual void ReleaseSurfaceLock();
245 * Retrieve the TtsPlayer.
246 * @param[in] mode The mode of TtsPlayer
247 * @return A handle to the TtsPlayer.
249 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
252 * @copydoc Dali::Adaptor::AddIdle()
254 virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
257 * Adds a new Window instance to the Adaptor
258 * @param[in] childWindow The child window instance
259 * @param[in] childWindowName The child window title/name
260 * @param[in] childWindowClassName The class name that the child window belongs to
261 * @param[in] childWindowMode The mode of the child window
263 virtual bool AddWindow( Dali::Integration::SceneHolder childWindow,
264 const std::string& childWindowName,
265 const std::string& childWindowClassName,
266 bool childWindowMode );
269 * Removes an existing Window instance from the Adaptor
270 * @param[in] window The Window instance
272 virtual bool RemoveWindow( Dali::Integration::SceneHolder* childWindow );
275 * Removes an existing Window instance from the Adaptor
276 * @param[in] windowName The Window name
277 * @note If two Windows have the same name, the first one that matches will be removed
279 virtual bool RemoveWindow( std::string childWindowName );
282 * @copydoc Dali::Adaptor::RemoveIdle()
284 virtual void RemoveIdle( CallbackBase* callback );
287 * Sets a pre-render callback.
289 void SetPreRenderCallback( CallbackBase* callback );
292 * Removes an existing Window instance from the Adaptor
293 * @param[in] childWindow The Window instance
295 bool RemoveWindow( Dali::Internal::Adaptor::SceneHolder* childWindow );
298 * @brief Deletes the rendering surface
299 * @param[in] surface to delete
301 void DeleteSurface( Dali::RenderSurfaceInterface& surface );
304 * @brief Retrieve the window that the given actor is added to.
306 * @param[in] actor The actor
307 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
309 Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
312 * @copydoc Dali::Adaptor::GetWindows()
314 Dali::WindowContainer GetWindows() const;
317 * @copydoc Dali::Adaptor::GetSceneHolders()
319 Dali::SceneHolderList GetSceneHolders() const;
324 * @return the Core instance
326 virtual Dali::Integration::Core& GetCore();
329 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
331 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
334 * Return the PlatformAbstraction.
335 * @return The PlatformAbstraction.
337 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
340 * Destroy the TtsPlayer of specific mode.
341 * @param[in] mode The mode of TtsPlayer to destroy
343 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
346 * Gets native window handle
348 * @return native window handle
350 Any GetNativeWindowHandle();
353 * @brief Retrieve native window handle that the given actor is added to.
355 * @param[in] actor The actor
356 * @return native window handle
358 Any GetNativeWindowHandle( Dali::Actor actor );
361 * Get the native display associated with the graphics backend
363 * @return A handle to the native display
365 Any GetGraphicsDisplay();
368 * Sets use remote surface for Surface output
369 * @param[in] useRemoteSurface True if the remote surface is used
371 void SetUseRemoteSurface(bool useRemoteSurface);
376 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
377 * @param[in] observer The observer.
378 * @note Observers should remove themselves when they are destroyed.
380 void AddObserver( LifeCycleObserver& observer );
383 * Removes the observer from the adaptor.
384 * @param[in] observer The observer to remove.
385 * @note Observers should remove themselves when they are destroyed.
387 void RemoveObserver( LifeCycleObserver& observer );
390 * Emits the Notification event to the Dali core.
392 void SendNotificationEvent();
395 * Request adaptor to update once
397 void RequestUpdateOnce();
400 * @copydoc Dali::Adaptor::NotifySceneCreated()
402 void NotifySceneCreated();
405 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
407 void NotifyLanguageChanged();
410 * Gets AppId of current application
412 void GetAppId( std::string& appId );
415 * @copydoc Dali::Adaptor::SurfaceResizePrepare
417 void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
420 * @copydoc Dali::Adaptor::SurfaceResizeComplete
422 void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
425 * Sets layout direction of root by system language
426 * @param[in] locale System locale
428 void SetRootLayoutDirection( std::string locale );
431 * @copydoc Dali::Adaptor::RenderOnce
436 * @copydoc Dali::Adaptor::GetLogFactory
438 const LogFactoryInterface& GetLogFactory();
441 * @copydoc Dali::Adaptor::RegisterProcessor
443 void RegisterProcessor( Integration::Processor& processor );
446 * @coydoc Dali::Adaptor::UnregisterProcessor
448 void UnregisterProcessor( Integration::Processor& processor );
450 public: //AdaptorInternalServices
453 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
455 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
458 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
460 virtual Dali::DisplayConnection& GetDisplayConnectionInterface();
463 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
465 virtual GraphicsInterface& GetGraphicsInterface();
468 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
470 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
473 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
475 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
478 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
480 virtual SocketFactoryInterface& GetSocketFactoryInterface();
483 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
485 virtual Dali::RenderSurfaceInterface* GetRenderSurfaceInterface();
488 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
490 virtual PerformanceInterface* GetPerformanceInterface();
493 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
495 virtual TraceInterface& GetKernelTraceInterface();
498 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
500 virtual TraceInterface& GetSystemTraceInterface();
505 * @copydoc Dali::Adaptor::SignalResized
507 AdaptorSignalType& ResizedSignal()
509 return mResizedSignal;
513 * @copydoc Dali::Adaptor::LanguageChangedSignal
515 AdaptorSignalType& LanguageChangedSignal()
517 return mLanguageChangedSignal;
521 * @copydoc Dali::Adaptor::WindowCreatedSignal
523 WindowCreatedSignalType& WindowCreatedSignal()
525 return mWindowCreatedSignal;
528 public: // From Dali::Internal::Adaptor::CoreEventInterface
531 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
533 virtual void ProcessCoreEvents();
535 private: // From Dali::Internal::Adaptor::CoreEventInterface
538 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
540 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
542 private: // From Dali::Integration::RenderController
545 * @copydoc Dali::Integration::RenderController::RequestUpdate()
547 virtual void RequestUpdate( bool forceUpdate );
550 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
552 virtual void RequestProcessEventsOnIdle( bool forceProcess );
554 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
557 * Called when the window becomes fully or partially visible.
559 virtual void OnWindowShown();
562 * Called when the window is fully hidden.
564 virtual void OnWindowHidden();
566 private: // From Dali::Internal::Adaptor::DamageObserver
569 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
571 void OnDamaged( const DamageArea& area );
576 Adaptor(const Adaptor&) = delete;
577 Adaptor& operator=(Adaptor&) = delete;
582 * Assigns the render surface to the adaptor
585 void SetSurface(Dali::RenderSurfaceInterface *surface);
588 * called after surface is created
590 void SurfaceInitialized();
593 * Sends an notification message from main loop idle handler
595 bool ProcessCoreEventsFromIdle();
598 * Gets path for data/resource storage.
599 * @param[out] path Path for data/resource storage
601 void GetDataStoragePath(std::string& path);
604 * Sets up system information if needs
606 void SetupSystemInformation();
609 * Adds a callback to be run when entering an idle state.
611 * A callback of the following type should be used:
615 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
617 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
620 * Removes a previously added the idle enterer callback.
622 void RemoveIdleEnterer( CallbackBase* callback );
628 * @param[in] window window handle
629 * @param[in] adaptor The public adaptor
630 * @param[in] surface A render surface can be one of the following
631 * - Pixmap, adaptor will use existing Pixmap to draw on to
632 * - Window, adaptor will use existing Window to draw on to
633 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
635 Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions );
641 READY, ///< Initial state before Adaptor::Start is called.
642 RUNNING, ///< Adaptor is running.
643 PAUSED, ///< Adaptor has been paused.
644 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
645 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
646 STOPPED, ///< Adaptor has been stopped.
649 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
650 // so we have to store the raw pointer.
651 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
652 using ObserverContainer = std::vector<LifeCycleObserver*>;
656 AdaptorSignalType mResizedSignal; ///< Resized signal.
657 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
658 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
660 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
661 State mState; ///< Current state of the adaptor
662 Dali::Integration::Core* mCore; ///< Dali Core
663 ThreadController* mThreadController; ///< Controls the threads
665 GraphicsInterface* mGraphics; ///< Graphics interface
666 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
667 WindowContainer mWindows; ///< A container of all the Windows that are currently created
669 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
671 CallbackManager* mCallbackManager; ///< Used to install callbacks
672 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
673 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
674 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
675 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
676 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
677 ObserverContainer mObservers; ///< A list of adaptor observer pointers
678 EnvironmentOptions* mEnvironmentOptions; ///< environment options
679 PerformanceInterface* mPerformanceInterface; ///< Performance interface
680 KernelTrace mKernelTracer; ///< Kernel tracer
681 SystemTrace mSystemTracer; ///< System tracer
682 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
683 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
684 SocketFactory mSocketFactory; ///< Socket factory
685 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
686 bool mUseRemoteSurface; ///< whether the remoteSurface is used or not
689 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
692 } // namespace Internal
694 } // namespace Adaptor
698 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H