Merge branch 'devel/master' into tizen
[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) 2017 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/devel-api/adaptor-framework/render-surface.h>
32 #include <dali/public-api/adaptor-framework/tts-player.h>
33 #include <dali/devel-api/adaptor-framework/imf-manager.h>
34 #include <dali/devel-api/adaptor-framework/clipboard.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 namespace Dali
49 {
50
51 class RenderSurface;
52 class Window;
53
54 namespace Integration
55 {
56 class Core;
57 class GlAbstraction;
58 }
59
60 namespace Internal
61 {
62
63 namespace Adaptor
64 {
65 class EventHandler;
66 class EglFactory;
67 class GestureManager;
68 class GlImplementation;
69 class GlSyncImplementation;
70 class ThreadController;
71 class TriggerEvent;
72 class CallbackManager;
73 class FeedbackPluginProxy;
74 class FeedbackController;
75 class RotationObserver;
76 class VSyncMonitor;
77 class PerformanceInterface;
78 class LifeCycleObserver;
79 class ObjectProfiler;
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   typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
93
94   typedef Uint16Pair SurfaceSize;          ///< Surface size type
95
96   /**
97    * Creates a New Adaptor
98    * @param[in]  nativeWindow        Native window handle
99    * @param[in]  surface             A render surface can be one of the following
100    *                                  - Pixmap, adaptor will use existing Pixmap to draw on to
101    *                                  - Window, adaptor will use existing Window to draw on to
102    * @param[in]  configuration       The context loss configuration ( to choose resource discard policy )
103    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
104    */
105   static Dali::Adaptor* New( Any nativeWindow,
106                              RenderSurface* surface,
107                              Dali::Configuration::ContextLoss configuration,
108                              EnvironmentOptions* environmentOptions );
109
110   /**
111    * Creates a New Adaptor
112    * @param[in]  nativeWindow        native window handle
113    * @param[in]  configuration       The context loss configuration ( to choose resource discard policy )
114    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
115    */
116   static Dali::Adaptor* New( Dali::Window window, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions );
117
118   /**
119    * 2-step initialisation, this should be called after creating an adaptor instance.
120    */
121   void Initialize(Dali::Configuration::ContextLoss configuration);
122
123   /**
124    * Virtual destructor.
125    */
126   virtual ~Adaptor();
127
128   /**
129    * @copydoc Dali::Adaptor::Get()
130    */
131   static Dali::Adaptor& Get();
132
133   /**
134    * @copydoc Dali::Adaptor::IsAvailable()
135    */
136   static bool IsAvailable();
137
138   /**
139    * @copydoc Dali::Core::SceneCreated();
140    */
141   void SceneCreated();
142
143 public: // AdaptorInternalServices implementation
144   /**
145    * @copydoc Dali::Adaptor::Start()
146    */
147   virtual void Start();
148
149   /**
150    * @copydoc Dali::Adaptor::Pause()
151    */
152   virtual void Pause();
153
154   /**
155    * @copydoc Dali::Adaptor::Resume()
156    */
157   virtual void Resume();
158
159   /**
160    * @copydoc Dali::Adaptor::Stop()
161    */
162   virtual void Stop();
163
164   /**
165    * @copydoc Dali::Adaptor::ContextLost()
166    */
167   virtual void ContextLost();
168
169   /**
170    * @copydoc Dali::Adaptor::ContextRegained()
171    */
172   virtual void ContextRegained();
173
174   /**
175    * @copydoc Dali::EventFeeder::FeedTouchPoint()
176    */
177   virtual void FeedTouchPoint( TouchPoint& point, int timeStamp );
178
179   /**
180    * @copydoc Dali::EventFeeder::FeedWheelEvent()
181    */
182   virtual void FeedWheelEvent( WheelEvent& wheelEvent );
183
184   /**
185    * @copydoc Dali::EventFeeder::FeedKeyEvent()
186    */
187   virtual void FeedKeyEvent( KeyEvent& keyEvent );
188
189   /**
190    * @copydoc AdaptorInterface::ReplaceSurface()
191    */
192   virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
193
194   /**
195    * @copydoc Dali::Adaptor::GetSurface()
196    */
197   virtual RenderSurface& GetSurface() const;
198
199   /**
200    * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
201    */
202   virtual void ReleaseSurfaceLock();
203
204   /**
205    * Retrieve the TtsPlayer.
206    * @param[in] mode The mode of TtsPlayer
207    * @return A handle to the TtsPlayer.
208    */
209   virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
210
211   /**
212    * @copydoc Dali::Adaptor::AddIdle()
213    */
214   virtual bool AddIdle( CallbackBase* callback, bool forceAdd );
215
216   /**
217    * @copydoc Dali::Adaptor::RemoveIdle()
218    */
219   virtual void RemoveIdle( CallbackBase* callback );
220
221 public:
222
223   /**
224    * @return the Core instance
225    */
226   virtual Dali::Integration::Core& GetCore();
227
228   /**
229    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
230    */
231   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
232
233   /**
234    * @copydoc Dali::Adaptor::SetUseHardwareVSync()
235    */
236   void SetUseHardwareVSync(bool useHardware);
237
238   /**
239    * @return reference to EglFactory class
240    */
241   EglFactory& GetEGLFactory() const;
242
243   /**
244    * Return GlAbstraction.
245    * @return the GlAbstraction.
246    */
247   Integration::GlAbstraction& GetGlAbstraction() const;
248
249   /**
250    * Return the PlatformAbstraction.
251    * @return The PlatformAbstraction.
252    */
253   Integration::PlatformAbstraction& GetPlatformAbstraction() const;
254
255   /**
256    * Sets the Drag & Drop Listener.
257    * @param[in] detector The detector to send Drag & Drop events to.
258    */
259   void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
260
261   /**
262    * Sets a rotation observer, or set to NULL to remove.
263    * @pre Adaptor::Start() has been called ( to create EventHandler )
264    * @param[in] observer The observer to listen for window rotation events
265    */
266   void SetRotationObserver( RotationObserver* observer );
267
268   /**
269    * Destroy the TtsPlayer of sepcific mode.
270    * @param[in] mode The mode of TtsPlayer to destroy
271    */
272   void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
273
274   /**
275    * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
276    * trigger a pinch gesture
277    *
278    * @param[in] distance The minimum pinch distance in pixels
279    */
280   void SetMinimumPinchDistance(float distance);
281
282   /**
283    * Gets native window handle
284    *
285    * @return native window handle
286    */
287   Any GetNativeWindowHandle();
288
289   /**
290    * Sets use remote surface for eglSurface output
291    * @param[in] useRemoteSurface True if the remote surface is used
292    */
293   void SetUseRemoteSurface(bool useRemoteSurface);
294
295 public:
296
297   /**
298    * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
299    * @param[in]  observer  The observer.
300    * @note Observers should remove themselves when they are destroyed.
301    */
302   void AddObserver( LifeCycleObserver& observer );
303
304   /**
305    * Removes the observer from the adaptor.
306    * @param[in]  observer  The observer to remove.
307    * @note Observers should remove themselves when they are destroyed.
308    */
309   void RemoveObserver( LifeCycleObserver& observer );
310
311   /**
312    * Emits the Notification event to the Dali core.
313    */
314   void SendNotificationEvent();
315
316   /**
317    * Request adaptor to update once
318    */
319   void RequestUpdateOnce();
320
321   /**
322    * Request adaptor to update indicator's height
323    */
324   void IndicatorSizeChanged(int height);
325
326   /**
327    * @copydoc Dali::Adaptor::NotifySceneCreated()
328    */
329   void NotifySceneCreated();
330
331   /**
332    * @copydoc Dali::Adaptor::NotifyLanguageChanged()
333    */
334   void NotifyLanguageChanged();
335
336   /**
337    * Gets AppId of current application
338    */
339   void GetAppId( std::string& appId );
340
341   /**
342    * Informs core the surface size has changed
343    */
344   void SurfaceResizePrepare( SurfaceSize surfaceSize );
345
346   /**
347    * Informs ThreadController the surface size has changed
348    */
349   void SurfaceResizeComplete( SurfaceSize surfaceSize );
350
351   /**
352    * Sets layout direction of root by system language
353    * @param[in] locale System locale
354    */
355   void SetRootLayoutDirection( std::string locale );
356
357   /**
358    * @copydoc Dali::Adaptor::RenderOnce
359    */
360   void RenderOnce();
361
362   /**
363    * @copydoc Dali::Adaptor::GetLogFactory
364    */
365   const LogFactoryInterface& GetLogFactory();
366
367 public:  //AdaptorInternalServices
368
369   /**
370    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
371    */
372   virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
373
374   /**
375    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
376    */
377   virtual Dali::Integration::GlAbstraction& GetGlesInterface();
378
379   /**
380   * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
381   */
382   virtual EglFactoryInterface& GetEGLFactoryInterface() const;
383
384   /**
385    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
386    */
387   virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
388
389   /**
390    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
391    */
392   virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
393
394   /**
395    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
396    */
397   virtual SocketFactoryInterface& GetSocketFactoryInterface();
398
399   /**
400    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
401    */
402   virtual RenderSurface* GetRenderSurfaceInterface();
403
404   /**
405    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
406    */
407   virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
408
409   /**
410    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
411    */
412   virtual PerformanceInterface* GetPerformanceInterface();
413
414   /**
415    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
416    */
417   virtual TraceInterface& GetKernelTraceInterface();
418
419   /**
420    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
421    */
422   virtual TraceInterface& GetSystemTraceInterface();
423
424 public: // Stereoscopy
425
426   /**
427    * @copydoc Dali::Integration::Core::SetViewMode()
428    */
429   void SetViewMode( ViewMode viewMode );
430
431   /**
432    * @copydoc Dali::Integration::Core::GetViewMode()
433    */
434   ViewMode GetViewMode() const;
435
436   /**
437    * @copydoc Dali::Integration::Core::SetStereoBase()
438    */
439   void SetStereoBase( float stereoBase );
440
441   /**
442    * @copydoc Dali::Integration::Core::GetStereoBase()
443    */
444   float GetStereoBase() const;
445
446 public: // Signals
447
448   /**
449    * @copydoc Dali::Adaptor::SignalResized
450    */
451   AdaptorSignalType& ResizedSignal()
452   {
453     return mResizedSignal;
454   }
455
456   /**
457    * @copydoc Dali::Adaptor::LanguageChangedSignal
458    */
459   AdaptorSignalType& LanguageChangedSignal()
460   {
461     return mLanguageChangedSignal;
462   }
463
464 private: // From Dali::Internal::Adaptor::CoreEventInterface
465
466   /**
467    * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
468    */
469   virtual void QueueCoreEvent(const Dali::Integration::Event& event);
470
471   /**
472    * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
473    */
474   virtual void ProcessCoreEvents();
475
476 private: // From Dali::Integration::RenderController
477
478   /**
479    * @copydoc Dali::Integration::RenderController::RequestUpdate()
480    */
481   virtual void RequestUpdate( bool forceUpdate );
482
483   /**
484    * @copydoc Dali::Integration::RenderController::RequestProcessEventsOnIdle()
485    */
486   virtual void RequestProcessEventsOnIdle( bool forceProcess );
487
488 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
489
490   /**
491    * Called when the window becomes fully or partially visible.
492    */
493   virtual void OnWindowShown();
494
495   /**
496    * Called when the window is fully hidden.
497    */
498   virtual void OnWindowHidden();
499
500 private: // From Dali::Internal::Adaptor::DamageObserver
501
502   /**
503    * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
504    */
505   void OnDamaged( const DamageArea& area );
506
507 private:
508
509   // Undefined
510   Adaptor(const Adaptor&);
511   Adaptor& operator=(Adaptor&);
512
513 private:
514
515   /**
516    * Assigns the render surface to the adaptor
517    *
518    */
519   void SetSurface(RenderSurface *surface);
520
521   /**
522    * called after surface is created
523    */
524   void SurfaceInitialized();
525
526   /**
527    * Sends an notification message from main loop idle handler
528    */
529   void ProcessCoreEventsFromIdle();
530
531   /**
532    * Gets path for data/resource storage.
533    * @param[out] path Path for data/resource storage
534    */
535   void GetDataStoragePath(std::string& path);
536
537   /**
538    * Sets up system information if needs
539    */
540   void SetupSystemInformation();
541
542 private:
543
544   /**
545    * Constructor
546    * @param[in]  nativeWindow native window handle
547    * @param[in]  adaptor      The public adaptor
548    * @param[in]  surface      A render surface can be one of the following
549    *                          - Pixmap, adaptor will use existing Pixmap to draw on to
550    *                          - Window, adaptor will use existing Window to draw on to
551    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
552    */
553   Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions );
554
555 private: // Types
556
557   enum State
558   {
559     READY,               ///< Initial state before Adaptor::Start is called.
560     RUNNING,             ///< Adaptor is running.
561     PAUSED,              ///< Adaptor has been paused.
562     PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
563     STOPPED,             ///< Adaptor has been stopped.
564   };
565
566   typedef std::vector<LifeCycleObserver*>  ObserverContainer;
567
568 private: // Data
569
570   AdaptorSignalType                     mResizedSignal;               ///< Resized signal.
571   AdaptorSignalType                     mLanguageChangedSignal;       ///< Language changed signal.
572
573   Dali::Adaptor&                        mAdaptor;                     ///< Reference to public adaptor instance.
574   State                                 mState;                       ///< Current state of the adaptor
575   Dali::Integration::Core*              mCore;                        ///< Dali Core
576   ThreadController*                     mThreadController;            ///< Controls the threads
577   VSyncMonitor*                         mVSyncMonitor;                ///< Monitors VSync events
578   GlImplementation*                     mGLES;                        ///< GL implementation
579   GlSyncImplementation*                 mGlSync;                      ///< GL Sync implementation
580   EglFactory*                           mEglFactory;                  ///< EGL Factory
581
582   Any                                   mNativeWindow;                ///< window identifier
583   RenderSurface*                        mSurface;                     ///< Current surface
584   TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction;      ///< Platform abstraction
585
586   EventHandler*                         mEventHandler;                ///< event handler
587   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
588   bool                                  mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
589   TriggerEventInterface*                mNotificationTrigger;         ///< Notification event trigger
590   GestureManager*                       mGestureManager;              ///< Gesture manager
591   FeedbackPluginProxy*                  mDaliFeedbackPlugin;          ///< Used to access feedback support
592   FeedbackController*                   mFeedbackController;          ///< Plays feedback effects for Dali-Toolkit UI Controls.
593   Dali::TtsPlayer                       mTtsPlayers[Dali::TtsPlayer::MODE_NUM];                   ///< Provides TTS support
594   ObserverContainer                     mObservers;                   ///< A list of adaptor observer pointers
595   DragAndDropDetectorPtr                mDragAndDropDetector;         ///< The Drag & Drop detector
596   RotationObserver*                     mDeferredRotationObserver;    ///< deferred Rotation observer needs event handler
597   EnvironmentOptions*                   mEnvironmentOptions;          ///< environment options
598   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
599   KernelTrace                           mKernelTracer;                ///< Kernel tracer
600   SystemTrace                           mSystemTracer;                ///< System tracer
601   TriggerEventFactory                   mTriggerEventFactory;         ///< Trigger event factory
602   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
603   SocketFactory                         mSocketFactory;               ///< Socket factory
604   const bool                            mEnvironmentOptionsOwned:1;   ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
605   bool                                  mUseRemoteSurface;            ///< whether the remoteSurface is used or not
606 public:
607   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
608 };
609
610 } // namespace Internal
611
612 } // namespace Adaptor
613
614 } // namespace Dali
615
616 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__