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