Merge "Change "SLP" to "Tizen"" 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
46 namespace Dali
47 {
48
49 namespace Integration
50 {
51 class Core;
52 class GlAbstraction;
53 }
54
55 namespace Internal
56 {
57
58 namespace Adaptor
59 {
60 class EventHandler;
61 class EglFactory;
62 class GestureManager;
63 class GlImplementation;
64 class GlSyncImplementation;
65 class RenderSurface;
66 class UpdateRenderController;
67 class TriggerEvent;
68 class CallbackManager;
69 class FeedbackPluginProxy;
70 class FeedbackController;
71 class RotationObserver;
72 class VSyncMonitor;
73 class PerformanceInterface;
74 class LifeCycleObserver;
75 class ObjectProfiler;
76
77 /**
78  * Implementation of the Adaptor class.
79  */
80 class Adaptor : public Integration::RenderController,
81                 public AdaptorInternalServices,
82                 public CoreEventInterface,
83                 public DamageObserver,
84                 public WindowVisibilityObserver
85 {
86 public:
87
88   typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
89
90   /**
91    * Creates a New Adaptor
92    * @param[in]  surface     A render surface can be one of the following
93    *                         - Pixmap, adaptor will use existing Pixmap to draw on to
94    *                         - Window, adaptor will use existing Window to draw on to
95    * @param[in]  baseLayout  The base layout that the application has been written for
96    * @param[in]  configuration The context loss configuration ( to choose resource discard policy )
97    */
98   static Dali::Adaptor* New( RenderSurface* surface,
99                              const DeviceLayout& baseLayout,
100                              Dali::Configuration::ContextLoss configuration );
101
102   /**
103    * 2-step initialisation, this should be called after creating an adaptor instance.
104    */
105   void Initialize(Dali::Configuration::ContextLoss configuration);
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( CallbackBase* callback );
194
195   /**
196    * @copydoc Internal::Framework::CallFromMainLoop()
197    */
198   virtual bool CallFromMainLoop( CallbackBase* 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   AdaptorSignalType& ResizedSignal()
375   {
376     return mResizedSignal;
377   }
378
379   /**
380    * @copydoc Dali::Adaptor::LanguageChangedSignal
381    */
382   AdaptorSignalType& LanguageChangedSignal()
383   {
384     return mLanguageChangedSignal;
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    * Called by Dali core when it requires an notification event being sent on idle.
408    * Multi-threading note: this method must be called from the main thread only.
409    */
410   virtual void RequestProcessEventsOnIdle();
411
412 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
413
414   /**
415    * Called when the window becomes fully or partially visible.
416    */
417   virtual void OnWindowShown();
418
419   /**
420    * Called when the window is fully hidden.
421    */
422   virtual void OnWindowHidden();
423
424 private: // From Dali::Internal::Adaptor::DamageObserver
425
426   /**
427    * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
428    */
429   void OnDamaged( const DamageArea& area );
430
431 private:
432
433   // Undefined
434   Adaptor(const Adaptor&);
435   Adaptor& operator=(Adaptor&);
436
437 private:
438
439   /**
440    * Helper to parse log options
441    */
442   void ParseEnvironmentOptions();
443
444   /**
445    * Informs core the surface size has changed
446    */
447   void SurfaceSizeChanged(const PositionSize& positionSize);
448
449   /**
450    * Assigns the render surface to the adaptor
451    *
452    */
453   void SetSurface(Dali::RenderSurface *surface);
454
455   /**
456    * Sends an notification message from main loop idle handler
457    */
458   void ProcessCoreEventsFromIdle();
459
460   /**
461    * Gets path for data/resource storage.
462    * @param[out] path Path for data/resource storage
463    */
464   void GetDataStoragePath(std::string& path);
465
466 private:
467
468   /**
469    * Constructor
470    * @param[in]  adaptor     The public adaptor
471    * @param[in]  surface     A render surface can be one of the following
472    *                         - Pixmap, adaptor will use existing Pixmap to draw on to
473    *                         - Window, adaptor will use existing Window to draw on to
474    * @param[in]  baseLayout  The base layout that the application has been written for
475    */
476   Adaptor( Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLayout& baseLayout );
477
478 private: // Types
479
480   enum State
481   {
482     READY,               ///< Initial state before Adaptor::Start is called.
483     RUNNING,             ///< Adaptor is running.
484     PAUSED,              ///< Adaptor has been paused.
485     PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
486     STOPPED,             ///< Adaptor has been stopped.
487   };
488
489   typedef std::vector<LifeCycleObserver*>  ObserverContainer;
490
491 private: // Data
492
493   AdaptorSignalType                       mResizedSignal;             ///< Resized signal.
494   AdaptorSignalType                       mLanguageChangedSignal;     ///< Language changed signal.
495
496   Dali::Adaptor&                        mAdaptor;                     ///< Reference to public adaptor instance.
497   State                                 mState;                       ///< Current state of the adaptor
498   Dali::Integration::Core*              mCore;                        ///< Dali Core
499   UpdateRenderController*               mUpdateRenderController;      ///< Controls update/render threads
500   VSyncMonitor*                         mVSyncMonitor;                ///< Monitors VSync events
501   GlImplementation*                     mGLES;                        ///< GL implementation
502   GlSyncImplementation*                 mGlSync;                      ///< GL Sync implementation
503   EglFactory*                           mEglFactory;                  ///< EGL Factory
504
505   RenderSurface*                        mSurface;                     ///< Current surface
506   TizenPlatform::TizenPlatformAbstraction*  mPlatformAbstraction;         ///< Platform abstraction
507
508   EventHandler*                         mEventHandler;                ///< event handler
509   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
510   bool                                  mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
511   TriggerEvent*                         mNotificationTrigger;         ///< Notification event trigger
512   GestureManager*                       mGestureManager;              ///< Gesture manager
513   size_t                                mHDpi;                        ///< Override horizontal DPI
514   size_t                                mVDpi;                        ///< Override vertical DPI
515   FeedbackPluginProxy*                  mDaliFeedbackPlugin;          ///< Used to access feedback support
516   FeedbackController*                   mFeedbackController;          ///< Plays feedback effects for Dali-Toolkit UI Controls.
517   Dali::TtsPlayer                       mTtsPlayers[Dali::TtsPlayer::MODE_NUM];                   ///< Provides TTS support
518   ObserverContainer                     mObservers;                   ///< A list of adaptor observer pointers
519   DragAndDropDetectorPtr                mDragAndDropDetector;         ///< The Drag & Drop detector
520   RotationObserver*                     mDeferredRotationObserver;    ///< deferred Rotation observer needs event handler
521   DeviceLayout                          mBaseLayout;                  ///< The base layout of the application
522   EnvironmentOptions                    mEnvironmentOptions;          ///< environment options
523   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
524   KernelTrace                           mKernelTracer;                ///< Kernel tracer
525   TriggerEventFactory                   mTriggerEventFactory;         ///< Trigger event factory
526   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
527 public:
528   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
529 };
530
531 } // namespace Internal
532
533 } // namespace Adaptor
534
535 } // namespace Dali
536
537 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__