Return captured results with PixelBuffer
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / capture-impl.h
index 11c29e9..6de3a90 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_CAPTURE_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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 <string>
-#include <memory>
-#include <dali/public-api/object/ref-object.h>
 #include <dali/public-api/object/base-object.h>
+#include <dali/public-api/object/ref-object.h>
 #include <dali/public-api/render-tasks/render-task.h>
-#include <dali/public-api/rendering/texture.h>
 #include <dali/public-api/rendering/frame-buffer.h>
+#include <dali/public-api/rendering/texture.h>
+#include <memory>
+#include <string>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/dali-adaptor-common.h>
-#include <dali/public-api/capture/capture.h>
 #include <dali/public-api/adaptor-framework/native-image-source.h>
 #include <dali/public-api/adaptor-framework/timer.h>
+#include <dali/public-api/capture/capture.h>
+#include <dali/public-api/dali-adaptor-common.h>
+#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 namespace Adaptor
 {
-
 class Capture;
 typedef IntrusivePtr<Capture> CapturePtr;
 
 class Capture : public BaseObject, public ConnectionTracker
 {
 public:
-
   static constexpr uint32_t DEFAULT_QUALITY = 100;
 
   /**
@@ -56,7 +53,7 @@ public:
    */
   Capture();
 
-  Capture( Dali::CameraActor cameraActor );
+  Capture(Dali::CameraActor cameraActor);
 
   /**
    * @copydoc Dali::Capture::New
@@ -66,17 +63,22 @@ public:
   /**
    * @copydoc Dali::Capture::New
    */
-  static CapturePtr New( Dali::CameraActor cameraActor );
+  static CapturePtr New(Dali::CameraActor cameraActor);
 
   /**
    * @copydoc Dali::Capture::Start
    */
-  void Start( Dali::Actor source, const Dali::Vector2& size, const std::string &path, const Dali::Vector4& clearColor, const uint32_t quality );
+  void Start(Dali::Actor source, const Dali::Vector2& position, const Dali::Vector2& size, const std::string& path, const Dali::Vector4& clearColor, const uint32_t quality);
 
   /**
    * @copydoc Dali::Capture::Start
    */
-  void Start( Dali::Actor source, const Dali::Vector2& size, const std::string &path, const Dali::Vector4& clearColor );
+  void Start(Dali::Actor source, const Dali::Vector2& position, const Dali::Vector2& size, const std::string& path, const Dali::Vector4& clearColor);
+
+  /**
+   * @copydoc Dali::Capture::SetImageQuality
+   */
+  void SetImageQuality(uint32_t quality);
 
   /**
    * @copydoc Dali::Capture::GetNativeImageSource
@@ -84,12 +86,16 @@ public:
   Dali::NativeImageSourcePtr GetNativeImageSource() const;
 
   /**
+   * @copydoc Dali::Capture::GetCapturedBuffer
+   */
+  Dali::Devel::PixelBuffer GetCapturedBuffer();
+
+  /**
    * @copydoc Dali::Capture::FinishedSignal
    */
   Dali::Capture::CaptureFinishedSignalType& FinishedSignal();
 
 protected:
-
   /**
    * @brief A reference counted object may only be deleted by calling Unreference()
    */
@@ -97,9 +103,9 @@ protected:
 
 private:
   /**
-   * @brief Create native image source.
+   * @brief Create texture.
    */
-  void CreateNativeImageSource( const Dali::Vector2& size );
+  void CreateTexture(const Dali::Vector2& size);
 
   /**
    * @brief Delete native image source.
@@ -107,13 +113,6 @@ private:
   void DeleteNativeImageSource();
 
   /**
-   * @brief Query whether native image source is created or not.
-   *
-   * @return True is native image source is created.
-   */
-  bool IsNativeImageSourceCreated();
-
-  /**
    * @brief Create frame buffer.
    */
   void CreateFrameBuffer();
@@ -133,10 +132,13 @@ private:
   /**
    * @brief Setup render task.
    *
-   * @param[in] source is captured.
+   * @param[in] position top-left position of area to be captured
+   *            this position is defined in the window.
+   * @param[in] size two dimensional size of area to be captured
+   * @param[in] source sub-scene tree to be captured.
    * @param[in] clearColor background color
    */
-  void SetupRenderTask( Dali::Actor source, const Dali::Vector4& clearColor );
+  void SetupRenderTask(const Dali::Vector2& position, const Dali::Vector2& size, Dali::Actor source, const Dali::Vector4& clearColor);
 
   /**
    * @brief Unset render task.
@@ -153,11 +155,13 @@ private:
   /**
    * @brief Setup resources for capture.
    *
-   * @param[in] size is surface size.
-   * @param[in] clearColor is clear color of surface.
-   * @param[in] source is captured.
+   * @param[in] position top-left position of area to be captured
+   *            this position is defined in the window.
+   * @param[in] size two dimensional size of area to be captured
+   * @param[in] clearColor color to clear background surface.
+   * @param[in] source sub-scene tree to be captured.
    */
-  void SetupResources( const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source );
+  void SetupResources(const Dali::Vector2& position, const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source);
 
   /**
    * @brief Unset resources for capture.
@@ -169,7 +173,7 @@ private:
    *
    * @param[in] task is used for capture.
    */
-  void OnRenderFinished( Dali::RenderTask& task );
+  void OnRenderFinished(Dali::RenderTask& task);
 
   /**
    * @brief Callback when timer is finished.
@@ -186,51 +190,50 @@ private:
   bool SaveFile();
 
 private:
-
   // Undefined
-  Capture( const Capture& );
+  Capture(const Capture&);
 
   // Undefined
-  Capture& operator=( const Capture& rhs );
+  Capture& operator=(const Capture& rhs);
 
 private:
-  uint32_t                                    mQuality;
-  Dali::Texture                               mNativeTexture;
-  Dali::FrameBuffer                           mFrameBuffer;
-  Dali::RenderTask                            mRenderTask;
-  Dali::Actor                                 mParent;
-  Dali::Actor                                 mSource;
-  Dali::CameraActor                           mCameraActor;
-  Dali::Timer                                 mTimer;           ///< For timeout.
-  Dali::Capture::CaptureFinishedSignalType    mFinishedSignal;
-  std::string                                 mPath;
-  Dali::NativeImageSourcePtr                  mNativeImageSourcePtr;  ///< pointer to surface image
-  bool                                        mFileSave;
+  uint32_t                                 mQuality;
+  Dali::Texture                            mTexture;
+  Dali::FrameBuffer                        mFrameBuffer;
+  Dali::RenderTask                         mRenderTask;
+  Dali::Actor                              mSource;
+  Dali::CameraActor                        mCameraActor;
+  Dali::Timer                              mTimer; ///< For timeout.
+  Dali::Capture::CaptureFinishedSignalType mFinishedSignal;
+  std::string                              mPath;
+  Dali::NativeImageSourcePtr               mNativeImageSourcePtr; ///< pointer to surface image
+  Dali::Devel::PixelBuffer                 mPixelBuffer;
+  bool                                     mFileSave;
 };
 
-}  // End of namespace Adaptor
-}  // End of namespace Internal
+} // End of namespace Adaptor
+} // End of namespace Internal
 
 // Helpers for public-api forwarding methods
 
-inline Internal::Adaptor::Capture& GetImpl( Dali::Capture& captureWorker)
+inline Internal::Adaptor::Capture& GetImpl(Dali::Capture& captureWorker)
 {
-  DALI_ASSERT_ALWAYS( captureWorker && "Capture handle is empty" );
+  DALI_ASSERT_ALWAYS(captureWorker && "Capture handle is empty");
 
   BaseObject& handle = captureWorker.GetBaseObject();
 
-  return static_cast< Internal::Adaptor::Capture& >( handle );
+  return static_cast<Internal::Adaptor::Capture&>(handle);
 }
 
-inline const Internal::Adaptor::Capture& GetImpl( const Dali::Capture& captureWorker )
+inline const Internal::Adaptor::Capture& GetImpl(const Dali::Capture& captureWorker)
 {
-  DALI_ASSERT_ALWAYS( captureWorker && "Capture handle is empty" );
+  DALI_ASSERT_ALWAYS(captureWorker && "Capture handle is empty");
 
   const BaseObject& handle = captureWorker.GetBaseObject();
 
-  return static_cast< const Internal::Adaptor::Capture& >( handle );
+  return static_cast<const Internal::Adaptor::Capture&>(handle);
 }
 
-}  // End of namespace Dali
+} // End of namespace Dali
 
 #endif // DALI_INTERNAL_CAPTURE_H