Revert "[Tizen] Apply screen rotation to create window"
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-render-surface.h
index b27414a..c00395f 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H
 
 /*
- * Copyright (c) 2019 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/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
 {
@@ -47,7 +51,8 @@ class WindowRenderSurface : public Dali::RenderSurfaceInterface, public Connecti
 {
 public:
 
-  typedef Signal< void ( ) > OutputSignalType;
+  using OutputSignalType = Signal< void ( ) >;
+  using DamagedRectsContainer = std::list< std::vector< Rect< int > > >;
 
   /**
     * Uses an window surface to render to.
@@ -112,16 +117,16 @@ public: // API
    */
   OutputSignalType& OutputTransformedSignal();
 
-public: // from Dali::Integration::RenderSurface
+public: // from Dali::RenderSurfaceInterface
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::GetPositionSize()
+   * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
    */
-  virtual PositionSize GetPositionSize() const override;
+  PositionSize GetPositionSize() const override;
 
   /**
    */
-  virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) override;
+  void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) override;
 
   /**
    * @brief Return the orientation of the surface.
@@ -130,79 +135,79 @@ public: // from Dali::Integration::RenderSurface
   virtual int GetOrientation() const override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::InitializeGraphics()
+   * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
    */
-  virtual void InitializeGraphics() override;
+  void InitializeGraphics() override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::CreateSurface()
+   * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
    */
-  virtual void CreateSurface() override;
+  void CreateSurface() override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::DestroySurface()
+   * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
    */
-  virtual void DestroySurface() override;
+  void DestroySurface() override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::ReplaceGraphicsSurface()
+   * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
    */
-  virtual bool ReplaceGraphicsSurface() override;
+  bool ReplaceGraphicsSurface() override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::MoveResize()
+   * @copydoc Dali::RenderSurfaceInterface::MoveResize()
    */
-  virtual void MoveResize( Dali::PositionSize positionSize) override;
+  void MoveResize( Dali::PositionSize positionSize) override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::StartRender()
+   * @copydoc Dali::RenderSurfaceInterface::StartRender()
    */
-  virtual void StartRender() override;
+  void StartRender() override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::PreRender()
+   * @copydoc Dali::RenderSurfaceInterface::PreRender()
    */
-  virtual bool PreRender( bool resizingSurface ) override;
+  bool PreRender( bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect ) override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::PostRender()
+   * @copydoc Dali::RenderSurfaceInterface::PostRender()
    */
-  virtual void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface );
+  void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects ) override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::StopRender()
+   * @copydoc Dali::RenderSurfaceInterface::StopRender()
    */
-  virtual void StopRender() override;
+  void StopRender() override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::SetThreadSynchronization
+   * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
    */
-  virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) override;
+  void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::ReleaseLock()
+   * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
    */
-  virtual void ReleaseLock() override;
+  void ReleaseLock() override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::GetSurfaceType()
+   * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
    */
-  virtual Integration::RenderSurface::Type GetSurfaceType() override;
+  Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::MakeContextCurrent()
+   * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
    */
-  virtual void MakeContextCurrent() override;
+  void MakeContextCurrent() override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::GetDepthBufferRequired()
+   * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
    */
-  virtual Integration::DepthBufferAvailable GetDepthBufferRequired() override;
+  Integration::DepthBufferAvailable GetDepthBufferRequired() override;
 
   /**
-   * @copydoc Dali::Integration::RenderSurface::GetStencilBufferRequired()
+   * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
    */
-  virtual Integration::StencilBufferAvailable GetStencilBufferRequired() override;
+  Integration::StencilBufferAvailable GetStencilBufferRequired() override;
 
 private:
 
@@ -221,6 +226,31 @@ private:
    */
   void ProcessRotationRequest();
 
+  /**
+   * @brief Used as the callback for the frame rendered / presented.
+   */
+  void ProcessFrameCallback();
+
+  /**
+   * @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
+   */
+  void OnFileDescriptorEventDispatched( FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor );
+
+  /**
+   * @brief Set the buffer damage rects.
+   * @param[in] damagedRects List of damaged rects
+   * @param[in] clippingRect The rect to clip rendered scene
+   */
+  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:
 
   // Undefined
@@ -229,6 +259,36 @@ 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;
@@ -238,22 +298,25 @@ private: // Data
   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;
 
-  uint32_t                        mDpiHorizontal;
-  uint32_t                        mDpiVertical;
-
 }; // class WindowRenderSurface
 
 } // namespace Adaptor