Revert "[Tizen](ATSPI) squashed implementation"
[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 GlImplementation;
76 class GlSyncImplementation;
77 class ThreadController;
78 class TriggerEvent;
79 class CallbackManager;
80 class FeedbackPluginProxy;
81 class FeedbackController;
82 class VSyncMonitor;
83 class PerformanceInterface;
84 class LifeCycleObserver;
85 class ObjectProfiler;
86 class SceneHolder;
87
88 /**
89  * Implementation of the Adaptor class.
90  */
91 class Adaptor : public Integration::RenderController,
92                 public AdaptorInternalServices,
93                 public CoreEventInterface,
94                 public DamageObserver,
95                 public WindowVisibilityObserver
96 {
97 public:
98
99   using AdaptorSignalType =  Dali::Adaptor::AdaptorSignalType;
100   using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType;
101
102   using SurfaceSize = Uint16Pair;          ///< 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                           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   /**
298    * @brief Deletes the rendering surface
299    * @param[in] surface to delete
300    */
301   void DeleteSurface( Dali::RenderSurfaceInterface& surface );
302
303   /**
304    * @brief Retrieve the window that the given actor is added to.
305    *
306    * @param[in] actor The actor
307    * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
308    */
309   Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
310
311   /**
312    * @copydoc Dali::Adaptor::GetWindows()
313    */
314   Dali::WindowContainer GetWindows() const;
315
316 public:
317
318   /**
319    * @return the Core instance
320    */
321   virtual Dali::Integration::Core& GetCore();
322
323   /**
324    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
325    */
326   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
327
328   /**
329    * Return the PlatformAbstraction.
330    * @return The PlatformAbstraction.
331    */
332   Integration::PlatformAbstraction& GetPlatformAbstraction() const;
333
334   /**
335    * Destroy the TtsPlayer of specific mode.
336    * @param[in] mode The mode of TtsPlayer to destroy
337    */
338   void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
339
340   /**
341    * Gets native window handle
342    *
343    * @return native window handle
344    */
345   Any GetNativeWindowHandle();
346
347   /**
348    * @brief Retrieve native window handle that the given actor is added to.
349    *
350    * @param[in] actor The actor
351    * @return native window handle
352    */
353   Any GetNativeWindowHandle( Dali::Actor actor );
354
355   /**
356    * Get the native display associated with the graphics backend
357    *
358    * @return A handle to the native display
359    */
360   Any GetGraphicsDisplay();
361
362   /**
363    * Sets use remote surface for Surface output
364    * @param[in] useRemoteSurface True if the remote surface is used
365    */
366   void SetUseRemoteSurface(bool useRemoteSurface);
367
368 public:
369
370   /**
371    * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
372    * @param[in]  observer  The observer.
373    * @note Observers should remove themselves when they are destroyed.
374    */
375   void AddObserver( LifeCycleObserver& observer );
376
377   /**
378    * Removes the observer from the adaptor.
379    * @param[in]  observer  The observer to remove.
380    * @note Observers should remove themselves when they are destroyed.
381    */
382   void RemoveObserver( LifeCycleObserver& observer );
383
384   /**
385    * Emits the Notification event to the Dali core.
386    */
387   void SendNotificationEvent();
388
389   /**
390    * Request adaptor to update once
391    */
392   void RequestUpdateOnce();
393
394   /**
395    * @copydoc Dali::Adaptor::NotifySceneCreated()
396    */
397   void NotifySceneCreated();
398
399   /**
400    * @copydoc Dali::Adaptor::NotifyLanguageChanged()
401    */
402   void NotifyLanguageChanged();
403
404   /**
405    * Gets AppId of current application
406    */
407   void GetAppId( std::string& appId );
408
409   /**
410    * @copydoc Dali::Adaptor::SurfaceResizePrepare
411    */
412   void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
413
414   /**
415    * @copydoc Dali::Adaptor::SurfaceResizeComplete
416    */
417   void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
418
419   /**
420    * Sets layout direction of root by system language
421    * @param[in] locale System locale
422    */
423   void SetRootLayoutDirection( std::string locale );
424
425   /**
426    * @copydoc Dali::Adaptor::RenderOnce
427    */
428   void RenderOnce();
429
430   /**
431    * @copydoc Dali::Adaptor::GetLogFactory
432    */
433   const LogFactoryInterface& GetLogFactory();
434
435   /**
436    * @copydoc Dali::Adaptor::RegisterProcessor
437    */
438   void RegisterProcessor( Integration::Processor& processor );
439
440   /**
441    * @coydoc Dali::Adaptor::UnregisterProcessor
442    */
443   void UnregisterProcessor( Integration::Processor& processor );
444
445 public:  //AdaptorInternalServices
446
447   /**
448    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
449    */
450   virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
451
452   /**
453    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
454    */
455   virtual Dali::DisplayConnection& GetDisplayConnectionInterface();
456
457   /**
458    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
459    */
460   virtual GraphicsInterface& GetGraphicsInterface();
461
462   /**
463    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
464    */
465   virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
466
467   /**
468    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
469    */
470   virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
471
472   /**
473    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
474    */
475   virtual SocketFactoryInterface& GetSocketFactoryInterface();
476
477   /**
478    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
479    */
480   virtual Dali::RenderSurfaceInterface* GetRenderSurfaceInterface();
481
482   /**
483    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
484    */
485   virtual PerformanceInterface* GetPerformanceInterface();
486
487   /**
488    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
489    */
490   virtual TraceInterface& GetKernelTraceInterface();
491
492   /**
493    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
494    */
495   virtual TraceInterface& GetSystemTraceInterface();
496
497 public: // Signals
498
499   /**
500    * @copydoc Dali::Adaptor::SignalResized
501    */
502   AdaptorSignalType& ResizedSignal()
503   {
504     return mResizedSignal;
505   }
506
507   /**
508    * @copydoc Dali::Adaptor::LanguageChangedSignal
509    */
510   AdaptorSignalType& LanguageChangedSignal()
511   {
512     return mLanguageChangedSignal;
513   }
514
515   /**
516    * @copydoc Dali::Adaptor::WindowCreatedSignal
517    */
518   WindowCreatedSignalType& WindowCreatedSignal()
519   {
520     return mWindowCreatedSignal;
521   }
522
523 public: // From Dali::Internal::Adaptor::CoreEventInterface
524
525   /**
526    * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
527    */
528   virtual void ProcessCoreEvents();
529
530 private: // From Dali::Internal::Adaptor::CoreEventInterface
531
532   /**
533    * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
534    */
535   virtual void QueueCoreEvent(const Dali::Integration::Event& event);
536
537 private: // From Dali::Integration::RenderController
538
539   /**
540    * @copydoc Dali::Integration::RenderController::RequestUpdate()
541    */
542   virtual void RequestUpdate( bool forceUpdate );
543
544   /**
545    * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
546    */
547   virtual void RequestProcessEventsOnIdle( bool forceProcess );
548
549 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
550
551   /**
552    * Called when the window becomes fully or partially visible.
553    */
554   virtual void OnWindowShown();
555
556   /**
557    * Called when the window is fully hidden.
558    */
559   virtual void OnWindowHidden();
560
561 private: // From Dali::Internal::Adaptor::DamageObserver
562
563   /**
564    * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
565    */
566   void OnDamaged( const DamageArea& area );
567
568 private:
569
570   // Undefined
571   Adaptor(const Adaptor&) = delete;
572   Adaptor& operator=(Adaptor&) = delete;
573
574 private:
575
576   /**
577    * Assigns the render surface to the adaptor
578    *
579    */
580   void SetSurface(Dali::RenderSurfaceInterface *surface);
581
582   /**
583    * called after surface is created
584    */
585   void SurfaceInitialized();
586
587   /**
588    * Sends an notification message from main loop idle handler
589    */
590   bool ProcessCoreEventsFromIdle();
591
592   /**
593    * Gets path for data/resource storage.
594    * @param[out] path Path for data/resource storage
595    */
596   void GetDataStoragePath(std::string& path);
597
598   /**
599    * Sets up system information if needs
600    */
601   void SetupSystemInformation();
602
603   /**
604    * Adds a callback to be run when entering an idle state.
605    *
606    * A callback of the following type should be used:
607    * @code
608    *   bool MyFunction();
609    * @endcode
610    * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
611    */
612   bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
613
614   /**
615    * Removes a previously added the idle enterer callback.
616    */
617   void RemoveIdleEnterer( CallbackBase* callback );
618
619 private:
620
621   /**
622    * Constructor
623    * @param[in]  window       window handle
624    * @param[in]  adaptor      The public adaptor
625    * @param[in]  surface      A render surface can be one of the following
626    *                          - Pixmap, adaptor will use existing Pixmap to draw on to
627    *                          - Window, adaptor will use existing Window to draw on to
628    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
629    */
630   Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions );
631
632 private: // Types
633
634   enum State
635   {
636     READY,                     ///< Initial state before Adaptor::Start is called.
637     RUNNING,                   ///< Adaptor is running.
638     PAUSED,                    ///< Adaptor has been paused.
639     PAUSED_WHILE_HIDDEN,       ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
640     PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
641     STOPPED,                   ///< Adaptor has been stopped.
642   };
643
644   // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
645   // so we have to store the raw pointer.
646   using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
647   using ObserverContainer = std::vector<LifeCycleObserver*>;
648
649 private: // Data
650
651   AdaptorSignalType                     mResizedSignal;               ///< Resized signal.
652   AdaptorSignalType                     mLanguageChangedSignal;       ///< Language changed signal.
653   WindowCreatedSignalType               mWindowCreatedSignal;         ///< Window created signal.
654
655   Dali::Adaptor&                        mAdaptor;                     ///< Reference to public adaptor instance.
656   State                                 mState;                       ///< Current state of the adaptor
657   Dali::Integration::Core*              mCore;                        ///< Dali Core
658   ThreadController*                     mThreadController;            ///< Controls the threads
659
660   GraphicsInterface*                    mGraphics;                    ///< Graphics interface
661   Dali::DisplayConnection*              mDisplayConnection;           ///< Display connection
662   WindowContainer                       mWindows;                     ///< A container of all the Windows that are currently created
663
664   TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction;      ///< Platform abstraction
665
666   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
667   bool                                  mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
668   TriggerEventInterface*                mNotificationTrigger;         ///< Notification event trigger
669   FeedbackPluginProxy*                  mDaliFeedbackPlugin;          ///< Used to access feedback support
670   FeedbackController*                   mFeedbackController;          ///< Plays feedback effects for Dali-Toolkit UI Controls.
671   Dali::TtsPlayer                       mTtsPlayers[Dali::TtsPlayer::MODE_NUM];                   ///< Provides TTS support
672   ObserverContainer                     mObservers;                   ///< A list of adaptor observer pointers
673   EnvironmentOptions*                   mEnvironmentOptions;          ///< environment options
674   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
675   KernelTrace                           mKernelTracer;                ///< Kernel tracer
676   SystemTrace                           mSystemTracer;                ///< System tracer
677   TriggerEventFactory                   mTriggerEventFactory;         ///< Trigger event factory
678   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
679   SocketFactory                         mSocketFactory;               ///< Socket factory
680   const bool                            mEnvironmentOptionsOwned:1;   ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
681   bool                                  mUseRemoteSurface;            ///< whether the remoteSurface is used or not
682
683 public:
684   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
685 };
686
687 } // namespace Internal
688
689 } // namespace Adaptor
690
691 } // namespace Dali
692
693 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H