c343cc5ea82fe55878799838a40afe01eb48d82a
[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) 2017 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/public-api/math/uint-16-pair.h>
27 #include <dali/integration-api/render-controller.h>
28
29 // INTERNAL INCLUDES
30 #include <window.h>
31 #include <adaptor.h>
32 #include <render-surface.h>
33 #include <tts-player.h>
34 #include <imf-manager.h>
35 #include <clipboard.h>
36
37 #include <tizen-platform-abstraction.h>
38 #include <base/interfaces/adaptor-internal-services.h>
39 #include <base/environment-options.h>
40 #include <base/core-event-interface.h>
41 #include <drag-and-drop-detector-impl.h>
42 #include <damage-observer.h>
43 #include <window-visibility-observer.h>
44 #include <kernel-trace.h>
45 #include <system-trace.h>
46 #include <trigger-event-factory.h>
47 #include <networking/socket-factory.h>
48
49 namespace Dali
50 {
51
52 class RenderSurface;
53 class Window;
54
55 namespace Integration
56 {
57 class Core;
58 class GlAbstraction;
59 }
60
61 namespace Internal
62 {
63
64 namespace Adaptor
65 {
66 class EventHandler;
67 class EglFactory;
68 class GestureManager;
69 class GlImplementation;
70 class GlSyncImplementation;
71 class ThreadController;
72 class TriggerEvent;
73 class CallbackManager;
74 class FeedbackPluginProxy;
75 class FeedbackController;
76 class RotationObserver;
77 class VSyncMonitor;
78 class PerformanceInterface;
79 class LifeCycleObserver;
80 class ObjectProfiler;
81
82 /**
83  * Implementation of the Adaptor class.
84  */
85 class Adaptor : public Integration::RenderController,
86                 public AdaptorInternalServices,
87                 public CoreEventInterface,
88                 public DamageObserver,
89                 public WindowVisibilityObserver
90 {
91 public:
92
93   typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
94
95   typedef Uint16Pair SurfaceSize;          ///< Surface size type
96
97   /**
98    * Creates a New Adaptor
99    * @param[in]  nativeWindow        Native window handle
100    * @param[in]  surface             A render surface can be one of the following
101    *                                  - Pixmap, adaptor will use existing Pixmap to draw on to
102    *                                  - Window, adaptor will use existing Window to draw on to
103    * @param[in]  configuration       The context loss configuration ( to choose resource discard policy )
104    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
105    */
106   static Dali::Adaptor* New( Any nativeWindow,
107                              RenderSurface* surface,
108                              Dali::Configuration::ContextLoss configuration,
109                              EnvironmentOptions* environmentOptions );
110
111   /**
112    * Creates a New Adaptor
113    * @param[in]  nativeWindow        native window handle
114    * @param[in]  configuration       The context loss configuration ( to choose resource discard policy )
115    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
116    */
117   static Dali::Adaptor* New( Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions );
118
119   /**
120    * 2-step initialisation, this should be called after creating an adaptor instance.
121    */
122   void Initialize(Dali::Configuration::ContextLoss configuration);
123
124   /**
125    * Virtual destructor.
126    */
127   virtual ~Adaptor();
128
129   /**
130    * @copydoc Dali::Adaptor::Get()
131    */
132   static Dali::Adaptor& Get();
133
134   /**
135    * @copydoc Dali::Adaptor::IsAvailable()
136    */
137   static bool IsAvailable();
138
139   /**
140    * @copydoc Dali::Core::SceneCreated();
141    */
142   void SceneCreated();
143
144 public: // AdaptorInternalServices implementation
145   /**
146    * @copydoc Dali::Adaptor::Start()
147    */
148   virtual void Start();
149
150   /**
151    * @copydoc Dali::Adaptor::Pause()
152    */
153   virtual void Pause();
154
155   /**
156    * @copydoc Dali::Adaptor::Resume()
157    */
158   virtual void Resume();
159
160   /**
161    * @copydoc Dali::Adaptor::Stop()
162    */
163   virtual void Stop();
164
165   /**
166    * @copydoc Dali::Adaptor::ContextLost()
167    */
168   virtual void ContextLost();
169
170   /**
171    * @copydoc Dali::Adaptor::ContextRegained()
172    */
173   virtual void ContextRegained();
174
175   /**
176    * @copydoc Dali::EventFeeder::FeedTouchPoint()
177    */
178   virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
179
180   /**
181    * @copydoc Dali::EventFeeder::FeedWheelEvent()
182    */
183   virtual void FeedWheelEvent( WheelEvent& wheelEvent );
184
185   /**
186    * @copydoc Dali::EventFeeder::FeedKeyEvent()
187    */
188   virtual void FeedKeyEvent( KeyEvent& keyEvent );
189
190   /**
191    * @copydoc AdaptorInterface::ReplaceSurface()
192    */
193   virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
194
195   /**
196    * @copydoc Dali::Adaptor::GetSurface()
197    */
198   virtual RenderSurface& GetSurface() const;
199
200   /**
201    * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
202    */
203   virtual void ReleaseSurfaceLock();
204
205   /**
206    * Retrieve the TtsPlayer.
207    * @param[in] mode The mode of TtsPlayer
208    * @return A handle to the TtsPlayer.
209    */
210   virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
211
212   /**
213    * @copydoc Dali::Adaptor::AddIdle()
214    */
215   virtual bool AddIdle( CallbackBase* callback, bool forceAdd );
216
217   /**
218    * @copydoc Dali::Adaptor::RemoveIdle()
219    */
220   virtual void RemoveIdle( CallbackBase* callback );
221
222 public:
223
224   /**
225    * @return the Core instance
226    */
227   virtual Dali::Integration::Core& GetCore();
228
229   /**
230    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
231    */
232   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
233
234   /**
235    * @copydoc Dali::Adaptor::SetUseHardwareVSync()
236    */
237   void SetUseHardwareVSync(bool useHardware);
238
239   /**
240    * @return reference to EglFactory class
241    */
242   EglFactory& GetEGLFactory() const;
243
244   /**
245    * Return GlAbstraction.
246    * @return the GlAbstraction.
247    */
248   Integration::GlAbstraction& GetGlAbstraction() const;
249
250   /**
251    * Return the PlatformAbstraction.
252    * @return The PlatformAbstraction.
253    */
254   Integration::PlatformAbstraction& GetPlatformAbstraction() const;
255
256   /**
257    * Sets the Drag & Drop Listener.
258    * @param[in] detector The detector to send Drag & Drop events to.
259    */
260   void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
261
262   /**
263    * Sets a rotation observer, or set to NULL to remove.
264    * @pre Adaptor::Start() has been called ( to create EventHandler )
265    * @param[in] observer The observer to listen for window rotation events
266    */
267   void SetRotationObserver( RotationObserver* observer );
268
269   /**
270    * Destroy the TtsPlayer of sepcific mode.
271    * @param[in] mode The mode of TtsPlayer to destroy
272    */
273   void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
274
275   /**
276    * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
277    * trigger a pinch gesture
278    *
279    * @param[in] distance The minimum pinch distance in pixels
280    */
281   void SetMinimumPinchDistance(float distance);
282
283   /**
284    * Gets native window handle
285    *
286    * @return native window handle
287    */
288   Any GetNativeWindowHandle();
289
290   /**
291    * Sets use remote surface for eglSurface output
292    * @param[in] useRemoteSurface True if the remote surface is used
293    */
294   void SetUseRemoteSurface(bool useRemoteSurface);
295
296 public:
297
298   /**
299    * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
300    * @param[in]  observer  The observer.
301    * @note Observers should remove themselves when they are destroyed.
302    */
303   void AddObserver( LifeCycleObserver& observer );
304
305   /**
306    * Removes the observer from the adaptor.
307    * @param[in]  observer  The observer to remove.
308    * @note Observers should remove themselves when they are destroyed.
309    */
310   void RemoveObserver( LifeCycleObserver& observer );
311
312   /**
313    * Emits the Notification event to the Dali core.
314    */
315   void SendNotificationEvent();
316
317   /**
318    * Request adaptor to update once
319    */
320   void RequestUpdateOnce();
321
322   /**
323    * Request adaptor to update indicator's height
324    */
325   void IndicatorSizeChanged(int height);
326
327   /**
328    * @copydoc Dali::Adaptor::NotifySceneCreated()
329    */
330   void NotifySceneCreated();
331
332   /**
333    * @copydoc Dali::Adaptor::NotifyLanguageChanged()
334    */
335   void NotifyLanguageChanged();
336
337   /**
338    * Gets AppId of current application
339    */
340   void GetAppId( std::string& appId );
341
342   /**
343    * Informs core the surface size has changed
344    */
345   void SurfaceResizePrepare( SurfaceSize surfaceSize );
346
347   /**
348    * Informs ThreadController the surface size has changed
349    */
350   void SurfaceResizeComplete( SurfaceSize surfaceSize );
351
352   /**
353    * Sets layout direction of root by system language
354    * @param[in] locale System locale
355    */
356   void SetRootLayoutDirection( std::string locale );
357
358   /**
359    * @copydoc Dali::Adaptor::RenderOnce
360    */
361   void RenderOnce();
362
363 public:  //AdaptorInternalServices
364
365   /**
366    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
367    */
368   virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
369
370   /**
371    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
372    */
373   virtual Dali::Integration::GlAbstraction& GetGlesInterface();
374
375   /**
376   * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
377   */
378   virtual EglFactoryInterface& GetEGLFactoryInterface() const;
379
380   /**
381    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
382    */
383   virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
384
385   /**
386    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
387    */
388   virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
389
390   /**
391    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
392    */
393   virtual SocketFactoryInterface& GetSocketFactoryInterface();
394
395   /**
396    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
397    */
398   virtual RenderSurface* GetRenderSurfaceInterface();
399
400   /**
401    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
402    */
403   virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
404
405   /**
406    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
407    */
408   virtual PerformanceInterface* GetPerformanceInterface();
409
410   /**
411    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
412    */
413   virtual TraceInterface& GetKernelTraceInterface();
414
415   /**
416    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
417    */
418   virtual TraceInterface& GetSystemTraceInterface();
419
420 public: // Stereoscopy
421
422   /**
423    * @copydoc Dali::Integration::Core::SetViewMode()
424    */
425   void SetViewMode( ViewMode viewMode );
426
427   /**
428    * @copydoc Dali::Integration::Core::GetViewMode()
429    */
430   ViewMode GetViewMode() const;
431
432   /**
433    * @copydoc Dali::Integration::Core::SetStereoBase()
434    */
435   void SetStereoBase( float stereoBase );
436
437   /**
438    * @copydoc Dali::Integration::Core::GetStereoBase()
439    */
440   float GetStereoBase() const;
441
442   /**
443    * Set Window handle.
444    */
445   void SetWindow( Dali::Window window );
446
447   /**
448    * Return Window handle.
449    */
450   Dali::Window GetWindow();
451
452 public: // Signals
453
454   /**
455    * @copydoc Dali::Adaptor::SignalResized
456    */
457   AdaptorSignalType& ResizedSignal()
458   {
459     return mResizedSignal;
460   }
461
462   /**
463    * @copydoc Dali::Adaptor::LanguageChangedSignal
464    */
465   AdaptorSignalType& LanguageChangedSignal()
466   {
467     return mLanguageChangedSignal;
468   }
469
470 private: // From Dali::Internal::Adaptor::CoreEventInterface
471
472   /**
473    * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
474    */
475   virtual void QueueCoreEvent(const Dali::Integration::Event& event);
476
477   /**
478    * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
479    */
480   virtual void ProcessCoreEvents();
481
482 private: // From Dali::Integration::RenderController
483
484   /**
485    * @copydoc Dali::Integration::RenderController::RequestUpdate()
486    */
487   virtual void RequestUpdate( bool forceUpdate );
488
489   /**
490    * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
491    */
492   virtual void RequestProcessEventsOnIdle( bool forceProcess );
493
494 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
495
496   /**
497    * Called when the window becomes fully or partially visible.
498    */
499   virtual void OnWindowShown();
500
501   /**
502    * Called when the window is fully hidden.
503    */
504   virtual void OnWindowHidden();
505
506 private: // From Dali::Internal::Adaptor::DamageObserver
507
508   /**
509    * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
510    */
511   void OnDamaged( const DamageArea& area );
512
513 private:
514
515   // Undefined
516   Adaptor(const Adaptor&);
517   Adaptor& operator=(Adaptor&);
518
519 private:
520
521   /**
522    * Assigns the render surface to the adaptor
523    *
524    */
525   void SetSurface(RenderSurface *surface);
526
527   /**
528    * called after surface is created
529    */
530   void SurfaceInitialized();
531
532   /**
533    * Sends an notification message from main loop idle handler
534    */
535   void ProcessCoreEventsFromIdle();
536
537   /**
538    * Gets path for data/resource storage.
539    * @param[out] path Path for data/resource storage
540    */
541   void GetDataStoragePath(std::string& path);
542
543   /**
544    * Sets up system information if needs
545    */
546   void SetupSystemInformation();
547
548 private:
549
550   /**
551    * Constructor
552    * @param[in]  nativeWindow native window handle
553    * @param[in]  adaptor      The public adaptor
554    * @param[in]  surface      A render surface can be one of the following
555    *                          - Pixmap, adaptor will use existing Pixmap to draw on to
556    *                          - Window, adaptor will use existing Window to draw on to
557    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
558    */
559   Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions );
560
561 private: // Types
562
563   enum State
564   {
565     READY,               ///< Initial state before Adaptor::Start is called.
566     RUNNING,             ///< Adaptor is running.
567     PAUSED,              ///< Adaptor has been paused.
568     PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
569     STOPPED,             ///< Adaptor has been stopped.
570   };
571
572   typedef std::vector<LifeCycleObserver*>  ObserverContainer;
573
574 private: // Data
575
576   AdaptorSignalType                     mResizedSignal;               ///< Resized signal.
577   AdaptorSignalType                     mLanguageChangedSignal;       ///< Language changed signal.
578
579   Dali::Adaptor&                        mAdaptor;                     ///< Reference to public adaptor instance.
580   State                                 mState;                       ///< Current state of the adaptor
581   Dali::Integration::Core*              mCore;                        ///< Dali Core
582   ThreadController*                     mThreadController;            ///< Controls the threads
583   VSyncMonitor*                         mVSyncMonitor;                ///< Monitors VSync events
584   GlImplementation*                     mGLES;                        ///< GL implementation
585   GlSyncImplementation*                 mGlSync;                      ///< GL Sync implementation
586   EglFactory*                           mEglFactory;                  ///< EGL Factory
587
588   Any                                   mNativeWindow;                ///< window identifier
589   RenderSurface*                        mSurface;                     ///< Current surface
590   TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction;      ///< Platform abstraction
591
592   EventHandler*                         mEventHandler;                ///< event handler
593   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
594   bool                                  mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
595   TriggerEventInterface*                mNotificationTrigger;         ///< Notification event trigger
596   GestureManager*                       mGestureManager;              ///< Gesture manager
597   FeedbackPluginProxy*                  mDaliFeedbackPlugin;          ///< Used to access feedback support
598   FeedbackController*                   mFeedbackController;          ///< Plays feedback effects for Dali-Toolkit UI Controls.
599   Dali::TtsPlayer                       mTtsPlayers[Dali::TtsPlayer::MODE_NUM];                   ///< Provides TTS support
600   ObserverContainer                     mObservers;                   ///< A list of adaptor observer pointers
601   DragAndDropDetectorPtr                mDragAndDropDetector;         ///< The Drag & Drop detector
602   RotationObserver*                     mDeferredRotationObserver;    ///< deferred Rotation observer needs event handler
603   EnvironmentOptions*                   mEnvironmentOptions;          ///< environment options
604   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
605   KernelTrace                           mKernelTracer;                ///< Kernel tracer
606   SystemTrace                           mSystemTracer;                ///< System tracer
607   TriggerEventFactory                   mTriggerEventFactory;         ///< Trigger event factory
608   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
609   SocketFactory                         mSocketFactory;               ///< Socket factory
610   Dali::Window                          mWindow;                      ///< Window handle
611   const bool                            mEnvironmentOptionsOwned:1;   ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
612   bool                                  mUseRemoteSurface;            ///< whether the remoteSurface is used or not
613 public:
614   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
615 };
616
617 } // namespace Internal
618
619 } // namespace Adaptor
620
621 } // namespace Dali
622
623 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__