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>
26 #include <dali/public-api/common/vector-wrapper.h>
27 #include <dali/public-api/common/view-mode.h>
28 #include <dali/public-api/math/rect.h>
29 #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::AdaptorSignalType AdaptorSignalType;
94 * Creates a New Adaptor
95 * @param[in] surface A render surface can be one of the following
96 * - Pixmap, adaptor will use existing Pixmap to draw on to
97 * - Window, adaptor will use existing Window to draw on to
98 * @param[in] baseLayout The base layout that the application has been written for
99 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
101 static Dali::Adaptor* New( RenderSurface* surface,
102 const DeviceLayout& baseLayout,
103 Dali::Configuration::ContextLoss configuration );
106 * 2-step initialisation, this should be called after creating an adaptor instance.
108 void Initialize(Dali::Configuration::ContextLoss configuration);
111 * Virtual destructor.
116 * @copydoc Dali::Adaptor::Get()
118 static Dali::Adaptor& Get();
121 * @copydoc Dali::Adaptor::IsAvailable()
123 static bool IsAvailable();
125 public: // AdaptorInternalServices implementation
127 * @copydoc Dali::Adaptor::Start()
129 virtual void Start();
132 * @copydoc Dali::Adaptor::Pause()
134 virtual void Pause();
137 * @copydoc Dali::Adaptor::Resume()
139 virtual void Resume();
142 * @copydoc Dali::Adaptor::Stop()
147 * @copydoc Dali::EventFeeder::FeedTouchPoint()
149 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
152 * @copydoc Dali::EventFeeder::FeedWheelEvent()
154 virtual void FeedWheelEvent( MouseWheelEvent& wheelEvent );
157 * @copydoc Dali::EventFeeder::FeedKeyEvent()
159 virtual void FeedKeyEvent( KeyEvent& keyEvent );
162 * @copydoc AdaptorInterface::MoveResize()
164 virtual bool MoveResize( const PositionSize& positionSize );
167 * @copydoc AdaptorInterface::SurfaceResized()
169 virtual void SurfaceResized( const PositionSize& positionSize );
172 * @copydoc AdaptorInterface::ReplaceSurface()
174 virtual void ReplaceSurface( Dali::RenderSurface& surface );
177 * @copydoc Dali::Adaptor::GetSurface()
179 virtual Dali::RenderSurface& GetSurface() const;
182 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
184 virtual void ReleaseSurfaceLock();
187 * Retrieve the TtsPlayer.
188 * @param[in] mode The mode of TtsPlayer
189 * @return A handle to the TtsPlayer.
191 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
194 * @copydoc Dali::Adaptor::AddIdle()
196 virtual bool AddIdle( boost::function<void(void)> callBack );
199 * @copydoc Internal::Framework::CallFromMainLoop()
201 virtual bool CallFromMainLoop(boost::function<void(void)> callBack);
206 * @return the Core instance
208 virtual Dali::Integration::Core& GetCore();
211 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
213 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
216 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
218 void SetUseHardwareVSync(bool useHardware);
221 * @return reference to EglFactory class
223 EglFactory& GetEGLFactory() const;
226 * Return GlAbstraction.
227 * @return the GlAbstraction.
229 Integration::GlAbstraction& GetGlAbstraction() const;
232 * Return the PlatformAbstraction.
233 * @return The PlatformAbstraction.
235 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
238 * Sets the Drag & Drop Listener.
239 * @param[in] detector The detector to send Drag & Drop events to.
241 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
244 * Sets a rotation observer, or set to NULL to remove.
245 * @pre Adaptor::Start() has been called ( to create EventHandler )
246 * @param[in] observer The observer to listen for window rotation events
248 void SetRotationObserver( RotationObserver* observer );
251 * Destroy the TtsPlayer of sepcific mode.
252 * @param[in] mode The mode of TtsPlayer to destroy
254 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
257 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
258 * trigger a pinch gesture
260 * @param[in] distance The minimum pinch distance in pixels
262 void SetMinimumPinchDistance(float distance);
267 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
268 * @param[in] observer The observer.
269 * @note Observers should remove themselves when they are destroyed.
271 void AddObserver( LifeCycleObserver& observer );
274 * Removes the observer from the adaptor.
275 * @param[in] observer The observer to remove.
276 * @note Observers should remove themselves when they are destroyed.
278 void RemoveObserver( LifeCycleObserver& observer );
281 * Emits the Notification event to the Dali core.
283 void SendNotificationEvent();
286 * Request adaptor to update once
288 void RequestUpdateOnce();
291 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
293 void NotifyLanguageChanged();
295 public: //AdaptorInternalServices
298 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
300 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
303 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
305 virtual Dali::Integration::GlAbstraction& GetGlesInterface();
308 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
310 virtual EglFactoryInterface& GetEGLFactoryInterface() const;
313 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
315 virtual TriggerEventInterface& GetTriggerEventInterface();
318 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
320 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
323 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
325 virtual RenderSurface* GetRenderSurfaceInterface();
328 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
330 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
333 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
335 virtual PerformanceInterface* GetPerformanceInterface();
338 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
340 virtual KernelTraceInterface& GetKernelTraceInterface();
342 public: // Stereoscopy
345 * @copydoc Dali::Integration::Core::SetViewMode()
347 void SetViewMode( ViewMode viewMode );
350 * @copydoc Dali::Integration::Core::GetViewMode()
352 ViewMode GetViewMode() const;
355 * @copydoc Dali::Integration::Core::SetStereoBase()
357 void SetStereoBase( float stereoBase );
360 * @copydoc Dali::Integration::Core::GetStereoBase()
362 float GetStereoBase() const;
367 * @copydoc Dali::Adaptor::SignalResized
369 AdaptorSignalType& ResizedSignal()
371 return mResizedSignal;
375 * @copydoc Dali::Adaptor::LanguageChangedSignal
377 AdaptorSignalType& LanguageChangedSignal()
379 return mLanguageChangedSignal;
382 private: // From Dali::Internal::Adaptor::CoreEventInterface
385 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
387 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
390 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
392 virtual void ProcessCoreEvents();
394 private: // From Dali::Integration::RenderController
397 * Called by the Dali core when it requires another update
399 virtual void RequestUpdate();
402 * Called by Dali core when it requires an notification event being sent on idle.
403 * Multi-threading note: this method must be called from the main thread only.
405 virtual void RequestProcessEventsOnIdle();
407 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
410 * Called when the window becomes fully or partially visible.
412 virtual void OnWindowShown();
415 * Called when the window is fully hidden.
417 virtual void OnWindowHidden();
419 private: // From Dali::Internal::Adaptor::DamageObserver
422 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
424 void OnDamaged( const DamageArea& area );
429 Adaptor(const Adaptor&);
430 Adaptor& operator=(Adaptor&);
435 * Helper to parse log options
437 void ParseEnvironmentOptions();
440 * Informs core the surface size has changed
442 void SurfaceSizeChanged(const PositionSize& positionSize);
445 * Assigns the render surface to the adaptor
448 void SetSurface(Dali::RenderSurface *surface);
451 * Sends an notification message from main loop idle handler
453 void ProcessCoreEventsFromIdle();
459 * @param[in] adaptor The public adaptor
460 * @param[in] surface A render surface can be one of the following
461 * - Pixmap, adaptor will use existing Pixmap to draw on to
462 * - Window, adaptor will use existing Window to draw on to
463 * @param[in] baseLayout The base layout that the application has been written for
465 Adaptor( Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLayout& baseLayout );
471 READY, ///< Initial state before Adaptor::Start is called.
472 RUNNING, ///< Adaptor is running.
473 PAUSED, ///< Adaptor has been paused.
474 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
475 STOPPED, ///< Adaptor has been stopped.
478 typedef std::vector<LifeCycleObserver*> ObserverContainer;
482 AdaptorSignalType mResizedSignal; ///< Resized signal.
483 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
485 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
486 State mState; ///< Current state of the adaptor
487 Dali::Integration::Core* mCore; ///< Dali Core
488 UpdateRenderController* mUpdateRenderController; ///< Controls update/render threads
489 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
490 GlImplementation* mGLES; ///< GL implementation
491 GlSyncImplementation* mGlSync; ///< GL Sync implementation
492 EglFactory* mEglFactory; ///< EGL Factory
494 RenderSurface* mSurface; ///< Current surface
495 SlpPlatform::SlpPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
497 EventHandler* mEventHandler; ///< event handler
498 CallbackManager* mCallbackManager; ///< Used to install callbacks
499 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
500 TriggerEvent* mNotificationTrigger; ///< Notification event trigger
501 GestureManager* mGestureManager; ///< Gesture manager
502 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
503 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
504 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
505 ObserverContainer mObservers; ///< A list of adaptor observer pointers
506 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
507 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
508 DeviceLayout mBaseLayout; ///< The base layout of the application
509 EnvironmentOptions mEnvironmentOptions; ///< environment options
510 PerformanceInterface* mPerformanceInterface; ///< Performance interface
511 KernelTrace mKernelTracer; ///< Kernel tracer
512 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
513 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
515 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
518 } // namespace Internal
520 } // namespace Adaptor
524 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__