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>
52 class RenderSurfaceInterface;
67 class DisplayConnection;
68 class GraphicsFactory;
71 class GlImplementation;
72 class GlSyncImplementation;
73 class ThreadController;
75 class CallbackManager;
76 class FeedbackPluginProxy;
77 class FeedbackController;
78 class RotationObserver;
80 class PerformanceInterface;
81 class LifeCycleObserver;
85 * Implementation of the Adaptor class.
87 class Adaptor : public Integration::RenderController,
88 public AdaptorInternalServices,
89 public CoreEventInterface,
90 public DamageObserver,
91 public WindowVisibilityObserver
95 typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
97 typedef Uint16Pair SurfaceSize; ///< Surface size type
100 * Creates a New Adaptor
101 * @param[in] nativeWindow Native window handle
102 * @param[in] surface A render surface can be one of the following
103 * - Pixmap, adaptor will use existing Pixmap to draw on to
104 * - Window, adaptor will use existing Window to draw on to
105 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
106 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
108 static Dali::Adaptor* New( Any nativeWindow,
109 Dali::RenderSurfaceInterface* surface,
110 Dali::Configuration::ContextLoss configuration,
111 EnvironmentOptions* environmentOptions );
114 * Creates a New Adaptor
115 * @param[in] nativeWindow native window handle
116 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
117 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
119 static Dali::Adaptor* New( Dali::Window window,
120 Dali::Configuration::ContextLoss configuration,
121 EnvironmentOptions* environmentOptions );
124 * Creates a New Adaptor
125 * @param[in] graphicsFactory A factory that creates the graphics interface
126 * @param[in] nativeWindow Native window handle
127 * @param[in] surface A render surface can be one of the following
128 * - Pixmap, adaptor will use existing Pixmap to draw on to
129 * - Window, adaptor will use existing Window to draw on to
130 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
131 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
133 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
135 Dali::RenderSurfaceInterface* surface,
136 Dali::Configuration::ContextLoss configuration,
137 EnvironmentOptions* environmentOptions );
140 * Creates a New Adaptor
141 * @param[in] graphicsFactory A factory that creates the graphics interface
142 * @param[in] nativeWindow native window handle
143 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
144 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
146 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
148 Dali::Configuration::ContextLoss configuration,
149 EnvironmentOptions* environmentOptions );
152 * 2-step initialisation, this should be called after creating an adaptor instance.
153 * @param[in] graphicsFactory A factory that creates the graphics interface
154 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
156 void Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration );
159 * Virtual destructor.
164 * @copydoc Dali::Adaptor::Get()
166 static Dali::Adaptor& Get();
169 * @copydoc Dali::Adaptor::IsAvailable()
171 static bool IsAvailable();
174 * @copydoc Dali::Core::SceneCreated();
178 public: // AdaptorInternalServices implementation
180 * @copydoc Dali::Adaptor::Start()
182 virtual void Start();
185 * @copydoc Dali::Adaptor::Pause()
187 virtual void Pause();
190 * @copydoc Dali::Adaptor::Resume()
192 virtual void Resume();
195 * @copydoc Dali::Adaptor::Stop()
200 * @copydoc Dali::Adaptor::ContextLost()
202 virtual void ContextLost();
205 * @copydoc Dali::Adaptor::ContextRegained()
207 virtual void ContextRegained();
210 * @copydoc Dali::EventFeeder::FeedTouchPoint()
212 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
215 * @copydoc Dali::EventFeeder::FeedWheelEvent()
217 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
220 * @copydoc Dali::EventFeeder::FeedKeyEvent()
222 virtual void FeedKeyEvent( KeyEvent& keyEvent );
225 * @copydoc AdaptorInterface::ReplaceSurface()
227 virtual void ReplaceSurface( Any nativeWindow, Dali::RenderSurfaceInterface& surface );
230 * @copydoc Dali::Adaptor::GetSurface()
232 virtual Dali::RenderSurfaceInterface& GetSurface() const;
235 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
237 virtual void ReleaseSurfaceLock();
240 * Retrieve the TtsPlayer.
241 * @param[in] mode The mode of TtsPlayer
242 * @return A handle to the TtsPlayer.
244 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
247 * @copydoc Dali::Adaptor::AddIdle()
249 virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
252 * Adds a new Window instance to the Adaptor
253 * @param[in] childWindow The child window instance
254 * @param[in] childWindowName The child window title/name
255 * @param[in] childWindowClassName The class name that the child window belongs to
256 * @param[in] childWindowMode The mode of the child window
258 virtual bool AddWindow( Dali::Window* childWindow,
259 const std::string& childWindowName,
260 const std::string& childWindowClassName,
261 const bool& childWindowMode );
264 * Removes an existing Window instance from the Adaptor
265 * @param[in] window The Window instance
267 virtual bool RemoveWindow( Dali::Window* childWindow );
270 * Removes an existing Window instance from the Adaptor
271 * @param[in] windowName The Window name
272 * @note If two Windows have the same name, the first one that matches will be removed
274 virtual bool RemoveWindow( std::string childWindowName );
277 * @copydoc Dali::Adaptor::RemoveIdle()
279 virtual void RemoveIdle( CallbackBase* callback );
282 * Sets a pre-render callback.
284 void SetPreRenderCallback( CallbackBase* callback );
287 * Removes an existing Window instance from the Adaptor
288 * @param[in] childWindow The Window instance
290 bool RemoveWindow( Dali::Internal::Adaptor::Window* childWindow );
295 * @return the Core instance
297 virtual Dali::Integration::Core& GetCore();
300 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
302 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
305 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
307 void SetUseHardwareVSync(bool useHardware);
310 * Return the PlatformAbstraction.
311 * @return The PlatformAbstraction.
313 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
316 * Sets the Drag & Drop Listener.
317 * @param[in] detector The detector to send Drag & Drop events to.
319 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
322 * Sets a rotation observer, or set to NULL to remove.
323 * @pre Adaptor::Start() has been called ( to create EventHandler )
324 * @param[in] observer The observer to listen for window rotation events
326 void SetRotationObserver( RotationObserver* observer );
329 * Destroy the TtsPlayer of specific mode.
330 * @param[in] mode The mode of TtsPlayer to destroy
332 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
335 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
336 * trigger a pinch gesture
338 * @param[in] distance The minimum pinch distance in pixels
340 void SetMinimumPinchDistance(float distance);
343 * Gets native window handle
345 * @return native window handle
347 Any GetNativeWindowHandle();
350 * Get the native display associated with the graphics backend
352 * @return A handle to the native display
354 Any GetGraphicsDisplay();
357 * Sets use remote surface for Surface output
358 * @param[in] useRemoteSurface True if the remote surface is used
360 void SetUseRemoteSurface(bool useRemoteSurface);
365 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
366 * @param[in] observer The observer.
367 * @note Observers should remove themselves when they are destroyed.
369 void AddObserver( LifeCycleObserver& observer );
372 * Removes the observer from the adaptor.
373 * @param[in] observer The observer to remove.
374 * @note Observers should remove themselves when they are destroyed.
376 void RemoveObserver( LifeCycleObserver& observer );
379 * Emits the Notification event to the Dali core.
381 void SendNotificationEvent();
384 * Request adaptor to update once
386 void RequestUpdateOnce();
389 * @copydoc Dali::Adaptor::NotifySceneCreated()
391 void NotifySceneCreated();
394 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
396 void NotifyLanguageChanged();
399 * Gets AppId of current application
401 void GetAppId( std::string& appId );
404 * Informs core the surface size has changed
406 void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
409 * Informs ThreadController the surface size has changed
411 void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
414 * Sets layout direction of root by system language
415 * @param[in] locale System locale
417 void SetRootLayoutDirection( std::string locale );
420 * @copydoc Dali::Adaptor::RenderOnce
425 * @copydoc Dali::Adaptor::GetLogFactory
427 const LogFactoryInterface& GetLogFactory();
430 * @copydoc Dali::Adaptor::RegisterProcessor
432 void RegisterProcessor( Integration::Processor& processor );
435 * @coydoc Dali::Adaptor::UnregisterProcessor
437 void UnregisterProcessor( Integration::Processor& processor );
439 public: //AdaptorInternalServices
442 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
444 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
447 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
449 virtual Dali::DisplayConnection& GetDisplayConnectionInterface();
452 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
454 virtual GraphicsInterface& GetGraphicsInterface();
457 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
459 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
462 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
464 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
467 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
469 virtual SocketFactoryInterface& GetSocketFactoryInterface();
472 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
474 virtual Dali::RenderSurfaceInterface* GetRenderSurfaceInterface();
477 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
479 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
482 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
484 virtual PerformanceInterface* GetPerformanceInterface();
487 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
489 virtual TraceInterface& GetKernelTraceInterface();
492 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
494 virtual TraceInterface& GetSystemTraceInterface();
499 * @copydoc Dali::Adaptor::SignalResized
501 AdaptorSignalType& ResizedSignal()
503 return mResizedSignal;
507 * @copydoc Dali::Adaptor::LanguageChangedSignal
509 AdaptorSignalType& LanguageChangedSignal()
511 return mLanguageChangedSignal;
514 private: // From Dali::Internal::Adaptor::CoreEventInterface
517 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
519 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
522 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
524 virtual void ProcessCoreEvents();
526 private: // From Dali::Integration::RenderController
529 * @copydoc Dali::Integration::RenderController::RequestUpdate()
531 virtual void RequestUpdate( bool forceUpdate );
534 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
536 virtual void RequestProcessEventsOnIdle( bool forceProcess );
538 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
541 * Called when the window becomes fully or partially visible.
543 virtual void OnWindowShown();
546 * Called when the window is fully hidden.
548 virtual void OnWindowHidden();
550 private: // From Dali::Internal::Adaptor::DamageObserver
553 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
555 void OnDamaged( const DamageArea& area );
560 Adaptor(const Adaptor&) = delete;
561 Adaptor& operator=(Adaptor&) = delete;
566 * Assigns the render surface to the adaptor
569 void SetSurface(Dali::RenderSurfaceInterface *surface);
572 * called after surface is created
574 void SurfaceInitialized();
577 * Sends an notification message from main loop idle handler
579 bool ProcessCoreEventsFromIdle();
582 * Gets path for data/resource storage.
583 * @param[out] path Path for data/resource storage
585 void GetDataStoragePath(std::string& path);
588 * Sets up system information if needs
590 void SetupSystemInformation();
593 * Adds a callback to be run when entering an idle state.
595 * A callback of the following type should be used:
599 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
601 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
604 * Removes a previously added the idle enterer callback.
606 void RemoveIdleEnterer( CallbackBase* callback );
612 * @param[in] nativeWindow native window handle
613 * @param[in] adaptor The public adaptor
614 * @param[in] surface A render surface can be one of the following
615 * - Pixmap, adaptor will use existing Pixmap to draw on to
616 * - Window, adaptor will use existing Window to draw on to
617 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
619 Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions );
625 READY, ///< Initial state before Adaptor::Start is called.
626 RUNNING, ///< Adaptor is running.
627 PAUSED, ///< Adaptor has been paused.
628 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
629 STOPPED, ///< Adaptor has been stopped.
632 // A structure to encapsulate each Window instance for the Adaptor to track them
633 typedef struct WindowPane
635 Dali::Window* instance; ///< Window object
636 std::string window_name; ///< Name (title)_of the window
637 std::string class_name; ///< Class name that the window belongs to
638 bool window_mode; ///< Display mode of the window
639 Any nativeWindow; ///< window identifier
640 uint32_t id; ///< unique Window ID
641 Dali::RenderSurfaceInterface* surface; ///< The surface the Window is bound to
644 typedef std::vector<WindowPane> WindowFrames;
646 typedef std::vector<LifeCycleObserver*> ObserverContainer;
650 AdaptorSignalType mResizedSignal; ///< Resized signal.
651 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
653 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
654 State mState; ///< Current state of the adaptor
655 Dali::Integration::Core* mCore; ///< Dali Core
656 ThreadController* mThreadController; ///< Controls the threads
657 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
659 GraphicsInterface* mGraphics; ///< Graphics interface
660 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
661 WindowFrames mWindowFrame; ///< A container of all the Windows that are currently created
663 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
665 EventHandler* mEventHandler; ///< event handler
666 CallbackManager* mCallbackManager; ///< Used to install callbacks
667 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
668 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
669 GestureManager* mGestureManager; ///< Gesture manager
670 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
671 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
672 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
673 ObserverContainer mObservers; ///< A list of adaptor observer pointers
674 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
675 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
676 EnvironmentOptions* mEnvironmentOptions; ///< environment options
677 PerformanceInterface* mPerformanceInterface; ///< Performance interface
678 KernelTrace mKernelTracer; ///< Kernel tracer
679 SystemTrace mSystemTracer; ///< System tracer
680 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
681 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
682 SocketFactory mSocketFactory; ///< Socket factory
683 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
684 bool mUseRemoteSurface; ///< whether the remoteSurface is used or not
687 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
690 } // namespace Internal
692 } // namespace Adaptor
696 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H