1 #ifndef DALI_INTERNAL_ADAPTOR_IMPL_H
2 #define DALI_INTERNAL_ADAPTOR_IMPL_H
5 * Copyright (c) 2018 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>
32 #include <dali/public-api/adaptor-framework/tts-player.h>
33 #include <dali/devel-api/adaptor-framework/clipboard.h>
35 #include <dali/internal/graphics/common/graphics-interface.h>
37 #include <dali/internal/legacy/common/tizen-platform-abstraction.h>
38 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
39 #include <dali/internal/system/common/environment-options.h>
40 #include <dali/internal/system/common/core-event-interface.h>
41 #include <dali/internal/input/common/drag-and-drop-detector-impl.h>
42 #include <dali/internal/window-system/common/damage-observer.h>
43 #include <dali/internal/window-system/common/window-impl.h>
44 #include <dali/internal/window-system/common/window-visibility-observer.h>
45 #include <dali/internal/system/common/kernel-trace.h>
46 #include <dali/internal/system/common/system-trace.h>
47 #include <dali/integration-api/trigger-event-factory.h>
48 #include <dali/internal/network/common/socket-factory.h>
54 class RenderSurfaceInterface;
69 class DisplayConnection;
70 class GraphicsFactory;
72 class GlImplementation;
73 class GlSyncImplementation;
74 class ThreadController;
76 class CallbackManager;
77 class FeedbackPluginProxy;
78 class FeedbackController;
79 class RotationObserver;
81 class PerformanceInterface;
82 class LifeCycleObserver;
86 * Implementation of the Adaptor class.
88 class Adaptor : public Integration::RenderController,
89 public AdaptorInternalServices,
90 public CoreEventInterface,
91 public DamageObserver,
92 public WindowVisibilityObserver
96 typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
98 typedef Uint16Pair SurfaceSize; ///< Surface size type
101 * Creates a New Adaptor
102 * @param[in] window The window handle
103 * @param[in] surface A render surface can be one of the following
104 * - Pixmap, adaptor will use existing Pixmap to draw on to
105 * - Window, adaptor will use existing Window to draw on to
106 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
107 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
109 static Dali::Adaptor* New( Dali::Window window,
110 Dali::RenderSurfaceInterface* surface,
111 Dali::Configuration::ContextLoss configuration,
112 EnvironmentOptions* environmentOptions );
115 * Creates a New Adaptor
116 * @param[in] window The window handle
117 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
118 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
120 static Dali::Adaptor* New( Dali::Window window,
121 Dali::Configuration::ContextLoss configuration,
122 EnvironmentOptions* environmentOptions );
125 * Creates a New Adaptor
126 * @param[in] graphicsFactory A factory that creates the graphics interface
127 * @param[in] window The window handle
128 * @param[in] surface A render surface can be one of the following
129 * - Pixmap, adaptor will use existing Pixmap to draw on to
130 * - Window, adaptor will use existing Window to draw on to
131 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
132 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
134 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
136 Dali::RenderSurfaceInterface* surface,
137 Dali::Configuration::ContextLoss configuration,
138 EnvironmentOptions* environmentOptions );
141 * Creates a New Adaptor
142 * @param[in] graphicsFactory A factory that creates the graphics interface
143 * @param[in] window The window handle
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.
147 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
149 Dali::Configuration::ContextLoss configuration,
150 EnvironmentOptions* environmentOptions );
153 * 2-step initialisation, this should be called after creating an adaptor instance.
154 * @param[in] graphicsFactory A factory that creates the graphics interface
155 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
157 void Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration );
160 * Virtual destructor.
165 * @copydoc Dali::Adaptor::Get()
167 static Dali::Adaptor& Get();
170 * @copydoc Dali::Adaptor::IsAvailable()
172 static bool IsAvailable();
175 * @copydoc Dali::Core::SceneCreated();
179 public: // AdaptorInternalServices implementation
181 * @copydoc Dali::Adaptor::Start()
183 virtual void Start();
186 * @copydoc Dali::Adaptor::Pause()
188 virtual void Pause();
191 * @copydoc Dali::Adaptor::Resume()
193 virtual void Resume();
196 * @copydoc Dali::Adaptor::Stop()
201 * @copydoc Dali::Adaptor::ContextLost()
203 virtual void ContextLost();
206 * @copydoc Dali::Adaptor::ContextRegained()
208 virtual void ContextRegained();
211 * @copydoc Dali::EventFeeder::FeedTouchPoint()
213 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
216 * @copydoc Dali::EventFeeder::FeedWheelEvent()
218 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
221 * @copydoc Dali::EventFeeder::FeedKeyEvent()
223 virtual void FeedKeyEvent( KeyEvent& keyEvent );
226 * @copydoc AdaptorInterface::ReplaceSurface()
228 virtual void ReplaceSurface( Dali::Window window, Dali::RenderSurfaceInterface& surface );
231 * @copydoc Dali::Adaptor::GetSurface()
233 virtual Dali::RenderSurfaceInterface& GetSurface() const;
236 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
238 virtual void ReleaseSurfaceLock();
241 * Retrieve the TtsPlayer.
242 * @param[in] mode The mode of TtsPlayer
243 * @return A handle to the TtsPlayer.
245 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
248 * @copydoc Dali::Adaptor::AddIdle()
250 virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
253 * Adds a new Window instance to the Adaptor
254 * @param[in] childWindow The child window instance
255 * @param[in] childWindowName The child window title/name
256 * @param[in] childWindowClassName The class name that the child window belongs to
257 * @param[in] childWindowMode The mode of the child window
259 virtual bool AddWindow( Dali::Window* childWindow,
260 const std::string& childWindowName,
261 const std::string& childWindowClassName,
262 const bool& childWindowMode );
265 * Removes an existing Window instance from the Adaptor
266 * @param[in] window The Window instance
268 virtual bool RemoveWindow( Dali::Window* childWindow );
271 * Removes an existing Window instance from the Adaptor
272 * @param[in] windowName The Window name
273 * @note If two Windows have the same name, the first one that matches will be removed
275 virtual bool RemoveWindow( std::string childWindowName );
278 * @copydoc Dali::Adaptor::RemoveIdle()
280 virtual void RemoveIdle( CallbackBase* callback );
283 * Sets a pre-render callback.
285 void SetPreRenderCallback( CallbackBase* callback );
288 * Removes an existing Window instance from the Adaptor
289 * @param[in] childWindow The Window instance
291 bool RemoveWindow( Dali::Internal::Adaptor::Window* childWindow );
296 * @return the Core instance
298 virtual Dali::Integration::Core& GetCore();
301 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
303 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
306 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
308 void SetUseHardwareVSync(bool useHardware);
311 * Return the PlatformAbstraction.
312 * @return The PlatformAbstraction.
314 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
317 * Sets the Drag & Drop Listener.
318 * @param[in] detector The detector to send Drag & Drop events to.
320 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
323 * Sets a rotation observer, or set to NULL to remove.
324 * @pre Adaptor::Start() has been called ( to create EventHandler )
325 * @param[in] observer The observer to listen for window rotation events
327 void SetRotationObserver( RotationObserver* observer );
330 * Destroy the TtsPlayer of specific mode.
331 * @param[in] mode The mode of TtsPlayer to destroy
333 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
336 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
337 * trigger a pinch gesture
339 * @param[in] distance The minimum pinch distance in pixels
341 void SetMinimumPinchDistance(float distance);
344 * Gets native window handle
346 * @return native window handle
348 Any GetNativeWindowHandle();
351 * Get the native display associated with the graphics backend
353 * @return A handle to the native display
355 Any GetGraphicsDisplay();
358 * Sets use remote surface for Surface output
359 * @param[in] useRemoteSurface True if the remote surface is used
361 void SetUseRemoteSurface(bool useRemoteSurface);
366 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
367 * @param[in] observer The observer.
368 * @note Observers should remove themselves when they are destroyed.
370 void AddObserver( LifeCycleObserver& observer );
373 * Removes the observer from the adaptor.
374 * @param[in] observer The observer to remove.
375 * @note Observers should remove themselves when they are destroyed.
377 void RemoveObserver( LifeCycleObserver& observer );
380 * Emits the Notification event to the Dali core.
382 void SendNotificationEvent();
385 * Request adaptor to update once
387 void RequestUpdateOnce();
390 * @copydoc Dali::Adaptor::NotifySceneCreated()
392 void NotifySceneCreated();
395 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
397 void NotifyLanguageChanged();
400 * Gets AppId of current application
402 void GetAppId( std::string& appId );
405 * Informs core the surface size has changed
407 void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
410 * Informs ThreadController the surface size has changed
412 void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
415 * Sets layout direction of root by system language
416 * @param[in] locale System locale
418 void SetRootLayoutDirection( std::string locale );
421 * @copydoc Dali::Adaptor::RenderOnce
426 * @copydoc Dali::Adaptor::GetLogFactory
428 const LogFactoryInterface& GetLogFactory();
431 * @copydoc Dali::Adaptor::RegisterProcessor
433 void RegisterProcessor( Integration::Processor& processor );
436 * @coydoc Dali::Adaptor::UnregisterProcessor
438 void UnregisterProcessor( Integration::Processor& processor );
440 public: //AdaptorInternalServices
443 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
445 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
448 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
450 virtual Dali::DisplayConnection& GetDisplayConnectionInterface();
453 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
455 virtual GraphicsInterface& GetGraphicsInterface();
458 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
460 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
463 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
465 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
468 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
470 virtual SocketFactoryInterface& GetSocketFactoryInterface();
473 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
475 virtual Dali::RenderSurfaceInterface* GetRenderSurfaceInterface();
478 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
480 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
483 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
485 virtual PerformanceInterface* GetPerformanceInterface();
488 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
490 virtual TraceInterface& GetKernelTraceInterface();
493 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
495 virtual TraceInterface& GetSystemTraceInterface();
500 * @copydoc Dali::Adaptor::SignalResized
502 AdaptorSignalType& ResizedSignal()
504 return mResizedSignal;
508 * @copydoc Dali::Adaptor::LanguageChangedSignal
510 AdaptorSignalType& LanguageChangedSignal()
512 return mLanguageChangedSignal;
516 * Gets the gesture manager.
517 * @return The GestureManager
519 GestureManager* GetGestureManager() const
521 return mGestureManager;
524 private: // From Dali::Internal::Adaptor::CoreEventInterface
527 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
529 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
532 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
534 virtual void ProcessCoreEvents();
536 private: // From Dali::Integration::RenderController
539 * @copydoc Dali::Integration::RenderController::RequestUpdate()
541 virtual void RequestUpdate( bool forceUpdate );
544 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
546 virtual void RequestProcessEventsOnIdle( bool forceProcess );
548 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
551 * Called when the window becomes fully or partially visible.
553 virtual void OnWindowShown();
556 * Called when the window is fully hidden.
558 virtual void OnWindowHidden();
560 private: // From Dali::Internal::Adaptor::DamageObserver
563 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
565 void OnDamaged( const DamageArea& area );
570 Adaptor(const Adaptor&) = delete;
571 Adaptor& operator=(Adaptor&) = delete;
576 * Assigns the render surface to the adaptor
579 void SetSurface(Dali::RenderSurfaceInterface *surface);
582 * called after surface is created
584 void SurfaceInitialized();
587 * Sends an notification message from main loop idle handler
589 bool ProcessCoreEventsFromIdle();
592 * Gets path for data/resource storage.
593 * @param[out] path Path for data/resource storage
595 void GetDataStoragePath(std::string& path);
598 * Sets up system information if needs
600 void SetupSystemInformation();
603 * Adds a callback to be run when entering an idle state.
605 * A callback of the following type should be used:
609 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
611 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
614 * Removes a previously added the idle enterer callback.
616 void RemoveIdleEnterer( CallbackBase* callback );
622 * @param[in] window window handle
623 * @param[in] adaptor The public adaptor
624 * @param[in] surface A render surface can be one of the following
625 * - Pixmap, adaptor will use existing Pixmap to draw on to
626 * - Window, adaptor will use existing Window to draw on to
627 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
629 Adaptor( Dali::Window window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions );
635 READY, ///< Initial state before Adaptor::Start is called.
636 RUNNING, ///< Adaptor is running.
637 PAUSED, ///< Adaptor has been paused.
638 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
639 STOPPED, ///< Adaptor has been stopped.
642 using WindowPtr = IntrusivePtr< Window >;
643 using WindowContainer = std::vector<WindowPtr>;
644 using ObserverContainer = std::vector<LifeCycleObserver*>;
648 AdaptorSignalType mResizedSignal; ///< Resized signal.
649 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
651 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
652 State mState; ///< Current state of the adaptor
653 Dali::Integration::Core* mCore; ///< Dali Core
654 ThreadController* mThreadController; ///< Controls the threads
655 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
657 GraphicsInterface* mGraphics; ///< Graphics interface
658 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
659 WindowContainer mWindows; ///< A container of all the Windows that are currently created
661 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
663 CallbackManager* mCallbackManager; ///< Used to install callbacks
664 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
665 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
666 GestureManager* mGestureManager; ///< Gesture manager
667 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
668 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
669 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
670 ObserverContainer mObservers; ///< A list of adaptor observer pointers
671 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
672 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
673 EnvironmentOptions* mEnvironmentOptions; ///< environment options
674 PerformanceInterface* mPerformanceInterface; ///< Performance interface
675 KernelTrace mKernelTracer; ///< Kernel tracer
676 SystemTrace mSystemTracer; ///< System tracer
677 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
678 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
679 SocketFactory mSocketFactory; ///< Socket factory
680 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
681 bool mUseRemoteSurface; ///< whether the remoteSurface is used or not
684 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
687 } // namespace Internal
689 } // namespace Adaptor
693 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H