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 <tizen-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);
219 * Primarily for host/simulation testing
220 * @param[in] hDpi The Horizontal DPI
221 * @param[in] vDpi The Vertical DPI
223 void SetDpi(size_t hDpi, size_t vDpi);
226 * @return reference to EglFactory class
228 EglFactory& GetEGLFactory() const;
231 * Return GlAbstraction.
232 * @return the GlAbstraction.
234 Integration::GlAbstraction& GetGlAbstraction() const;
237 * Return the PlatformAbstraction.
238 * @return The PlatformAbstraction.
240 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
243 * Sets the Drag & Drop Listener.
244 * @param[in] detector The detector to send Drag & Drop events to.
246 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
249 * Sets a rotation observer, or set to NULL to remove.
250 * @pre Adaptor::Start() has been called ( to create EventHandler )
251 * @param[in] observer The observer to listen for window rotation events
253 void SetRotationObserver( RotationObserver* observer );
256 * Destroy the TtsPlayer of sepcific mode.
257 * @param[in] mode The mode of TtsPlayer to destroy
259 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
262 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
263 * trigger a pinch gesture
265 * @param[in] distance The minimum pinch distance in pixels
267 void SetMinimumPinchDistance(float distance);
272 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
273 * @param[in] observer The observer.
274 * @note Observers should remove themselves when they are destroyed.
276 void AddObserver( LifeCycleObserver& observer );
279 * Removes the observer from the adaptor.
280 * @param[in] observer The observer to remove.
281 * @note Observers should remove themselves when they are destroyed.
283 void RemoveObserver( LifeCycleObserver& observer );
286 * Emits the Notification event to the Dali core.
288 void SendNotificationEvent();
291 * Request adaptor to update once
293 void RequestUpdateOnce();
296 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
298 void NotifyLanguageChanged();
300 public: //AdaptorInternalServices
303 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
305 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
308 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
310 virtual Dali::Integration::GlAbstraction& GetGlesInterface();
313 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
315 virtual EglFactoryInterface& GetEGLFactoryInterface() const;
318 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
320 virtual TriggerEventInterface& GetTriggerEventInterface();
323 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
325 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
328 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
330 virtual RenderSurface* GetRenderSurfaceInterface();
333 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
335 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
338 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
340 virtual PerformanceInterface* GetPerformanceInterface();
343 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
345 virtual KernelTraceInterface& GetKernelTraceInterface();
347 public: // Stereoscopy
350 * @copydoc Dali::Integration::Core::SetViewMode()
352 void SetViewMode( ViewMode viewMode );
355 * @copydoc Dali::Integration::Core::GetViewMode()
357 ViewMode GetViewMode() const;
360 * @copydoc Dali::Integration::Core::SetStereoBase()
362 void SetStereoBase( float stereoBase );
365 * @copydoc Dali::Integration::Core::GetStereoBase()
367 float GetStereoBase() const;
372 * @copydoc Dali::Adaptor::SignalResized
374 AdaptorSignalType& ResizedSignal()
376 return mResizedSignal;
380 * @copydoc Dali::Adaptor::LanguageChangedSignal
382 AdaptorSignalType& LanguageChangedSignal()
384 return mLanguageChangedSignal;
387 private: // From Dali::Internal::Adaptor::CoreEventInterface
390 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
392 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
395 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
397 virtual void ProcessCoreEvents();
399 private: // From Dali::Integration::RenderController
402 * Called by the Dali core when it requires another update
404 virtual void RequestUpdate();
407 * Called by Dali core when it requires an notification event being sent on idle.
408 * Multi-threading note: this method must be called from the main thread only.
410 virtual void RequestProcessEventsOnIdle();
412 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
415 * Called when the window becomes fully or partially visible.
417 virtual void OnWindowShown();
420 * Called when the window is fully hidden.
422 virtual void OnWindowHidden();
424 private: // From Dali::Internal::Adaptor::DamageObserver
427 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
429 void OnDamaged( const DamageArea& area );
434 Adaptor(const Adaptor&);
435 Adaptor& operator=(Adaptor&);
440 * Helper to parse log options
442 void ParseEnvironmentOptions();
445 * Informs core the surface size has changed
447 void SurfaceSizeChanged(const PositionSize& positionSize);
450 * Assigns the render surface to the adaptor
453 void SetSurface(Dali::RenderSurface *surface);
456 * Sends an notification message from main loop idle handler
458 void ProcessCoreEventsFromIdle();
461 * Gets path for data/resource storage.
462 * @param[out] path Path for data/resource storage
464 void GetDataStoragePath(std::string& path);
470 * @param[in] adaptor The public adaptor
471 * @param[in] surface A render surface can be one of the following
472 * - Pixmap, adaptor will use existing Pixmap to draw on to
473 * - Window, adaptor will use existing Window to draw on to
474 * @param[in] baseLayout The base layout that the application has been written for
476 Adaptor( Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLayout& baseLayout );
482 READY, ///< Initial state before Adaptor::Start is called.
483 RUNNING, ///< Adaptor is running.
484 PAUSED, ///< Adaptor has been paused.
485 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
486 STOPPED, ///< Adaptor has been stopped.
489 typedef std::vector<LifeCycleObserver*> ObserverContainer;
493 AdaptorSignalType mResizedSignal; ///< Resized signal.
494 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
496 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
497 State mState; ///< Current state of the adaptor
498 Dali::Integration::Core* mCore; ///< Dali Core
499 UpdateRenderController* mUpdateRenderController; ///< Controls update/render threads
500 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
501 GlImplementation* mGLES; ///< GL implementation
502 GlSyncImplementation* mGlSync; ///< GL Sync implementation
503 EglFactory* mEglFactory; ///< EGL Factory
505 RenderSurface* mSurface; ///< Current surface
506 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
508 EventHandler* mEventHandler; ///< event handler
509 CallbackManager* mCallbackManager; ///< Used to install callbacks
510 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
511 TriggerEvent* mNotificationTrigger; ///< Notification event trigger
512 GestureManager* mGestureManager; ///< Gesture manager
513 size_t mHDpi; ///< Override horizontal DPI
514 size_t mVDpi; ///< Override vertical DPI
515 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
516 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
517 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
518 ObserverContainer mObservers; ///< A list of adaptor observer pointers
519 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
520 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
521 DeviceLayout mBaseLayout; ///< The base layout of the application
522 EnvironmentOptions mEnvironmentOptions; ///< environment options
523 PerformanceInterface* mPerformanceInterface; ///< Performance interface
524 KernelTrace mKernelTracer; ///< Kernel tracer
525 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
526 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
528 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
531 } // namespace Internal
533 } // namespace Adaptor
537 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__