(Build) Combined common & application libraries
[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   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 Dali::Adaptor::GetSurface()
175    */
176   virtual Dali::RenderSurface& GetSurface() const;
177
178   /**
179    * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
180    */
181   virtual void ReleaseSurfaceLock();
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    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
209    */
210   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
211
212   /**
213    * @copydoc Dali::Adaptor::SetUseHardwareVSync()
214    */
215   void SetUseHardwareVSync(bool useHardware);
216
217   /**
218    * Overrides DPI.
219    * Primarily for host/simulation testing
220    * @param[in] hDpi The Horizontal DPI
221    * @param[in] vDpi The Vertical DPI
222    */
223   void SetDpi(size_t hDpi, size_t vDpi);
224
225   /**
226    * @return reference to EglFactory class
227    */
228   EglFactory& GetEGLFactory() const;
229
230   /**
231    * Return GlAbstraction.
232    * @return the GlAbstraction.
233    */
234   Integration::GlAbstraction& GetGlAbstraction() const;
235
236   /**
237    * Return the PlatformAbstraction.
238    * @return The PlatformAbstraction.
239    */
240   Integration::PlatformAbstraction& GetPlatformAbstraction() const;
241
242   /**
243    * Sets the Drag & Drop Listener.
244    * @param[in] detector The detector to send Drag & Drop events to.
245    */
246   void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
247
248   /**
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
252    */
253   void SetRotationObserver( RotationObserver* observer );
254
255   /**
256    * Destroy the TtsPlayer of sepcific mode.
257    * @param[in] mode The mode of TtsPlayer to destroy
258    */
259   void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
260
261   /**
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
264    *
265    * @param[in] distance The minimum pinch distance in pixels
266    */
267   void SetMinimumPinchDistance(float distance);
268
269 public:
270
271   /**
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.
275    */
276   void AddObserver( LifeCycleObserver& observer );
277
278   /**
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.
282    */
283   void RemoveObserver( LifeCycleObserver& observer );
284
285   /**
286    * Emits the Notification event to the Dali core.
287    */
288   void SendNotificationEvent();
289
290   /**
291    * Request adaptor to update once
292    */
293   void RequestUpdateOnce();
294
295   /**
296    * @copydoc Dali::Adaptor::NotifyLanguageChanged()
297    */
298   void NotifyLanguageChanged();
299
300 public:  //AdaptorInternalServices
301
302   /**
303    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
304    */
305   virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
306
307   /**
308    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
309    */
310   virtual Dali::Integration::GlAbstraction& GetGlesInterface();
311
312   /**
313   * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
314   */
315   virtual EglFactoryInterface& GetEGLFactoryInterface() const;
316
317   /**
318    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
319    */
320   virtual TriggerEventInterface& GetTriggerEventInterface();
321
322   /**
323    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
324    */
325   virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
326
327   /**
328    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
329    */
330   virtual RenderSurface* GetRenderSurfaceInterface();
331
332   /**
333    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
334    */
335   virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
336
337   /**
338    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
339    */
340   virtual PerformanceInterface* GetPerformanceInterface();
341
342   /**
343    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
344    */
345   virtual KernelTraceInterface& GetKernelTraceInterface();
346
347 public: // Stereoscopy
348
349   /**
350    * @copydoc Dali::Integration::Core::SetViewMode()
351    */
352   void SetViewMode( ViewMode viewMode );
353
354   /**
355    * @copydoc Dali::Integration::Core::GetViewMode()
356    */
357   ViewMode GetViewMode() const;
358
359   /**
360    * @copydoc Dali::Integration::Core::SetStereoBase()
361    */
362   void SetStereoBase( float stereoBase );
363
364   /**
365    * @copydoc Dali::Integration::Core::GetStereoBase()
366    */
367   float GetStereoBase() const;
368
369 public: // Signals
370
371   /**
372    * @copydoc Dali::Adaptor::SignalResized
373    */
374   AdaptorSignalV2& ResizedSignal()
375   {
376     return mResizedSignalV2;
377   }
378
379   /**
380    * @copydoc Dali::Adaptor::LanguageChangedSignal
381    */
382   AdaptorSignalV2& LanguageChangedSignal()
383   {
384     return mLanguageChangedSignalV2;
385   }
386
387 private: // From Dali::Internal::Adaptor::CoreEventInterface
388
389   /**
390    * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
391    */
392   virtual void QueueCoreEvent(const Dali::Integration::Event& event);
393
394   /**
395    * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
396    */
397   virtual void ProcessCoreEvents();
398
399 private: // From Dali::Integration::RenderController
400
401   /**
402    * Called by the Dali core when it requires another update
403    */
404   virtual void RequestUpdate();
405
406   /**
407    * Call by the Dali core when it requires an notification event being sent on idle
408    */
409   virtual void RequestProcessEventsOnIdle();
410
411 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
412
413   /**
414    * Called when the window becomes fully or partially visible.
415    */
416   virtual void OnWindowShown();
417
418   /**
419    * Called when the window is fully hidden.
420    */
421   virtual void OnWindowHidden();
422
423 private: // From Dali::Internal::Adaptor::DamageObserver
424
425   /**
426    * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
427    */
428   void OnDamaged( const DamageArea& area );
429
430 private:
431
432   // Undefined
433   Adaptor(const Adaptor&);
434   Adaptor& operator=(Adaptor&);
435
436 private:
437
438   /**
439    * Helper to parse log options
440    */
441   void ParseEnvironmentOptions();
442
443   /**
444    * Informs core the surface size has changed
445    */
446   void SurfaceSizeChanged(const PositionSize& positionSize);
447
448   /**
449    * Assigns the render surface to the adaptor
450    *
451    */
452   void SetSurface(Dali::RenderSurface *surface);
453
454   /**
455    * Sends an notification message from main loop idle handler
456    */
457   void ProcessCoreEventsFromIdle();
458
459 private:
460
461   /**
462    * Constructor
463    * @param[in]  adaptor     The public adaptor
464    * @param[in]  surface     A render surface can be one of the following
465    *                         - Pixmap, adaptor will use existing Pixmap to draw on to
466    *                         - Window, adaptor will use existing Window to draw on to
467    * @param[in]  baseLayout  The base layout that the application has been written for
468    */
469   Adaptor( Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLayout& baseLayout );
470
471 private: // Types
472
473   enum State
474   {
475     READY,               ///< Initial state before Adaptor::Start is called.
476     RUNNING,             ///< Adaptor is running.
477     PAUSED,              ///< Adaptor has been paused.
478     PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
479     STOPPED,             ///< Adaptor has been stopped.
480   };
481
482   typedef std::vector<LifeCycleObserver*>  ObserverContainer;
483
484 private: // Data
485
486   AdaptorSignalV2                       mResizedSignalV2;             ///< Resized signal.
487   AdaptorSignalV2                       mLanguageChangedSignalV2;     ///< Language changed signal.
488
489   Dali::Adaptor&                        mAdaptor;                     ///< Reference to public adaptor instance.
490   State                                 mState;                       ///< Current state of the adaptor
491   Dali::Integration::Core*              mCore;                        ///< Dali Core
492   UpdateRenderController*               mUpdateRenderController;      ///< Controls update/render threads
493   VSyncMonitor*                         mVSyncMonitor;                ///< Monitors VSync events
494   GlImplementation*                     mGLES;                        ///< GL implementation
495   GlSyncImplementation*                 mGlSync;                      ///< GL Sync implementation
496   EglFactory*                           mEglFactory;                  ///< EGL Factory
497
498   RenderSurface*                        mSurface;                     ///< Current surface
499   SlpPlatform::SlpPlatformAbstraction*  mPlatformAbstraction;         ///< Platform abstraction
500
501   EventHandler*                         mEventHandler;                ///< event handler
502   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
503   bool                                  mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
504   TriggerEvent*                         mNotificationTrigger;         ///< Notification event trigger
505   GestureManager*                       mGestureManager;              ///< Gesture manager
506   boost::mutex                          mIdleInstaller;               ///< mutex to ensure two threads don't try to install idle handler at the same time
507   size_t                                mHDpi;                        ///< Override horizontal DPI
508   size_t                                mVDpi;                        ///< Override vertical DPI
509   FeedbackPluginProxy*                  mDaliFeedbackPlugin;          ///< Used to access feedback support
510   FeedbackController*                   mFeedbackController;          ///< Plays feedback effects for Dali-Toolkit UI Controls.
511   Dali::TtsPlayer                       mTtsPlayers[Dali::TtsPlayer::MODE_NUM];                   ///< Provides TTS support
512   ObserverContainer                     mObservers;                   ///< A list of adaptor observer pointers
513   DragAndDropDetectorPtr                mDragAndDropDetector;         ///< The Drag & Drop detector
514   RotationObserver*                     mDeferredRotationObserver;    ///< deferred Rotation observer needs event handler
515   DeviceLayout                          mBaseLayout;                  ///< The base layout of the application
516   EnvironmentOptions                    mEnvironmentOptions;          ///< environment options
517   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
518   KernelTrace                           mKernelTracer;                ///< Kernel tracer
519   TriggerEventFactory                   mTriggerEventFactory;         ///< Trigger event factory
520   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
521 public:
522   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
523 };
524
525 } // namespace Internal
526
527 } // namespace Adaptor
528
529 } // namespace Dali
530
531 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__