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