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 <boost/bind.hpp>
23 #include <boost/function.hpp>
24 #include <boost/thread.hpp>
27 #include <dali/public-api/common/vector-wrapper.h>
28 #include <dali/public-api/common/view-mode.h>
29 #include <dali/public-api/math/rect.h>
30 #include <dali/integration-api/render-controller.h>
33 #include <render-surface.h>
34 #include <tts-player.h>
35 #include <imf-manager.h>
36 #include <device-layout.h>
37 #include <clipboard.h>
39 #include <slp-platform-abstraction.h>
40 #include <base/interfaces/adaptor-internal-services.h>
41 #include <base/environment-options.h>
42 #include <base/core-event-interface.h>
43 #include <drag-and-drop-detector-impl.h>
44 #include <damage-observer.h>
45 #include <window-visibility-observer.h>
46 #include <kernel-trace.h>
47 #include <trigger-event-factory.h>
66 class GlImplementation;
67 class GlSyncImplementation;
69 class UpdateRenderController;
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::AdaptorSignalV2 AdaptorSignalV2;
93 typedef std::pair<std::string, BaseHandle> SingletonPair;
94 typedef std::map<std::string, BaseHandle> SingletonContainer;
95 typedef SingletonContainer::const_iterator SingletonConstIter;
98 * Creates a New Adaptor
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] baseLayout The base layout that the application has been written for
104 DALI_IMPORT_API static Dali::Adaptor* New( RenderSurface* surface, const DeviceLayout& baseLayout );
107 * 2-step initialisation, this should be called after creating an adaptor instance.
112 * Virtual destructor.
117 * @copydoc Dali::Adaptor::Get()
119 static Dali::Adaptor& Get();
122 * @copydoc Dali::Adaptor::IsAvailable()
124 static bool IsAvailable();
126 public: // AdaptorInternalServices implementation
128 * @copydoc Dali::Adaptor::Start()
130 virtual void Start();
133 * @copydoc Dali::Adaptor::Pause()
135 virtual void Pause();
138 * @copydoc Dali::Adaptor::Resume()
140 virtual void Resume();
143 * @copydoc Dali::Adaptor::Stop()
148 * @copydoc Dali::EventFeeder::FeedTouchPoint()
150 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
153 * @copydoc Dali::EventFeeder::FeedWheelEvent()
155 virtual void FeedWheelEvent( MouseWheelEvent& wheelEvent );
158 * @copydoc Dali::EventFeeder::FeedKeyEvent()
160 virtual void FeedKeyEvent( KeyEvent& keyEvent );
163 * @copydoc AdaptorInterface::MoveResize()
165 virtual bool MoveResize( const PositionSize& positionSize );
168 * @copydoc AdaptorInterface::SurfaceResized()
170 virtual void SurfaceResized( const PositionSize& positionSize );
173 * @copydoc AdaptorInterface::ReplaceSurface()
175 virtual void ReplaceSurface( Dali::RenderSurface& surface );
178 * @copydoc AdaptorInterface::RenderSync()
180 virtual void RenderSync();
183 * @copydoc Dali::Adaptor::GetSurface()
185 virtual Dali::RenderSurface& GetSurface() const;
188 * Retrieve the TtsPlayer.
189 * @param[in] mode The mode of TtsPlayer
190 * @return A handle to the TtsPlayer.
192 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
195 * @copydoc Dali::Adaptor::AddIdle()
197 virtual bool AddIdle( boost::function<void(void)> callBack );
200 * @copydoc Internal::Framework::CallFromMainLoop()
202 virtual bool CallFromMainLoop(boost::function<void(void)> callBack);
205 * @copydoc Dali::Adaptor::RegisterSingleton()
207 virtual void RegisterSingleton(const std::type_info& info, BaseHandle singleton);
210 * @copydoc Dali::Adaptor::GetSingleton()
212 virtual BaseHandle GetSingleton(const std::type_info& info) const;
217 * @return the Core instance
219 virtual Dali::Integration::Core& GetCore();
222 * Disables GL draw synchronisation with the display.
224 DALI_IMPORT_API void DisableVSync();
228 * Primarily for host/simulation testing
229 * @param[in] hDpi The Horizontal DPI
230 * @param[in] vDpi The Vertical DPI
232 DALI_IMPORT_API void SetDpi(size_t hDpi, size_t vDpi);
235 * @return reference to EglFactory class
237 EglFactory& GetEGLFactory() const;
240 * Return GlAbstraction.
241 * @return the GlAbstraction.
243 Integration::GlAbstraction& GetGlAbstraction() const;
246 * Return the PlatformAbstraction.
247 * @return The PlatformAbstraction.
249 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
252 * Sets the Drag & Drop Listener.
253 * @param[in] detector The detector to send Drag & Drop events to.
255 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
258 * Sets a rotation observer, or set to NULL to remove.
259 * @pre Adaptor::Start() has been called ( to create EventHandler )
260 * @param[in] observer The observer to listen for window rotation events
262 void SetRotationObserver( RotationObserver* observer );
265 * Destroy the TtsPlayer of sepcific mode.
266 * @param[in] mode The mode of TtsPlayer to destroy
268 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
271 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
272 * trigger a pinch gesture
274 * @param[in] distance The minimum pinch distance in pixels
276 void SetMinimumPinchDistance(float distance);
281 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
282 * @param[in] observer The observer.
283 * @note Observers should remove themselves when they are destroyed.
285 void AddObserver( LifeCycleObserver& observer );
288 * Removes the observer from the adaptor.
289 * @param[in] observer The observer to remove.
290 * @note Observers should remove themselves when they are destroyed.
292 void RemoveObserver( LifeCycleObserver& observer );
295 * Emits the Notification event to the Dali core.
297 void SendNotificationEvent();
300 * Request adaptor to update once
302 void RequestUpdateOnce();
305 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
307 void NotifyLanguageChanged();
309 public: //AdaptorInternalServices
312 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
314 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
317 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
319 virtual Dali::Integration::GlAbstraction& GetGlesInterface();
322 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
324 virtual EglFactoryInterface& GetEGLFactoryInterface() const;
327 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
329 virtual TriggerEventInterface& GetTriggerEventInterface();
332 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
334 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
337 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
339 virtual RenderSurface* GetRenderSurfaceInterface();
342 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
344 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
347 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
349 virtual PerformanceInterface* GetPerformanceInterface();
352 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
354 virtual KernelTraceInterface& GetKernelTraceInterface();
356 public: // Stereoscopy
359 * @copydoc Dali::Integration::Core::SetViewMode()
361 DALI_IMPORT_API void SetViewMode( ViewMode viewMode );
364 * @copydoc Dali::Integration::Core::GetViewMode()
366 DALI_IMPORT_API ViewMode GetViewMode() const;
369 * @copydoc Dali::Integration::Core::SetStereoBase()
371 DALI_IMPORT_API void SetStereoBase( float stereoBase );
374 * @copydoc Dali::Integration::Core::GetStereoBase()
376 DALI_IMPORT_API float GetStereoBase() const;
381 * @copydoc Dali::Adaptor::SignalResized
383 AdaptorSignalV2& ResizedSignal()
385 return mResizedSignalV2;
389 * @copydoc Dali::Adaptor::LanguageChangedSignal
391 AdaptorSignalV2& LanguageChangedSignal()
393 return mLanguageChangedSignalV2;
396 private: // From Dali::Internal::Adaptor::CoreEventInterface
399 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
401 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
404 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
406 virtual void ProcessCoreEvents();
408 private: // From Dali::Integration::RenderController
411 * Called by the Dali core when it requires another update
413 virtual void RequestUpdate();
416 * Call by the Dali core when it requires an notification event being sent on idle
418 virtual void RequestProcessEventsOnIdle();
420 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
423 * Called when the window becomes fully or partially visible.
425 virtual void OnWindowShown();
428 * Called when the window is fully hidden.
430 virtual void OnWindowHidden();
432 private: // From Dali::Internal::Adaptor::DamageObserver
435 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
437 void OnDamaged( const DamageArea& area );
442 Adaptor(const Adaptor&);
443 Adaptor& operator=(Adaptor&);
448 * Helper to parse log options
450 void ParseEnvironmentOptions();
453 * Informs core the surface size has changed
455 void SurfaceSizeChanged(const PositionSize& positionSize);
458 * Assigns the render surface to the adaptor
461 void SetSurface(Dali::RenderSurface *surface);
464 * Sends an notification message from main loop idle handler
466 void ProcessCoreEventsFromIdle();
472 * @param[in] adaptor The public adaptor
473 * @param[in] surface A render surface can be one of the following
474 * - Pixmap, adaptor will use existing Pixmap to draw on to
475 * - Window, adaptor will use existing Window to draw on to
476 * @param[in] baseLayout The base layout that the application has been written for
478 Adaptor( Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLayout& baseLayout );
484 READY, ///< Initial state before Adaptor::Start is called.
485 RUNNING, ///< Adaptor is running.
486 PAUSED, ///< Adaptor has been paused.
487 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
488 STOPPED, ///< Adaptor has been stopped.
491 typedef std::vector<LifeCycleObserver*> ObserverContainer;
495 AdaptorSignalV2 mResizedSignalV2; ///< Resized signal.
496 AdaptorSignalV2 mLanguageChangedSignalV2; ///< Language changed signal.
498 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
499 State mState; ///< Current state of the adaptor
500 Dali::Integration::Core* mCore; ///< Dali Core
501 UpdateRenderController* mUpdateRenderController; ///< Controls update/render threads
502 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
503 GlImplementation* mGLES; ///< GL implementation
504 GlSyncImplementation* mGlSync; ///< GL Sync implementation
505 EglFactory* mEglFactory; ///< EGL Factory
507 RenderSurface* mSurface; ///< Current surface
508 SlpPlatform::SlpPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
510 EventHandler* mEventHandler; ///< event handler
511 CallbackManager* mCallbackManager; ///< Used to install callbacks
512 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
513 TriggerEvent* mNotificationTrigger; ///< Notification event trigger
514 GestureManager* mGestureManager; ///< Gesture manager
515 boost::mutex mIdleInstaller; ///< mutex to ensure two threads don't try to install idle handler at the same time
516 size_t mHDpi; ///< Override horizontal DPI
517 size_t mVDpi; ///< Override vertical DPI
518 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
519 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
520 SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name
521 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
522 ObserverContainer mObservers; ///< A list of adaptor observer pointers
523 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
524 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
525 DeviceLayout mBaseLayout; ///< The base layout of the application
526 EnvironmentOptions mEnvironmentOptions; ///< environment options
527 PerformanceInterface* mPerformanceInterface; ///< Performance interface
528 KernelTrace mKernelTracer; ///< Kernel tracer
529 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
530 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
532 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
535 } // namespace Internal
537 } // namespace Adaptor
541 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__