Merge "Remove unused set/get available orientations that uses vector-wrapper (which...
[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 <clipboard.h>
34
35 #include <tizen-platform-abstraction.h>
36 #include <base/interfaces/adaptor-internal-services.h>
37 #include <base/environment-options.h>
38 #include <base/core-event-interface.h>
39 #include <drag-and-drop-detector-impl.h>
40 #include <damage-observer.h>
41 #include <window-visibility-observer.h>
42 #include <kernel-trace.h>
43 #include <system-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]  configuration The context loss configuration ( to choose resource discard policy )
99    */
100   static Dali::Adaptor* New( Any nativeWindow,
101                              RenderSurface* surface,
102                              Dali::Configuration::ContextLoss configuration );
103
104   /**
105    * 2-step initialisation, this should be called after creating an adaptor instance.
106    */
107   void Initialize(Dali::Configuration::ContextLoss configuration);
108
109   /**
110    * Virtual destructor.
111    */
112   virtual ~Adaptor();
113
114   /**
115    * @copydoc Dali::Adaptor::Get()
116    */
117   static Dali::Adaptor& Get();
118
119   /**
120    * @copydoc Dali::Adaptor::IsAvailable()
121    */
122   static bool IsAvailable();
123
124 public: // AdaptorInternalServices implementation
125   /**
126    * @copydoc Dali::Adaptor::Start()
127    */
128   virtual void Start();
129
130   /**
131    * @copydoc Dali::Adaptor::Pause()
132    */
133   virtual void Pause();
134
135   /**
136    * @copydoc Dali::Adaptor::Resume()
137    */
138   virtual void Resume();
139
140   /**
141    * @copydoc Dali::Adaptor::Stop()
142    */
143   virtual void Stop();
144
145   /**
146    * @copydoc Dali::EventFeeder::FeedTouchPoint()
147    */
148   virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
149
150   /**
151    * @copydoc Dali::EventFeeder::FeedWheelEvent()
152    */
153   virtual void FeedWheelEvent( MouseWheelEvent& wheelEvent );
154
155   /**
156    * @copydoc Dali::EventFeeder::FeedKeyEvent()
157    */
158   virtual void FeedKeyEvent( KeyEvent& keyEvent );
159
160   /**
161    * @copydoc AdaptorInterface::MoveResize()
162    */
163   virtual bool MoveResize( const PositionSize& positionSize );
164
165   /**
166    * @copydoc AdaptorInterface::SurfaceResized()
167    */
168   virtual void SurfaceResized( const PositionSize& positionSize );
169
170   /**
171    * @copydoc AdaptorInterface::ReplaceSurface()
172    */
173   virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
174
175   /**
176    * @copydoc Dali::Adaptor::GetSurface()
177    */
178   virtual RenderSurface& GetSurface() const;
179
180   /**
181    * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
182    */
183   virtual void ReleaseSurfaceLock();
184
185   /**
186    * Retrieve the TtsPlayer.
187    * @param[in] mode The mode of TtsPlayer
188    * @return A handle to the TtsPlayer.
189    */
190   virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
191
192   /**
193    * @copydoc Dali::Adaptor::AddIdle()
194    */
195   virtual bool AddIdle( CallbackBase* callback );
196
197   /**
198    * @copydoc Internal::Framework::CallFromMainLoop()
199    */
200   virtual bool CallFromMainLoop( CallbackBase* callback );
201
202 public:
203
204   /**
205    * @return the Core instance
206    */
207   virtual Dali::Integration::Core& GetCore();
208
209   /**
210    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
211    */
212   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
213
214   /**
215    * @copydoc Dali::Adaptor::SetUseHardwareVSync()
216    */
217   void SetUseHardwareVSync(bool useHardware);
218
219   /**
220    * @return reference to EglFactory class
221    */
222   EglFactory& GetEGLFactory() const;
223
224   /**
225    * Return GlAbstraction.
226    * @return the GlAbstraction.
227    */
228   Integration::GlAbstraction& GetGlAbstraction() const;
229
230   /**
231    * Return the PlatformAbstraction.
232    * @return The PlatformAbstraction.
233    */
234   Integration::PlatformAbstraction& GetPlatformAbstraction() const;
235
236   /**
237    * Sets the Drag & Drop Listener.
238    * @param[in] detector The detector to send Drag & Drop events to.
239    */
240   void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
241
242   /**
243    * Sets a rotation observer, or set to NULL to remove.
244    * @pre Adaptor::Start() has been called ( to create EventHandler )
245    * @param[in] observer The observer to listen for window rotation events
246    */
247   void SetRotationObserver( RotationObserver* observer );
248
249   /**
250    * Destroy the TtsPlayer of sepcific mode.
251    * @param[in] mode The mode of TtsPlayer to destroy
252    */
253   void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
254
255   /**
256    * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
257    * trigger a pinch gesture
258    *
259    * @param[in] distance The minimum pinch distance in pixels
260    */
261   void SetMinimumPinchDistance(float distance);
262
263   /**
264    * Gets native window handle
265    *
266    * @return native window handle
267    */
268   Any GetNativeWindowHandle();
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 TraceInterface& GetKernelTraceInterface();
352
353   /**
354    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
355    */
356   virtual TraceInterface& GetSystemTraceInterface();
357
358 public: // Stereoscopy
359
360   /**
361    * @copydoc Dali::Integration::Core::SetViewMode()
362    */
363   void SetViewMode( ViewMode viewMode );
364
365   /**
366    * @copydoc Dali::Integration::Core::GetViewMode()
367    */
368   ViewMode GetViewMode() const;
369
370   /**
371    * @copydoc Dali::Integration::Core::SetStereoBase()
372    */
373   void SetStereoBase( float stereoBase );
374
375   /**
376    * @copydoc Dali::Integration::Core::GetStereoBase()
377    */
378   float GetStereoBase() const;
379
380 public: // Signals
381
382   /**
383    * @copydoc Dali::Adaptor::SignalResized
384    */
385   AdaptorSignalType& ResizedSignal()
386   {
387     return mResizedSignal;
388   }
389
390   /**
391    * @copydoc Dali::Adaptor::LanguageChangedSignal
392    */
393   AdaptorSignalType& LanguageChangedSignal()
394   {
395     return mLanguageChangedSignal;
396   }
397
398 private: // From Dali::Internal::Adaptor::CoreEventInterface
399
400   /**
401    * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
402    */
403   virtual void QueueCoreEvent(const Dali::Integration::Event& event);
404
405   /**
406    * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
407    */
408   virtual void ProcessCoreEvents();
409
410 private: // From Dali::Integration::RenderController
411
412   /**
413    * Called by the Dali core when it requires another update
414    */
415   virtual void RequestUpdate();
416
417   /**
418    * Called by Dali core when it requires an notification event being sent on idle.
419    * Multi-threading note: this method must be called from the main thread only.
420    */
421   virtual void RequestProcessEventsOnIdle();
422
423 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
424
425   /**
426    * Called when the window becomes fully or partially visible.
427    */
428   virtual void OnWindowShown();
429
430   /**
431    * Called when the window is fully hidden.
432    */
433   virtual void OnWindowHidden();
434
435 private: // From Dali::Internal::Adaptor::DamageObserver
436
437   /**
438    * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
439    */
440   void OnDamaged( const DamageArea& area );
441
442 private:
443
444   // Undefined
445   Adaptor(const Adaptor&);
446   Adaptor& operator=(Adaptor&);
447
448 private:
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(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]  nativeWindow native window handle
477    * @param[in]  adaptor      The public adaptor
478    * @param[in]  surface      A render surface can be one of the following
479    *                          - Pixmap, adaptor will use existing Pixmap to draw on to
480    *                          - Window, adaptor will use existing Window to draw on to
481    */
482   Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface );
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   Any                                   mNativeWindow;                ///< window identifier
512   RenderSurface*                        mSurface;                     ///< Current surface
513   TizenPlatform::TizenPlatformAbstraction*  mPlatformAbstraction;         ///< Platform abstraction
514
515   EventHandler*                         mEventHandler;                ///< event handler
516   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
517   bool                                  mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
518   TriggerEvent*                         mNotificationTrigger;         ///< Notification event trigger
519   GestureManager*                       mGestureManager;              ///< Gesture manager
520   FeedbackPluginProxy*                  mDaliFeedbackPlugin;          ///< Used to access feedback support
521   FeedbackController*                   mFeedbackController;          ///< Plays feedback effects for Dali-Toolkit UI Controls.
522   Dali::TtsPlayer                       mTtsPlayers[Dali::TtsPlayer::MODE_NUM];                   ///< Provides TTS support
523   ObserverContainer                     mObservers;                   ///< A list of adaptor observer pointers
524   DragAndDropDetectorPtr                mDragAndDropDetector;         ///< The Drag & Drop detector
525   RotationObserver*                     mDeferredRotationObserver;    ///< deferred Rotation observer needs event handler
526   EnvironmentOptions                    mEnvironmentOptions;          ///< environment options
527   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
528   KernelTrace                           mKernelTracer;                ///< Kernel tracer
529   SystemTrace                           mSystemTracer;                ///< System tracer
530   TriggerEventFactory                   mTriggerEventFactory;         ///< Trigger event factory
531   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
532   SocketFactory                         mSocketFactory;               ///< Socket factory
533 public:
534   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
535 };
536
537 } // namespace Internal
538
539 } // namespace Adaptor
540
541 } // namespace Dali
542
543 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__