1 #ifndef __DALI_INTERNAL_ADAPTOR_IMPL_H__
2 #define __DALI_INTERNAL_ADAPTOR_IMPL_H__
5 * Copyright (c) 2014 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 <device-layout.h>
34 #include <clipboard.h>
36 #include <slp-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 <trigger-event-factory.h>
63 class GlImplementation;
64 class GlSyncImplementation;
66 class UpdateRenderController;
68 class CallbackManager;
69 class FeedbackPluginProxy;
70 class FeedbackController;
71 class RotationObserver;
73 class PerformanceInterface;
74 class LifeCycleObserver;
78 * Implementation of the Adaptor class.
80 class Adaptor : public Integration::RenderController,
81 public AdaptorInternalServices,
82 public CoreEventInterface,
83 public DamageObserver,
84 public WindowVisibilityObserver
88 typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
91 * Creates a New Adaptor
92 * @param[in] surface A render surface can be one of the following
93 * - Pixmap, adaptor will use existing Pixmap to draw on to
94 * - Window, adaptor will use existing Window to draw on to
95 * @param[in] baseLayout The base layout that the application has been written for
96 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
98 static Dali::Adaptor* New( RenderSurface* surface,
99 const DeviceLayout& baseLayout,
100 Dali::Configuration::ContextLoss configuration );
103 * 2-step initialisation, this should be called after creating an adaptor instance.
105 void Initialize(Dali::Configuration::ContextLoss configuration);
108 * Virtual destructor.
113 * @copydoc Dali::Adaptor::Get()
115 static Dali::Adaptor& Get();
118 * @copydoc Dali::Adaptor::IsAvailable()
120 static bool IsAvailable();
122 public: // AdaptorInternalServices implementation
124 * @copydoc Dali::Adaptor::Start()
126 virtual void Start();
129 * @copydoc Dali::Adaptor::Pause()
131 virtual void Pause();
134 * @copydoc Dali::Adaptor::Resume()
136 virtual void Resume();
139 * @copydoc Dali::Adaptor::Stop()
144 * @copydoc Dali::EventFeeder::FeedTouchPoint()
146 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
149 * @copydoc Dali::EventFeeder::FeedWheelEvent()
151 virtual void FeedWheelEvent( MouseWheelEvent& wheelEvent );
154 * @copydoc Dali::EventFeeder::FeedKeyEvent()
156 virtual void FeedKeyEvent( KeyEvent& keyEvent );
159 * @copydoc AdaptorInterface::MoveResize()
161 virtual bool MoveResize( const PositionSize& positionSize );
164 * @copydoc AdaptorInterface::SurfaceResized()
166 virtual void SurfaceResized( const PositionSize& positionSize );
169 * @copydoc AdaptorInterface::ReplaceSurface()
171 virtual void ReplaceSurface( Dali::RenderSurface& surface );
174 * @copydoc Dali::Adaptor::GetSurface()
176 virtual Dali::RenderSurface& GetSurface() const;
179 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
181 virtual void ReleaseSurfaceLock();
184 * Retrieve the TtsPlayer.
185 * @param[in] mode The mode of TtsPlayer
186 * @return A handle to the TtsPlayer.
188 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
191 * @copydoc Dali::Adaptor::AddIdle()
193 virtual bool AddIdle( CallbackBase* callback );
196 * @copydoc Internal::Framework::CallFromMainLoop()
198 virtual bool CallFromMainLoop( CallbackBase* callback );
203 * @return the Core instance
205 virtual Dali::Integration::Core& GetCore();
208 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
210 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
213 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
215 void SetUseHardwareVSync(bool useHardware);
218 * @return reference to EglFactory class
220 EglFactory& GetEGLFactory() const;
223 * Return GlAbstraction.
224 * @return the GlAbstraction.
226 Integration::GlAbstraction& GetGlAbstraction() const;
229 * Return the PlatformAbstraction.
230 * @return The PlatformAbstraction.
232 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
235 * Sets the Drag & Drop Listener.
236 * @param[in] detector The detector to send Drag & Drop events to.
238 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
241 * Sets a rotation observer, or set to NULL to remove.
242 * @pre Adaptor::Start() has been called ( to create EventHandler )
243 * @param[in] observer The observer to listen for window rotation events
245 void SetRotationObserver( RotationObserver* observer );
248 * Destroy the TtsPlayer of sepcific mode.
249 * @param[in] mode The mode of TtsPlayer to destroy
251 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
254 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
255 * trigger a pinch gesture
257 * @param[in] distance The minimum pinch distance in pixels
259 void SetMinimumPinchDistance(float distance);
264 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
265 * @param[in] observer The observer.
266 * @note Observers should remove themselves when they are destroyed.
268 void AddObserver( LifeCycleObserver& observer );
271 * Removes the observer from the adaptor.
272 * @param[in] observer The observer to remove.
273 * @note Observers should remove themselves when they are destroyed.
275 void RemoveObserver( LifeCycleObserver& observer );
278 * Emits the Notification event to the Dali core.
280 void SendNotificationEvent();
283 * Request adaptor to update once
285 void RequestUpdateOnce();
288 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
290 void NotifyLanguageChanged();
292 public: //AdaptorInternalServices
295 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
297 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
300 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
302 virtual Dali::Integration::GlAbstraction& GetGlesInterface();
305 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
307 virtual EglFactoryInterface& GetEGLFactoryInterface() const;
310 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
312 virtual TriggerEventInterface& GetTriggerEventInterface();
315 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
317 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
320 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
322 virtual RenderSurface* GetRenderSurfaceInterface();
325 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
327 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
330 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
332 virtual PerformanceInterface* GetPerformanceInterface();
335 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
337 virtual KernelTraceInterface& GetKernelTraceInterface();
339 public: // Stereoscopy
342 * @copydoc Dali::Integration::Core::SetViewMode()
344 void SetViewMode( ViewMode viewMode );
347 * @copydoc Dali::Integration::Core::GetViewMode()
349 ViewMode GetViewMode() const;
352 * @copydoc Dali::Integration::Core::SetStereoBase()
354 void SetStereoBase( float stereoBase );
357 * @copydoc Dali::Integration::Core::GetStereoBase()
359 float GetStereoBase() const;
364 * @copydoc Dali::Adaptor::SignalResized
366 AdaptorSignalType& ResizedSignal()
368 return mResizedSignal;
372 * @copydoc Dali::Adaptor::LanguageChangedSignal
374 AdaptorSignalType& LanguageChangedSignal()
376 return mLanguageChangedSignal;
379 private: // From Dali::Internal::Adaptor::CoreEventInterface
382 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
384 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
387 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
389 virtual void ProcessCoreEvents();
391 private: // From Dali::Integration::RenderController
394 * Called by the Dali core when it requires another update
396 virtual void RequestUpdate();
399 * Called by Dali core when it requires an notification event being sent on idle.
400 * Multi-threading note: this method must be called from the main thread only.
402 virtual void RequestProcessEventsOnIdle();
404 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
407 * Called when the window becomes fully or partially visible.
409 virtual void OnWindowShown();
412 * Called when the window is fully hidden.
414 virtual void OnWindowHidden();
416 private: // From Dali::Internal::Adaptor::DamageObserver
419 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
421 void OnDamaged( const DamageArea& area );
426 Adaptor(const Adaptor&);
427 Adaptor& operator=(Adaptor&);
432 * Helper to parse log options
434 void ParseEnvironmentOptions();
437 * Informs core the surface size has changed
439 void SurfaceSizeChanged(const PositionSize& positionSize);
442 * Assigns the render surface to the adaptor
445 void SetSurface(Dali::RenderSurface *surface);
448 * Sends an notification message from main loop idle handler
450 void ProcessCoreEventsFromIdle();
453 * Gets path for data/resource storage.
454 * @param[out] path Path for data/resource storage
456 void GetDataStoragePath(std::string& path);
462 * @param[in] adaptor The public adaptor
463 * @param[in] surface A render surface can be one of the following
464 * - Pixmap, adaptor will use existing Pixmap to draw on to
465 * - Window, adaptor will use existing Window to draw on to
466 * @param[in] baseLayout The base layout that the application has been written for
468 Adaptor( Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLayout& baseLayout );
474 READY, ///< Initial state before Adaptor::Start is called.
475 RUNNING, ///< Adaptor is running.
476 PAUSED, ///< Adaptor has been paused.
477 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
478 STOPPED, ///< Adaptor has been stopped.
481 typedef std::vector<LifeCycleObserver*> ObserverContainer;
485 AdaptorSignalType mResizedSignal; ///< Resized signal.
486 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
488 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
489 State mState; ///< Current state of the adaptor
490 Dali::Integration::Core* mCore; ///< Dali Core
491 UpdateRenderController* mUpdateRenderController; ///< Controls update/render threads
492 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
493 GlImplementation* mGLES; ///< GL implementation
494 GlSyncImplementation* mGlSync; ///< GL Sync implementation
495 EglFactory* mEglFactory; ///< EGL Factory
497 RenderSurface* mSurface; ///< Current surface
498 SlpPlatform::SlpPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
500 EventHandler* mEventHandler; ///< event handler
501 CallbackManager* mCallbackManager; ///< Used to install callbacks
502 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
503 TriggerEvent* mNotificationTrigger; ///< Notification event trigger
504 GestureManager* mGestureManager; ///< Gesture manager
505 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
506 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
507 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
508 ObserverContainer mObservers; ///< A list of adaptor observer pointers
509 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
510 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
511 DeviceLayout mBaseLayout; ///< The base layout of the application
512 EnvironmentOptions mEnvironmentOptions; ///< environment options
513 PerformanceInterface* mPerformanceInterface; ///< Performance interface
514 KernelTrace mKernelTracer; ///< Kernel tracer
515 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
516 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
518 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
521 } // namespace Internal
523 } // namespace Adaptor
527 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__