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>
31 #include <render-surface.h>
32 #include <tts-player.h>
33 #include <imf-manager.h>
34 #include <clipboard.h>
36 #include <tizen-platform-abstraction.h>
37 #include <base/interfaces/adaptor-internal-services.h>
38 #include <base/environment-options.h>
39 #include <base/core-event-interface.h>
40 #include <drag-and-drop-detector-impl.h>
41 #include <damage-observer.h>
42 #include <window-visibility-observer.h>
43 #include <kernel-trace.h>
44 #include <system-trace.h>
45 #include <trigger-event-factory.h>
46 #include <networking/socket-factory.h>
68 class GlImplementation;
69 class GlSyncImplementation;
70 class ThreadController;
72 class CallbackManager;
73 class FeedbackPluginProxy;
74 class FeedbackController;
75 class RotationObserver;
77 class PerformanceInterface;
78 class LifeCycleObserver;
82 * Implementation of the Adaptor class.
84 class Adaptor : public Integration::RenderController,
85 public AdaptorInternalServices,
86 public CoreEventInterface,
87 public DamageObserver,
88 public WindowVisibilityObserver
92 typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
94 typedef Uint16Pair SurfaceSize; ///< Surface size type
97 * Creates a New Adaptor
98 * @param[in] nativeWindow Native window handle
99 * @param[in] surface A render surface can be one of the following
100 * - Pixmap, adaptor will use existing Pixmap to draw on to
101 * - Window, adaptor will use existing Window to draw on to
102 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
103 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
105 static Dali::Adaptor* New( Any nativeWindow,
106 RenderSurface* surface,
107 Dali::Configuration::ContextLoss configuration,
108 EnvironmentOptions* environmentOptions );
111 * Creates a New Adaptor
112 * @param[in] nativeWindow native window handle
113 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
114 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
116 static Dali::Adaptor* New( Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions );
119 * 2-step initialisation, this should be called after creating an adaptor instance.
121 void Initialize(Dali::Configuration::ContextLoss configuration);
124 * Virtual destructor.
129 * @copydoc Dali::Adaptor::Get()
131 static Dali::Adaptor& Get();
134 * @copydoc Dali::Adaptor::IsAvailable()
136 static bool IsAvailable();
139 * @copydoc Dali::Core::SceneCreated();
143 public: // AdaptorInternalServices implementation
145 * @copydoc Dali::Adaptor::Start()
147 virtual void Start();
150 * @copydoc Dali::Adaptor::Pause()
152 virtual void Pause();
155 * @copydoc Dali::Adaptor::Resume()
157 virtual void Resume();
160 * @copydoc Dali::Adaptor::Stop()
165 * @copydoc Dali::Adaptor::ContextLost()
167 virtual void ContextLost();
170 * @copydoc Dali::Adaptor::ContextRegained()
172 virtual void ContextRegained();
175 * @copydoc Dali::EventFeeder::FeedTouchPoint()
177 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
180 * @copydoc Dali::EventFeeder::FeedWheelEvent()
182 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
185 * @copydoc Dali::EventFeeder::FeedKeyEvent()
187 virtual void FeedKeyEvent( KeyEvent& keyEvent );
190 * @copydoc AdaptorInterface::ReplaceSurface()
192 virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
195 * @copydoc Dali::Adaptor::GetSurface()
197 virtual RenderSurface& GetSurface() const;
200 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
202 virtual void ReleaseSurfaceLock();
205 * Retrieve the TtsPlayer.
206 * @param[in] mode The mode of TtsPlayer
207 * @return A handle to the TtsPlayer.
209 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
212 * @copydoc Dali::Adaptor::AddIdle()
214 virtual bool AddIdle( CallbackBase* callback );
217 * @copydoc Dali::Adaptor::RemoveIdle()
219 virtual void RemoveIdle( CallbackBase* callback );
224 * @return the Core instance
226 virtual Dali::Integration::Core& GetCore();
229 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
231 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
234 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
236 void SetUseHardwareVSync(bool useHardware);
239 * @return reference to EglFactory class
241 EglFactory& GetEGLFactory() const;
244 * Return GlAbstraction.
245 * @return the GlAbstraction.
247 Integration::GlAbstraction& GetGlAbstraction() const;
250 * Return the PlatformAbstraction.
251 * @return The PlatformAbstraction.
253 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
256 * Sets the Drag & Drop Listener.
257 * @param[in] detector The detector to send Drag & Drop events to.
259 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
262 * Sets a rotation observer, or set to NULL to remove.
263 * @pre Adaptor::Start() has been called ( to create EventHandler )
264 * @param[in] observer The observer to listen for window rotation events
266 void SetRotationObserver( RotationObserver* observer );
269 * Destroy the TtsPlayer of sepcific mode.
270 * @param[in] mode The mode of TtsPlayer to destroy
272 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
275 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
276 * trigger a pinch gesture
278 * @param[in] distance The minimum pinch distance in pixels
280 void SetMinimumPinchDistance(float distance);
283 * Gets native window handle
285 * @return native window handle
287 Any GetNativeWindowHandle();
290 * Sets use remote surface for eglSurface output
291 * @param[in] useRemoteSurface True if the remote surface is used
293 void SetUseRemoteSurface(bool useRemoteSurface);
298 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
299 * @param[in] observer The observer.
300 * @note Observers should remove themselves when they are destroyed.
302 void AddObserver( LifeCycleObserver& observer );
305 * Removes the observer from the adaptor.
306 * @param[in] observer The observer to remove.
307 * @note Observers should remove themselves when they are destroyed.
309 void RemoveObserver( LifeCycleObserver& observer );
312 * Emits the Notification event to the Dali core.
314 void SendNotificationEvent();
317 * Request adaptor to update once
319 void RequestUpdateOnce();
322 * Request adaptor to update indicator's height
324 void IndicatorSizeChanged(int height);
327 * @copydoc Dali::Adaptor::NotifySceneCreated()
329 void NotifySceneCreated();
332 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
334 void NotifyLanguageChanged();
337 * Gets AppId of current application
339 void GetAppId( std::string& appId );
342 * Informs core the surface size has changed
344 void SurfaceResizePrepare( SurfaceSize surfaceSize );
347 * Informs ThreadController the surface size has changed
349 void SurfaceResizeComplete( SurfaceSize surfaceSize );
352 * Sets layout direction of root by system language
353 * @param[in] locale System locale
355 void SetRootLayoutDirection( std::string locale );
358 * @copydoc Dali::Adaptor::RenderOnce
362 public: //AdaptorInternalServices
365 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
367 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
370 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
372 virtual Dali::Integration::GlAbstraction& GetGlesInterface();
375 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
377 virtual EglFactoryInterface& GetEGLFactoryInterface() const;
380 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
382 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
385 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
387 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
390 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
392 virtual SocketFactoryInterface& GetSocketFactoryInterface();
395 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
397 virtual RenderSurface* GetRenderSurfaceInterface();
400 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
402 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
405 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
407 virtual PerformanceInterface* GetPerformanceInterface();
410 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
412 virtual TraceInterface& GetKernelTraceInterface();
415 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
417 virtual TraceInterface& GetSystemTraceInterface();
419 public: // Stereoscopy
422 * @copydoc Dali::Integration::Core::SetViewMode()
424 void SetViewMode( ViewMode viewMode );
427 * @copydoc Dali::Integration::Core::GetViewMode()
429 ViewMode GetViewMode() const;
432 * @copydoc Dali::Integration::Core::SetStereoBase()
434 void SetStereoBase( float stereoBase );
437 * @copydoc Dali::Integration::Core::GetStereoBase()
439 float GetStereoBase() const;
444 * @copydoc Dali::Adaptor::SignalResized
446 AdaptorSignalType& ResizedSignal()
448 return mResizedSignal;
452 * @copydoc Dali::Adaptor::LanguageChangedSignal
454 AdaptorSignalType& LanguageChangedSignal()
456 return mLanguageChangedSignal;
459 private: // From Dali::Internal::Adaptor::CoreEventInterface
462 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
464 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
467 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
469 virtual void ProcessCoreEvents();
471 private: // From Dali::Integration::RenderController
474 * Called by the Dali core when it requires another update
476 virtual void RequestUpdate();
479 * Called by Dali core when it requires an notification event being sent on idle.
480 * Multi-threading note: this method must be called from the main thread only.
482 virtual void RequestProcessEventsOnIdle();
484 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
487 * Called when the window becomes fully or partially visible.
489 virtual void OnWindowShown();
492 * Called when the window is fully hidden.
494 virtual void OnWindowHidden();
496 private: // From Dali::Internal::Adaptor::DamageObserver
499 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
501 void OnDamaged( const DamageArea& area );
506 Adaptor(const Adaptor&);
507 Adaptor& operator=(Adaptor&);
512 * Assigns the render surface to the adaptor
515 void SetSurface(RenderSurface *surface);
518 * called after surface is created
520 void SurfaceInitialized();
523 * Sends an notification message from main loop idle handler
525 void ProcessCoreEventsFromIdle();
528 * Gets path for data/resource storage.
529 * @param[out] path Path for data/resource storage
531 void GetDataStoragePath(std::string& path);
534 * Sets up system information if needs
536 void SetupSystemInformation();
542 * @param[in] nativeWindow native window handle
543 * @param[in] adaptor The public adaptor
544 * @param[in] surface A render surface can be one of the following
545 * - Pixmap, adaptor will use existing Pixmap to draw on to
546 * - Window, adaptor will use existing Window to draw on to
547 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
549 Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions );
555 READY, ///< Initial state before Adaptor::Start is called.
556 RUNNING, ///< Adaptor is running.
557 PAUSED, ///< Adaptor has been paused.
558 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
559 STOPPED, ///< Adaptor has been stopped.
562 typedef std::vector<LifeCycleObserver*> ObserverContainer;
566 AdaptorSignalType mResizedSignal; ///< Resized signal.
567 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
569 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
570 State mState; ///< Current state of the adaptor
571 Dali::Integration::Core* mCore; ///< Dali Core
572 ThreadController* mThreadController; ///< Controls the threads
573 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
574 GlImplementation* mGLES; ///< GL implementation
575 GlSyncImplementation* mGlSync; ///< GL Sync implementation
576 EglFactory* mEglFactory; ///< EGL Factory
578 Any mNativeWindow; ///< window identifier
579 RenderSurface* mSurface; ///< Current surface
580 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
582 EventHandler* mEventHandler; ///< event handler
583 CallbackManager* mCallbackManager; ///< Used to install callbacks
584 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
585 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
586 GestureManager* mGestureManager; ///< Gesture manager
587 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
588 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
589 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
590 ObserverContainer mObservers; ///< A list of adaptor observer pointers
591 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
592 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
593 EnvironmentOptions* mEnvironmentOptions; ///< environment options
594 PerformanceInterface* mPerformanceInterface; ///< Performance interface
595 KernelTrace mKernelTracer; ///< Kernel tracer
596 SystemTrace mSystemTracer; ///< System tracer
597 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
598 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
599 SocketFactory mSocketFactory; ///< Socket factory
600 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
601 bool mUseRemoteSurface; ///< whether the remoteSurface is used or not
603 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
606 } // namespace Internal
608 } // namespace Adaptor
612 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__