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