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