1 #ifndef __DALI_INTERNAL_ADAPTOR_IMPL_H__
2 #define __DALI_INTERNAL_ADAPTOR_IMPL_H__
5 * Copyright (c) 2015 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 <clipboard.h>
35 #include <tizen-platform-abstraction.h>
36 #include <base/interfaces/adaptor-internal-services.h>
37 #include <base/environment-options.h>
38 #include <base/core-event-interface.h>
39 #include <drag-and-drop-detector-impl.h>
40 #include <damage-observer.h>
41 #include <window-visibility-observer.h>
42 #include <kernel-trace.h>
43 #include <system-trace.h>
44 #include <trigger-event-factory.h>
45 #include <networking/socket-factory.h>
66 class GlImplementation;
67 class GlSyncImplementation;
68 class UpdateRenderController;
70 class CallbackManager;
71 class FeedbackPluginProxy;
72 class FeedbackController;
73 class RotationObserver;
75 class PerformanceInterface;
76 class LifeCycleObserver;
80 * Implementation of the Adaptor class.
82 class Adaptor : public Integration::RenderController,
83 public AdaptorInternalServices,
84 public CoreEventInterface,
85 public DamageObserver,
86 public WindowVisibilityObserver
90 typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
93 * Creates a New Adaptor
94 * @param[in] nativeWindow native window handle
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] configuration The context loss configuration ( to choose resource discard policy )
100 static Dali::Adaptor* New( Any nativeWindow,
101 RenderSurface* surface,
102 Dali::Configuration::ContextLoss configuration );
105 * 2-step initialisation, this should be called after creating an adaptor instance.
107 void Initialize(Dali::Configuration::ContextLoss configuration);
110 * Virtual destructor.
115 * @copydoc Dali::Adaptor::Get()
117 static Dali::Adaptor& Get();
120 * @copydoc Dali::Adaptor::IsAvailable()
122 static bool IsAvailable();
124 public: // AdaptorInternalServices implementation
126 * @copydoc Dali::Adaptor::Start()
128 virtual void Start();
131 * @copydoc Dali::Adaptor::Pause()
133 virtual void Pause();
136 * @copydoc Dali::Adaptor::Resume()
138 virtual void Resume();
141 * @copydoc Dali::Adaptor::Stop()
146 * @copydoc Dali::EventFeeder::FeedTouchPoint()
148 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
151 * @copydoc Dali::EventFeeder::FeedWheelEvent()
153 virtual void FeedWheelEvent( MouseWheelEvent& wheelEvent );
156 * @copydoc Dali::EventFeeder::FeedKeyEvent()
158 virtual void FeedKeyEvent( KeyEvent& keyEvent );
161 * @copydoc AdaptorInterface::MoveResize()
163 virtual bool MoveResize( const PositionSize& positionSize );
166 * @copydoc AdaptorInterface::SurfaceResized()
168 virtual void SurfaceResized( const PositionSize& positionSize );
171 * @copydoc AdaptorInterface::ReplaceSurface()
173 virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
176 * @copydoc Dali::Adaptor::GetSurface()
178 virtual RenderSurface& GetSurface() const;
181 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
183 virtual void ReleaseSurfaceLock();
186 * Retrieve the TtsPlayer.
187 * @param[in] mode The mode of TtsPlayer
188 * @return A handle to the TtsPlayer.
190 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
193 * @copydoc Dali::Adaptor::AddIdle()
195 virtual bool AddIdle( CallbackBase* callback );
198 * @copydoc Internal::Framework::CallFromMainLoop()
200 virtual bool CallFromMainLoop( CallbackBase* callback );
205 * @return the Core instance
207 virtual Dali::Integration::Core& GetCore();
210 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
212 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
215 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
217 void SetUseHardwareVSync(bool useHardware);
220 * @return reference to EglFactory class
222 EglFactory& GetEGLFactory() const;
225 * Return GlAbstraction.
226 * @return the GlAbstraction.
228 Integration::GlAbstraction& GetGlAbstraction() const;
231 * Return the PlatformAbstraction.
232 * @return The PlatformAbstraction.
234 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
237 * Sets the Drag & Drop Listener.
238 * @param[in] detector The detector to send Drag & Drop events to.
240 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
243 * Sets a rotation observer, or set to NULL to remove.
244 * @pre Adaptor::Start() has been called ( to create EventHandler )
245 * @param[in] observer The observer to listen for window rotation events
247 void SetRotationObserver( RotationObserver* observer );
250 * Destroy the TtsPlayer of sepcific mode.
251 * @param[in] mode The mode of TtsPlayer to destroy
253 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
256 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
257 * trigger a pinch gesture
259 * @param[in] distance The minimum pinch distance in pixels
261 void SetMinimumPinchDistance(float distance);
264 * Gets native window handle
266 * @return native window handle
268 Any GetNativeWindowHandle();
273 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
274 * @param[in] observer The observer.
275 * @note Observers should remove themselves when they are destroyed.
277 void AddObserver( LifeCycleObserver& observer );
280 * Removes the observer from the adaptor.
281 * @param[in] observer The observer to remove.
282 * @note Observers should remove themselves when they are destroyed.
284 void RemoveObserver( LifeCycleObserver& observer );
287 * Emits the Notification event to the Dali core.
289 void SendNotificationEvent();
292 * Request adaptor to update once
294 void RequestUpdateOnce();
297 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
299 void NotifyLanguageChanged();
301 public: //AdaptorInternalServices
304 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
306 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
309 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
311 virtual Dali::Integration::GlAbstraction& GetGlesInterface();
314 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
316 virtual EglFactoryInterface& GetEGLFactoryInterface() const;
319 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
321 virtual TriggerEventInterface& GetTriggerEventInterface();
324 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
326 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
329 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
331 virtual SocketFactoryInterface& GetSocketFactoryInterface();
334 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
336 virtual RenderSurface* GetRenderSurfaceInterface();
339 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
341 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
344 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
346 virtual PerformanceInterface* GetPerformanceInterface();
349 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
351 virtual TraceInterface& GetKernelTraceInterface();
354 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
356 virtual TraceInterface& GetSystemTraceInterface();
358 public: // Stereoscopy
361 * @copydoc Dali::Integration::Core::SetViewMode()
363 void SetViewMode( ViewMode viewMode );
366 * @copydoc Dali::Integration::Core::GetViewMode()
368 ViewMode GetViewMode() const;
371 * @copydoc Dali::Integration::Core::SetStereoBase()
373 void SetStereoBase( float stereoBase );
376 * @copydoc Dali::Integration::Core::GetStereoBase()
378 float GetStereoBase() const;
383 * @copydoc Dali::Adaptor::SignalResized
385 AdaptorSignalType& ResizedSignal()
387 return mResizedSignal;
391 * @copydoc Dali::Adaptor::LanguageChangedSignal
393 AdaptorSignalType& LanguageChangedSignal()
395 return mLanguageChangedSignal;
398 private: // From Dali::Internal::Adaptor::CoreEventInterface
401 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
403 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
406 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
408 virtual void ProcessCoreEvents();
410 private: // From Dali::Integration::RenderController
413 * Called by the Dali core when it requires another update
415 virtual void RequestUpdate();
418 * Called by Dali core when it requires an notification event being sent on idle.
419 * Multi-threading note: this method must be called from the main thread only.
421 virtual void RequestProcessEventsOnIdle();
423 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
426 * Called when the window becomes fully or partially visible.
428 virtual void OnWindowShown();
431 * Called when the window is fully hidden.
433 virtual void OnWindowHidden();
435 private: // From Dali::Internal::Adaptor::DamageObserver
438 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
440 void OnDamaged( const DamageArea& area );
445 Adaptor(const Adaptor&);
446 Adaptor& operator=(Adaptor&);
451 * Informs core the surface size has changed
453 void SurfaceSizeChanged(const PositionSize& positionSize);
456 * Assigns the render surface to the adaptor
459 void SetSurface(RenderSurface *surface);
462 * Sends an notification message from main loop idle handler
464 void ProcessCoreEventsFromIdle();
467 * Gets path for data/resource storage.
468 * @param[out] path Path for data/resource storage
470 void GetDataStoragePath(std::string& path);
476 * @param[in] nativeWindow native window handle
477 * @param[in] adaptor The public adaptor
478 * @param[in] surface A render surface can be one of the following
479 * - Pixmap, adaptor will use existing Pixmap to draw on to
480 * - Window, adaptor will use existing Window to draw on to
482 Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface );
488 READY, ///< Initial state before Adaptor::Start is called.
489 RUNNING, ///< Adaptor is running.
490 PAUSED, ///< Adaptor has been paused.
491 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
492 STOPPED, ///< Adaptor has been stopped.
495 typedef std::vector<LifeCycleObserver*> ObserverContainer;
499 AdaptorSignalType mResizedSignal; ///< Resized signal.
500 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
502 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
503 State mState; ///< Current state of the adaptor
504 Dali::Integration::Core* mCore; ///< Dali Core
505 UpdateRenderController* mUpdateRenderController; ///< Controls update/render threads
506 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
507 GlImplementation* mGLES; ///< GL implementation
508 GlSyncImplementation* mGlSync; ///< GL Sync implementation
509 EglFactory* mEglFactory; ///< EGL Factory
511 Any mNativeWindow; ///< window identifier
512 RenderSurface* mSurface; ///< Current surface
513 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
515 EventHandler* mEventHandler; ///< event handler
516 CallbackManager* mCallbackManager; ///< Used to install callbacks
517 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
518 TriggerEvent* mNotificationTrigger; ///< Notification event trigger
519 GestureManager* mGestureManager; ///< Gesture manager
520 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
521 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
522 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
523 ObserverContainer mObservers; ///< A list of adaptor observer pointers
524 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
525 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
526 EnvironmentOptions mEnvironmentOptions; ///< environment options
527 PerformanceInterface* mPerformanceInterface; ///< Performance interface
528 KernelTrace mKernelTracer; ///< Kernel tracer
529 SystemTrace mSystemTracer; ///< System tracer
530 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
531 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
532 SocketFactory mSocketFactory; ///< Socket factory
534 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
537 } // namespace Internal
539 } // namespace Adaptor
543 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__