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