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