Added SingletonService, removed Singleton APIs from Adaptor & removed Application...
[platform/core/uifw/dali-adaptor.git] / adaptors / common / adaptor-impl.h
1 #ifndef __DALI_INTERNAL_ADAPTOR_IMPL_H__
2 #define __DALI_INTERNAL_ADAPTOR_IMPL_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <boost/bind.hpp>
23 #include <boost/function.hpp>
24 #include <boost/thread.hpp>
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/common/vector-wrapper.h>
28 #include <dali/public-api/common/view-mode.h>
29 #include <dali/public-api/math/rect.h>
30 #include <dali/integration-api/render-controller.h>
31
32 #include <adaptor.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>
38
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>
48
49 namespace Dali
50 {
51
52 namespace Integration
53 {
54 class Core;
55 class GlAbstraction;
56 }
57
58 namespace Internal
59 {
60
61 namespace Adaptor
62 {
63 class EventHandler;
64 class EglFactory;
65 class GestureManager;
66 class GlImplementation;
67 class GlSyncImplementation;
68 class RenderSurface;
69 class UpdateRenderController;
70 class TriggerEvent;
71 class CallbackManager;
72 class FeedbackPluginProxy;
73 class FeedbackController;
74 class RotationObserver;
75 class VSyncMonitor;
76 class PerformanceInterface;
77 class LifeCycleObserver;
78 class ObjectProfiler;
79
80 /**
81  * Implementation of the Adaptor class.
82  */
83 class Adaptor : public Integration::RenderController,
84                 public AdaptorInternalServices,
85                 public CoreEventInterface,
86                 public DamageObserver,
87                 public WindowVisibilityObserver
88 {
89 public:
90
91   typedef Dali::Adaptor::AdaptorSignalV2 AdaptorSignalV2;
92
93   /**
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    */
100   DALI_IMPORT_API static Dali::Adaptor* New( RenderSurface* surface, const DeviceLayout& baseLayout );
101
102   /**
103    * 2-step initialisation, this should be called after creating an adaptor instance.
104    */
105   void Initialize();
106
107   /**
108    * Virtual destructor.
109    */
110   virtual ~Adaptor();
111
112   /**
113    * @copydoc Dali::Adaptor::Get()
114    */
115   static Dali::Adaptor& Get();
116
117   /**
118    * @copydoc Dali::Adaptor::IsAvailable()
119    */
120   static bool IsAvailable();
121
122 public: // AdaptorInternalServices implementation
123   /**
124    * @copydoc Dali::Adaptor::Start()
125    */
126   virtual void Start();
127
128   /**
129    * @copydoc Dali::Adaptor::Pause()
130    */
131   virtual void Pause();
132
133   /**
134    * @copydoc Dali::Adaptor::Resume()
135    */
136   virtual void Resume();
137
138   /**
139    * @copydoc Dali::Adaptor::Stop()
140    */
141   virtual void Stop();
142
143   /**
144    * @copydoc Dali::EventFeeder::FeedTouchPoint()
145    */
146   virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
147
148   /**
149    * @copydoc Dali::EventFeeder::FeedWheelEvent()
150    */
151   virtual void FeedWheelEvent( MouseWheelEvent& wheelEvent );
152
153   /**
154    * @copydoc Dali::EventFeeder::FeedKeyEvent()
155    */
156   virtual void FeedKeyEvent( KeyEvent& keyEvent );
157
158   /**
159    * @copydoc AdaptorInterface::MoveResize()
160    */
161   virtual bool MoveResize( const PositionSize& positionSize );
162
163   /**
164    * @copydoc AdaptorInterface::SurfaceResized()
165    */
166   virtual void SurfaceResized( const PositionSize& positionSize );
167
168   /**
169    * @copydoc AdaptorInterface::ReplaceSurface()
170    */
171   virtual void ReplaceSurface( Dali::RenderSurface& surface );
172
173   /**
174    * @copydoc AdaptorInterface::RenderSync()
175    */
176   virtual void RenderSync();
177
178   /**
179    * @copydoc Dali::Adaptor::GetSurface()
180    */
181   virtual Dali::RenderSurface& GetSurface() const;
182
183   /**
184    * Retrieve the TtsPlayer.
185    * @param[in] mode The mode of TtsPlayer
186    * @return A handle to the TtsPlayer.
187    */
188   virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
189
190   /**
191    * @copydoc Dali::Adaptor::AddIdle()
192    */
193   virtual bool AddIdle( boost::function<void(void)> callBack );
194
195   /**
196    * @copydoc Internal::Framework::CallFromMainLoop()
197    */
198   virtual bool CallFromMainLoop(boost::function<void(void)> callBack);
199
200 public:
201
202   /**
203    * @return the Core instance
204    */
205   virtual Dali::Integration::Core& GetCore();
206
207   /**
208    * Disables GL draw synchronisation with the display.
209    */
210   DALI_IMPORT_API void DisableVSync();
211
212   /**
213    * Overrides DPI.
214    * Primarily for host/simulation testing
215    * @param[in] hDpi The Horizontal DPI
216    * @param[in] vDpi The Vertical DPI
217    */
218   DALI_IMPORT_API void SetDpi(size_t hDpi, size_t vDpi);
219
220   /**
221    * @return reference to EglFactory class
222    */
223   EglFactory& GetEGLFactory() const;
224
225   /**
226    * Return GlAbstraction.
227    * @return the GlAbstraction.
228    */
229   Integration::GlAbstraction& GetGlAbstraction() const;
230
231   /**
232    * Return the PlatformAbstraction.
233    * @return The PlatformAbstraction.
234    */
235   Integration::PlatformAbstraction& GetPlatformAbstraction() const;
236
237   /**
238    * Sets the Drag & Drop Listener.
239    * @param[in] detector The detector to send Drag & Drop events to.
240    */
241   void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
242
243   /**
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
247    */
248   void SetRotationObserver( RotationObserver* observer );
249
250   /**
251    * Destroy the TtsPlayer of sepcific mode.
252    * @param[in] mode The mode of TtsPlayer to destroy
253    */
254   void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
255
256   /**
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
259    *
260    * @param[in] distance The minimum pinch distance in pixels
261    */
262   void SetMinimumPinchDistance(float distance);
263
264 public:
265
266   /**
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.
270    */
271   void AddObserver( LifeCycleObserver& observer );
272
273   /**
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.
277    */
278   void RemoveObserver( LifeCycleObserver& observer );
279
280   /**
281    * Emits the Notification event to the Dali core.
282    */
283   void SendNotificationEvent();
284
285   /**
286    * Request adaptor to update once
287    */
288   void RequestUpdateOnce();
289
290   /**
291    * @copydoc Dali::Adaptor::NotifyLanguageChanged()
292    */
293   void NotifyLanguageChanged();
294
295 public:  //AdaptorInternalServices
296
297   /**
298    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
299    */
300   virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
301
302   /**
303    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
304    */
305   virtual Dali::Integration::GlAbstraction& GetGlesInterface();
306
307   /**
308   * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
309   */
310   virtual EglFactoryInterface& GetEGLFactoryInterface() const;
311
312   /**
313    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
314    */
315   virtual TriggerEventInterface& GetTriggerEventInterface();
316
317   /**
318    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
319    */
320   virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
321
322   /**
323    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
324    */
325   virtual RenderSurface* GetRenderSurfaceInterface();
326
327   /**
328    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
329    */
330   virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
331
332   /**
333    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
334    */
335   virtual PerformanceInterface* GetPerformanceInterface();
336
337   /**
338    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
339    */
340   virtual KernelTraceInterface& GetKernelTraceInterface();
341
342 public: // Stereoscopy
343
344   /**
345    * @copydoc Dali::Integration::Core::SetViewMode()
346    */
347   DALI_IMPORT_API void SetViewMode( ViewMode viewMode );
348
349   /**
350    * @copydoc Dali::Integration::Core::GetViewMode()
351    */
352   DALI_IMPORT_API ViewMode GetViewMode() const;
353
354   /**
355    * @copydoc Dali::Integration::Core::SetStereoBase()
356    */
357   DALI_IMPORT_API void SetStereoBase( float stereoBase );
358
359   /**
360    * @copydoc Dali::Integration::Core::GetStereoBase()
361    */
362   DALI_IMPORT_API float GetStereoBase() const;
363
364 public: // Signals
365
366   /**
367    * @copydoc Dali::Adaptor::SignalResized
368    */
369   AdaptorSignalV2& ResizedSignal()
370   {
371     return mResizedSignalV2;
372   }
373
374   /**
375    * @copydoc Dali::Adaptor::LanguageChangedSignal
376    */
377   AdaptorSignalV2& LanguageChangedSignal()
378   {
379     return mLanguageChangedSignalV2;
380   }
381
382 private: // From Dali::Internal::Adaptor::CoreEventInterface
383
384   /**
385    * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
386    */
387   virtual void QueueCoreEvent(const Dali::Integration::Event& event);
388
389   /**
390    * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
391    */
392   virtual void ProcessCoreEvents();
393
394 private: // From Dali::Integration::RenderController
395
396   /**
397    * Called by the Dali core when it requires another update
398    */
399   virtual void RequestUpdate();
400
401   /**
402    * Call by the Dali core when it requires an notification event being sent on idle
403    */
404   virtual void RequestProcessEventsOnIdle();
405
406 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
407
408   /**
409    * Called when the window becomes fully or partially visible.
410    */
411   virtual void OnWindowShown();
412
413   /**
414    * Called when the window is fully hidden.
415    */
416   virtual void OnWindowHidden();
417
418 private: // From Dali::Internal::Adaptor::DamageObserver
419
420   /**
421    * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
422    */
423   void OnDamaged( const DamageArea& area );
424
425 private:
426
427   // Undefined
428   Adaptor(const Adaptor&);
429   Adaptor& operator=(Adaptor&);
430
431 private:
432
433   /**
434    * Helper to parse log options
435    */
436   void ParseEnvironmentOptions();
437
438   /**
439    * Informs core the surface size has changed
440    */
441   void SurfaceSizeChanged(const PositionSize& positionSize);
442
443   /**
444    * Assigns the render surface to the adaptor
445    *
446    */
447   void SetSurface(Dali::RenderSurface *surface);
448
449   /**
450    * Sends an notification message from main loop idle handler
451    */
452   void ProcessCoreEventsFromIdle();
453
454 private:
455
456   /**
457    * Constructor
458    * @param[in]  adaptor     The public adaptor
459    * @param[in]  surface     A render surface can be one of the following
460    *                         - Pixmap, adaptor will use existing Pixmap to draw on to
461    *                         - Window, adaptor will use existing Window to draw on to
462    * @param[in]  baseLayout  The base layout that the application has been written for
463    */
464   Adaptor( Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLayout& baseLayout );
465
466 private: // Types
467
468   enum State
469   {
470     READY,               ///< Initial state before Adaptor::Start is called.
471     RUNNING,             ///< Adaptor is running.
472     PAUSED,              ///< Adaptor has been paused.
473     PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
474     STOPPED,             ///< Adaptor has been stopped.
475   };
476
477   typedef std::vector<LifeCycleObserver*>  ObserverContainer;
478
479 private: // Data
480
481   AdaptorSignalV2                       mResizedSignalV2;             ///< Resized signal.
482   AdaptorSignalV2                       mLanguageChangedSignalV2;     ///< Language changed signal.
483
484   Dali::Adaptor&                        mAdaptor;                     ///< Reference to public adaptor instance.
485   State                                 mState;                       ///< Current state of the adaptor
486   Dali::Integration::Core*              mCore;                        ///< Dali Core
487   UpdateRenderController*               mUpdateRenderController;      ///< Controls update/render threads
488   VSyncMonitor*                         mVSyncMonitor;                ///< Monitors VSync events
489   GlImplementation*                     mGLES;                        ///< GL implementation
490   GlSyncImplementation*                 mGlSync;                      ///< GL Sync implementation
491   EglFactory*                           mEglFactory;                  ///< EGL Factory
492
493   RenderSurface*                        mSurface;                     ///< Current surface
494   SlpPlatform::SlpPlatformAbstraction*  mPlatformAbstraction;         ///< Platform abstraction
495
496   EventHandler*                         mEventHandler;                ///< event handler
497   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
498   bool                                  mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
499   TriggerEvent*                         mNotificationTrigger;         ///< Notification event trigger
500   GestureManager*                       mGestureManager;              ///< Gesture manager
501   boost::mutex                          mIdleInstaller;               ///< mutex to ensure two threads don't try to install idle handler at the same time
502   size_t                                mHDpi;                        ///< Override horizontal DPI
503   size_t                                mVDpi;                        ///< Override vertical DPI
504   FeedbackPluginProxy*                  mDaliFeedbackPlugin;          ///< Used to access feedback support
505   FeedbackController*                   mFeedbackController;          ///< Plays feedback effects for Dali-Toolkit UI Controls.
506   Dali::TtsPlayer                       mTtsPlayers[Dali::TtsPlayer::MODE_NUM];                   ///< Provides TTS support
507   ObserverContainer                     mObservers;                   ///< A list of adaptor observer pointers
508   DragAndDropDetectorPtr                mDragAndDropDetector;         ///< The Drag & Drop detector
509   RotationObserver*                     mDeferredRotationObserver;    ///< deferred Rotation observer needs event handler
510   DeviceLayout                          mBaseLayout;                  ///< The base layout of the application
511   EnvironmentOptions                    mEnvironmentOptions;          ///< environment options
512   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
513   KernelTrace                           mKernelTracer;                ///< Kernel tracer
514   TriggerEventFactory                   mTriggerEventFactory;         ///< Trigger event factory
515   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
516 public:
517   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
518 };
519
520 } // namespace Internal
521
522 } // namespace Adaptor
523
524 } // namespace Dali
525
526 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__