Merge "DALi Version 1.0.35" into tizen
[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 <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>
27
28 // INTERNAL INCLUDES
29 #include <adaptor.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>
35
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 <trigger-event-factory.h>
45 #include <networking/socket-factory.h>
46
47 namespace Dali
48 {
49
50 namespace Integration
51 {
52 class Core;
53 class GlAbstraction;
54 }
55
56 namespace Internal
57 {
58
59 namespace Adaptor
60 {
61 class EventHandler;
62 class EglFactory;
63 class GestureManager;
64 class GlImplementation;
65 class GlSyncImplementation;
66 class RenderSurface;
67 class UpdateRenderController;
68 class TriggerEvent;
69 class CallbackManager;
70 class FeedbackPluginProxy;
71 class FeedbackController;
72 class RotationObserver;
73 class VSyncMonitor;
74 class PerformanceInterface;
75 class LifeCycleObserver;
76 class ObjectProfiler;
77
78 /**
79  * Implementation of the Adaptor class.
80  */
81 class Adaptor : public Integration::RenderController,
82                 public AdaptorInternalServices,
83                 public CoreEventInterface,
84                 public DamageObserver,
85                 public WindowVisibilityObserver
86 {
87 public:
88
89   typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
90
91   /**
92    * Creates a New Adaptor
93    * @param[in]  surface     A render surface can be one of the following
94    *                         - Pixmap, adaptor will use existing Pixmap to draw on to
95    *                         - Window, adaptor will use existing Window to draw on to
96    * @param[in]  baseLayout  The base layout that the application has been written for
97    * @param[in]  configuration The context loss configuration ( to choose resource discard policy )
98    */
99   static Dali::Adaptor* New( RenderSurface* surface,
100                              const DeviceLayout& baseLayout,
101                              Dali::Configuration::ContextLoss configuration );
102
103   /**
104    * 2-step initialisation, this should be called after creating an adaptor instance.
105    */
106   void Initialize(Dali::Configuration::ContextLoss configuration);
107
108   /**
109    * Virtual destructor.
110    */
111   virtual ~Adaptor();
112
113   /**
114    * @copydoc Dali::Adaptor::Get()
115    */
116   static Dali::Adaptor& Get();
117
118   /**
119    * @copydoc Dali::Adaptor::IsAvailable()
120    */
121   static bool IsAvailable();
122
123 public: // AdaptorInternalServices implementation
124   /**
125    * @copydoc Dali::Adaptor::Start()
126    */
127   virtual void Start();
128
129   /**
130    * @copydoc Dali::Adaptor::Pause()
131    */
132   virtual void Pause();
133
134   /**
135    * @copydoc Dali::Adaptor::Resume()
136    */
137   virtual void Resume();
138
139   /**
140    * @copydoc Dali::Adaptor::Stop()
141    */
142   virtual void Stop();
143
144   /**
145    * @copydoc Dali::EventFeeder::FeedTouchPoint()
146    */
147   virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
148
149   /**
150    * @copydoc Dali::EventFeeder::FeedWheelEvent()
151    */
152   virtual void FeedWheelEvent( MouseWheelEvent& wheelEvent );
153
154   /**
155    * @copydoc Dali::EventFeeder::FeedKeyEvent()
156    */
157   virtual void FeedKeyEvent( KeyEvent& keyEvent );
158
159   /**
160    * @copydoc AdaptorInterface::MoveResize()
161    */
162   virtual bool MoveResize( const PositionSize& positionSize );
163
164   /**
165    * @copydoc AdaptorInterface::SurfaceResized()
166    */
167   virtual void SurfaceResized( const PositionSize& positionSize );
168
169   /**
170    * @copydoc AdaptorInterface::ReplaceSurface()
171    */
172   virtual void ReplaceSurface( Dali::RenderSurface& surface );
173
174   /**
175    * @copydoc Dali::Adaptor::GetSurface()
176    */
177   virtual Dali::RenderSurface& GetSurface() const;
178
179   /**
180    * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
181    */
182   virtual void ReleaseSurfaceLock();
183
184   /**
185    * Retrieve the TtsPlayer.
186    * @param[in] mode The mode of TtsPlayer
187    * @return A handle to the TtsPlayer.
188    */
189   virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
190
191   /**
192    * @copydoc Dali::Adaptor::AddIdle()
193    */
194   virtual bool AddIdle( CallbackBase* callback );
195
196   /**
197    * @copydoc Internal::Framework::CallFromMainLoop()
198    */
199   virtual bool CallFromMainLoop( CallbackBase* callback );
200
201 public:
202
203   /**
204    * @return the Core instance
205    */
206   virtual Dali::Integration::Core& GetCore();
207
208   /**
209    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
210    */
211   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
212
213   /**
214    * @copydoc Dali::Adaptor::SetUseHardwareVSync()
215    */
216   void SetUseHardwareVSync(bool useHardware);
217
218   /**
219    * Overrides DPI.
220    * Primarily for host/simulation testing
221    * @param[in] hDpi The Horizontal DPI
222    * @param[in] vDpi The Vertical DPI
223    */
224   void SetDpi(size_t hDpi, size_t vDpi);
225
226   /**
227    * @return reference to EglFactory class
228    */
229   EglFactory& GetEGLFactory() const;
230
231   /**
232    * Return GlAbstraction.
233    * @return the GlAbstraction.
234    */
235   Integration::GlAbstraction& GetGlAbstraction() const;
236
237   /**
238    * Return the PlatformAbstraction.
239    * @return The PlatformAbstraction.
240    */
241   Integration::PlatformAbstraction& GetPlatformAbstraction() const;
242
243   /**
244    * Sets the Drag & Drop Listener.
245    * @param[in] detector The detector to send Drag & Drop events to.
246    */
247   void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
248
249   /**
250    * Sets a rotation observer, or set to NULL to remove.
251    * @pre Adaptor::Start() has been called ( to create EventHandler )
252    * @param[in] observer The observer to listen for window rotation events
253    */
254   void SetRotationObserver( RotationObserver* observer );
255
256   /**
257    * Destroy the TtsPlayer of sepcific mode.
258    * @param[in] mode The mode of TtsPlayer to destroy
259    */
260   void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
261
262   /**
263    * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
264    * trigger a pinch gesture
265    *
266    * @param[in] distance The minimum pinch distance in pixels
267    */
268   void SetMinimumPinchDistance(float distance);
269
270 public:
271
272   /**
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.
276    */
277   void AddObserver( LifeCycleObserver& observer );
278
279   /**
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.
283    */
284   void RemoveObserver( LifeCycleObserver& observer );
285
286   /**
287    * Emits the Notification event to the Dali core.
288    */
289   void SendNotificationEvent();
290
291   /**
292    * Request adaptor to update once
293    */
294   void RequestUpdateOnce();
295
296   /**
297    * @copydoc Dali::Adaptor::NotifyLanguageChanged()
298    */
299   void NotifyLanguageChanged();
300
301 public:  //AdaptorInternalServices
302
303   /**
304    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
305    */
306   virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
307
308   /**
309    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
310    */
311   virtual Dali::Integration::GlAbstraction& GetGlesInterface();
312
313   /**
314   * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
315   */
316   virtual EglFactoryInterface& GetEGLFactoryInterface() const;
317
318   /**
319    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
320    */
321   virtual TriggerEventInterface& GetTriggerEventInterface();
322
323   /**
324    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
325    */
326   virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
327
328   /**
329    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
330    */
331   virtual SocketFactoryInterface& GetSocketFactoryInterface();
332
333   /**
334    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
335    */
336   virtual RenderSurface* GetRenderSurfaceInterface();
337
338   /**
339    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
340    */
341   virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
342
343   /**
344    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
345    */
346   virtual PerformanceInterface* GetPerformanceInterface();
347
348   /**
349    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
350    */
351   virtual KernelTraceInterface& GetKernelTraceInterface();
352
353 public: // Stereoscopy
354
355   /**
356    * @copydoc Dali::Integration::Core::SetViewMode()
357    */
358   void SetViewMode( ViewMode viewMode );
359
360   /**
361    * @copydoc Dali::Integration::Core::GetViewMode()
362    */
363   ViewMode GetViewMode() const;
364
365   /**
366    * @copydoc Dali::Integration::Core::SetStereoBase()
367    */
368   void SetStereoBase( float stereoBase );
369
370   /**
371    * @copydoc Dali::Integration::Core::GetStereoBase()
372    */
373   float GetStereoBase() const;
374
375 public: // Signals
376
377   /**
378    * @copydoc Dali::Adaptor::SignalResized
379    */
380   AdaptorSignalType& ResizedSignal()
381   {
382     return mResizedSignal;
383   }
384
385   /**
386    * @copydoc Dali::Adaptor::LanguageChangedSignal
387    */
388   AdaptorSignalType& LanguageChangedSignal()
389   {
390     return mLanguageChangedSignal;
391   }
392
393 private: // From Dali::Internal::Adaptor::CoreEventInterface
394
395   /**
396    * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
397    */
398   virtual void QueueCoreEvent(const Dali::Integration::Event& event);
399
400   /**
401    * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
402    */
403   virtual void ProcessCoreEvents();
404
405 private: // From Dali::Integration::RenderController
406
407   /**
408    * Called by the Dali core when it requires another update
409    */
410   virtual void RequestUpdate();
411
412   /**
413    * Called by Dali core when it requires an notification event being sent on idle.
414    * Multi-threading note: this method must be called from the main thread only.
415    */
416   virtual void RequestProcessEventsOnIdle();
417
418 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
419
420   /**
421    * Called when the window becomes fully or partially visible.
422    */
423   virtual void OnWindowShown();
424
425   /**
426    * Called when the window is fully hidden.
427    */
428   virtual void OnWindowHidden();
429
430 private: // From Dali::Internal::Adaptor::DamageObserver
431
432   /**
433    * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
434    */
435   void OnDamaged( const DamageArea& area );
436
437 private:
438
439   // Undefined
440   Adaptor(const Adaptor&);
441   Adaptor& operator=(Adaptor&);
442
443 private:
444
445   /**
446    * Helper to parse log options
447    */
448   void ParseEnvironmentOptions();
449
450   /**
451    * Informs core the surface size has changed
452    */
453   void SurfaceSizeChanged(const PositionSize& positionSize);
454
455   /**
456    * Assigns the render surface to the adaptor
457    *
458    */
459   void SetSurface(Dali::RenderSurface *surface);
460
461   /**
462    * Sends an notification message from main loop idle handler
463    */
464   void ProcessCoreEventsFromIdle();
465
466   /**
467    * Gets path for data/resource storage.
468    * @param[out] path Path for data/resource storage
469    */
470   void GetDataStoragePath(std::string& path);
471
472 private:
473
474   /**
475    * Constructor
476    * @param[in]  adaptor     The public adaptor
477    * @param[in]  surface     A render surface can be one of the following
478    *                         - Pixmap, adaptor will use existing Pixmap to draw on to
479    *                         - Window, adaptor will use existing Window to draw on to
480    * @param[in]  baseLayout  The base layout that the application has been written for
481    */
482   Adaptor( Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLayout& baseLayout );
483
484 private: // Types
485
486   enum State
487   {
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.
493   };
494
495   typedef std::vector<LifeCycleObserver*>  ObserverContainer;
496
497 private: // Data
498
499   AdaptorSignalType                       mResizedSignal;             ///< Resized signal.
500   AdaptorSignalType                       mLanguageChangedSignal;     ///< Language changed signal.
501
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
510
511   RenderSurface*                        mSurface;                     ///< Current surface
512   TizenPlatform::TizenPlatformAbstraction*  mPlatformAbstraction;         ///< Platform abstraction
513
514   EventHandler*                         mEventHandler;                ///< event handler
515   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
516   bool                                  mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
517   TriggerEvent*                         mNotificationTrigger;         ///< Notification event trigger
518   GestureManager*                       mGestureManager;              ///< Gesture manager
519   size_t                                mHDpi;                        ///< Override horizontal DPI
520   size_t                                mVDpi;                        ///< Override vertical DPI
521   FeedbackPluginProxy*                  mDaliFeedbackPlugin;          ///< Used to access feedback support
522   FeedbackController*                   mFeedbackController;          ///< Plays feedback effects for Dali-Toolkit UI Controls.
523   Dali::TtsPlayer                       mTtsPlayers[Dali::TtsPlayer::MODE_NUM];                   ///< Provides TTS support
524   ObserverContainer                     mObservers;                   ///< A list of adaptor observer pointers
525   DragAndDropDetectorPtr                mDragAndDropDetector;         ///< The Drag & Drop detector
526   RotationObserver*                     mDeferredRotationObserver;    ///< deferred Rotation observer needs event handler
527   DeviceLayout                          mBaseLayout;                  ///< The base layout of the application
528   EnvironmentOptions                    mEnvironmentOptions;          ///< environment options
529   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
530   KernelTrace                           mKernelTracer;                ///< Kernel tracer
531   TriggerEventFactory                   mTriggerEventFactory;         ///< Trigger event factory
532   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
533   SocketFactory                         mSocketFactory;               ///< Socket factory
534 public:
535   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
536 };
537
538 } // namespace Internal
539
540 } // namespace Adaptor
541
542 } // namespace Dali
543
544 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__