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/integration-api/render-controller.h>
30 #include <render-surface.h>
31 #include <tts-player.h>
32 #include <imf-manager.h>
33 #include <clipboard.h>
35 #include <tizen-platform-abstraction.h>
36 #include <base/interfaces/adaptor-internal-services.h>
37 #include <base/environment-options.h>
38 #include <base/core-event-interface.h>
39 #include <drag-and-drop-detector-impl.h>
40 #include <damage-observer.h>
41 #include <window-visibility-observer.h>
42 #include <kernel-trace.h>
43 #include <system-trace.h>
44 #include <trigger-event-factory.h>
45 #include <networking/socket-factory.h>
67 class GlImplementation;
68 class GlSyncImplementation;
69 class ThreadController;
71 class CallbackManager;
72 class FeedbackPluginProxy;
73 class FeedbackController;
74 class RotationObserver;
76 class PerformanceInterface;
77 class LifeCycleObserver;
81 * Implementation of the Adaptor class.
83 class Adaptor : public Integration::RenderController,
84 public AdaptorInternalServices,
85 public CoreEventInterface,
86 public DamageObserver,
87 public WindowVisibilityObserver
91 typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
94 * Creates a New Adaptor
95 * @param[in] nativeWindow Native window handle
96 * @param[in] surface A render surface can be one of the following
97 * - Pixmap, adaptor will use existing Pixmap to draw on to
98 * - Window, adaptor will use existing Window to draw on to
99 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
100 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
102 static Dali::Adaptor* New( Any nativeWindow,
103 RenderSurface* surface,
104 Dali::Configuration::ContextLoss configuration,
105 EnvironmentOptions* environmentOptions );
108 * Creates a New Adaptor
109 * @param[in] nativeWindow native window handle
110 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
111 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
113 static Dali::Adaptor* New( Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions );
116 * 2-step initialisation, this should be called after creating an adaptor instance.
118 void Initialize(Dali::Configuration::ContextLoss configuration);
121 * Virtual destructor.
126 * @copydoc Dali::Adaptor::Get()
128 static Dali::Adaptor& Get();
131 * @copydoc Dali::Adaptor::IsAvailable()
133 static bool IsAvailable();
136 * @copydoc Dali::Core::SceneCreated();
140 public: // AdaptorInternalServices implementation
142 * @copydoc Dali::Adaptor::Start()
144 virtual void Start();
147 * @copydoc Dali::Adaptor::Pause()
149 virtual void Pause();
152 * @copydoc Dali::Adaptor::Resume()
154 virtual void Resume();
157 * @copydoc Dali::Adaptor::Stop()
162 * @copydoc Dali::Adaptor::ContextLost()
164 virtual void ContextLost();
167 * @copydoc Dali::Adaptor::ContextRegained()
169 virtual void ContextRegained();
172 * @copydoc Dali::EventFeeder::FeedTouchPoint()
174 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
177 * @copydoc Dali::EventFeeder::FeedWheelEvent()
179 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
182 * @copydoc Dali::EventFeeder::FeedKeyEvent()
184 virtual void FeedKeyEvent( KeyEvent& keyEvent );
187 * @copydoc AdaptorInterface::ReplaceSurface()
189 virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
192 * @copydoc Dali::Adaptor::GetSurface()
194 virtual RenderSurface& GetSurface() const;
197 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
199 virtual void ReleaseSurfaceLock();
202 * Retrieve the TtsPlayer.
203 * @param[in] mode The mode of TtsPlayer
204 * @return A handle to the TtsPlayer.
206 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
209 * @copydoc Dali::Adaptor::AddIdle()
211 virtual bool AddIdle( CallbackBase* callback );
214 * @copydoc Dali::Adaptor::RemoveIdle()
216 virtual void RemoveIdle( CallbackBase* callback );
221 * @return the Core instance
223 virtual Dali::Integration::Core& GetCore();
226 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
228 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
231 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
233 void SetUseHardwareVSync(bool useHardware);
236 * @return reference to EglFactory class
238 EglFactory& GetEGLFactory() const;
241 * Return GlAbstraction.
242 * @return the GlAbstraction.
244 Integration::GlAbstraction& GetGlAbstraction() const;
247 * Return the PlatformAbstraction.
248 * @return The PlatformAbstraction.
250 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
253 * Sets the Drag & Drop Listener.
254 * @param[in] detector The detector to send Drag & Drop events to.
256 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
259 * Sets a rotation observer, or set to NULL to remove.
260 * @pre Adaptor::Start() has been called ( to create EventHandler )
261 * @param[in] observer The observer to listen for window rotation events
263 void SetRotationObserver( RotationObserver* observer );
266 * Destroy the TtsPlayer of sepcific mode.
267 * @param[in] mode The mode of TtsPlayer to destroy
269 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
272 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
273 * trigger a pinch gesture
275 * @param[in] distance The minimum pinch distance in pixels
277 void SetMinimumPinchDistance(float distance);
280 * Gets native window handle
282 * @return native window handle
284 Any GetNativeWindowHandle();
287 * Sets use remote surface for eglSurface output
288 * @param[in] useRemoteSurface True if the remote surface is used
290 void SetUseRemoteSurface(bool useRemoteSurface);
295 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
296 * @param[in] observer The observer.
297 * @note Observers should remove themselves when they are destroyed.
299 void AddObserver( LifeCycleObserver& observer );
302 * Removes the observer from the adaptor.
303 * @param[in] observer The observer to remove.
304 * @note Observers should remove themselves when they are destroyed.
306 void RemoveObserver( LifeCycleObserver& observer );
309 * Emits the Notification event to the Dali core.
311 void SendNotificationEvent();
314 * Request adaptor to update once
316 void RequestUpdateOnce();
319 * Request adaptor to update indicator's height
321 void IndicatorSizeChanged(int height);
324 * @copydoc Dali::Adaptor::NotifySceneCreated()
326 void NotifySceneCreated();
329 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
331 void NotifyLanguageChanged();
334 * Gets AppId of current application
336 void GetAppId( std::string& appId );
339 * Informs core the surface size has changed
341 void SurfaceResizePrepare( Dali::Adaptor::SurfaceSize surfaceSize );
344 * Informs ThreadController the surface size has changed
346 void SurfaceResizeComplete( Dali::Adaptor::SurfaceSize surfaceSize );
349 * Sets layout direction of root by system language
350 * @param[in] locale System locale
352 void SetRootLayoutDirection( std::string locale );
355 * @copydoc Dali::Adaptor::RenderOnce
359 public: //AdaptorInternalServices
362 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
364 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
367 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
369 virtual Dali::Integration::GlAbstraction& GetGlesInterface();
372 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
374 virtual EglFactoryInterface& GetEGLFactoryInterface() const;
377 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
379 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
382 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
384 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
387 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
389 virtual SocketFactoryInterface& GetSocketFactoryInterface();
392 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
394 virtual RenderSurface* GetRenderSurfaceInterface();
397 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
399 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
402 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
404 virtual PerformanceInterface* GetPerformanceInterface();
407 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
409 virtual TraceInterface& GetKernelTraceInterface();
412 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
414 virtual TraceInterface& GetSystemTraceInterface();
416 public: // Stereoscopy
419 * @copydoc Dali::Integration::Core::SetViewMode()
421 void SetViewMode( ViewMode viewMode );
424 * @copydoc Dali::Integration::Core::GetViewMode()
426 ViewMode GetViewMode() const;
429 * @copydoc Dali::Integration::Core::SetStereoBase()
431 void SetStereoBase( float stereoBase );
434 * @copydoc Dali::Integration::Core::GetStereoBase()
436 float GetStereoBase() const;
441 * @copydoc Dali::Adaptor::SignalResized
443 AdaptorSignalType& ResizedSignal()
445 return mResizedSignal;
449 * @copydoc Dali::Adaptor::LanguageChangedSignal
451 AdaptorSignalType& LanguageChangedSignal()
453 return mLanguageChangedSignal;
456 private: // From Dali::Internal::Adaptor::CoreEventInterface
459 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
461 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
464 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
466 virtual void ProcessCoreEvents();
468 private: // From Dali::Integration::RenderController
471 * Called by the Dali core when it requires another update
473 virtual void RequestUpdate();
476 * Called by Dali core when it requires an notification event being sent on idle.
477 * Multi-threading note: this method must be called from the main thread only.
479 virtual void RequestProcessEventsOnIdle();
481 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
484 * Called when the window becomes fully or partially visible.
486 virtual void OnWindowShown();
489 * Called when the window is fully hidden.
491 virtual void OnWindowHidden();
493 private: // From Dali::Internal::Adaptor::DamageObserver
496 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
498 void OnDamaged( const DamageArea& area );
503 Adaptor(const Adaptor&);
504 Adaptor& operator=(Adaptor&);
509 * Assigns the render surface to the adaptor
512 void SetSurface(RenderSurface *surface);
515 * called after surface is created
517 void SurfaceInitialized();
520 * Sends an notification message from main loop idle handler
522 void ProcessCoreEventsFromIdle();
525 * Gets path for data/resource storage.
526 * @param[out] path Path for data/resource storage
528 void GetDataStoragePath(std::string& path);
531 * Sets up system information if needs
533 void SetupSystemInformation();
539 * @param[in] nativeWindow native window handle
540 * @param[in] adaptor The public adaptor
541 * @param[in] surface A render surface can be one of the following
542 * - Pixmap, adaptor will use existing Pixmap to draw on to
543 * - Window, adaptor will use existing Window to draw on to
544 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
546 Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions );
552 READY, ///< Initial state before Adaptor::Start is called.
553 RUNNING, ///< Adaptor is running.
554 PAUSED, ///< Adaptor has been paused.
555 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
556 STOPPED, ///< Adaptor has been stopped.
559 typedef std::vector<LifeCycleObserver*> ObserverContainer;
563 AdaptorSignalType mResizedSignal; ///< Resized signal.
564 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
566 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
567 State mState; ///< Current state of the adaptor
568 Dali::Integration::Core* mCore; ///< Dali Core
569 ThreadController* mThreadController; ///< Controls the threads
570 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
571 GlImplementation* mGLES; ///< GL implementation
572 GlSyncImplementation* mGlSync; ///< GL Sync implementation
573 EglFactory* mEglFactory; ///< EGL Factory
575 Any mNativeWindow; ///< window identifier
576 RenderSurface* mSurface; ///< Current surface
577 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
579 EventHandler* mEventHandler; ///< event handler
580 CallbackManager* mCallbackManager; ///< Used to install callbacks
581 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
582 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
583 GestureManager* mGestureManager; ///< Gesture manager
584 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
585 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
586 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
587 ObserverContainer mObservers; ///< A list of adaptor observer pointers
588 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
589 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
590 EnvironmentOptions* mEnvironmentOptions; ///< environment options
591 PerformanceInterface* mPerformanceInterface; ///< Performance interface
592 KernelTrace mKernelTracer; ///< Kernel tracer
593 SystemTrace mSystemTracer; ///< System tracer
594 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
595 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
596 SocketFactory mSocketFactory; ///< Socket factory
597 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
598 bool mUseRemoteSurface; ///< whether the remoteSurface is used or not
600 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
603 } // namespace Internal
605 } // namespace Adaptor
609 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__