[Tizen] Revert "Not ref counting the windows in the adaptor"
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / adaptor-impl.h
index d014622..f0ff13c 100755 (executable)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_ADAPTOR_IMPL_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 // INTERNAL INCLUDES
 #include <dali/integration-api/adaptor.h>
+#include <dali/integration-api/scene.h>
+
+#ifdef DALI_ADAPTOR_COMPILATION
+#include <dali/integration-api/scene-holder-impl.h>
+#else
+#include <dali/integration-api/adaptors/scene-holder-impl.h>
+#endif
+
 #include <dali/public-api/adaptor-framework/tts-player.h>
 #include <dali/devel-api/adaptor-framework/clipboard.h>
 
@@ -37,7 +45,6 @@
 #include <dali/internal/adaptor/common/adaptor-internal-services.h>
 #include <dali/internal/system/common/environment-options.h>
 #include <dali/internal/system/common/core-event-interface.h>
-#include <dali/internal/input/common/drag-and-drop-detector-impl.h>
 #include <dali/internal/window-system/common/damage-observer.h>
 #include <dali/internal/window-system/common/window-visibility-observer.h>
 #include <dali/internal/system/common/kernel-trace.h>
 namespace Dali
 {
 
-class RenderSurface;
-class Window;
+class RenderSurfaceInterface;
 
 namespace Integration
 {
 class Core;
 class GlAbstraction;
+class Processor;
 }
 
 namespace Internal
@@ -65,7 +72,6 @@ namespace Adaptor
 {
 class DisplayConnection;
 class GraphicsFactory;
-class EventHandler;
 class GestureManager;
 class GlImplementation;
 class GlSyncImplementation;
@@ -74,11 +80,11 @@ class TriggerEvent;
 class CallbackManager;
 class FeedbackPluginProxy;
 class FeedbackController;
-class RotationObserver;
 class VSyncMonitor;
 class PerformanceInterface;
 class LifeCycleObserver;
 class ObjectProfiler;
+class SceneHolder;
 
 /**
  * Implementation of the Adaptor class.
@@ -91,38 +97,39 @@ class Adaptor : public Integration::RenderController,
 {
 public:
 
-  typedef Dali::Adaptor::AdaptorSignalType AdaptorSignalType;
+  using AdaptorSignalType =  Dali::Adaptor::AdaptorSignalType;
+  using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType;
 
-  typedef Uint16Pair SurfaceSize;          ///< Surface size type
+  using SurfaceSize = Uint16Pair;          ///< Surface size type
 
   /**
    * Creates a New Adaptor
-   * @param[in]  nativeWindow        Native window handle
+   * @param[in]  window              The window handle
    * @param[in]  surface             A render surface can be one of the following
    *                                  - Pixmap, adaptor will use existing Pixmap to draw on to
    *                                  - Window, adaptor will use existing Window to draw on to
    * @param[in]  configuration       The context loss configuration ( to choose resource discard policy )
    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
    */
-  static Dali::Adaptor* New( Any nativeWindow,
-                             RenderSurface* surface,
+  static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
+                             Dali::RenderSurfaceInterface* surface,
                              Dali::Configuration::ContextLoss configuration,
                              EnvironmentOptions* environmentOptions );
 
   /**
    * Creates a New Adaptor
-   * @param[in]  nativeWindow        native window handle
+   * @param[in]  window              The window handle
    * @param[in]  configuration       The context loss configuration ( to choose resource discard policy )
    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
    */
-  static Dali::Adaptor* New( Dali::Window window,
+  static Dali::Adaptor* New( Dali::Integration::SceneHolder window,
                              Dali::Configuration::ContextLoss configuration,
                              EnvironmentOptions* environmentOptions );
 
   /**
    * Creates a New Adaptor
    * @param[in]  graphicsFactory     A factory that creates the graphics interface
-   * @param[in]  nativeWindow        Native window handle
+   * @param[in]  window              The window handle
    * @param[in]  surface             A render surface can be one of the following
    *                                  - Pixmap, adaptor will use existing Pixmap to draw on to
    *                                  - Window, adaptor will use existing Window to draw on to
@@ -130,20 +137,20 @@ public:
    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
    */
   static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
-                             Any nativeWindow,
-                             RenderSurface* surface,
+                             Dali::Integration::SceneHolder window,
+                             Dali::RenderSurfaceInterface* surface,
                              Dali::Configuration::ContextLoss configuration,
                              EnvironmentOptions* environmentOptions );
 
   /**
    * Creates a New Adaptor
    * @param[in]  graphicsFactory     A factory that creates the graphics interface
-   * @param[in]  nativeWindow        native window handle
+   * @param[in]  window              The window handle
    * @param[in]  configuration       The context loss configuration ( to choose resource discard policy )
    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
    */
   static Dali::Adaptor* New( GraphicsFactory& graphicsFactory,
-                             Dali::Window window,
+                             Dali::Integration::SceneHolder window,
                              Dali::Configuration::ContextLoss configuration,
                              EnvironmentOptions* environmentOptions );
 
@@ -221,14 +228,14 @@ public: // AdaptorInternalServices implementation
   virtual void FeedKeyEvent( KeyEvent& keyEvent );
 
   /**
-   * @copydoc AdaptorInterface::ReplaceSurface()
+   * @copydoc Dali::Adaptor::ReplaceSurface()
    */
-  virtual void ReplaceSurface( Any nativeWindow, RenderSurface& surface );
+  virtual void ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface );
 
   /**
    * @copydoc Dali::Adaptor::GetSurface()
    */
-  virtual RenderSurface& GetSurface() const;
+  virtual Dali::RenderSurfaceInterface& GetSurface() const;
 
   /**
    * @copydoc Dali::Adaptor::ReleaseSurfaceLock()
@@ -254,16 +261,16 @@ public: // AdaptorInternalServices implementation
    * @param[in]  childWindowClassName The class name that the child window belongs to
    * @param[in]  childWindowMode The mode of the child window
    */
-  virtual bool AddWindow( Dali::Window* childWindow,
+  virtual bool AddWindow( Dali::Integration::SceneHolder childWindow,
                           const std::string& childWindowName,
                           const std::string& childWindowClassName,
-                          const bool& childWindowMode );
+                          bool childWindowMode );
 
   /**
    * Removes an existing Window instance from the Adaptor
    * @param[in]  window The Window instance
    */
-  virtual bool RemoveWindow( Dali::Window* childWindow );
+  virtual bool RemoveWindow( Dali::Integration::SceneHolder* childWindow );
 
   /**
    * Removes an existing Window instance from the Adaptor
@@ -282,41 +289,42 @@ public: // AdaptorInternalServices implementation
    */
   void SetPreRenderCallback( CallbackBase* callback );
 
-public:
-
   /**
-   * @return the Core instance
+   * Removes an existing Window instance from the Adaptor
+   * @param[in]  childWindow The Window instance
    */
-  virtual Dali::Integration::Core& GetCore();
+  bool RemoveWindow( Dali::Internal::Adaptor::SceneHolder* childWindow );
 
   /**
-   * @copydoc Dali::Adaptor::SetRenderRefreshRate()
+   * @brief Retrieve the window that the given actor is added to.
+   *
+   * @param[in] actor The actor
+   * @return The window the actor is added to or a null pointer if the actor is not added to any widnow.
    */
-  void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
+  Dali::Internal::Adaptor::SceneHolder* GetWindow( Dali::Actor& actor );
 
   /**
-   * @copydoc Dali::Adaptor::SetUseHardwareVSync()
+   * @copydoc Dali::Adaptor::GetWindows()
    */
-  void SetUseHardwareVSync(bool useHardware);
+  Dali::WindowContainer GetWindows() const;
+
+public:
 
   /**
-   * Return the PlatformAbstraction.
-   * @return The PlatformAbstraction.
+   * @return the Core instance
    */
-  Integration::PlatformAbstraction& GetPlatformAbstraction() const;
+  virtual Dali::Integration::Core& GetCore();
 
   /**
-   * Sets the Drag & Drop Listener.
-   * @param[in] detector The detector to send Drag & Drop events to.
+   * @copydoc Dali::Adaptor::SetRenderRefreshRate()
    */
-  void SetDragAndDropDetector( DragAndDropDetectorPtr detector );
+  void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
 
   /**
-   * Sets a rotation observer, or set to NULL to remove.
-   * @pre Adaptor::Start() has been called ( to create EventHandler )
-   * @param[in] observer The observer to listen for window rotation events
+   * Return the PlatformAbstraction.
+   * @return The PlatformAbstraction.
    */
-  void SetRotationObserver( RotationObserver* observer );
+  Integration::PlatformAbstraction& GetPlatformAbstraction() const;
 
   /**
    * Destroy the TtsPlayer of specific mode.
@@ -325,14 +333,6 @@ public:
   void DestroyTtsPlayer(Dali::TtsPlayer::Mode mode);
 
   /**
-   * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
-   * trigger a pinch gesture
-   *
-   * @param[in] distance The minimum pinch distance in pixels
-   */
-  void SetMinimumPinchDistance(float distance);
-
-  /**
    * Gets native window handle
    *
    * @return native window handle
@@ -379,11 +379,6 @@ public:
   void RequestUpdateOnce();
 
   /**
-   * Request adaptor to update indicator's height
-   */
-  void IndicatorSizeChanged(int height);
-
-  /**
    * @copydoc Dali::Adaptor::NotifySceneCreated()
    */
   void NotifySceneCreated();
@@ -399,14 +394,14 @@ public:
   void GetAppId( std::string& appId );
 
   /**
-   * Informs core the surface size has changed
+   * @copydoc Dali::Adaptor::SurfaceResizePrepare
    */
-  void SurfaceResizePrepare( SurfaceSize surfaceSize );
+  void SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
 
   /**
-   * Informs ThreadController the surface size has changed
+   * @copydoc Dali::Adaptor::SurfaceResizeComplete
    */
-  void SurfaceResizeComplete( SurfaceSize surfaceSize );
+  void SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize );
 
   /**
    * Sets layout direction of root by system language
@@ -424,6 +419,16 @@ public:
    */
   const LogFactoryInterface& GetLogFactory();
 
+  /**
+   * @copydoc Dali::Adaptor::RegisterProcessor
+   */
+  void RegisterProcessor( Integration::Processor& processor );
+
+  /**
+   * @coydoc Dali::Adaptor::UnregisterProcessor
+   */
+  void UnregisterProcessor( Integration::Processor& processor );
+
 public:  //AdaptorInternalServices
 
   /**
@@ -459,12 +464,7 @@ public:  //AdaptorInternalServices
   /**
    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
    */
-  virtual RenderSurface* GetRenderSurfaceInterface();
-
-  /**
-   * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetVSyncMonitorInterface()
-   */
-  virtual VSyncMonitorInterface* GetVSyncMonitorInterface();
+  virtual Dali::RenderSurfaceInterface* GetRenderSurfaceInterface();
 
   /**
    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetPerformanceInterface()
@@ -499,18 +499,28 @@ public: // Signals
     return mLanguageChangedSignal;
   }
 
-private: // From Dali::Internal::Adaptor::CoreEventInterface
-
   /**
-   * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
+   * @copydoc Dali::Adaptor::WindowCreatedSignal
    */
-  virtual void QueueCoreEvent(const Dali::Integration::Event& event);
+  WindowCreatedSignalType& WindowCreatedSignal()
+  {
+    return mWindowCreatedSignal;
+  }
+
+public: // From Dali::Internal::Adaptor::CoreEventInterface
 
   /**
    * @copydoc Dali::Internal::Adaptor:CoreEventInterface:::ProcessCoreEvents()
    */
   virtual void ProcessCoreEvents();
 
+private: // From Dali::Internal::Adaptor::CoreEventInterface
+
+  /**
+   * @copydoc Dali::Internal::Adaptor::CoreEventInterface::QueueCoreEvent()
+   */
+  virtual void QueueCoreEvent(const Dali::Integration::Event& event);
+
 private: // From Dali::Integration::RenderController
 
   /**
@@ -523,7 +533,7 @@ private: // From Dali::Integration::RenderController
    */
   virtual void RequestProcessEventsOnIdle( bool forceProcess );
 
-private: // From Dali::Internal::Adaptor::WindowVisibilityObserver
+public: // From Dali::Internal::Adaptor::WindowVisibilityObserver
 
   /**
    * Called when the window becomes fully or partially visible.
@@ -554,7 +564,7 @@ private:
    * Assigns the render surface to the adaptor
    *
    */
-  void SetSurface(RenderSurface *surface);
+  void SetSurface(Dali::RenderSurfaceInterface *surface);
 
   /**
    * called after surface is created
@@ -597,69 +607,55 @@ private:
 
   /**
    * Constructor
-   * @param[in]  nativeWindow native window handle
+   * @param[in]  window       window handle
    * @param[in]  adaptor      The public adaptor
    * @param[in]  surface      A render surface can be one of the following
    *                          - Pixmap, adaptor will use existing Pixmap to draw on to
    *                          - Window, adaptor will use existing Window to draw on to
    * @param[in]  environmentOptions  A pointer to the environment options. If NULL then one is created.
    */
-  Adaptor( Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions );
+  Adaptor( Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions );
 
 private: // Types
 
   enum State
   {
-    READY,               ///< Initial state before Adaptor::Start is called.
-    RUNNING,             ///< Adaptor is running.
-    PAUSED,              ///< Adaptor has been paused.
-    PAUSED_WHILE_HIDDEN, ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
-    STOPPED,             ///< Adaptor has been stopped.
+    READY,                     ///< Initial state before Adaptor::Start is called.
+    RUNNING,                   ///< Adaptor is running.
+    PAUSED,                    ///< Adaptor has been paused.
+    PAUSED_WHILE_HIDDEN,       ///< Adaptor is paused while window is hidden (& cannot be resumed until window is shown).
+    PAUSED_WHILE_INITIALIZING, ///< Adaptor is paused while application is initializing.
+    STOPPED,                   ///< Adaptor has been stopped.
   };
 
-  // A structure to encapsulate each Window instance for the Adaptor to track them
-  typedef struct WindowPane
-  {
-    Dali::Window*  instance;     ///< Window object
-    std::string    window_name;  ///< Name (title)_of the window
-    std::string    class_name;   ///< Class name that the window belongs to
-    bool           window_mode;  ///< Display mode of the window
-    Any            nativeWindow; ///< window identifier
-    RenderSurface* surface;      ///< The surface the Window is bound to
-  } WindowPane;
-
-  typedef std::vector<WindowPane> WindowFrames;
-
-  typedef std::vector<LifeCycleObserver*>  ObserverContainer;
+  using SceneHolderPtr = IntrusivePtr< Dali::Internal::Adaptor::SceneHolder >;
+  using WindowContainer = std::vector<SceneHolderPtr>;
+  using ObserverContainer = std::vector<LifeCycleObserver*>;
 
 private: // Data
 
   AdaptorSignalType                     mResizedSignal;               ///< Resized signal.
   AdaptorSignalType                     mLanguageChangedSignal;       ///< Language changed signal.
+  WindowCreatedSignalType               mWindowCreatedSignal;         ///< Window created signal.
 
   Dali::Adaptor&                        mAdaptor;                     ///< Reference to public adaptor instance.
   State                                 mState;                       ///< Current state of the adaptor
   Dali::Integration::Core*              mCore;                        ///< Dali Core
   ThreadController*                     mThreadController;            ///< Controls the threads
-  VSyncMonitor*                         mVSyncMonitor;                ///< Monitors VSync events
 
   GraphicsInterface*                    mGraphics;                    ///< Graphics interface
   Dali::DisplayConnection*              mDisplayConnection;           ///< Display connection
-  WindowFrames                          mWindowFrame;                 ///< A container of all the Windows that are currently created
+  WindowContainer                       mWindows;                     ///< A container of all the Windows that are currently created
 
   TizenPlatform::TizenPlatformAbstraction* mPlatformAbstraction;      ///< Platform abstraction
 
-  EventHandler*                         mEventHandler;                ///< event handler
   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
   bool                                  mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
   TriggerEventInterface*                mNotificationTrigger;         ///< Notification event trigger
-  GestureManager*                       mGestureManager;              ///< Gesture manager
   FeedbackPluginProxy*                  mDaliFeedbackPlugin;          ///< Used to access feedback support
   FeedbackController*                   mFeedbackController;          ///< Plays feedback effects for Dali-Toolkit UI Controls.
   Dali::TtsPlayer                       mTtsPlayers[Dali::TtsPlayer::MODE_NUM];                   ///< Provides TTS support
   ObserverContainer                     mObservers;                   ///< A list of adaptor observer pointers
-  DragAndDropDetectorPtr                mDragAndDropDetector;         ///< The Drag & Drop detector
-  RotationObserver*                     mDeferredRotationObserver;    ///< deferred Rotation observer needs event handler
   EnvironmentOptions*                   mEnvironmentOptions;          ///< environment options
   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
   KernelTrace                           mKernelTracer;                ///< Kernel tracer