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/devel-api/adaptor-framework/render-surface.h>
32 #include <dali/public-api/adaptor-framework/tts-player.h>
33 #include <dali/devel-api/adaptor-framework/clipboard.h>
35 #include <dali/internal/legacy/common/tizen-platform-abstraction.h>
36 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
37 #include <dali/internal/system/common/environment-options.h>
38 #include <dali/internal/system/common/core-event-interface.h>
39 #include <dali/internal/input/common/drag-and-drop-detector-impl.h>
40 #include <dali/internal/window-system/common/damage-observer.h>
41 #include <dali/internal/window-system/common/window-visibility-observer.h>
42 #include <dali/internal/system/common/kernel-trace.h>
43 #include <dali/internal/system/common/system-trace.h>
44 #include <dali/integration-api/trigger-event-factory.h>
45 #include <dali/internal/network/common/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;
93 typedef Uint16Pair SurfaceSize; ///< Surface size type
96 * Creates a New Adaptor
97 * @param[in] nativeWindow Native window handle
98 * @param[in] surface A render surface can be one of the following
99 * - Pixmap, adaptor will use existing Pixmap to draw on to
100 * - Window, adaptor will use existing Window to draw on to
101 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
102 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
104 static Dali::Adaptor* New( Any nativeWindow,
105 RenderSurface* surface,
106 Dali::Configuration::ContextLoss configuration,
107 EnvironmentOptions* environmentOptions );
110 * Creates a New Adaptor
111 * @param[in] nativeWindow native window handle
112 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
113 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
115 static Dali::Adaptor* New( Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions );
118 * 2-step initialisation, this should be called after creating an adaptor instance.
120 void Initialize(Dali::Configuration::ContextLoss configuration);
123 * Virtual destructor.
128 * @copydoc Dali::Adaptor::Get()
130 static Dali::Adaptor& Get();
133 * @copydoc Dali::Adaptor::IsAvailable()
135 static bool IsAvailable();
138 * @copydoc Dali::Core::SceneCreated();
142 public: // AdaptorInternalServices implementation
144 * @copydoc Dali::Adaptor::Start()
146 virtual void Start();
149 * @copydoc Dali::Adaptor::Pause()
151 virtual void Pause();
154 * @copydoc Dali::Adaptor::Resume()
156 virtual void Resume();
159 * @copydoc Dali::Adaptor::Stop()
164 * @copydoc Dali::Adaptor::ContextLost()
166 virtual void ContextLost();
169 * @copydoc Dali::Adaptor::ContextRegained()
171 virtual void ContextRegained();
174 * @copydoc Dali::EventFeeder::FeedTouchPoint()
176 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
179 * @copydoc Dali::EventFeeder::FeedWheelEvent()
181 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
184 * @copydoc Dali::EventFeeder::FeedKeyEvent()
186 virtual void FeedKeyEvent( KeyEvent& keyEvent );
189 * @copydoc AdaptorInterface::ReplaceSurface()
191 virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
194 * @copydoc Dali::Adaptor::GetSurface()
196 virtual RenderSurface& GetSurface() const;
199 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
201 virtual void ReleaseSurfaceLock();
204 * Retrieve the TtsPlayer.
205 * @param[in] mode The mode of TtsPlayer
206 * @return A handle to the TtsPlayer.
208 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
211 * @copydoc Dali::Adaptor::AddIdle()
213 virtual bool AddIdle( CallbackBase* callback, bool forceAdd );
216 * @copydoc Dali::Adaptor::RemoveIdle()
218 virtual void RemoveIdle( CallbackBase* callback );
223 * @return the Core instance
225 virtual Dali::Integration::Core& GetCore();
228 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
230 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
233 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
235 void SetUseHardwareVSync(bool useHardware);
238 * @return reference to EglFactory class
240 EglFactory& GetEGLFactory() const;
243 * Return GlAbstraction.
244 * @return the GlAbstraction.
246 Integration::GlAbstraction& GetGlAbstraction() const;
249 * Return the PlatformAbstraction.
250 * @return The PlatformAbstraction.
252 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
255 * Sets the Drag & Drop Listener.
256 * @param[in] detector The detector to send Drag & Drop events to.
258 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
261 * Sets a rotation observer, or set to NULL to remove.
262 * @pre Adaptor::Start() has been called ( to create EventHandler )
263 * @param[in] observer The observer to listen for window rotation events
265 void SetRotationObserver( RotationObserver* observer );
268 * Destroy the TtsPlayer of sepcific mode.
269 * @param[in] mode The mode of TtsPlayer to destroy
271 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
274 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
275 * trigger a pinch gesture
277 * @param[in] distance The minimum pinch distance in pixels
279 void SetMinimumPinchDistance(float distance);
282 * Gets native window handle
284 * @return native window handle
286 Any GetNativeWindowHandle();
289 * Sets use remote surface for eglSurface output
290 * @param[in] useRemoteSurface True if the remote surface is used
292 void SetUseRemoteSurface(bool useRemoteSurface);
297 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
298 * @param[in] observer The observer.
299 * @note Observers should remove themselves when they are destroyed.
301 void AddObserver( LifeCycleObserver& observer );
304 * Removes the observer from the adaptor.
305 * @param[in] observer The observer to remove.
306 * @note Observers should remove themselves when they are destroyed.
308 void RemoveObserver( LifeCycleObserver& observer );
311 * Emits the Notification event to the Dali core.
313 void SendNotificationEvent();
316 * Request adaptor to update once
318 void RequestUpdateOnce();
321 * Request adaptor to update indicator's height
323 void IndicatorSizeChanged(int height);
326 * @copydoc Dali::Adaptor::NotifySceneCreated()
328 void NotifySceneCreated();
331 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
333 void NotifyLanguageChanged();
336 * Gets AppId of current application
338 void GetAppId( std::string& appId );
341 * Informs core the surface size has changed
343 void SurfaceResizePrepare( SurfaceSize surfaceSize );
346 * Informs ThreadController the surface size has changed
348 void SurfaceResizeComplete( SurfaceSize surfaceSize );
351 * Sets layout direction of root by system language
352 * @param[in] locale System locale
354 void SetRootLayoutDirection( std::string locale );
357 * @copydoc Dali::Adaptor::RenderOnce
362 * @copydoc Dali::Adaptor::GetLogFactory
364 const LogFactoryInterface& GetLogFactory();
366 public: //AdaptorInternalServices
369 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
371 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
374 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
376 virtual Dali::Integration::GlAbstraction& GetGlesInterface();
379 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
381 virtual EglFactoryInterface& GetEGLFactoryInterface() const;
384 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
386 virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
389 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
391 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
394 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
396 virtual SocketFactoryInterface& GetSocketFactoryInterface();
399 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
401 virtual RenderSurface* GetRenderSurfaceInterface();
404 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
406 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
409 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
411 virtual PerformanceInterface* GetPerformanceInterface();
414 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
416 virtual TraceInterface& GetKernelTraceInterface();
419 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
421 virtual TraceInterface& GetSystemTraceInterface();
423 public: // Stereoscopy
426 * @copydoc Dali::Integration::Core::SetViewMode()
428 void SetViewMode( ViewMode viewMode );
431 * @copydoc Dali::Integration::Core::GetViewMode()
433 ViewMode GetViewMode() const;
436 * @copydoc Dali::Integration::Core::SetStereoBase()
438 void SetStereoBase( float stereoBase );
441 * @copydoc Dali::Integration::Core::GetStereoBase()
443 float GetStereoBase() const;
448 * @copydoc Dali::Adaptor::SignalResized
450 AdaptorSignalType& ResizedSignal()
452 return mResizedSignal;
456 * @copydoc Dali::Adaptor::LanguageChangedSignal
458 AdaptorSignalType& LanguageChangedSignal()
460 return mLanguageChangedSignal;
463 private: // From Dali::Internal::Adaptor::CoreEventInterface
466 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
468 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
471 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
473 virtual void ProcessCoreEvents();
475 private: // From Dali::Integration::RenderController
478 * @copydoc Dali::Integration::RenderController::RequestUpdate()
480 virtual void RequestUpdate( bool forceUpdate );
483 * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
485 virtual void RequestProcessEventsOnIdle( bool forceProcess );
487 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
490 * Called when the window becomes fully or partially visible.
492 virtual void OnWindowShown();
495 * Called when the window is fully hidden.
497 virtual void OnWindowHidden();
499 private: // From Dali::Internal::Adaptor::DamageObserver
502 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
504 void OnDamaged( const DamageArea& area );
509 Adaptor(const Adaptor&);
510 Adaptor& operator=(Adaptor&);
515 * Assigns the render surface to the adaptor
518 void SetSurface(RenderSurface *surface);
521 * called after surface is created
523 void SurfaceInitialized();
526 * Sends an notification message from main loop idle handler
528 void ProcessCoreEventsFromIdle();
531 * Gets path for data/resource storage.
532 * @param[out] path Path for data/resource storage
534 void GetDataStoragePath(std::string& path);
537 * Sets up system information if needs
539 void SetupSystemInformation();
545 * @param[in] nativeWindow native window handle
546 * @param[in] adaptor The public adaptor
547 * @param[in] surface A render surface can be one of the following
548 * - Pixmap, adaptor will use existing Pixmap to draw on to
549 * - Window, adaptor will use existing Window to draw on to
550 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
552 Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions );
558 READY, ///< Initial state before Adaptor::Start is called.
559 RUNNING, ///< Adaptor is running.
560 PAUSED, ///< Adaptor has been paused.
561 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
562 STOPPED, ///< Adaptor has been stopped.
565 typedef std::vector<LifeCycleObserver*> ObserverContainer;
569 AdaptorSignalType mResizedSignal; ///< Resized signal.
570 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
572 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
573 State mState; ///< Current state of the adaptor
574 Dali::Integration::Core* mCore; ///< Dali Core
575 ThreadController* mThreadController; ///< Controls the threads
576 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
577 GlImplementation* mGLES; ///< GL implementation
578 GlSyncImplementation* mGlSync; ///< GL Sync implementation
579 EglFactory* mEglFactory; ///< EGL Factory
581 Any mNativeWindow; ///< window identifier
582 RenderSurface* mSurface; ///< Current surface
583 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
585 EventHandler* mEventHandler; ///< event handler
586 CallbackManager* mCallbackManager; ///< Used to install callbacks
587 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
588 TriggerEventInterface* mNotificationTrigger; ///< Notification event trigger
589 GestureManager* mGestureManager; ///< Gesture manager
590 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
591 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
592 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
593 ObserverContainer mObservers; ///< A list of adaptor observer pointers
594 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
595 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
596 EnvironmentOptions* mEnvironmentOptions; ///< environment options
597 PerformanceInterface* mPerformanceInterface; ///< Performance interface
598 KernelTrace mKernelTracer; ///< Kernel tracer
599 SystemTrace mSystemTracer; ///< System tracer
600 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
601 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
602 SocketFactory mSocketFactory; ///< Socket factory
603 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
604 bool mUseRemoteSurface; ///< whether the remoteSurface is used or not
606 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
609 } // namespace Internal
611 } // namespace Adaptor
615 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__