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 <system-trace.h>
45 #include <trigger-event-factory.h>
46 #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] baseLayout The base layout that the application has been written for
100 * @param[in] configuration The context loss configuration ( to choose resource discard policy )
102 static Dali::Adaptor* New( Any nativeWindow,
103 RenderSurface* surface,
104 const DeviceLayout& baseLayout,
105 Dali::Configuration::ContextLoss configuration );
108 * 2-step initialisation, this should be called after creating an adaptor instance.
110 void Initialize(Dali::Configuration::ContextLoss configuration);
113 * Virtual destructor.
118 * @copydoc Dali::Adaptor::Get()
120 static Dali::Adaptor& Get();
123 * @copydoc Dali::Adaptor::IsAvailable()
125 static bool IsAvailable();
127 public: // AdaptorInternalServices implementation
129 * @copydoc Dali::Adaptor::Start()
131 virtual void Start();
134 * @copydoc Dali::Adaptor::Pause()
136 virtual void Pause();
139 * @copydoc Dali::Adaptor::Resume()
141 virtual void Resume();
144 * @copydoc Dali::Adaptor::Stop()
149 * @copydoc Dali::EventFeeder::FeedTouchPoint()
151 virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
154 * @copydoc Dali::EventFeeder::FeedWheelEvent()
156 virtual void FeedWheelEvent( MouseWheelEvent& wheelEvent );
159 * @copydoc Dali::EventFeeder::FeedKeyEvent()
161 virtual void FeedKeyEvent( KeyEvent& keyEvent );
164 * @copydoc AdaptorInterface::MoveResize()
166 virtual bool MoveResize( const PositionSize& positionSize );
169 * @copydoc AdaptorInterface::SurfaceResized()
171 virtual void SurfaceResized( const PositionSize& positionSize );
174 * @copydoc AdaptorInterface::ReplaceSurface()
176 virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
179 * @copydoc Dali::Adaptor::GetSurface()
181 virtual RenderSurface& GetSurface() const;
184 * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
186 virtual void ReleaseSurfaceLock();
189 * Retrieve the TtsPlayer.
190 * @param[in] mode The mode of TtsPlayer
191 * @return A handle to the TtsPlayer.
193 virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
196 * @copydoc Dali::Adaptor::AddIdle()
198 virtual bool AddIdle( CallbackBase* callback );
201 * @copydoc Internal::Framework::CallFromMainLoop()
203 virtual bool CallFromMainLoop( CallbackBase* callback );
208 * @return the Core instance
210 virtual Dali::Integration::Core& GetCore();
213 * @copydoc Dali::Adaptor::SetRenderRefreshRate()
215 void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
218 * @copydoc Dali::Adaptor::SetUseHardwareVSync()
220 void SetUseHardwareVSync(bool useHardware);
223 * @return reference to EglFactory class
225 EglFactory& GetEGLFactory() const;
228 * Return GlAbstraction.
229 * @return the GlAbstraction.
231 Integration::GlAbstraction& GetGlAbstraction() const;
234 * Return the PlatformAbstraction.
235 * @return The PlatformAbstraction.
237 Integration::PlatformAbstraction& GetPlatformAbstraction() const;
240 * Sets the Drag & Drop Listener.
241 * @param[in] detector The detector to send Drag & Drop events to.
243 void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
246 * Sets a rotation observer, or set to NULL to remove.
247 * @pre Adaptor::Start() has been called ( to create EventHandler )
248 * @param[in] observer The observer to listen for window rotation events
250 void SetRotationObserver( RotationObserver* observer );
253 * Destroy the TtsPlayer of sepcific mode.
254 * @param[in] mode The mode of TtsPlayer to destroy
256 void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
259 * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
260 * trigger a pinch gesture
262 * @param[in] distance The minimum pinch distance in pixels
264 void SetMinimumPinchDistance(float distance);
267 * Gets native window handle
269 * @return native window handle
271 Any GetNativeWindowHandle();
276 * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
277 * @param[in] observer The observer.
278 * @note Observers should remove themselves when they are destroyed.
280 void AddObserver( LifeCycleObserver& observer );
283 * Removes the observer from the adaptor.
284 * @param[in] observer The observer to remove.
285 * @note Observers should remove themselves when they are destroyed.
287 void RemoveObserver( LifeCycleObserver& observer );
290 * Emits the Notification event to the Dali core.
292 void SendNotificationEvent();
295 * Request adaptor to update once
297 void RequestUpdateOnce();
300 * @copydoc Dali::Adaptor::NotifyLanguageChanged()
302 void NotifyLanguageChanged();
304 public: //AdaptorInternalServices
307 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
309 virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
312 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
314 virtual Dali::Integration::GlAbstraction& GetGlesInterface();
317 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
319 virtual EglFactoryInterface& GetEGLFactoryInterface() const;
322 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
324 virtual TriggerEventInterface& GetTriggerEventInterface();
327 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
329 virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
332 * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
334 virtual SocketFactoryInterface& GetSocketFactoryInterface();
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 TraceInterface& GetKernelTraceInterface();
357 * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
359 virtual TraceInterface& GetSystemTraceInterface();
361 public: // Stereoscopy
364 * @copydoc Dali::Integration::Core::SetViewMode()
366 void SetViewMode( ViewMode viewMode );
369 * @copydoc Dali::Integration::Core::GetViewMode()
371 ViewMode GetViewMode() const;
374 * @copydoc Dali::Integration::Core::SetStereoBase()
376 void SetStereoBase( float stereoBase );
379 * @copydoc Dali::Integration::Core::GetStereoBase()
381 float GetStereoBase() const;
386 * @copydoc Dali::Adaptor::SignalResized
388 AdaptorSignalType& ResizedSignal()
390 return mResizedSignal;
394 * @copydoc Dali::Adaptor::LanguageChangedSignal
396 AdaptorSignalType& LanguageChangedSignal()
398 return mLanguageChangedSignal;
401 private: // From Dali::Internal::Adaptor::CoreEventInterface
404 * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
406 virtual void QueueCoreEvent(const Dali::Integration::Event& event);
409 * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
411 virtual void ProcessCoreEvents();
413 private: // From Dali::Integration::RenderController
416 * Called by the Dali core when it requires another update
418 virtual void RequestUpdate();
421 * Called by Dali core when it requires an notification event being sent on idle.
422 * Multi-threading note: this method must be called from the main thread only.
424 virtual void RequestProcessEventsOnIdle();
426 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
429 * Called when the window becomes fully or partially visible.
431 virtual void OnWindowShown();
434 * Called when the window is fully hidden.
436 virtual void OnWindowHidden();
438 private: // From Dali::Internal::Adaptor::DamageObserver
441 * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
443 void OnDamaged( const DamageArea& area );
448 Adaptor(const Adaptor&);
449 Adaptor& operator=(Adaptor&);
454 * Helper to parse log options
456 void ParseEnvironmentOptions();
459 * Informs core the surface size has changed
461 void SurfaceSizeChanged(const PositionSize& positionSize);
464 * Assigns the render surface to the adaptor
467 void SetSurface(RenderSurface *surface);
470 * Sends an notification message from main loop idle handler
472 void ProcessCoreEventsFromIdle();
475 * Gets path for data/resource storage.
476 * @param[out] path Path for data/resource storage
478 void GetDataStoragePath(std::string& path);
484 * @param[in] nativeWindow native window handle
485 * @param[in] adaptor The public adaptor
486 * @param[in] surface A render surface can be one of the following
487 * - Pixmap, adaptor will use existing Pixmap to draw on to
488 * - Window, adaptor will use existing Window to draw on to
489 * @param[in] baseLayout The base layout that the application has been written for
491 Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLayout& baseLayout );
497 READY, ///< Initial state before Adaptor::Start is called.
498 RUNNING, ///< Adaptor is running.
499 PAUSED, ///< Adaptor has been paused.
500 PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
501 STOPPED, ///< Adaptor has been stopped.
504 typedef std::vector<LifeCycleObserver*> ObserverContainer;
508 AdaptorSignalType mResizedSignal; ///< Resized signal.
509 AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal.
511 Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance.
512 State mState; ///< Current state of the adaptor
513 Dali::Integration::Core* mCore; ///< Dali Core
514 UpdateRenderController* mUpdateRenderController; ///< Controls update/render threads
515 VSyncMonitor* mVSyncMonitor; ///< Monitors VSync events
516 GlImplementation* mGLES; ///< GL implementation
517 GlSyncImplementation* mGlSync; ///< GL Sync implementation
518 EglFactory* mEglFactory; ///< EGL Factory
520 Any mNativeWindow; ///< window identifier
521 RenderSurface* mSurface; ///< Current surface
522 TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction; ///< Platform abstraction
524 EventHandler* mEventHandler; ///< event handler
525 CallbackManager* mCallbackManager; ///< Used to install callbacks
526 bool mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
527 TriggerEvent* mNotificationTrigger; ///< Notification event trigger
528 GestureManager* mGestureManager; ///< Gesture manager
529 FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support
530 FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls.
531 Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support
532 ObserverContainer mObservers; ///< A list of adaptor observer pointers
533 DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector
534 RotationObserver* mDeferredRotationObserver; ///< deferred Rotation observer needs event handler
535 DeviceLayout mBaseLayout; ///< The base layout of the application
536 EnvironmentOptions mEnvironmentOptions; ///< environment options
537 PerformanceInterface* mPerformanceInterface; ///< Performance interface
538 KernelTrace mKernelTracer; ///< Kernel tracer
539 SystemTrace mSystemTracer; ///< System tracer
540 TriggerEventFactory mTriggerEventFactory; ///< Trigger event factory
541 ObjectProfiler* mObjectProfiler; ///< Tracks object lifetime for profiling
542 SocketFactory mSocketFactory; ///< Socket factory
544 inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
547 } // namespace Internal
549 } // namespace Adaptor
553 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__