|
|
|
@ -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<AdapterT>(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<Adapter>; |
|
|
|
|
using Adapter = IAdapter; // Keep backward compatibility
|
|
|
|
|
using AdapterP = std::shared_ptr<IAdapter>; |
|
|
|
|
|
|
|
|
|
RMat() = default; |
|
|
|
|
RMat(AdapterP&& a) : m_adapter(std::move(a)) {} |
|
|
|
@ -136,7 +138,7 @@ public: |
|
|
|
|
// return nullptr if underlying type is different
|
|
|
|
|
template<typename T> T* get() const |
|
|
|
|
{ |
|
|
|
|
static_assert(std::is_base_of<Adapter, T>::value, "T is not derived from Adapter!"); |
|
|
|
|
static_assert(std::is_base_of<IAdapter, T>::value, "T is not derived from IAdapter!"); |
|
|
|
|
GAPI_Assert(m_adapter != nullptr); |
|
|
|
|
return dynamic_cast<T*>(m_adapter.get()); |
|
|
|
|
} |
|
|
|
|