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/public-api/adaptor-framework/tts-player.h>
32 #include <dali/devel-api/adaptor-framework/clipboard.h>
34 #include <dali/internal/graphics/common/graphics-interface.h>
36 #include <dali/internal/legacy/common/tizen-platform-abstraction.h>
37 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
38 #include <dali/internal/system/common/environment-options.h>
39 #include <dali/internal/system/common/core-event-interface.h>
40 #include <dali/internal/input/common/drag-and-drop-detector-impl.h>
41 #include <dali/internal/window-system/common/damage-observer.h>
42 #include <dali/internal/window-system/common/window-visibility-observer.h>
43 #include <dali/internal/system/common/kernel-trace.h>
44 #include <dali/internal/system/common/system-trace.h>
45 #include <dali/integration-api/trigger-event-factory.h>
46 #include <dali/internal/network/common/socket-factory.h>
66 class DisplayConnection;
67 class GraphicsFactory;
70 class GlImplementation;
71 class GlSyncImplementation;
72 class ThreadController;
74 class CallbackManager;
75 class FeedbackPluginProxy;
76 class FeedbackController;
77 class RotationObserver;
79 class PerformanceInterface;
80 class LifeCycleObserver;
84 * Implementation of the Adaptor class.
86 class Adaptor : public Integration::RenderController,
87 public AdaptorInternalServices,
88 public CoreEventInterface,
89 public DamageObserver,
90 public WindowVisibilityObserver
94 typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
96 typedef Uint16Pair SurfaceSize; ///< Surface size type
99 * Creates a New Adaptor
100 * @param[in] nativeWindow Native window handle
101 * @param[in] surface A render surface can be one of the following
102 * - Pixmap, adaptor will use existing Pixmap to draw on to
103 * - Window, adaptor will use existing Window to draw on to
104 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
105 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
107 static Dali::Adaptor* New( Any nativeWindow,
108 RenderSurface* surface,
109 Dali::Configuration::ContextLoss configuration,
110 EnvironmentOptions* environmentOptions );
113 * Creates a New Adaptor
114 * @param[in] nativeWindow native window handle
115 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
116 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
118 static Dali::Adaptor* New( Dali::Window window,
119 Dali::Configuration::ContextLoss configuration,
120 EnvironmentOptions* environmentOptions );
123 * Creates a New Adaptor
124 * @param[in] graphicsFactory A factory that creates the graphics interface
125 * @param[in] nativeWindow Native window handle
126 * @param[in] surface A render surface can be one of the following
127 * - Pixmap, adaptor will use existing Pixmap to draw on to
128 * - Window, adaptor will use existing Window to draw on to
129 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
130 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
132 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
134 RenderSurface* surface,
135 Dali::Configuration::ContextLoss configuration,
136 EnvironmentOptions* environmentOptions );
139 * Creates a New Adaptor
140 * @param[in] graphicsFactory A factory that creates the graphics interface
141 * @param[in] nativeWindow native window handle
142 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
143 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
145 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
147 Dali::Configuration::ContextLoss configuration,
148 EnvironmentOptions* environmentOptions );
151 * 2-step initialisation, this should be called after creating an adaptor instance.
152 * @param[in] graphicsFactory A factory that creates the graphics interface
153 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
155 void Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration );
158 * Virtual destructor.
163 * @copydoc Dali::Adaptor::Get()
165 static Dali::Adaptor& Get();
168 * @copydoc Dali::Adaptor::IsAvailable()
170 static bool IsAvailable();
173 * @copydoc Dali::Core::SceneCreated();
177 public: // AdaptorInternalServices implementation
179 * @copydoc Dali::Adaptor::Start()
181 virtual void Start();
184 * @copydoc Dali::Adaptor::Pause()
186 virtual void Pause();
189 * @copydoc Dali::Adaptor::Resume()
191 virtual void Resume();
194 * @copydoc Dali::Adaptor::Stop()
199 * @copydoc Dali::Adaptor::ContextLost()
201 virtual void ContextLost();
204 * @copydoc Dali::Adaptor::ContextRegained()
206 virtual void ContextRegained();
209 * @copydoc Dali::EventFeeder::FeedTouchPoint()
211 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
214 * @copydoc Dali::EventFeeder::FeedWheelEvent()
216 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
219 * @copydoc Dali::EventFeeder::FeedKeyEvent()
221 virtual void FeedKeyEvent( KeyEvent& keyEvent );
224 * @copydoc AdaptorInterface::ReplaceSurface()
226 virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
229 * @copydoc Dali::Adaptor::GetSurface()
231 virtual RenderSurface& GetSurface() const;
234 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
236 virtual void ReleaseSurfaceLock();
239 * Retrieve the TtsPlayer.
240 * @param[in] mode The mode of TtsPlayer
241 * @return A handle to the TtsPlayer.
243 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
246 * @copydoc Dali::Adaptor::AddIdle()
248 virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
251 * Adds a new Window instance to the Adaptor
252 * @param[in] childWindow The child window instance
253 * @param[in] childWindowName The child window title/name
254 * @param[in] childWindowClassName The class name that the child window belongs to
255 * @param[in] childWindowMode The mode of the child window
257 virtual bool AddWindow( Dali::Window* childWindow,
258 const std::string& childWindowName,
259 const std::string& childWindowClassName,
260 const bool& childWindowMode );
263 * Removes an existing Window instance from the Adaptor
264 * @param[in] window The Window instance
266 virtual bool RemoveWindow( Dali::Window* childWindow );
269 * Removes an existing Window instance from the Adaptor
270 * @param[in] windowName The Window name
271 * @note If two Windows have the same name, the first one that matches will be removed
273 virtual bool RemoveWindow( std::string childWindowName );
276 * @copydoc Dali::Adaptor::RemoveIdle()
278 virtual void RemoveIdle( CallbackBase* callback );
281 * Sets a pre-render callback.
283 void SetPreRenderCallback( CallbackBase* callback );
288 * @return the Core instance
290 virtual Dali::Integration::Core& GetCore();
293 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
295 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
298 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
300 void SetUseHardwareVSync(bool useHardware);
303 * Return the PlatformAbstraction.
304 * @return The PlatformAbstraction.
306 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
309 * Sets the Drag & Drop Listener.
310 * @param[in] detector The detector to send Drag & Drop events to.
312 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
315 * Sets a rotation observer, or set to NULL to remove.
316 * @pre Adaptor::Start() has been called ( to create EventHandler )
317 * @param[in] observer The observer to listen for window rotation events
319 void SetRotationObserver( RotationObserver* observer );
322 * Destroy the TtsPlayer of specific mode.
323 * @param[in] mode The mode of TtsPlayer to destroy
325 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
328 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
329 * trigger a pinch gesture
331 * @param[in] distance The minimum pinch distance in pixels
333 void SetMinimumPinchDistance(float distance);
336 * Gets native window handle
338 * @return native window handle
340 Any GetNativeWindowHandle();
343 * Get the native display associated with the graphics backend
345 * @return A handle to the native display
347 Any GetGraphicsDisplay();
350 * Sets use remote surface for Surface output
351 * @param[in] useRemoteSurface True if the remote surface is used
353 void SetUseRemoteSurface(bool useRemoteSurface);
358 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
359 * @param[in] observer The observer.
360 * @note Observers should remove themselves when they are destroyed.
362 void AddObserver( LifeCycleObserver& observer );
365 * Removes the observer from the adaptor.
366 * @param[in] observer The observer to remove.
367 * @note Observers should remove themselves when they are destroyed.
369 void RemoveObserver( LifeCycleObserver& observer );
372 * Emits the Notification event to the Dali core.
374 void SendNotificationEvent();
377 * Request adaptor to update once
379 void RequestUpdateOnce();
382 * Request adaptor to update indicator's height
384 void IndicatorSizeChanged(int height);
387 * @copydoc Dali::Adaptor::NotifySceneCreated()
389 void NotifySceneCreated();
392 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
394 void NotifyLanguageChanged();
397 * Gets AppId of current application
399 void GetAppId( std::string& appId );
402 * Informs core the surface size has changed
404 void SurfaceResizePrepare( SurfaceSize surfaceSize );
407 * Informs ThreadController the surface size has changed
409 void SurfaceResizeComplete( SurfaceSize surfaceSize );
412 * Sets layout direction of root by system language
413 * @param[in] locale System locale
415 void SetRootLayoutDirection( std::string locale );
418 * @copydoc Dali::Adaptor::RenderOnce
423 * @copydoc Dali::Adaptor::GetLogFactory
425 const LogFactoryInterface& GetLogFactory();
427 public: //AdaptorInternalServices
430 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
432 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
435 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
437 virtual Dali::DisplayConnection& GetDisplayConnectionInterface();
440 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
442 virtual GraphicsInterface& GetGraphicsInterface();
445 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
447 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
450 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
452 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
455 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
457 virtual SocketFactoryInterface& GetSocketFactoryInterface();
460 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
462 virtual RenderSurface* GetRenderSurfaceInterface();
465 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
467 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
470 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
472 virtual PerformanceInterface* GetPerformanceInterface();
475 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
477 virtual TraceInterface& GetKernelTraceInterface();
480 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
482 virtual TraceInterface& GetSystemTraceInterface();
487 * @copydoc Dali::Adaptor::SignalResized
489 AdaptorSignalType& ResizedSignal()
491 return mResizedSignal;
495 * @copydoc Dali::Adaptor::LanguageChangedSignal
497 AdaptorSignalType& LanguageChangedSignal()
499 return mLanguageChangedSignal;
502 private: // From Dali::Internal::Adaptor::CoreEventInterface
505 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
507 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
510 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
512 virtual void ProcessCoreEvents();
514 private: // From Dali::Integration::RenderController
517 * @copydoc Dali::Integration::RenderController::RequestUpdate()
519 virtual void RequestUpdate( bool forceUpdate );
522 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
524 virtual void RequestProcessEventsOnIdle( bool forceProcess );
526 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
529 * Called when the window becomes fully or partially visible.
531 virtual void OnWindowShown();
534 * Called when the window is fully hidden.
536 virtual void OnWindowHidden();
538 private: // From Dali::Internal::Adaptor::DamageObserver
541 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
543 void OnDamaged( const DamageArea& area );
548 Adaptor(const Adaptor&) = delete;
549 Adaptor& operator=(Adaptor&) = delete;
554 * Assigns the render surface to the adaptor
557 void SetSurface(RenderSurface *surface);
560 * called after surface is created
562 void SurfaceInitialized();
565 * Sends an notification message from main loop idle handler
567 bool ProcessCoreEventsFromIdle();
570 * Gets path for data/resource storage.
571 * @param[out] path Path for data/resource storage
573 void GetDataStoragePath(std::string& path);
576 * Sets up system information if needs
578 void SetupSystemInformation();
581 * Adds a callback to be run when entering an idle state.
583 * A callback of the following type should be used:
587 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
589 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
592 * Removes a previously added the idle enterer callback.
594 void RemoveIdleEnterer( CallbackBase* callback );
600 * @param[in] nativeWindow native window handle
601 * @param[in] adaptor The public adaptor
602 * @param[in] surface A render surface can be one of the following
603 * - Pixmap, adaptor will use existing Pixmap to draw on to
604 * - Window, adaptor will use existing Window to draw on to
605 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
607 Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions );
613 READY, ///< Initial state before Adaptor::Start is called.
614 RUNNING, ///< Adaptor is running.
615 PAUSED, ///< Adaptor has been paused.
616 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
617 STOPPED, ///< Adaptor has been stopped.
620 // A structure to encapsulate each Window instance for the Adaptor to track them
621 typedef struct WindowPane
623 Dali::Window* instance; ///< Window object
624 std::string window_name; ///< Name (title)_of the window
625 std::string class_name; ///< Class name that the window belongs to
626 bool window_mode; ///< Display mode of the window
627 Any nativeWindow; ///< window identifier
628 RenderSurface* surface; ///< The surface the Window is bound to
631 typedef std::vector<WindowPane> WindowFrames;
633 typedef std::vector<LifeCycleObserver*> ObserverContainer;
637 AdaptorSignalType mResizedSignal; ///< Resized signal.
638 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
640 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
641 State mState; ///< Current state of the adaptor
642 Dali::Integration::Core* mCore; ///< Dali Core
643 ThreadController* mThreadController; ///< Controls the threads
644 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
646 GraphicsInterface* mGraphics; ///< Graphics interface
647 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
648 WindowFrames mWindowFrame; ///< A container of all the Windows that are currently created
650 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
652 EventHandler* mEventHandler; ///< event handler
653 CallbackManager* mCallbackManager; ///< Used to install callbacks
654 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
655 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
656 GestureManager* mGestureManager; ///< Gesture manager
657 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
658 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
659 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
660 ObserverContainer mObservers; ///< A list of adaptor observer pointers
661 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
662 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
663 EnvironmentOptions* mEnvironmentOptions; ///< environment options
664 PerformanceInterface* mPerformanceInterface; ///< Performance interface
665 KernelTrace mKernelTracer; ///< Kernel tracer
666 SystemTrace mSystemTracer; ///< System tracer
667 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
668 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
669 SocketFactory mSocketFactory; ///< Socket factory
670 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
671 bool mUseRemoteSurface; ///< whether the remoteSurface is used or not
674 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
677 } // namespace Internal
679 } // namespace Adaptor
683 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H