9b61083bc45cfaf143e0c3b9923e3e6b5ea01190
[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/integration-api/scene.h>
32 #include <dali/public-api/adaptor-framework/tts-player.h>
33 #include <dali/devel-api/adaptor-framework/clipboard.h>
34
35 #include <dali/internal/graphics/common/graphics-interface.h>
36
37 #include <dali/internal/legacy/common/tizen-platform-abstraction.h>
38 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
39 #include <dali/internal/system/common/environment-options.h>
40 #include <dali/internal/system/common/core-event-interface.h>
41 #include <dali/internal/input/common/drag-and-drop-detector-impl.h>
42 #include <dali/internal/window-system/common/damage-observer.h>
43 #include <dali/internal/window-system/common/window-impl.h>
44 #include <dali/internal/window-system/common/window-visibility-observer.h>
45 #include <dali/internal/system/common/kernel-trace.h>
46 #include <dali/internal/system/common/system-trace.h>
47 #include <dali/integration-api/trigger-event-factory.h>
48 #include <dali/internal/network/common/socket-factory.h>
49
50
51 namespace Dali
52 {
53
54 class RenderSurfaceInterface;
55 class Window;
56
57 namespace Integration
58 {
59 class Core;
60 class GlAbstraction;
61 class Processor;
62 }
63
64 namespace Internal
65 {
66
67 namespace Adaptor
68 {
69 class DisplayConnection;
70 class GraphicsFactory;
71 class GestureManager;
72 class GlImplementation;
73 class GlSyncImplementation;
74 class ThreadController;
75 class TriggerEvent;
76 class CallbackManager;
77 class FeedbackPluginProxy;
78 class FeedbackController;
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]  window              The 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( Dali::Window window,
109                              Dali::RenderSurfaceInterface* surface,
110                              Dali::Configuration::ContextLoss configuration,
111                              EnvironmentOptions* environmentOptions );
112
113   /**
114    * Creates a New Adaptor
115    * @param[in]  window              The 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]  window              The 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                              Dali::Window window,
135                              Dali::RenderSurfaceInterface* 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]  window              The 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( Dali::Window window, Dali::RenderSurfaceInterface& surface );
228
229   /**
230    * @copydoc Dali::Adaptor::GetSurface()
231    */
232   virtual Dali::RenderSurfaceInterface& 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   /**
287    * Removes an existing Window instance from the Adaptor
288    * @param[in]  childWindow The Window instance
289    */
290   bool RemoveWindow( Dali::Internal::Adaptor::Window* childWindow );
291
292 public:
293
294   /**
295    * @return the Core instance
296    */
297   virtual Dali::Integration::Core& GetCore();
298
299   /**
300    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
301    */
302   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
303
304   /**
305    * @copydoc Dali::Adaptor::SetUseHardwareVSync()
306    */
307   void SetUseHardwareVSync(bool useHardware);
308
309   /**
310    * Return the PlatformAbstraction.
311    * @return The PlatformAbstraction.
312    */
313   Integration::PlatformAbstraction& GetPlatformAbstraction() const;
314
315   /**
316    * Sets the Drag & Drop Listener.
317    * @param[in] detector The detector to send Drag & Drop events to.
318    */
319   void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
320
321   /**
322    * Destroy the TtsPlayer of specific mode.
323    * @param[in] mode The mode of TtsPlayer to destroy
324    */
325   void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
326
327   /**
328    * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
329    * trigger a pinch gesture
330    *
331    * @param[in] distance The minimum pinch distance in pixels
332    */
333   void SetMinimumPinchDistance(float distance);
334
335   /**
336    * Gets native window handle
337    *
338    * @return native window handle
339    */
340   Any GetNativeWindowHandle();
341
342   /**
343    * Get the native display associated with the graphics backend
344    *
345    * @return A handle to the native display
346    */
347   Any GetGraphicsDisplay();
348
349   /**
350    * Sets use remote surface for Surface output
351    * @param[in] useRemoteSurface True if the remote surface is used
352    */
353   void SetUseRemoteSurface(bool useRemoteSurface);
354
355 public:
356
357   /**
358    * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
359    * @param[in]  observer  The observer.
360    * @note Observers should remove themselves when they are destroyed.
361    */
362   void AddObserver( LifeCycleObserver& observer );
363
364   /**
365    * Removes the observer from the adaptor.
366    * @param[in]  observer  The observer to remove.
367    * @note Observers should remove themselves when they are destroyed.
368    */
369   void RemoveObserver( LifeCycleObserver& observer );
370
371   /**
372    * Emits the Notification event to the Dali core.
373    */
374   void SendNotificationEvent();
375
376   /**
377    * Request adaptor to update once
378    */
379   void RequestUpdateOnce();
380
381   /**
382    * @copydoc Dali::Adaptor::NotifySceneCreated()
383    */
384   void NotifySceneCreated();
385
386   /**
387    * @copydoc Dali::Adaptor::NotifyLanguageChanged()
388    */
389   void NotifyLanguageChanged();
390
391   /**
392    * Gets AppId of current application
393    */
394   void GetAppId( std::string& appId );
395
396   /**
397    * Informs core the surface size has changed
398    */
399   void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
400
401   /**
402    * Informs ThreadController the surface size has changed
403    */
404   void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
405
406   /**
407    * Sets layout direction of root by system language
408    * @param[in] locale System locale
409    */
410   void SetRootLayoutDirection( std::string locale );
411
412   /**
413    * @copydoc Dali::Adaptor::RenderOnce
414    */
415   void RenderOnce();
416
417   /**
418    * @copydoc Dali::Adaptor::GetLogFactory
419    */
420   const LogFactoryInterface& GetLogFactory();
421
422   /**
423    * @copydoc Dali::Adaptor::RegisterProcessor
424    */
425   void RegisterProcessor( Integration::Processor& processor );
426
427   /**
428    * @coydoc Dali::Adaptor::UnregisterProcessor
429    */
430   void UnregisterProcessor( Integration::Processor& processor );
431
432 public:  //AdaptorInternalServices
433
434   /**
435    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
436    */
437   virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
438
439   /**
440    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
441    */
442   virtual Dali::DisplayConnection& GetDisplayConnectionInterface();
443
444   /**
445    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
446    */
447   virtual GraphicsInterface& GetGraphicsInterface();
448
449   /**
450    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
451    */
452   virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
453
454   /**
455    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
456    */
457   virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
458
459   /**
460    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
461    */
462   virtual SocketFactoryInterface& GetSocketFactoryInterface();
463
464   /**
465    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
466    */
467   virtual Dali::RenderSurfaceInterface* GetRenderSurfaceInterface();
468
469   /**
470    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
471    */
472   virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
473
474   /**
475    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
476    */
477   virtual PerformanceInterface* GetPerformanceInterface();
478
479   /**
480    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
481    */
482   virtual TraceInterface& GetKernelTraceInterface();
483
484   /**
485    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
486    */
487   virtual TraceInterface& GetSystemTraceInterface();
488
489 public: // Signals
490
491   /**
492    * @copydoc Dali::Adaptor::SignalResized
493    */
494   AdaptorSignalType& ResizedSignal()
495   {
496     return mResizedSignal;
497   }
498
499   /**
500    * @copydoc Dali::Adaptor::LanguageChangedSignal
501    */
502   AdaptorSignalType& LanguageChangedSignal()
503   {
504     return mLanguageChangedSignal;
505   }
506
507   /**
508    * Gets the gesture manager.
509    * @return The GestureManager
510    */
511   GestureManager* GetGestureManager() const
512   {
513     return mGestureManager;
514   }
515
516 private: // From Dali::Internal::Adaptor::CoreEventInterface
517
518   /**
519    * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
520    */
521   virtual void QueueCoreEvent(const Dali::Integration::Event& event);
522
523   /**
524    * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
525    */
526   virtual void ProcessCoreEvents();
527
528 private: // From Dali::Integration::RenderController
529
530   /**
531    * @copydoc Dali::Integration::RenderController::RequestUpdate()
532    */
533   virtual void RequestUpdate( bool forceUpdate );
534
535   /**
536    * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
537    */
538   virtual void RequestProcessEventsOnIdle( bool forceProcess );
539
540 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
541
542   /**
543    * Called when the window becomes fully or partially visible.
544    */
545   virtual void OnWindowShown();
546
547   /**
548    * Called when the window is fully hidden.
549    */
550   virtual void OnWindowHidden();
551
552 private: // From Dali::Internal::Adaptor::DamageObserver
553
554   /**
555    * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
556    */
557   void OnDamaged( const DamageArea& area );
558
559 private:
560
561   // Undefined
562   Adaptor(const Adaptor&) = delete;
563   Adaptor& operator=(Adaptor&) = delete;
564
565 private:
566
567   /**
568    * Assigns the render surface to the adaptor
569    *
570    */
571   void SetSurface(Dali::RenderSurfaceInterface *surface);
572
573   /**
574    * called after surface is created
575    */
576   void SurfaceInitialized();
577
578   /**
579    * Sends an notification message from main loop idle handler
580    */
581   bool ProcessCoreEventsFromIdle();
582
583   /**
584    * Gets path for data/resource storage.
585    * @param[out] path Path for data/resource storage
586    */
587   void GetDataStoragePath(std::string& path);
588
589   /**
590    * Sets up system information if needs
591    */
592   void SetupSystemInformation();
593
594   /**
595    * Adds a callback to be run when entering an idle state.
596    *
597    * A callback of the following type should be used:
598    * @code
599    *   bool MyFunction();
600    * @endcode
601    * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
602    */
603   bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
604
605   /**
606    * Removes a previously added the idle enterer callback.
607    */
608   void RemoveIdleEnterer( CallbackBase* callback );
609
610 private:
611
612   /**
613    * Constructor
614    * @param[in]  window       window handle
615    * @param[in]  adaptor      The public adaptor
616    * @param[in]  surface      A render surface can be one of the following
617    *                          - Pixmap, adaptor will use existing Pixmap to draw on to
618    *                          - Window, adaptor will use existing Window to draw on to
619    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
620    */
621   Adaptor( Dali::Window window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions );
622
623 private: // Types
624
625   enum State
626   {
627     READY,               ///< Initial state before Adaptor::Start is called.
628     RUNNING,             ///< Adaptor is running.
629     PAUSED,              ///< Adaptor has been paused.
630     PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
631     STOPPED,             ///< Adaptor has been stopped.
632   };
633
634   using WindowPtr = IntrusivePtr< Window >;
635   using WindowContainer = std::vector<WindowPtr>;
636   using ObserverContainer = std::vector<LifeCycleObserver*>;
637
638 private: // Data
639
640   AdaptorSignalType                     mResizedSignal;               ///< Resized signal.
641   AdaptorSignalType                     mLanguageChangedSignal;       ///< Language changed signal.
642
643   Dali::Adaptor&                        mAdaptor;                     ///< Reference to public adaptor instance.
644   State                                 mState;                       ///< Current state of the adaptor
645   Dali::Integration::Core*              mCore;                        ///< Dali Core
646   ThreadController*                     mThreadController;            ///< Controls the threads
647   VSyncMonitor*                         mVSyncMonitor;                ///< Monitors VSync events
648
649   GraphicsInterface*                    mGraphics;                    ///< Graphics interface
650   Dali::DisplayConnection*              mDisplayConnection;           ///< Display connection
651   WindowContainer                       mWindows;                     ///< A container of all the Windows that are currently created
652
653   TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction;      ///< Platform abstraction
654
655   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
656   bool                                  mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
657   TriggerEventInterface*                mNotificationTrigger;         ///< Notification event trigger
658   GestureManager*                       mGestureManager;              ///< Gesture manager
659   FeedbackPluginProxy*                  mDaliFeedbackPlugin;          ///< Used to access feedback support
660   FeedbackController*                   mFeedbackController;          ///< Plays feedback effects for Dali-Toolkit UI Controls.
661   Dali::TtsPlayer                       mTtsPlayers[Dali::TtsPlayer::MODE_NUM];                   ///< Provides TTS support
662   ObserverContainer                     mObservers;                   ///< A list of adaptor observer pointers
663   DragAndDropDetectorPtr                mDragAndDropDetector;         ///< The Drag & Drop detector
664   EnvironmentOptions*                   mEnvironmentOptions;          ///< environment options
665   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
666   KernelTrace                           mKernelTracer;                ///< Kernel tracer
667   SystemTrace                           mSystemTracer;                ///< System tracer
668   TriggerEventFactory                   mTriggerEventFactory;         ///< Trigger event factory
669   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
670   SocketFactory                         mSocketFactory;               ///< Socket factory
671   const bool                            mEnvironmentOptionsOwned:1;   ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
672   bool                                  mUseRemoteSurface;            ///< whether the remoteSurface is used or not
673
674 public:
675   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
676 };
677
678 } // namespace Internal
679
680 } // namespace Adaptor
681
682 } // namespace Dali
683
684 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H