From 17234f82d025e3bbfbf611089637e5aa2038e7b8 Mon Sep 17 00:00:00 2001 From: Trutnev Aleksei Date: Mon, 1 Nov 2021 15:43:27 +0300 Subject: [PATCH] Merge pull request #20836 from alexgiving:atrutnev/rename_Adapter_to_IAdapter * Rename RMat::Adapter to RMat::IAdapter * Add comments --- modules/gapi/include/opencv2/gapi/rmat.hpp | 18 ++++++++++-------- modules/gapi/include/opencv2/gapi/s11n.hpp | 2 +- modules/gapi/src/backends/common/gbackend.hpp | 4 ++-- modules/gapi/test/rmat/rmat_test_common.hpp | 4 ++-- modules/gapi/test/rmat/rmat_tests.cpp | 4 ++-- modules/gapi/test/s11n/gapi_s11n_tests.cpp | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/modules/gapi/include/opencv2/gapi/rmat.hpp b/modules/gapi/include/opencv2/gapi/rmat.hpp index 6b289001e7..38668d67a5 100644 --- a/modules/gapi/include/opencv2/gapi/rmat.hpp +++ b/modules/gapi/include/opencv2/gapi/rmat.hpp @@ -25,11 +25,11 @@ namespace cv { // "Remote Mat", a general class which provides an abstraction layer over the data // storage and placement (host, remote device etc) and allows to access this data. // -// The device specific implementation is hidden in the RMat::Adapter class +// The device specific implementation is hidden in the RMat::IAdapter class // // The basic flow is the following: // * Backend which is aware of the remote device: -// - Implements own AdapterT class which is derived from RMat::Adapter +// - Implements own AdapterT class which is derived from RMat::IAdapter // - Wraps device memory into RMat via make_rmat utility function: // cv::RMat rmat = cv::make_rmat(args); // @@ -101,25 +101,27 @@ public: }; enum class Access { R, W }; - class Adapter + class IAdapter + // Adapter class is going to be deleted and renamed as IAdapter { public: - virtual ~Adapter() = default; + virtual ~IAdapter() = default; virtual GMatDesc desc() const = 0; // Implementation is responsible for setting the appropriate callback to // the view when accessed for writing, to ensure that the data from the view // is transferred to the device when the view is destroyed virtual View access(Access) = 0; virtual void serialize(cv::gapi::s11n::IOStream&) { - GAPI_Assert(false && "Generic serialize method of RMat::Adapter does nothing by default. " + GAPI_Assert(false && "Generic serialize method of RMat::IAdapter does nothing by default. " "Please, implement it in derived class to properly serialize the object."); } virtual void deserialize(cv::gapi::s11n::IIStream&) { - GAPI_Assert(false && "Generic deserialize method of RMat::Adapter does nothing by default. " + GAPI_Assert(false && "Generic deserialize method of RMat::IAdapter does nothing by default. " "Please, implement it in derived class to properly deserialize the object."); } }; - using AdapterP = std::shared_ptr; + using Adapter = IAdapter; // Keep backward compatibility + using AdapterP = std::shared_ptr; RMat() = default; RMat(AdapterP&& a) : m_adapter(std::move(a)) {} @@ -136,7 +138,7 @@ public: // return nullptr if underlying type is different template T* get() const { - static_assert(std::is_base_of::value, "T is not derived from Adapter!"); + static_assert(std::is_base_of::value, "T is not derived from IAdapter!"); GAPI_Assert(m_adapter != nullptr); return dynamic_cast(m_adapter.get()); } diff --git a/modules/gapi/include/opencv2/gapi/s11n.hpp b/modules/gapi/include/opencv2/gapi/s11n.hpp index 53800970d1..6863a5ecab 100644 --- a/modules/gapi/include/opencv2/gapi/s11n.hpp +++ b/modules/gapi/include/opencv2/gapi/s11n.hpp @@ -431,7 +431,7 @@ struct deserialize_runarg { static GRunArg exec(cv::gapi::s11n::IIStream& is, uint32_t idx) { if (idx == GRunArg::index_of()) { // Type or void (if not found) - using TA = typename cv::util::find_adapter_impl::type; + using TA = typename cv::util::find_adapter_impl::type; return deserialize_arg_with_adapter::exec(is); } else if (idx == GRunArg::index_of()) { // Type or void (if not found) diff --git a/modules/gapi/src/backends/common/gbackend.hpp b/modules/gapi/src/backends/common/gbackend.hpp index b22ec5e177..f005135d87 100644 --- a/modules/gapi/src/backends/common/gbackend.hpp +++ b/modules/gapi/src/backends/common/gbackend.hpp @@ -45,7 +45,7 @@ namespace gimpl { #endif } - class RMatAdapter : public RMat::Adapter { + class RMatAdapter : public RMat::IAdapter { cv::Mat m_mat; public: const void* data() const { return m_mat.data; } @@ -58,7 +58,7 @@ namespace gimpl { struct Data; struct RcDesc; - struct GAPI_EXPORTS RMatMediaFrameAdapter final: public cv::RMat::Adapter + struct GAPI_EXPORTS RMatMediaFrameAdapter final: public cv::RMat::IAdapter { using MapDescF = std::function; using MapDataF = std::function; diff --git a/modules/gapi/test/rmat/rmat_test_common.hpp b/modules/gapi/test/rmat/rmat_test_common.hpp index 5685d06253..218b21b632 100644 --- a/modules/gapi/test/rmat/rmat_test_common.hpp +++ b/modules/gapi/test/rmat/rmat_test_common.hpp @@ -11,7 +11,7 @@ #include namespace opencv_test { -class RMatAdapterRef : public RMat::Adapter { +class RMatAdapterRef : public RMat::IAdapter { cv::Mat& m_mat; bool& m_callbackCalled; public: @@ -36,7 +36,7 @@ public: virtual cv::GMatDesc desc() const override { return cv::descr_of(m_mat); } }; -class RMatAdapterCopy : public RMat::Adapter { +class RMatAdapterCopy : public RMat::IAdapter { cv::Mat& m_deviceMat; cv::Mat m_hostMat; bool& m_callbackCalled; diff --git a/modules/gapi/test/rmat/rmat_tests.cpp b/modules/gapi/test/rmat/rmat_tests.cpp index 52c3806c5b..ea2f9040e5 100644 --- a/modules/gapi/test/rmat/rmat_tests.cpp +++ b/modules/gapi/test/rmat/rmat_tests.cpp @@ -94,7 +94,7 @@ TYPED_TEST(RMatTypedTest, CorrectAdapterCast) { EXPECT_NE(nullptr, this->rmat().template get()); } -class DummyAdapter : public RMat::Adapter { +class DummyAdapter : public RMat::IAdapter { virtual RMat::View access(RMat::Access) override { return {}; } virtual cv::GMatDesc desc() const override { return {}; } }; @@ -103,7 +103,7 @@ TYPED_TEST(RMatTypedTest, IncorrectAdapterCast) { EXPECT_EQ(nullptr, this->rmat().template get()); } -class RMatAdapterForBackend : public RMat::Adapter { +class RMatAdapterForBackend : public RMat::IAdapter { int m_i; public: RMatAdapterForBackend(int i) : m_i(i) {} diff --git a/modules/gapi/test/s11n/gapi_s11n_tests.cpp b/modules/gapi/test/s11n/gapi_s11n_tests.cpp index 4c6e63b552..94b99f877a 100644 --- a/modules/gapi/test/s11n/gapi_s11n_tests.cpp +++ b/modules/gapi/test/s11n/gapi_s11n_tests.cpp @@ -127,7 +127,7 @@ template<> struct CompileArgTag { } // namespace cv namespace { -class MyRMatAdapter : public cv::RMat::Adapter { +class MyRMatAdapter : public cv::RMat::IAdapter { cv::Mat m_mat; int m_value; std::string m_str;