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