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