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