Changed shared_ptr to unique_ptr for Priv storage in fluid::View

pull/15907/head
Ruslan Garnov 5 years ago
parent 6c93e42d94
commit 65ccafd494
  1. 8
      modules/gapi/include/opencv2/gapi/fluid/gfluidbuffer.hpp
  2. 2
      modules/gapi/include/opencv2/gapi/fluid/gfluidkernel.hpp
  3. 6
      modules/gapi/src/backends/fluid/gfluidbackend.cpp
  4. 25
      modules/gapi/src/backends/fluid/gfluidbuffer.cpp
  5. 4
      modules/gapi/src/backends/fluid/gfluidbuffer_priv.hpp
  6. 2
      modules/gapi/test/gapi_kernel_tests.cpp

@ -85,10 +85,13 @@ public:
Priv& priv(); // internal use only
const Priv& priv() const; // internal use only
View(Priv* p);
View(std::unique_ptr<Priv>&& p);
View(View&& v);
View& operator=(View&& v);
~View();
private:
std::shared_ptr<Priv> m_priv;
std::unique_ptr<Priv> m_priv;
const Cache* m_cache;
};
@ -139,6 +142,7 @@ public:
inline const GMatDesc& meta() const { return m_cache->m_desc; }
View mkView(int borderSize, bool ownStorage);
void addView(const View* v);
class GAPI_EXPORTS Priv; // internal use only
Priv& priv(); // internal use only

@ -172,7 +172,7 @@ template<> struct fluid_get_in<cv::GMat>
{
static const cv::gapi::fluid::View& get(const cv::GArgs &in_args, int idx)
{
return in_args[idx].unsafe_get<cv::gapi::fluid::View>();
return *in_args[idx].unsafe_get<cv::gapi::fluid::View*>();
}
};

@ -880,10 +880,10 @@ cv::gimpl::GFluidExecutable::GFluidExecutable(const ade::Graph
auto inEdge = GModel::getInEdgeByPort(m_g, agent->op_handle, in_idx);
auto ownStorage = fg.metadata(inEdge).get<FluidUseOwnBorderBuffer>().use;
gapi::fluid::View view = buffer.mkView(fu.border_size, ownStorage);
// NB: It is safe to keep ptr as view lifetime is buffer lifetime
agent->in_views[in_idx] = view;
agent->in_args[in_idx] = GArg(view);
agent->in_views[in_idx] = buffer.mkView(fu.border_size, ownStorage);
agent->in_args[in_idx] = GArg(&agent->in_views[in_idx]);
buffer.addView(&agent->in_views[in_idx]);
}
else
{

@ -577,7 +577,7 @@ bool fluid::Buffer::Priv::full() const
{
// reset with maximum possible value and then find minimum
slowest_y = m_desc.size.height;
for (const auto &v : m_views) slowest_y = std::min(slowest_y, v.y());
for (const auto &v : m_views) slowest_y = std::min(slowest_y, v->y());
}
return m_write_caret + lpi() - slowest_y > m_storage->rows();
@ -609,7 +609,7 @@ void fluid::Buffer::Priv::reset()
int fluid::Buffer::Priv::size() const
{
std::size_t view_sz = 0;
for (const auto &v : m_views) view_sz += v.priv().size();
for (const auto &v : m_views) view_sz += v->priv().size();
auto total = view_sz;
if (m_storage) total += m_storage->size();
@ -693,17 +693,24 @@ int fluid::Buffer::lpi() const
return m_priv->lpi();
}
fluid::View::View(Priv* p)
: m_priv(p), m_cache(&p->cache())
fluid::View::View(std::unique_ptr<Priv>&& p)
: m_priv(std::move(p)), m_cache(&m_priv->cache())
{ /* nothing */ }
fluid::View::View(View&&) = default;
fluid::View& fluid::View::operator=(View&&) = default;
fluid::View::~View() = default;
fluid::View fluid::Buffer::mkView(int borderSize, bool ownStorage)
{
// FIXME: logic outside of Priv (because View takes pointer to Buffer)
auto view = ownStorage ? View(new ViewPrivWithOwnBorder(this, borderSize))
: View(new ViewPrivWithoutOwnBorder(this, borderSize));
m_priv->addView(view);
return view;
return ownStorage ? View(std::unique_ptr<ViewPrivWithOwnBorder>(new ViewPrivWithOwnBorder(this, borderSize)))
: View(std::unique_ptr<ViewPrivWithoutOwnBorder>(new ViewPrivWithoutOwnBorder(this, borderSize)));
}
void fluid::Buffer::addView(const View* v)
{
m_priv->addView(v);
}
void fluid::debugBufferPriv(const fluid::Buffer& buffer, std::ostream &os)
@ -717,7 +724,7 @@ void fluid::debugBufferPriv(const fluid::Buffer& buffer, std::ostream &os)
<<" (phys " << "[" << p.storage().cols() << " x " << p.storage().rows() << "]" << ") :"
<< " w: " << p.m_write_caret
<< ", r: [";
for (const auto &v : p.m_views) { os << &v.priv() << ":" << v.y() << " "; }
for (const auto &v : p.m_views) { os << &v->priv() << ":" << v->y() << " "; }
os << "], avail: " << buffer.linesReady()
<< std::endl;
}

@ -239,7 +239,7 @@ class GAPI_EXPORTS Buffer::Priv
int m_write_caret = -1;
std::vector<View> m_views;
std::vector<const View*> m_views;
std::unique_ptr<BufferStorage> m_storage;
@ -265,7 +265,7 @@ public:
void allocate(BorderOpt border, int border_size, int line_consumption, int skew);
void bindTo(const cv::gapi::own::Mat &data, bool is_input);
inline void addView(const View& view) { m_views.push_back(view); }
inline void addView(const View* view) { m_views.emplace_back(view); }
inline const GMatDesc& meta() const { return m_desc; }

@ -101,7 +101,7 @@ namespace
GAPI_FLUID_KERNEL(GClone, I::GClone, false)
{
static const int Window = 1;
static void run(const cv::gapi::fluid::View&, cv::gapi::fluid::Buffer)
static void run(const cv::gapi::fluid::View&, cv::gapi::fluid::Buffer&)
{
HeteroGraph::registerCallKernel(KernelTags::FLUID_CUSTOM_CLONE);
}

Loading…
Cancel
Save