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