a62bede62aff82a201eb3bdda92297fc1ea8a1bc
[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) 2020 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/math/rect.h>
24 #include <dali/public-api/signals/callback.h>
25 #include <dali/public-api/math/uint-16-pair.h>
26 #include <dali/integration-api/render-controller.h>
27
28 // INTERNAL INCLUDES
29 #include <dali/public-api/adaptor-framework/tts-player.h>
30 #include <dali/devel-api/adaptor-framework/clipboard.h>
31 #include <dali/integration-api/scene.h>
32 #include <dali/integration-api/adaptor-framework/adaptor.h>
33 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
34 #include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
35 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
36 #include <dali/internal/graphics/common/graphics-interface.h>
37 #include <dali/internal/legacy/common/tizen-platform-abstraction.h>
38 #include <dali/internal/network/common/socket-factory.h>
39 #include <dali/internal/system/common/core-event-interface.h>
40 #include <dali/internal/system/common/environment-options.h>
41 #include <dali/internal/system/common/kernel-trace.h>
42 #include <dali/internal/system/common/system-trace.h>
43 #include <dali/internal/window-system/common/damage-observer.h>
44 #include <dali/internal/window-system/common/window-visibility-observer.h>
45
46 namespace Dali
47 {
48
49 class RenderSurfaceInterface;
50
51 namespace Integration
52 {
53 class Core;
54 class GlAbstraction;
55 class Processor;
56 class AddOnManager;
57 }
58
59 namespace Internal
60 {
61
62 namespace Adaptor
63 {
64 class DisplayConnection;
65 class GraphicsFactory;
66 class GlImplementation;
67 class GlSyncImplementation;
68 class ThreadController;
69 class TriggerEvent;
70 class CallbackManager;
71 class FeedbackPluginProxy;
72 class FeedbackController;
73 class VSyncMonitor;
74 class PerformanceInterface;
75 class LifeCycleObserver;
76 class ObjectProfiler;
77 class SceneHolder;
78 class ConfigurationManager;
79 enum class ThreadMode;
80
81 /**
82  * Implementation of the Adaptor class.
83  */
84 class Adaptor : public Integration::RenderController,
85                 public AdaptorInternalServices,
86                 public CoreEventInterface,
87                 public DamageObserver,
88                 public WindowVisibilityObserver
89 {
90 public:
91
92   using AdaptorSignalType =  Dali::Adaptor::AdaptorSignalType;
93   using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType;
94
95   using SurfaceSize = Uint16Pair;          ///< Surface size type
96
97   /**
98    * Creates a New Adaptor
99    * @param[in]  window              The window handle
100    * @param[in]  surface             A render surface can be one of the following
101    *                                  - Pixmap, adaptor will use existing Pixmap to draw on to
102    *                                  - Window, adaptor will use existing Window to draw on to
103    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
104    */
105   static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
106                              Dali::RenderSurfaceInterface* surface,
107                              EnvironmentOptions* environmentOptions );
108
109   /**
110    * Creates a New Adaptor
111    * @param[in]  window              The window handle
112    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
113    */
114   static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
115                              EnvironmentOptions* environmentOptions );
116
117   /**
118    * Creates a New Adaptor
119    * @param[in]  graphicsFactory     A factory that creates the graphics interface
120    * @param[in]  window              The window handle
121    * @param[in]  surface             A render surface can be one of the following
122    *                                  - Pixmap, adaptor will use existing Pixmap to draw on to
123    *                                  - Window, adaptor will use existing Window to draw on to
124    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
125    */
126   static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
127                              Dali::Integration::SceneHolder window,
128                              Dali::RenderSurfaceInterface* surface,
129                              EnvironmentOptions* environmentOptions );
130
131   /**
132    * Creates a New Adaptor
133    * @param[in]  graphicsFactory     A factory that creates the graphics interface
134    * @param[in]  window              The window handle
135    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
136    */
137   static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
138                              Dali::Integration::SceneHolder window,
139                              EnvironmentOptions* environmentOptions );
140
141   /**
142    * 2-step initialisation, this should be called after creating an adaptor instance.
143    * @param[in]  graphicsFactory     A factory that creates the graphics interface
144    */
145   void Initialize( GraphicsFactory& graphicsFactory );
146
147   /**
148    * Virtual destructor.
149    */
150   ~Adaptor() override;
151
152   /**
153    * @copydoc Dali::Adaptor::Get()
154    */
155   static Dali::Adaptor& Get();
156
157   /**
158    * @copydoc Dali::Adaptor::IsAvailable()
159    */
160   static bool IsAvailable();
161
162   /**
163    * @copydoc Dali::Core::SceneCreated();
164    */
165   void SceneCreated();
166
167 public: // AdaptorInternalServices implementation
168   /**
169    * @copydoc Dali::Adaptor::Start()
170    */
171   virtual void Start();
172
173   /**
174    * @copydoc Dali::Adaptor::Pause()
175    */
176   virtual void Pause();
177
178   /**
179    * @copydoc Dali::Adaptor::Resume()
180    */
181   virtual void Resume();
182
183   /**
184    * @copydoc Dali::Adaptor::Stop()
185    */
186   virtual void Stop();
187
188   /**
189    * @copydoc Dali::Adaptor::ContextLost()
190    */
191   virtual void ContextLost();
192
193   /**
194    * @copydoc Dali::Adaptor::ContextRegained()
195    */
196   virtual void ContextRegained();
197
198   /**
199    * @copydoc Dali::EventFeeder::FeedTouchPoint()
200    */
201   virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
202
203   /**
204    * @copydoc Dali::EventFeeder::FeedWheelEvent()
205    */
206   virtual void FeedWheelEvent( Dali::WheelEvent& wheelEvent );
207
208   /**
209    * @copydoc Dali::EventFeeder::FeedKeyEvent()
210    */
211   virtual void FeedKeyEvent( Dali::KeyEvent& keyEvent );
212
213   /**
214    * @copydoc Dali::Adaptor::ReplaceSurface()
215    */
216   virtual void ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface );
217
218   /**
219    * @copydoc Dali::Adaptor::GetSurface()
220    */
221   virtual Dali::RenderSurfaceInterface& GetSurface() const;
222
223   /**
224    * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
225    */
226   virtual void ReleaseSurfaceLock();
227
228   /**
229    * Retrieve the TtsPlayer.
230    * @param[in] mode The mode of TtsPlayer
231    * @return A handle to the TtsPlayer.
232    */
233   virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
234
235   /**
236    * @copydoc Dali::Adaptor::AddIdle()
237    */
238   virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
239
240   /**
241    * Adds a new Window instance to the Adaptor
242    * @param[in]  childWindow The child window instance
243    */
244   virtual bool AddWindow( Dali::Integration::SceneHolder childWindow );
245
246   /**
247    * Removes an existing Window instance from the Adaptor
248    * @param[in]  window The Window instance
249    */
250   virtual bool RemoveWindow( Dali::Integration::SceneHolder* childWindow );
251
252   /**
253    * Removes an existing Window instance from the Adaptor
254    * @param[in]  windowName The Window name
255    * @note If two Windows have the same name, the first one that matches will be removed
256    */
257   virtual bool RemoveWindow( std::string childWindowName );
258
259   /**
260    * @copydoc Dali::Adaptor::RemoveIdle()
261    */
262   virtual void RemoveIdle( CallbackBase* callback );
263
264   /**
265    * @copydoc Dali::Adaptor::ProcessIdle()
266    */
267   virtual void ProcessIdle();
268
269   /**
270    * Sets a pre-render callback.
271    */
272   void SetPreRenderCallback( CallbackBase* callback );
273
274   /**
275    * Removes an existing Window instance from the Adaptor
276    * @param[in]  childWindow The Window instance
277    */
278   bool RemoveWindow( Dali::Internal::Adaptor::SceneHolder* childWindow );
279
280   /**
281    * @brief Deletes the rendering surface
282    * @param[in] surface to delete
283    */
284   void DeleteSurface( Dali::RenderSurfaceInterface& surface );
285
286   /**
287    * @brief Retrieve the window that the given actor is added to.
288    *
289    * @param[in] actor The actor
290    * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
291    */
292   Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
293
294   /**
295    * @copydoc Dali::Adaptor::GetWindows()
296    */
297   Dali::WindowContainer GetWindows() const;
298
299   /**
300    * @copydoc Dali::Adaptor::GetSceneHolders()
301    */
302   Dali::SceneHolderList GetSceneHolders() const;
303
304   /**
305    * @copydoc Dali::Adaptor::GetObjectRegistry()
306    */
307   Dali::ObjectRegistry GetObjectRegistry() const;
308
309 public:
310
311   /**
312    * @return the Core instance
313    */
314   Dali::Integration::Core& GetCore() override;
315
316   /**
317    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
318    */
319   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
320
321   /**
322    * Return the PlatformAbstraction.
323    * @return The PlatformAbstraction.
324    */
325   Integration::PlatformAbstraction& GetPlatformAbstraction() const;
326
327   /**
328    * Destroy the TtsPlayer of specific mode.
329    * @param[in] mode The mode of TtsPlayer to destroy
330    */
331   void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
332
333   /**
334    * Gets native window handle
335    *
336    * @return native window handle
337    */
338   Any GetNativeWindowHandle();
339
340   /**
341    * @brief Retrieve native window handle that the given actor is added to.
342    *
343    * @param[in] actor The actor
344    * @return native window handle
345    */
346   Any GetNativeWindowHandle( Dali::Actor actor );
347
348   /**
349    * Get the native display associated with the graphics backend
350    *
351    * @return A handle to the native display
352    */
353   Any GetGraphicsDisplay();
354
355   /**
356    * Sets use remote surface for Surface output
357    * @param[in] useRemoteSurface True if the remote surface is used
358    */
359   void SetUseRemoteSurface(bool useRemoteSurface);
360
361 public:
362
363   /**
364    * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
365    * @param[in]  observer  The observer.
366    * @note Observers should remove themselves when they are destroyed.
367    */
368   void AddObserver( LifeCycleObserver& observer );
369
370   /**
371    * Removes the observer from the adaptor.
372    * @param[in]  observer  The observer to remove.
373    * @note Observers should remove themselves when they are destroyed.
374    */
375   void RemoveObserver( LifeCycleObserver& observer );
376
377   /**
378    * Emits the Notification event to the Dali core.
379    */
380   void SendNotificationEvent();
381
382   /**
383    * Request adaptor to update once
384    */
385   void RequestUpdateOnce();
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    * @copydoc Dali::Adaptor::SurfaceResizePrepare
404    */
405   void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
406
407   /**
408    * @copydoc Dali::Adaptor::SurfaceResizeComplete
409    */
410   void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, 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   /**
439    * Check MultipleWindow is supported
440    */
441   bool IsMultipleWindowSupported() const;
442
443 public:  //AdaptorInternalServices
444
445   /**
446    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
447    */
448   Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface() override;
449
450   /**
451    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetDisplayConnectionInterface()
452    */
453   Dali::DisplayConnection& GetDisplayConnectionInterface() override;
454
455   /**
456    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGraphicsInterface()
457    */
458   GraphicsInterface& GetGraphicsInterface() override;
459
460   /**
461    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
462    */
463   TriggerEventInterface& GetProcessCoreEventsTrigger() override;
464
465   /**
466    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
467    */
468   SocketFactoryInterface& GetSocketFactoryInterface() override;
469
470   /**
471    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
472    */
473   Dali::RenderSurfaceInterface* GetRenderSurfaceInterface() override;
474
475   /**
476    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
477    */
478   PerformanceInterface* GetPerformanceInterface() override;
479
480   /**
481    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
482    */
483   TraceInterface& GetKernelTraceInterface() override;
484
485   /**
486    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
487    */
488   TraceInterface& GetSystemTraceInterface() override;
489
490   /**
491    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetWindowContainerInterface()
492    */
493   void GetWindowContainerInterface( WindowContainer& windows ) override;
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   /**
514    * @copydoc Dali::Adaptor::WindowCreatedSignal
515    */
516   WindowCreatedSignalType& WindowCreatedSignal()
517   {
518     return mWindowCreatedSignal;
519   }
520
521 public: // From Dali::Internal::Adaptor::CoreEventInterface
522
523   /**
524    * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
525    */
526   void ProcessCoreEvents() override;
527
528 private: // From Dali::Internal::Adaptor::CoreEventInterface
529
530   /**
531    * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
532    */
533   void QueueCoreEvent(const Dali::Integration::Event& event) override;
534
535 private: // From Dali::Integration::RenderController
536
537   /**
538    * @copydoc Dali::Integration::RenderController::RequestUpdate()
539    */
540   void RequestUpdate( bool forceUpdate ) override;
541
542   /**
543    * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
544    */
545   void RequestProcessEventsOnIdle( bool forceProcess ) override;
546
547 public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
548
549   /**
550    * Called when the window becomes fully or partially visible.
551    */
552   void OnWindowShown() override;
553
554   /**
555    * Called when the window is fully hidden.
556    */
557   void OnWindowHidden() override;
558
559 private: // From Dali::Internal::Adaptor::DamageObserver
560
561   /**
562    * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
563    */
564   void OnDamaged( const DamageArea& area ) override;
565
566 private:
567
568   // Undefined
569   Adaptor(const Adaptor&) = delete;
570   Adaptor& operator=(Adaptor&) = delete;
571
572 private:
573
574   /**
575    * Assigns the render surface to the adaptor
576    *
577    */
578   void SetSurface(Dali::RenderSurfaceInterface *surface);
579
580   /**
581    * called after surface is created
582    */
583   void SurfaceInitialized();
584
585   /**
586    * Sends an notification message from main loop idle handler
587    */
588   bool ProcessCoreEventsFromIdle();
589
590   /**
591    * Gets path for data/resource storage.
592    * @param[out] path Path for data/resource storage
593    */
594   void GetDataStoragePath(std::string& path);
595
596   /**
597    * Sets up system information if needs
598    */
599   void SetupSystemInformation();
600
601   /**
602    * Adds a callback to be run when entering an idle state.
603    *
604    * A callback of the following type should be used:
605    * @code
606    *   bool MyFunction();
607    * @endcode
608    * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
609    */
610   bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
611
612   /**
613    * Removes a previously added the idle enterer callback.
614    */
615   void RemoveIdleEnterer( CallbackBase* callback );
616
617 private:
618
619   /**
620    * Constructor
621    * @param[in]  window       window handle
622    * @param[in]  adaptor      The public adaptor
623    * @param[in]  surface      A render surface can be one of the following
624    *                          - Pixmap, adaptor will use existing Pixmap to draw on to
625    *                          - Window, adaptor will use existing Window to draw on to
626    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
627    */
628   Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions );
629
630 private: // Types
631
632   enum State
633   {
634     READY,                     ///< Initial state before Adaptor::Start is called.
635     RUNNING,                   ///< Adaptor is running.
636     PAUSED,                    ///< Adaptor has been paused.
637     PAUSED_WHILE_HIDDEN,       ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
638     PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
639     STOPPED,                   ///< Adaptor has been stopped.
640   };
641
642   // There is no weak handle for BaseHandle in DALi, but we can't ref count the window here,
643   // so we have to store the raw pointer.
644   using WindowContainer = std::vector<Dali::Internal::Adaptor::SceneHolder*>;
645   using ObserverContainer = std::vector<LifeCycleObserver*>;
646
647 private: // Data
648
649   AdaptorSignalType                     mResizedSignal;               ///< Resized signal.
650   AdaptorSignalType                     mLanguageChangedSignal;       ///< Language changed signal.
651   WindowCreatedSignalType               mWindowCreatedSignal;    ///< Window created signal.
652
653   Dali::Adaptor&                        mAdaptor;                     ///< Reference to public adaptor instance.
654   State                                 mState;                       ///< Current state of the adaptor
655   Dali::Integration::Core*              mCore;                        ///< Dali Core
656   ThreadController*                     mThreadController;            ///< Controls the threads
657
658   std::unique_ptr< GraphicsInterface >  mGraphics;                    ///< Graphics interface
659   Dali::DisplayConnection*              mDisplayConnection;           ///< Display connection
660   WindowContainer                       mWindows;                     ///< A container of all the Windows that are currently created
661
662   std::unique_ptr<ConfigurationManager> mConfigurationManager;        ///< Configuration manager
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   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
678   SocketFactory                         mSocketFactory;               ///< Socket factory
679   ThreadMode                            mThreadMode;                  ///< The thread mode
680   const bool                            mEnvironmentOptionsOwned:1;   ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
681   bool                                  mUseRemoteSurface:1;          ///< whether the remoteSurface is used or not
682   Dali::LayoutDirection::Type           mRootLayoutDirection;         ///< LayoutDirection of window
683
684   std::unique_ptr<Integration::AddOnManager> mAddOnManager;           ///< Pointer to the addon manager
685
686 public:
687   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) { return *adaptor.mImpl; }
688 };
689
690 } // namespace Internal
691
692 } // namespace Adaptor
693
694 } // namespace Dali
695
696 #endif // DALI_INTERNAL_ADAPTOR_IMPL_H