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>
67 class GlImplementation;
68 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] nativeWindow Native window handle
96 * @param[in] surface A render surface can be one of the following
97 * - Pixmap, adaptor will use existing Pixmap to draw on to
98 * - Window, adaptor will use existing Window to draw on to
99 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
100 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
102 static Dali::Adaptor* New( Any nativeWindow,
103 RenderSurface* surface,
104 Dali::Configuration::ContextLoss configuration,
105 EnvironmentOptions* environmentOptions );
108 * Creates a New Adaptor
109 * @param[in] nativeWindow native window handle
110 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
111 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
113 static Dali::Adaptor* New( Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions );
116 * 2-step initialisation, this should be called after creating an adaptor instance.
118 void Initialize(Dali::Configuration::ContextLoss configuration);
121 * Virtual destructor.
126 * @copydoc Dali::Adaptor::Get()
128 static Dali::Adaptor& Get();
131 * @copydoc Dali::Adaptor::IsAvailable()
133 static bool IsAvailable();
135 public: // AdaptorInternalServices implementation
137 * @copydoc Dali::Adaptor::Start()
139 virtual void Start();
142 * @copydoc Dali::Adaptor::Pause()
144 virtual void Pause();
147 * @copydoc Dali::Adaptor::Resume()
149 virtual void Resume();
152 * @copydoc Dali::Adaptor::Stop()
157 * @copydoc Dali::EventFeeder::FeedTouchPoint()
159 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
162 * @copydoc Dali::EventFeeder::FeedWheelEvent()
164 virtual void FeedWheelEvent( WheelEvent& wheelEvent );
167 * @copydoc Dali::EventFeeder::FeedKeyEvent()
169 virtual void FeedKeyEvent( KeyEvent& keyEvent );
172 * @copydoc AdaptorInterface::MoveResize()
174 virtual bool MoveResize( const PositionSize& positionSize );
177 * @copydoc AdaptorInterface::SurfaceResized()
179 virtual void SurfaceResized( const PositionSize& positionSize );
182 * @copydoc AdaptorInterface::ReplaceSurface()
184 virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
187 * @copydoc Dali::Adaptor::GetSurface()
189 virtual RenderSurface& GetSurface() const;
192 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
194 virtual void ReleaseSurfaceLock();
197 * Retrieve the TtsPlayer.
198 * @param[in] mode The mode of TtsPlayer
199 * @return A handle to the TtsPlayer.
201 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
204 * @copydoc Dali::Adaptor::AddIdle()
206 virtual bool AddIdle( CallbackBase* callback );
209 * @copydoc Internal::Framework::CallFromMainLoop()
211 virtual bool CallFromMainLoop( CallbackBase* callback );
216 * @return the Core instance
218 virtual Dali::Integration::Core& GetCore();
221 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
223 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
226 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
228 void SetUseHardwareVSync(bool useHardware);
231 * @return reference to EglFactory class
233 EglFactory& GetEGLFactory() const;
236 * Return GlAbstraction.
237 * @return the GlAbstraction.
239 Integration::GlAbstraction& GetGlAbstraction() const;
242 * Return the PlatformAbstraction.
243 * @return The PlatformAbstraction.
245 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
248 * Sets the Drag & Drop Listener.
249 * @param[in] detector The detector to send Drag & Drop events to.
251 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
254 * Sets a rotation observer, or set to NULL to remove.
255 * @pre Adaptor::Start() has been called ( to create EventHandler )
256 * @param[in] observer The observer to listen for window rotation events
258 void SetRotationObserver( RotationObserver* observer );
261 * Destroy the TtsPlayer of sepcific mode.
262 * @param[in] mode The mode of TtsPlayer to destroy
264 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
267 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
268 * trigger a pinch gesture
270 * @param[in] distance The minimum pinch distance in pixels
272 void SetMinimumPinchDistance(float distance);
275 * Gets native window handle
277 * @return native window handle
279 Any GetNativeWindowHandle();
284 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
285 * @param[in] observer The observer.
286 * @note Observers should remove themselves when they are destroyed.
288 void AddObserver( LifeCycleObserver& observer );
291 * Removes the observer from the adaptor.
292 * @param[in] observer The observer to remove.
293 * @note Observers should remove themselves when they are destroyed.
295 void RemoveObserver( LifeCycleObserver& observer );
298 * Emits the Notification event to the Dali core.
300 void SendNotificationEvent();
303 * Request adaptor to update once
305 void RequestUpdateOnce();
308 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
310 void NotifyLanguageChanged();
312 public: //AdaptorInternalServices
315 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
317 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
320 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
322 virtual Dali::Integration::GlAbstraction& GetGlesInterface();
325 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
327 virtual EglFactoryInterface& GetEGLFactoryInterface() const;
330 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
332 virtual TriggerEventInterface& GetTriggerEventInterface();
335 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
337 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
340 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
342 virtual SocketFactoryInterface& GetSocketFactoryInterface();
345 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
347 virtual RenderSurface* GetRenderSurfaceInterface();
350 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
352 virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
355 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
357 virtual PerformanceInterface* GetPerformanceInterface();
360 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
362 virtual TraceInterface& GetKernelTraceInterface();
365 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
367 virtual TraceInterface& GetSystemTraceInterface();
369 public: // Stereoscopy
372 * @copydoc Dali::Integration::Core::SetViewMode()
374 void SetViewMode( ViewMode viewMode );
377 * @copydoc Dali::Integration::Core::GetViewMode()
379 ViewMode GetViewMode() const;
382 * @copydoc Dali::Integration::Core::SetStereoBase()
384 void SetStereoBase( float stereoBase );
387 * @copydoc Dali::Integration::Core::GetStereoBase()
389 float GetStereoBase() const;
394 * @copydoc Dali::Adaptor::SignalResized
396 AdaptorSignalType& ResizedSignal()
398 return mResizedSignal;
402 * @copydoc Dali::Adaptor::LanguageChangedSignal
404 AdaptorSignalType& LanguageChangedSignal()
406 return mLanguageChangedSignal;
409 private: // From Dali::Internal::Adaptor::CoreEventInterface
412 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
414 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
417 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
419 virtual void ProcessCoreEvents();
421 private: // From Dali::Integration::RenderController
424 * Called by the Dali core when it requires another update
426 virtual void RequestUpdate();
429 * Called by Dali core when it requires an notification event being sent on idle.
430 * Multi-threading note: this method must be called from the main thread only.
432 virtual void RequestProcessEventsOnIdle();
434 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
437 * Called when the window becomes fully or partially visible.
439 virtual void OnWindowShown();
442 * Called when the window is fully hidden.
444 virtual void OnWindowHidden();
446 private: // From Dali::Internal::Adaptor::DamageObserver
449 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
451 void OnDamaged( const DamageArea& area );
456 Adaptor(const Adaptor&);
457 Adaptor& operator=(Adaptor&);
462 * Informs core the surface size has changed
464 void SurfaceSizeChanged(const PositionSize& positionSize);
467 * Assigns the render surface to the adaptor
470 void SetSurface(RenderSurface *surface);
473 * Sends an notification message from main loop idle handler
475 void ProcessCoreEventsFromIdle();
478 * Gets path for data/resource storage.
479 * @param[out] path Path for data/resource storage
481 void GetDataStoragePath(std::string& path);
487 * @param[in] nativeWindow native window handle
488 * @param[in] adaptor The public adaptor
489 * @param[in] surface A render surface can be one of the following
490 * - Pixmap, adaptor will use existing Pixmap to draw on to
491 * - Window, adaptor will use existing Window to draw on to
492 * @param[in] environmentOptions A pointer to the environment options. If NULL then one is created.
494 Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions );
500 READY, ///< Initial state before Adaptor::Start is called.
501 RUNNING, ///< Adaptor is running.
502 PAUSED, ///< Adaptor has been paused.
503 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
504 STOPPED, ///< Adaptor has been stopped.
507 typedef std::vector<LifeCycleObserver*> ObserverContainer;
511 AdaptorSignalType mResizedSignal; ///< Resized signal.
512 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
514 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
515 State mState; ///< Current state of the adaptor
516 Dali::Integration::Core* mCore; ///< Dali Core
517 UpdateRenderController* mUpdateRenderController; ///< Controls update/render threads
518 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
519 GlImplementation* mGLES; ///< GL implementation
520 GlSyncImplementation* mGlSync; ///< GL Sync implementation
521 EglFactory* mEglFactory; ///< EGL Factory
523 Any mNativeWindow; ///< window identifier
524 RenderSurface* mSurface; ///< Current surface
525 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
527 EventHandler* mEventHandler; ///< event handler
528 CallbackManager* mCallbackManager; ///< Used to install callbacks
529 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
530 TriggerEvent* mNotificationTrigger; ///< Notification event trigger
531 GestureManager* mGestureManager; ///< Gesture manager
532 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
533 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
534 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
535 ObserverContainer mObservers; ///< A list of adaptor observer pointers
536 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
537 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
538 EnvironmentOptions* mEnvironmentOptions; ///< environment options
539 PerformanceInterface* mPerformanceInterface; ///< Performance interface
540 KernelTrace mKernelTracer; ///< Kernel tracer
541 SystemTrace mSystemTracer; ///< System tracer
542 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
543 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
544 SocketFactory mSocketFactory; ///< Socket factory
545 const bool mEnvironmentOptionsOwned:1; ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
547 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
550 } // namespace Internal
552 } // namespace Adaptor
556 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__