1 #ifndef __DALI_INTERNAL_ADAPTOR_IMPL_H__
2 #define __DALI_INTERNAL_ADAPTOR_IMPL_H__
5 * Copyright (c) 2017 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>
32 #include <render-surface.h>
33 #include <tts-player.h>
34 #include <imf-manager.h>
35 #include <clipboard.h>
37 #include <tizen-platform-abstraction.h>
38 #include <base/interfaces/adaptor-internal-services.h>
39 #include <base/environment-options.h>
40 #include <base/core-event-interface.h>
41 #include <drag-and-drop-detector-impl.h>
42 #include <damage-observer.h>
43 #include <window-visibility-observer.h>
44 #include <kernel-trace.h>
45 #include <system-trace.h>
46 #include <trigger-event-factory.h>
47 #include <networking/socket-factory.h>
69 class GlImplementation;
70 class GlSyncImplementation;
71 class ThreadController;
73 class CallbackManager;
74 class FeedbackPluginProxy;
75 class FeedbackController;
76 class RotationObserver;
78 class PerformanceInterface;
79 class LifeCycleObserver;
83 * Implementation of the Adaptor class.
85 class Adaptor : public Integration::RenderController,
86 public AdaptorInternalServices,
87 public CoreEventInterface,
88 public DamageObserver,
89 public WindowVisibilityObserver
93 typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
95 typedef Uint16Pair SurfaceSize; ///< Surface size type
98 * Creates a New Adaptor
99 * @param[in] nativeWindow Native window handle
100 * @param[in] surface A render surface can be one of the following
101 * - Pixmap, adaptor will use existing Pixmap to draw on to
102 * - Window, adaptor will use existing Window to draw on to
103 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
104 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
106 static Dali::Adaptor* New( Any nativeWindow,
107 RenderSurface* surface,
108 Dali::Configuration::ContextLoss configuration,
109 EnvironmentOptions* environmentOptions );
112 * Creates a New Adaptor
113 * @param[in] nativeWindow native window handle
114 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
115 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
117 static Dali::Adaptor* New( Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions );
120 * 2-step initialisation, this should be called after creating an adaptor instance.
122 void Initialize(Dali::Configuration::ContextLoss configuration);
125 * Virtual destructor.
130 * @copydoc Dali::Adaptor::Get()
132 static Dali::Adaptor& Get();
135 * @copydoc Dali::Adaptor::IsAvailable()
137 static bool IsAvailable();
140 * @copydoc Dali::Core::SceneCreated();
144 public: // AdaptorInternalServices implementation
146 * @copydoc Dali::Adaptor::Start()
148 virtual void Start();
151 * @copydoc Dali::Adaptor::Pause()
153 virtual void Pause();
156 * @copydoc Dali::Adaptor::Resume()
158 virtual void Resume();
161 * @copydoc Dali::Adaptor::Stop()
166 * @copydoc Dali::Adaptor::ContextLost()
168 virtual void ContextLost();
171 * @copydoc Dali::Adaptor::ContextRegained()
173 virtual void ContextRegained();
176 * @copydoc Dali::EventFeeder::FeedTouchPoint()
178 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
181 * @copydoc Dali::EventFeeder::FeedWheelEvent()
183 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
186 * @copydoc Dali::EventFeeder::FeedKeyEvent()
188 virtual void FeedKeyEvent( KeyEvent& keyEvent );
191 * @copydoc AdaptorInterface::ReplaceSurface()
193 virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
196 * @copydoc Dali::Adaptor::GetSurface()
198 virtual RenderSurface& GetSurface() const;
201 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
203 virtual void ReleaseSurfaceLock();
206 * Retrieve the TtsPlayer.
207 * @param[in] mode The mode of TtsPlayer
208 * @return A handle to the TtsPlayer.
210 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
213 * @copydoc Dali::Adaptor::AddIdle()
215 virtual bool AddIdle( CallbackBase* callback, bool forceAdd );
218 * @copydoc Dali::Adaptor::RemoveIdle()
220 virtual void RemoveIdle( CallbackBase* callback );
225 * @return the Core instance
227 virtual Dali::Integration::Core& GetCore();
230 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
232 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
235 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
237 void SetUseHardwareVSync(bool useHardware);
240 * @return reference to EglFactory class
242 EglFactory& GetEGLFactory() const;
245 * Return GlAbstraction.
246 * @return the GlAbstraction.
248 Integration::GlAbstraction& GetGlAbstraction() const;
251 * Return the PlatformAbstraction.
252 * @return The PlatformAbstraction.
254 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
257 * Sets the Drag & Drop Listener.
258 * @param[in] detector The detector to send Drag & Drop events to.
260 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
263 * Sets a rotation observer, or set to NULL to remove.
264 * @pre Adaptor::Start() has been called ( to create EventHandler )
265 * @param[in] observer The observer to listen for window rotation events
267 void SetRotationObserver( RotationObserver* observer );
270 * Destroy the TtsPlayer of sepcific mode.
271 * @param[in] mode The mode of TtsPlayer to destroy
273 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
276 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
277 * trigger a pinch gesture
279 * @param[in] distance The minimum pinch distance in pixels
281 void SetMinimumPinchDistance(float distance);
284 * Gets native window handle
286 * @return native window handle
288 Any GetNativeWindowHandle();
291 * Sets use remote surface for eglSurface output
292 * @param[in] useRemoteSurface True if the remote surface is used
294 void SetUseRemoteSurface(bool useRemoteSurface);
299 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
300 * @param[in] observer The observer.
301 * @note Observers should remove themselves when they are destroyed.
303 void AddObserver( LifeCycleObserver& observer );
306 * Removes the observer from the adaptor.
307 * @param[in] observer The observer to remove.
308 * @note Observers should remove themselves when they are destroyed.
310 void RemoveObserver( LifeCycleObserver& observer );
313 * Emits the Notification event to the Dali core.
315 void SendNotificationEvent();
318 * Request adaptor to update once
320 void RequestUpdateOnce();
323 * Request adaptor to update indicator's height
325 void IndicatorSizeChanged(int height);
328 * @copydoc Dali::Adaptor::NotifySceneCreated()
330 void NotifySceneCreated();
333 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
335 void NotifyLanguageChanged();
338 * Gets AppId of current application
340 void GetAppId( std::string& appId );
343 * Informs core the surface size has changed
345 void SurfaceResizePrepare( SurfaceSize surfaceSize );
348 * Informs ThreadController the surface size has changed
350 void SurfaceResizeComplete( SurfaceSize surfaceSize );
353 * Sets layout direction of root by system language
354 * @param[in] locale System locale
356 void SetRootLayoutDirection( std::string locale );
359 * @copydoc Dali::Adaptor::RenderOnce
363 public: //AdaptorInternalServices
366 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
368 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
371 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
373 virtual Dali::Integration::GlAbstraction& GetGlesInterface();
376 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
378 virtual EglFactoryInterface& GetEGLFactoryInterface() const;
381 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
383 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
386 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
388 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
391 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
393 virtual SocketFactoryInterface& GetSocketFactoryInterface();
396 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
398 virtual RenderSurface* GetRenderSurfaceInterface();
401 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
403 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
406 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
408 virtual PerformanceInterface* GetPerformanceInterface();
411 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
413 virtual TraceInterface& GetKernelTraceInterface();
416 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
418 virtual TraceInterface& GetSystemTraceInterface();
420 public: // Stereoscopy
423 * @copydoc Dali::Integration::Core::SetViewMode()
425 void SetViewMode( ViewMode viewMode );
428 * @copydoc Dali::Integration::Core::GetViewMode()
430 ViewMode GetViewMode() const;
433 * @copydoc Dali::Integration::Core::SetStereoBase()
435 void SetStereoBase( float stereoBase );
438 * @copydoc Dali::Integration::Core::GetStereoBase()
440 float GetStereoBase() const;
445 void SetWindow( Dali::Window window );
448 * Return Window handle.
450 Dali::Window GetWindow();
455 * @copydoc Dali::Adaptor::SignalResized
457 AdaptorSignalType& ResizedSignal()
459 return mResizedSignal;
463 * @copydoc Dali::Adaptor::LanguageChangedSignal
465 AdaptorSignalType& LanguageChangedSignal()
467 return mLanguageChangedSignal;
470 private: // From Dali::Internal::Adaptor::CoreEventInterface
473 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
475 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
478 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
480 virtual void ProcessCoreEvents();
482 private: // From Dali::Integration::RenderController
485 * @copydoc Dali::Integration::RenderController::RequestUpdate()
487 virtual void RequestUpdate( bool forceUpdate );
490 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
492 virtual void RequestProcessEventsOnIdle( bool forceProcess );
494 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
497 * Called when the window becomes fully or partially visible.
499 virtual void OnWindowShown();
502 * Called when the window is fully hidden.
504 virtual void OnWindowHidden();
506 private: // From Dali::Internal::Adaptor::DamageObserver
509 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
511 void OnDamaged( const DamageArea& area );
516 Adaptor(const Adaptor&);
517 Adaptor& operator=(Adaptor&);
522 * Assigns the render surface to the adaptor
525 void SetSurface(RenderSurface *surface);
528 * called after surface is created
530 void SurfaceInitialized();
533 * Sends an notification message from main loop idle handler
535 void ProcessCoreEventsFromIdle();
538 * Gets path for data/resource storage.
539 * @param[out] path Path for data/resource storage
541 void GetDataStoragePath(std::string& path);
544 * Sets up system information if needs
546 void SetupSystemInformation();
552 * @param[in] nativeWindow native window handle
553 * @param[in] adaptor The public adaptor
554 * @param[in] surface A render surface can be one of the following
555 * - Pixmap, adaptor will use existing Pixmap to draw on to
556 * - Window, adaptor will use existing Window to draw on to
557 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
559 Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions );
565 READY, ///< Initial state before Adaptor::Start is called.
566 RUNNING, ///< Adaptor is running.
567 PAUSED, ///< Adaptor has been paused.
568 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
569 STOPPED, ///< Adaptor has been stopped.
572 typedef std::vector<LifeCycleObserver*> ObserverContainer;
576 AdaptorSignalType mResizedSignal; ///< Resized signal.
577 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
579 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
580 State mState; ///< Current state of the adaptor
581 Dali::Integration::Core* mCore; ///< Dali Core
582 ThreadController* mThreadController; ///< Controls the threads
583 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
584 GlImplementation* mGLES; ///< GL implementation
585 GlSyncImplementation* mGlSync; ///< GL Sync implementation
586 EglFactory* mEglFactory; ///< EGL Factory
588 Any mNativeWindow; ///< window identifier
589 RenderSurface* mSurface; ///< Current surface
590 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
592 EventHandler* mEventHandler; ///< event handler
593 CallbackManager* mCallbackManager; ///< Used to install callbacks
594 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
595 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
596 GestureManager* mGestureManager; ///< Gesture manager
597 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
598 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
599 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
600 ObserverContainer mObservers; ///< A list of adaptor observer pointers
601 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
602 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
603 EnvironmentOptions* mEnvironmentOptions; ///< environment options
604 PerformanceInterface* mPerformanceInterface; ///< Performance interface
605 KernelTrace mKernelTracer; ///< Kernel tracer
606 SystemTrace mSystemTracer; ///< System tracer
607 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
608 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
609 SocketFactory mSocketFactory; ///< Socket factory
610 Dali::Window mWindow; ///< Window handle
611 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
612 bool mUseRemoteSurface; ///< whether the remoteSurface is used or not
614 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
617 } // namespace Internal
619 } // namespace Adaptor
623 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__