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