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