Merge "Changed 'virtual' function override declarations to 'override' in automated...
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-render-surface.h
index 1e0e5b0..395656f 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
  *
  */
 
+// EXTERNAL INCLUDES
+#include <dali/public-api/signals/connection-tracker.h>
+#include <dali/public-api/signals/dali-signal.h>
+#include <dali/devel-api/threading/mutex.h>
+#include <dali/integration-api/scene.h>
+#include <unistd.h>
+
 // INTERNAL INCLUDES
-#include <dali/integration-api/render-surface.h>
+#include <dali/integration-api/adaptor-framework/egl-interface.h>
+#include <dali/integration-api/adaptor-framework/render-surface-interface.h>
+#include <dali/internal/graphics/common/graphics-interface.h>
+#include <dali/internal/system/common/file-descriptor-monitor.h>
 
 namespace Dali
 {
@@ -31,47 +41,62 @@ namespace Internal
 namespace Adaptor
 {
 
+class WindowBase;
+class AdaptorInternalServices;
+
 /**
  * Window interface of render surface.
  */
-class WindowRenderSurface : public Dali::RenderSurface
+class WindowRenderSurface : public Dali::RenderSurfaceInterface, public ConnectionTracker
 {
 public:
 
+  using OutputSignalType = Signal< void ( ) >;
+  using DamagedRectsContainer = std::list< std::vector< Rect< int > > >;
+
   /**
-   * @brief Default constructor
-   */
-  WindowRenderSurface() = default;
+    * Uses an window surface to render to.
+    * @param [in] positionSize the position and size of the surface
+    * @param [in] surface can be a window or pixmap.
+    * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
+    */
+  WindowRenderSurface( Dali::PositionSize positionSize, Any surface, bool isTransparent = false );
 
   /**
    * @brief Destructor
    */
-  virtual ~WindowRenderSurface() = default;
+  virtual ~WindowRenderSurface();
 
 public: // API
 
   /**
-   * @brief Get the render surface the adaptor is using to render to.
-   * @return reference to current render surface
+   * @brief Get the native window handle
+   * @return The native window handle
    */
-  virtual Any GetWindow() = 0;
+  Any GetNativeWindow();
+
+  /**
+   * @brief Get the native window id
+   * @return The native window id
+   */
+  int GetNativeWindowId();
 
   /**
    * @brief Map window
    */
-  virtual void Map() = 0;
+  void Map();
 
   /**
    * @brief Sets the render notification trigger to call when render thread is completed a frame
    * @param renderNotification to use
    */
-  virtual void SetRenderNotification( TriggerEventInterface* renderNotification ) = 0;
+  void SetRenderNotification( TriggerEventInterface* renderNotification );
 
   /**
    * @brief Sets whether the surface is transparent or not.
    * @param[in] transparent Whether the surface is transparent
    */
-  virtual void SetTransparency( bool transparent ) = 0;
+  void SetTransparency( bool transparent );
 
   /**
    * Request surface rotation
@@ -79,25 +104,146 @@ public: // API
    * @param[in] width A new width of the surface
    * @param[in] height A new height of the surface
    */
-  virtual void RequestRotation( int angle, int width, int height ) = 0;
+  void RequestRotation( int angle, int width, int height );
 
-protected:
+  /**
+   * @brief Gets the window base object
+   * @return The window base object
+   */
+  WindowBase* GetWindowBase();
+
+  /**
+   * @brief This signal is emitted when the output is transformed.
+   */
+  OutputSignalType& OutputTransformedSignal();
+
+public: // from Dali::RenderSurfaceInterface
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
+   */
+  PositionSize GetPositionSize() const override;
+
+  /**
+   */
+  void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
+   */
+  void InitializeGraphics() override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
+   */
+  void CreateSurface() override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
+   */
+  void DestroySurface() override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
+   */
+  bool ReplaceGraphicsSurface() override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::MoveResize()
+   */
+  void MoveResize( Dali::PositionSize positionSize) override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::StartRender()
+   */
+  void StartRender() override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::PreRender()
+   */
+  bool PreRender( bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect ) override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::PostRender()
+   */
+  void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects ) override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::StopRender()
+   */
+  void StopRender() override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
+   */
+  void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
+   */
+  void ReleaseLock() override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
+   */
+  Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
+   */
+  void MakeContextCurrent() override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
+   */
+  Integration::DepthBufferAvailable GetDepthBufferRequired() override;
+
+  /**
+   * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
+   */
+  Integration::StencilBufferAvailable GetStencilBufferRequired() override;
+
+private:
 
   /**
    * @brief Second stage construction
    */
-  virtual void Initialize( Any surface ) = 0;
+  void Initialize( Any surface );
+
+  /**
+   * Notify output is transformed.
+   */
+  void OutputTransformed();
+
+  /**
+   * @brief Used as the callback for the rotation-trigger.
+   */
+  void ProcessRotationRequest();
+
+  /**
+   * @brief Used as the callback for the frame rendered / presented.
+   */
+  void ProcessFrameCallback();
 
   /**
-   * @brief Create window
+   * @brief Called when our event file descriptor has been written to.
+   * @param[in] eventBitMask bit mask of events that occured on the file descriptor
+   * @param[in] fileDescriptor The file descriptor
    */
-  virtual void CreateRenderable() = 0;
+  void OnFileDescriptorEventDispatched( FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor );
 
   /**
-   * @brief Use an existing render surface
-   * @param surfaceId the id of the surface
+   * @brief Set the buffer damage rects.
+   * @param[in] damagedRects List of damaged rects
+   * @param[in] clippingRect The rect to clip rendered scene
    */
-  virtual void UseExistingRenderable( unsigned int surfaceId ) = 0;
+  void SetBufferDamagedRects( const std::vector< Rect< int > >& damagedRects, Rect< int >& clippingRect );
+
+  /**
+   * @brief Swap buffers.
+   * @param[in] damagedRects List of damaged rects
+   */
+  void SwapBuffers( const std::vector<Rect<int>>& damagedRects );
 
 protected:
 
@@ -107,6 +253,64 @@ protected:
   // Undefined
   WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
 
+private:
+
+  struct FrameCallbackInfo
+  {
+    FrameCallbackInfo( Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd )
+    : callbacks(),
+      fileDescriptorMonitor(),
+      fileDescriptor( fd )
+    {
+      // Transfer owership of the CallbackBase
+      for( auto&& iter : callbackList )
+      {
+        callbacks.push_back( std::make_pair( std::move( iter.first ), iter.second ) );
+      }
+    }
+
+    ~FrameCallbackInfo()
+    {
+      // Delete FileDescriptorMonitor before close fd.
+      fileDescriptorMonitor.release();
+      close( fileDescriptor );
+    }
+
+    Dali::Integration::Scene::FrameCallbackContainer callbacks;
+    std::unique_ptr< FileDescriptorMonitor > fileDescriptorMonitor;
+    int fileDescriptor;
+  };
+
+  using FrameCallbackInfoContainer = std::vector< std::unique_ptr< FrameCallbackInfo > >;
+
+private: // Data
+
+  EglInterface*                   mEGL;
+  Dali::DisplayConnection*        mDisplayConnection;
+  PositionSize                    mPositionSize;       ///< Position
+  std::unique_ptr< WindowBase >   mWindowBase;
+  ThreadSynchronizationInterface* mThreadSynchronization;
+  TriggerEventInterface*          mRenderNotification; ///< Render notification trigger
+  TriggerEventInterface*          mRotationTrigger;
+  std::unique_ptr< TriggerEventInterface > mFrameRenderedTrigger;
+  GraphicsInterface*              mGraphics;           ///< Graphics interface
+  EGLSurface                      mEGLSurface;
+  EGLContext                      mEGLContext;
+  ColorDepth                      mColorDepth;         ///< Color depth of surface (32 bit or 24 bit)
+  OutputSignalType                mOutputTransformedSignal;
+  FrameCallbackInfoContainer      mFrameCallbackInfoContainer;
+  DamagedRectsContainer           mBufferDamagedRects;
+  Dali::Mutex                     mMutex;
+  int                             mRotationAngle;
+  int                             mScreenRotationAngle;
+  uint32_t                        mDpiHorizontal;
+  uint32_t                        mDpiVertical;
+  bool                            mOwnSurface;         ///< Whether we own the surface (responsible for deleting it)
+  bool                            mRotationSupported;
+  bool                            mRotationFinished;
+  bool                            mScreenRotationFinished;
+  bool                            mResizeFinished;
+
 }; // class WindowRenderSurface
 
 } // namespace Adaptor