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