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/legacy/common/tizen-platform-abstraction.h>
35 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
36 #include <dali/internal/system/common/environment-options.h>
37 #include <dali/internal/system/common/core-event-interface.h>
38 #include <dali/internal/input/common/drag-and-drop-detector-impl.h>
39 #include <dali/internal/window-system/common/damage-observer.h>
40 #include <dali/internal/window-system/common/window-visibility-observer.h>
41 #include <dali/internal/system/common/kernel-trace.h>
42 #include <dali/internal/system/common/system-trace.h>
43 #include <dali/integration-api/trigger-event-factory.h>
44 #include <dali/internal/network/common/socket-factory.h>
66 class GlImplementation;
67 class GlSyncImplementation;
68 class ThreadController;
70 class CallbackManager;
71 class FeedbackPluginProxy;
72 class FeedbackController;
73 class RotationObserver;
75 class PerformanceInterface;
76 class LifeCycleObserver;
80 * Implementation of the Adaptor class.
82 class Adaptor : public Integration::RenderController,
83 public AdaptorInternalServices,
84 public CoreEventInterface,
85 public DamageObserver,
86 public WindowVisibilityObserver
90 typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
92 typedef Uint16Pair SurfaceSize; ///< Surface size type
95 * Creates a New Adaptor
96 * @param[in] nativeWindow Native window handle
97 * @param[in] surface A render surface can be one of the following
98 * - Pixmap, adaptor will use existing Pixmap to draw on to
99 * - Window, adaptor will use existing Window to draw on to
100 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
101 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
103 static Dali::Adaptor* New( Any nativeWindow,
104 RenderSurface* surface,
105 Dali::Configuration::ContextLoss configuration,
106 EnvironmentOptions* environmentOptions );
109 * Creates a New Adaptor
110 * @param[in] nativeWindow native window handle
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::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions );
117 * 2-step initialisation, this should be called after creating an adaptor instance.
119 void Initialize(Dali::Configuration::ContextLoss configuration);
122 * Virtual destructor.
127 * @copydoc Dali::Adaptor::Get()
129 static Dali::Adaptor& Get();
132 * @copydoc Dali::Adaptor::IsAvailable()
134 static bool IsAvailable();
137 * @copydoc Dali::Core::SceneCreated();
141 public: // AdaptorInternalServices implementation
143 * @copydoc Dali::Adaptor::Start()
145 virtual void Start();
148 * @copydoc Dali::Adaptor::Pause()
150 virtual void Pause();
153 * @copydoc Dali::Adaptor::Resume()
155 virtual void Resume();
158 * @copydoc Dali::Adaptor::Stop()
163 * @copydoc Dali::Adaptor::ContextLost()
165 virtual void ContextLost();
168 * @copydoc Dali::Adaptor::ContextRegained()
170 virtual void ContextRegained();
173 * @copydoc Dali::EventFeeder::FeedTouchPoint()
175 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
178 * @copydoc Dali::EventFeeder::FeedWheelEvent()
180 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
183 * @copydoc Dali::EventFeeder::FeedKeyEvent()
185 virtual void FeedKeyEvent( KeyEvent& keyEvent );
188 * @copydoc AdaptorInterface::ReplaceSurface()
190 virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
193 * @copydoc Dali::Adaptor::GetSurface()
195 virtual RenderSurface& GetSurface() const;
198 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
200 virtual void ReleaseSurfaceLock();
203 * Retrieve the TtsPlayer.
204 * @param[in] mode The mode of TtsPlayer
205 * @return A handle to the TtsPlayer.
207 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
210 * @copydoc Dali::Adaptor::AddIdle()
212 virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
215 * @copydoc Dali::Adaptor::RemoveIdle()
217 virtual void RemoveIdle( CallbackBase* callback );
220 * Sets a pre-render callback.
222 void SetPreRenderCallback( CallbackBase* callback );
227 * @return the Core instance
229 virtual Dali::Integration::Core& GetCore();
232 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
234 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
237 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
239 void SetUseHardwareVSync(bool useHardware);
242 * @return reference to EglFactory class
244 EglFactory& GetEGLFactory() const;
247 * Return GlAbstraction.
248 * @return the GlAbstraction.
250 Integration::GlAbstraction& GetGlAbstraction() const;
253 * Return the PlatformAbstraction.
254 * @return The PlatformAbstraction.
256 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
259 * Sets the Drag & Drop Listener.
260 * @param[in] detector The detector to send Drag & Drop events to.
262 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
265 * Sets a rotation observer, or set to NULL to remove.
266 * @pre Adaptor::Start() has been called ( to create EventHandler )
267 * @param[in] observer The observer to listen for window rotation events
269 void SetRotationObserver( RotationObserver* observer );
272 * Destroy the TtsPlayer of sepcific mode.
273 * @param[in] mode The mode of TtsPlayer to destroy
275 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
278 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
279 * trigger a pinch gesture
281 * @param[in] distance The minimum pinch distance in pixels
283 void SetMinimumPinchDistance(float distance);
286 * Gets native window handle
288 * @return native window handle
290 Any GetNativeWindowHandle();
293 * Sets use remote surface for eglSurface output
294 * @param[in] useRemoteSurface True if the remote surface is used
296 void SetUseRemoteSurface(bool useRemoteSurface);
301 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
302 * @param[in] observer The observer.
303 * @note Observers should remove themselves when they are destroyed.
305 void AddObserver( LifeCycleObserver& observer );
308 * Removes the observer from the adaptor.
309 * @param[in] observer The observer to remove.
310 * @note Observers should remove themselves when they are destroyed.
312 void RemoveObserver( LifeCycleObserver& observer );
315 * Emits the Notification event to the Dali core.
317 void SendNotificationEvent();
320 * Request adaptor to update once
322 void RequestUpdateOnce();
325 * Request adaptor to update indicator's height
327 void IndicatorSizeChanged(int height);
330 * @copydoc Dali::Adaptor::NotifySceneCreated()
332 void NotifySceneCreated();
335 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
337 void NotifyLanguageChanged();
340 * Gets AppId of current application
342 void GetAppId( std::string& appId );
345 * Informs core the surface size has changed
347 void SurfaceResizePrepare( SurfaceSize surfaceSize );
350 * Informs ThreadController the surface size has changed
352 void SurfaceResizeComplete( SurfaceSize surfaceSize );
355 * Sets layout direction of root by system language
356 * @param[in] locale System locale
358 void SetRootLayoutDirection( std::string locale );
361 * @copydoc Dali::Adaptor::RenderOnce
366 * @copydoc Dali::Adaptor::GetLogFactory
368 const LogFactoryInterface& GetLogFactory();
370 public: //AdaptorInternalServices
373 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
375 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
378 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
380 virtual Dali::Integration::GlAbstraction& GetGlesInterface();
383 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
385 virtual EglFactoryInterface& GetEGLFactoryInterface() const;
388 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
390 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
393 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
395 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
398 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
400 virtual SocketFactoryInterface& GetSocketFactoryInterface();
403 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
405 virtual RenderSurface* GetRenderSurfaceInterface();
408 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
410 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
413 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
415 virtual PerformanceInterface* GetPerformanceInterface();
418 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
420 virtual TraceInterface& GetKernelTraceInterface();
423 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
425 virtual TraceInterface& GetSystemTraceInterface();
427 public: // Stereoscopy
430 * @copydoc Dali::Integration::Core::SetViewMode()
432 void SetViewMode( ViewMode viewMode );
435 * @copydoc Dali::Integration::Core::GetViewMode()
437 ViewMode GetViewMode() const;
440 * @copydoc Dali::Integration::Core::SetStereoBase()
442 void SetStereoBase( float stereoBase );
445 * @copydoc Dali::Integration::Core::GetStereoBase()
447 float GetStereoBase() const;
452 * @copydoc Dali::Adaptor::SignalResized
454 AdaptorSignalType& ResizedSignal()
456 return mResizedSignal;
460 * @copydoc Dali::Adaptor::LanguageChangedSignal
462 AdaptorSignalType& LanguageChangedSignal()
464 return mLanguageChangedSignal;
467 private: // From Dali::Internal::Adaptor::CoreEventInterface
470 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
472 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
475 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
477 virtual void ProcessCoreEvents();
479 private: // From Dali::Integration::RenderController
482 * @copydoc Dali::Integration::RenderController::RequestUpdate()
484 virtual void RequestUpdate( bool forceUpdate );
487 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
489 virtual void RequestProcessEventsOnIdle( bool forceProcess );
491 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
494 * Called when the window becomes fully or partially visible.
496 virtual void OnWindowShown();
499 * Called when the window is fully hidden.
501 virtual void OnWindowHidden();
503 private: // From Dali::Internal::Adaptor::DamageObserver
506 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
508 void OnDamaged( const DamageArea& area );
513 Adaptor(const Adaptor&);
514 Adaptor& operator=(Adaptor&);
519 * Assigns the render surface to the adaptor
522 void SetSurface(RenderSurface *surface);
525 * called after surface is created
527 void SurfaceInitialized();
530 * Sends an notification message from main loop idle handler
532 bool ProcessCoreEventsFromIdle();
535 * Gets path for data/resource storage.
536 * @param[out] path Path for data/resource storage
538 void GetDataStoragePath(std::string& path);
541 * Sets up system information if needs
543 void SetupSystemInformation();
546 * Adds a callback to be run when entering an idle state.
548 * A callback of the following type should be used:
552 * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
554 bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
557 * Removes a previously added the idle enterer callback.
559 void RemoveIdleEnterer( CallbackBase* callback );
565 * @param[in] nativeWindow native window handle
566 * @param[in] adaptor The public adaptor
567 * @param[in] surface A render surface can be one of the following
568 * - Pixmap, adaptor will use existing Pixmap to draw on to
569 * - Window, adaptor will use existing Window to draw on to
570 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
572 Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions );
578 READY, ///< Initial state before Adaptor::Start is called.
579 RUNNING, ///< Adaptor is running.
580 PAUSED, ///< Adaptor has been paused.
581 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
582 STOPPED, ///< Adaptor has been stopped.
585 typedef std::vector<LifeCycleObserver*> ObserverContainer;
589 AdaptorSignalType mResizedSignal; ///< Resized signal.
590 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
592 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
593 State mState; ///< Current state of the adaptor
594 Dali::Integration::Core* mCore; ///< Dali Core
595 ThreadController* mThreadController; ///< Controls the threads
596 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
597 GlImplementation* mGLES; ///< GL implementation
598 GlSyncImplementation* mGlSync; ///< GL Sync implementation
599 EglFactory* mEglFactory; ///< EGL Factory
601 Any mNativeWindow; ///< window identifier
602 RenderSurface* mSurface; ///< Current surface
603 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
605 EventHandler* mEventHandler; ///< event handler
606 CallbackManager* mCallbackManager; ///< Used to install callbacks
607 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
608 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
609 GestureManager* mGestureManager; ///< Gesture manager
610 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
611 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
612 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
613 ObserverContainer mObservers; ///< A list of adaptor observer pointers
614 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
615 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
616 EnvironmentOptions* mEnvironmentOptions; ///< environment options
617 PerformanceInterface* mPerformanceInterface; ///< Performance interface
618 KernelTrace mKernelTracer; ///< Kernel tracer
619 SystemTrace mSystemTracer; ///< System tracer
620 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
621 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
622 SocketFactory mSocketFactory; ///< Socket factory
623 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
624 bool mUseRemoteSurface; ///< whether the remoteSurface is used or not
626 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
629 } // namespace Internal
631 } // namespace Adaptor
635 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__