[3.0] Modify native render surface for sync. with replace surface
[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) 2016 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::MoveResize()
188    */
189   virtual bool MoveResize( const PositionSize& positionSize );
190
191   /**
192    * @copydoc AdaptorInterface::SurfaceResized()
193    */
194   virtual void SurfaceResized( const PositionSize& positionSize );
195
196   /**
197    * @copydoc AdaptorInterface::ReplaceSurface()
198    */
199   virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
200
201   /**
202    * @copydoc Dali::Adaptor::GetSurface()
203    */
204   virtual RenderSurface& GetSurface() const;
205
206   /**
207    * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
208    */
209   virtual void ReleaseSurfaceLock();
210
211   /**
212    * Retrieve the TtsPlayer.
213    * @param[in] mode The mode of TtsPlayer
214    * @return A handle to the TtsPlayer.
215    */
216   virtual Dali::TtsPlayer GetTtsPlayer(Dali::TtsPlayer::Mode mode);
217
218   /**
219    * @copydoc Dali::Adaptor::AddIdle()
220    */
221   virtual bool AddIdle( CallbackBase* callback );
222
223   /**
224    * @copydoc Dali::Adaptor::RemoveIdle()
225    */
226   virtual void RemoveIdle( CallbackBase* callback );
227
228 public:
229
230   /**
231    * @return the Core instance
232    */
233   virtual Dali::Integration::Core& GetCore();
234
235   /**
236    * @copydoc Dali::Adaptor::SetRenderRefreshRate()
237    */
238   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
239
240   /**
241    * @copydoc Dali::Adaptor::SetUseHardwareVSync()
242    */
243   void SetUseHardwareVSync(bool useHardware);
244
245   /**
246    * @return reference to EglFactory class
247    */
248   EglFactory& GetEGLFactory() const;
249
250   /**
251    * Return GlAbstraction.
252    * @return the GlAbstraction.
253    */
254   Integration::GlAbstraction& GetGlAbstraction() const;
255
256   /**
257    * Return the PlatformAbstraction.
258    * @return The PlatformAbstraction.
259    */
260   Integration::PlatformAbstraction& GetPlatformAbstraction() const;
261
262   /**
263    * Sets the Drag & Drop Listener.
264    * @param[in] detector The detector to send Drag & Drop events to.
265    */
266   void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
267
268   /**
269    * Sets a rotation observer, or set to NULL to remove.
270    * @pre Adaptor::Start() has been called ( to create EventHandler )
271    * @param[in] observer The observer to listen for window rotation events
272    */
273   void SetRotationObserver( RotationObserver* observer );
274
275   /**
276    * Destroy the TtsPlayer of sepcific mode.
277    * @param[in] mode The mode of TtsPlayer to destroy
278    */
279   void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
280
281   /**
282    * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
283    * trigger a pinch gesture
284    *
285    * @param[in] distance The minimum pinch distance in pixels
286    */
287   void SetMinimumPinchDistance(float distance);
288
289   /**
290    * Gets native window handle
291    *
292    * @return native window handle
293    */
294   Any GetNativeWindowHandle();
295
296 public:
297
298   /**
299    * Adds an adaptor observer so that we can observe the adaptor's lifetime events.
300    * @param[in]  observer  The observer.
301    * @note Observers should remove themselves when they are destroyed.
302    */
303   void AddObserver( LifeCycleObserver& observer );
304
305   /**
306    * Removes the observer from the adaptor.
307    * @param[in]  observer  The observer to remove.
308    * @note Observers should remove themselves when they are destroyed.
309    */
310   void RemoveObserver( LifeCycleObserver& observer );
311
312   /**
313    * Emits the Notification event to the Dali core.
314    */
315   void SendNotificationEvent();
316
317   /**
318    * Request adaptor to update once
319    */
320   void RequestUpdateOnce();
321
322   /**
323    * @copydoc Dali::Adaptor::NotifySceneCreated()
324    */
325   void NotifySceneCreated();
326
327   /**
328    * @copydoc Dali::Adaptor::NotifyLanguageChanged()
329    */
330   void NotifyLanguageChanged();
331
332   /**
333    * Gets AppId of current application
334    */
335   void GetAppId( std::string& appId );
336
337   /**
338    * Informs core the surface size has changed
339    */
340   void SurfaceSizeChanged( const PositionSize& positionSize );
341
342 public:  //AdaptorInternalServices
343
344   /**
345    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPlatformAbstractionInterface()
346    */
347   virtual Dali::Integration::PlatformAbstraction& GetPlatformAbstractionInterface();
348
349   /**
350    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetGlesInterface()
351    */
352   virtual Dali::Integration::GlAbstraction& GetGlesInterface();
353
354   /**
355   * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetEGLFactoryInterface()
356   */
357   virtual EglFactoryInterface& GetEGLFactoryInterface() const;
358
359   /**
360    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
361    */
362   virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
363
364   /**
365    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
366    */
367   virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
368
369   /**
370    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSocketFactoryInterface()
371    */
372   virtual SocketFactoryInterface& GetSocketFactoryInterface();
373
374   /**
375    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
376    */
377   virtual RenderSurface* GetRenderSurfaceInterface();
378
379   /**
380    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
381    */
382   virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
383
384   /**
385    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
386    */
387   virtual PerformanceInterface* GetPerformanceInterface();
388
389   /**
390    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
391    */
392   virtual TraceInterface& GetKernelTraceInterface();
393
394   /**
395    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
396    */
397   virtual TraceInterface& GetSystemTraceInterface();
398
399 public: // Stereoscopy
400
401   /**
402    * @copydoc Dali::Integration::Core::SetViewMode()
403    */
404   void SetViewMode( ViewMode viewMode );
405
406   /**
407    * @copydoc Dali::Integration::Core::GetViewMode()
408    */
409   ViewMode GetViewMode() const;
410
411   /**
412    * @copydoc Dali::Integration::Core::SetStereoBase()
413    */
414   void SetStereoBase( float stereoBase );
415
416   /**
417    * @copydoc Dali::Integration::Core::GetStereoBase()
418    */
419   float GetStereoBase() const;
420
421 public: // Signals
422
423   /**
424    * @copydoc Dali::Adaptor::SignalResized
425    */
426   AdaptorSignalType& ResizedSignal()
427   {
428     return mResizedSignal;
429   }
430
431   /**
432    * @copydoc Dali::Adaptor::LanguageChangedSignal
433    */
434   AdaptorSignalType& LanguageChangedSignal()
435   {
436     return mLanguageChangedSignal;
437   }
438
439 private: // From Dali::Internal::Adaptor::CoreEventInterface
440
441   /**
442    * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
443    */
444   virtual void QueueCoreEvent(const Dali::Integration::Event& event);
445
446   /**
447    * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
448    */
449   virtual void ProcessCoreEvents();
450
451 private: // From Dali::Integration::RenderController
452
453   /**
454    * Called by the Dali core when it requires another update
455    */
456   virtual void RequestUpdate();
457
458   /**
459    * Called by Dali core when it requires an notification event being sent on idle.
460    * Multi-threading note: this method must be called from the main thread only.
461    */
462   virtual void RequestProcessEventsOnIdle();
463
464 private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
465
466   /**
467    * Called when the window becomes fully or partially visible.
468    */
469   virtual void OnWindowShown();
470
471   /**
472    * Called when the window is fully hidden.
473    */
474   virtual void OnWindowHidden();
475
476 private: // From Dali::Internal::Adaptor::DamageObserver
477
478   /**
479    * @copydoc Dali::Internal::Adaptor::DamageObserver::OnDamaged()
480    */
481   void OnDamaged( const DamageArea& area );
482
483 private:
484
485   // Undefined
486   Adaptor(const Adaptor&);
487   Adaptor& operator=(Adaptor&);
488
489 private:
490
491   /**
492    * Assigns the render surface to the adaptor
493    *
494    */
495   void SetSurface(RenderSurface *surface);
496
497   /**
498    * Sends an notification message from main loop idle handler
499    */
500   void ProcessCoreEventsFromIdle();
501
502   /**
503    * Gets path for data/resource storage.
504    * @param[out] path Path for data/resource storage
505    */
506   void GetDataStoragePath(std::string& path);
507
508 private:
509
510   /**
511    * Constructor
512    * @param[in]  nativeWindow native window handle
513    * @param[in]  adaptor      The public adaptor
514    * @param[in]  surface      A render surface can be one of the following
515    *                          - Pixmap, adaptor will use existing Pixmap to draw on to
516    *                          - Window, adaptor will use existing Window to draw on to
517    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
518    */
519   Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions );
520
521 private: // Types
522
523   enum State
524   {
525     READY,               ///< Initial state before Adaptor::Start is called.
526     RUNNING,             ///< Adaptor is running.
527     PAUSED,              ///< Adaptor has been paused.
528     PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
529     STOPPED,             ///< Adaptor has been stopped.
530   };
531
532   typedef std::vector<LifeCycleObserver*>  ObserverContainer;
533
534 private: // Data
535
536   AdaptorSignalType                     mResizedSignal;               ///< Resized signal.
537   AdaptorSignalType                     mLanguageChangedSignal;       ///< Language changed signal.
538
539   Dali::Adaptor&                        mAdaptor;                     ///< Reference to public adaptor instance.
540   State                                 mState;                       ///< Current state of the adaptor
541   Dali::Integration::Core*              mCore;                        ///< Dali Core
542   ThreadController*                     mThreadController;            ///< Controls the threads
543   VSyncMonitor*                         mVSyncMonitor;                ///< Monitors VSync events
544   GlImplementation*                     mGLES;                        ///< GL implementation
545   GlSyncImplementation*                 mGlSync;                      ///< GL Sync implementation
546   EglFactory*                           mEglFactory;                  ///< EGL Factory
547
548   Any                                   mNativeWindow;                ///< window identifier
549   RenderSurface*                        mSurface;                     ///< Current surface
550   TizenPlatform::TizenPlatformAbstraction*  mPlatformAbstraction;         ///< Platform abstraction
551
552   EventHandler*                         mEventHandler;                ///< event handler
553   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
554   bool                                  mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
555   TriggerEventInterface*                mNotificationTrigger;         ///< Notification event trigger
556   GestureManager*                       mGestureManager;              ///< Gesture manager
557   FeedbackPluginProxy*                  mDaliFeedbackPlugin;          ///< Used to access feedback support
558   FeedbackController*                   mFeedbackController;          ///< Plays feedback effects for Dali-Toolkit UI Controls.
559   Dali::TtsPlayer                       mTtsPlayers[Dali::TtsPlayer::MODE_NUM];                   ///< Provides TTS support
560   ObserverContainer                     mObservers;                   ///< A list of adaptor observer pointers
561   DragAndDropDetectorPtr                mDragAndDropDetector;         ///< The Drag & Drop detector
562   RotationObserver*                     mDeferredRotationObserver;    ///< deferred Rotation observer needs event handler
563   EnvironmentOptions*                   mEnvironmentOptions;          ///< environment options
564   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
565   KernelTrace                           mKernelTracer;                ///< Kernel tracer
566   SystemTrace                           mSystemTracer;                ///< System tracer
567   TriggerEventFactory                   mTriggerEventFactory;         ///< Trigger event factory
568   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
569   SocketFactory                         mSocketFactory;               ///< Socket factory
570   const bool                            mEnvironmentOptionsOwned:1;   ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
571 public:
572   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
573 };
574
575 } // namespace Internal
576
577 } // namespace Adaptor
578
579 } // namespace Dali
580
581 #endif // __DALI_INTERNAL_ADAPTOR_IMPL_H__