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;
76 class GlImplementation;
77 class GlSyncImplementation;
78 class ThreadController;
80 class CallbackManager;
81 class FeedbackPluginProxy;
82 class FeedbackController;
84 class PerformanceInterface;
85 class LifeCycleObserver;
90 * Implementation of the Adaptor class.
92 class Adaptor : public Integration::RenderController,
93 public AdaptorInternalServices,
94 public CoreEventInterface,
95 public DamageObserver,
96 public WindowVisibilityObserver
100 using AdaptorSignalType = Dali::Adaptor::AdaptorSignalType;
101 using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType;
103 using SurfaceSize = Uint16Pair; ///< Surface size type
106 * Creates a New Adaptor
107 * @param[in] window The window handle
108 * @param[in] surface A render surface can be one of the following
109 * - Pixmap, adaptor will use existing Pixmap to draw on to
110 * - Window, adaptor will use existing Window to draw on to
111 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
112 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
114 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
115 Dali::RenderSurfaceInterface* surface,
116 Dali::Configuration::ContextLoss configuration,
117 EnvironmentOptions* environmentOptions );
120 * Creates a New Adaptor
121 * @param[in] window The window handle
122 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
123 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
125 static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
126 Dali::Configuration::ContextLoss configuration,
127 EnvironmentOptions* environmentOptions );
130 * Creates a New Adaptor
131 * @param[in] graphicsFactory A factory that creates the graphics interface
132 * @param[in] window The window handle
133 * @param[in] surface A render surface can be one of the following
134 * - Pixmap, adaptor will use existing Pixmap to draw on to
135 * - Window, adaptor will use existing Window to draw on to
136 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
137 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
139 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
140 Dali::Integration::SceneHolder window,
141 Dali::RenderSurfaceInterface* surface,
142 Dali::Configuration::ContextLoss configuration,
143 EnvironmentOptions* environmentOptions );
146 * Creates a New Adaptor
147 * @param[in] graphicsFactory A factory that creates the graphics interface
148 * @param[in] window The window handle
149 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
150 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
152 static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
153 Dali::Integration::SceneHolder window,
154 Dali::Configuration::ContextLoss configuration,
155 EnvironmentOptions* environmentOptions );
158 * 2-step initialisation, this should be called after creating an adaptor instance.
159 * @param[in] graphicsFactory A factory that creates the graphics interface
160 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
162 void Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration::ContextLoss configuration );
165 * Virtual destructor.
170 * @copydoc Dali::Adaptor::Get()
172 static Dali::Adaptor& Get();
175 * @copydoc Dali::Adaptor::IsAvailable()
177 static bool IsAvailable();
180 * @copydoc Dali::Core::SceneCreated();
184 public: // AdaptorInternalServices implementation
186 * @copydoc Dali::Adaptor::Start()
188 virtual void Start();
191 * @copydoc Dali::Adaptor::Pause()
193 virtual void Pause();
196 * @copydoc Dali::Adaptor::Resume()
198 virtual void Resume();
201 * @copydoc Dali::Adaptor::Stop()
206 * @copydoc Dali::Adaptor::ContextLost()
208 virtual void ContextLost();
211 * @copydoc Dali::Adaptor::ContextRegained()
213 virtual void ContextRegained();
216 * @copydoc Dali::EventFeeder::FeedTouchPoint()
218 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
221 * @copydoc Dali::EventFeeder::FeedWheelEvent()
223 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
226 * @copydoc Dali::EventFeeder::FeedKeyEvent()
228 virtual void FeedKeyEvent( KeyEvent& keyEvent );
231 * @copydoc Dali::Adaptor::ReplaceSurface()
233 virtual void ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface );
236 * @copydoc Dali::Adaptor::GetSurface()
238 virtual Dali::RenderSurfaceInterface& GetSurface() const;
241 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
243 virtual void ReleaseSurfaceLock();
246 * Retrieve the TtsPlayer.
247 * @param[in] mode The mode of TtsPlayer
248 * @return A handle to the TtsPlayer.
250 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
253 * @copydoc Dali::Adaptor::AddIdle()
255 virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
258 * Adds a new Window instance to the Adaptor
259 * @param[in] childWindow The child window instance
260 * @param[in] childWindowName The child window title/name
261 * @param[in] childWindowClassName The class name that the child window belongs to
262 * @param[in] childWindowMode The mode of the child window
264 virtual bool AddWindow( Dali::Integration::SceneHolder childWindow,
265 const std::string& childWindowName,
266 const std::string& childWindowClassName,
267 bool childWindowMode );
270 * Removes an existing Window instance from the Adaptor
271 * @param[in] window The Window instance
273 virtual bool RemoveWindow( Dali::Integration::SceneHolder* childWindow );
276 * Removes an existing Window instance from the Adaptor
277 * @param[in] windowName The Window name
278 * @note If two Windows have the same name, the first one that matches will be removed
280 virtual bool RemoveWindow( std::string childWindowName );
283 * @copydoc Dali::Adaptor::RemoveIdle()
285 virtual void RemoveIdle( CallbackBase* callback );
288 * Sets a pre-render callback.
290 void SetPreRenderCallback( CallbackBase* callback );
293 * Removes an existing Window instance from the Adaptor
294 * @param[in] childWindow The Window instance
296 bool RemoveWindow( Dali::Internal::Adaptor::SceneHolder* childWindow );
299 * @brief Retrieve the window that the given actor is added to.
301 * @param[in] actor The actor
302 * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
304 Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
307 * @copydoc Dali::Adaptor::GetWindows()
309 Dali::WindowContainer GetWindows() const;
314 * @return the Core instance
316 virtual Dali::Integration::Core& GetCore();
319 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
321 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
324 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
326 void SetUseHardwareVSync(bool useHardware);
329 * Return the PlatformAbstraction.
330 * @return The PlatformAbstraction.
332 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
335 * Destroy the TtsPlayer of specific mode.
336 * @param[in] mode The mode of TtsPlayer to destroy
338 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
341 * Gets native window handle
343 * @return native window handle
345 Any GetNativeWindowHandle();
348 * Get the native display associated with the graphics backend
350 * @return A handle to the native display
352 Any GetGraphicsDisplay();
355 * Sets use remote surface for Surface output
356 * @param[in] useRemoteSurface True if the remote surface is used
358 void SetUseRemoteSurface(bool useRemoteSurface);
363 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
364 * @param[in] observer The observer.
365 * @note Observers should remove themselves when they are destroyed.
367 void AddObserver( LifeCycleObserver& observer );
370 * Removes the observer from the adaptor.
371 * @param[in] observer The observer to remove.
372 * @note Observers should remove themselves when they are destroyed.
374 void RemoveObserver( LifeCycleObserver& observer );
377 * Emits the Notification event to the Dali core.
379 void SendNotificationEvent();
382 * Request adaptor to update once
384 void RequestUpdateOnce();
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 * @copydoc Dali::Adaptor::SurfaceResizePrepare
404 void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
407 * @copydoc Dali::Adaptor::SurfaceResizeComplete
409 void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, 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();
428 * @copydoc Dali::Adaptor::RegisterProcessor
430 void RegisterProcessor( Integration::Processor& processor );
433 * @coydoc Dali::Adaptor::UnregisterProcessor
435 void UnregisterProcessor( Integration::Processor& processor );
437 public: //AdaptorInternalServices
440 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
442 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
445 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
447 virtual Dali::DisplayConnection& GetDisplayConnectionInterface();
450 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
452 virtual GraphicsInterface& GetGraphicsInterface();
455 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
457 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
460 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
462 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
465 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
467 virtual SocketFactoryInterface& GetSocketFactoryInterface();
470 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
472 virtual Dali::RenderSurfaceInterface* GetRenderSurfaceInterface();
475 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
477 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
480 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
482 virtual PerformanceInterface* GetPerformanceInterface();
485 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
487 virtual TraceInterface& GetKernelTraceInterface();
490 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
492 virtual TraceInterface& GetSystemTraceInterface();
497 * @copydoc Dali::Adaptor::SignalResized
499 AdaptorSignalType& ResizedSignal()
501 return mResizedSignal;
505 * @copydoc Dali::Adaptor::LanguageChangedSignal
507 AdaptorSignalType& LanguageChangedSignal()
509 return mLanguageChangedSignal;
513 * @copydoc Dali::Adaptor::WindowCreatedSignal
515 WindowCreatedSignalType& WindowCreatedSignal()
517 return mWindowCreatedSignal;
520 public: // From Dali::Internal::Adaptor::CoreEventInterface
523 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
525 virtual void ProcessCoreEvents();
527 private: // From Dali::Internal::Adaptor::CoreEventInterface
530 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
532 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
534 private: // From Dali::Integration::RenderController
537 * @copydoc Dali::Integration::RenderController::RequestUpdate()
539 virtual void RequestUpdate( bool forceUpdate );
542 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
544 virtual void RequestProcessEventsOnIdle( bool forceProcess );
546 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
549 * Called when the window becomes fully or partially visible.
551 virtual void OnWindowShown();
554 * Called when the window is fully hidden.
556 virtual void OnWindowHidden();
558 private: // From Dali::Internal::Adaptor::DamageObserver
561 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
563 void OnDamaged( const DamageArea& area );
568 Adaptor(const Adaptor&) = delete;
569 Adaptor& operator=(Adaptor&) = delete;
574 * Assigns the render surface to the adaptor
577 void SetSurface(Dali::RenderSurfaceInterface *surface);
580 * called after surface is created
582 void SurfaceInitialized();
585 * Sends an notification message from main loop idle handler
587 bool ProcessCoreEventsFromIdle();
590 * Gets path for data/resource storage.
591 * @param[out] path Path for data/resource storage
593 void GetDataStoragePath(std::string& path);
596 * Sets up system information if needs
598 void SetupSystemInformation();
601 * Adds a callback to be run when entering an idle state.
603 * A callback of the following type should be used:
607 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
609 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
612 * Removes a previously added the idle enterer callback.
614 void RemoveIdleEnterer( CallbackBase* callback );
620 * @param[in] window window handle
621 * @param[in] adaptor The public adaptor
622 * @param[in] surface A render surface can be one of the following
623 * - Pixmap, adaptor will use existing Pixmap to draw on to
624 * - Window, adaptor will use existing Window to draw on to
625 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
627 Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions );
633 READY, ///< Initial state before Adaptor::Start is called.
634 RUNNING, ///< Adaptor is running.
635 PAUSED, ///< Adaptor has been paused.
636 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
637 PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
638 STOPPED, ///< Adaptor has been stopped.
641 // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
642 // so we have to store the raw pointer.
643 using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
644 using ObserverContainer = std::vector<LifeCycleObserver*>;
648 AdaptorSignalType mResizedSignal; ///< Resized signal.
649 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
650 WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal.
652 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
653 State mState; ///< Current state of the adaptor
654 Dali::Integration::Core* mCore; ///< Dali Core
655 ThreadController* mThreadController; ///< Controls the threads
656 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
658 GraphicsInterface* mGraphics; ///< Graphics interface
659 Dali::DisplayConnection* mDisplayConnection; ///< Display connection
660 WindowContainer mWindows; ///< A container of all the Windows that are currently created
662 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
664 CallbackManager* mCallbackManager; ///< Used to install callbacks
665 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
666 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
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 EnvironmentOptions* mEnvironmentOptions; ///< environment options
672 PerformanceInterface* mPerformanceInterface; ///< Performance interface
673 KernelTrace mKernelTracer; ///< Kernel tracer
674 SystemTrace mSystemTracer; ///< System tracer
675 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
676 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
677 SocketFactory mSocketFactory; ///< Socket factory
678 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
679 bool mUseRemoteSurface; ///< whether the remoteSurface is used or not
682 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
685 } // namespace Internal
687 } // namespace Adaptor
691 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H