Remove std::shared_ptr<GpuBuffer> argument from GetRead/WriteView
PiperOrigin-RevId: 488813004
This commit is contained in:
parent
1c0a1d0aab
commit
13b4b825d7
|
@ -255,9 +255,8 @@ void GlTextureBuffer::WaitForConsumersOnGpu() {
|
||||||
// precisely, on only one GL context.
|
// precisely, on only one GL context.
|
||||||
}
|
}
|
||||||
|
|
||||||
GlTextureView GlTextureBuffer::GetReadView(
|
GlTextureView GlTextureBuffer::GetReadView(internal::types<GlTextureView>,
|
||||||
internal::types<GlTextureView>, std::shared_ptr<GpuBuffer> gpu_buffer,
|
int plane) const {
|
||||||
int plane) const {
|
|
||||||
auto gl_context = GlContext::GetCurrent();
|
auto gl_context = GlContext::GetCurrent();
|
||||||
CHECK(gl_context);
|
CHECK(gl_context);
|
||||||
CHECK_EQ(plane, 0);
|
CHECK_EQ(plane, 0);
|
||||||
|
@ -269,13 +268,11 @@ GlTextureView GlTextureBuffer::GetReadView(
|
||||||
DidRead(texture.gl_context()->CreateSyncToken());
|
DidRead(texture.gl_context()->CreateSyncToken());
|
||||||
};
|
};
|
||||||
return GlTextureView(gl_context.get(), target(), name(), width(), height(),
|
return GlTextureView(gl_context.get(), target(), name(), width(), height(),
|
||||||
std::move(gpu_buffer), plane, std::move(detach),
|
plane, std::move(detach), nullptr);
|
||||||
nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GlTextureView GlTextureBuffer::GetWriteView(
|
GlTextureView GlTextureBuffer::GetWriteView(internal::types<GlTextureView>,
|
||||||
internal::types<GlTextureView>, std::shared_ptr<GpuBuffer> gpu_buffer,
|
int plane) {
|
||||||
int plane) {
|
|
||||||
auto gl_context = GlContext::GetCurrent();
|
auto gl_context = GlContext::GetCurrent();
|
||||||
CHECK(gl_context);
|
CHECK(gl_context);
|
||||||
CHECK_EQ(plane, 0);
|
CHECK_EQ(plane, 0);
|
||||||
|
@ -286,8 +283,7 @@ GlTextureView GlTextureBuffer::GetWriteView(
|
||||||
GlTextureView::DoneWritingFn done_writing =
|
GlTextureView::DoneWritingFn done_writing =
|
||||||
[this](const GlTextureView& texture) { ViewDoneWriting(texture); };
|
[this](const GlTextureView& texture) { ViewDoneWriting(texture); };
|
||||||
return GlTextureView(gl_context.get(), target(), name(), width(), height(),
|
return GlTextureView(gl_context.get(), target(), name(), width(), height(),
|
||||||
std::move(gpu_buffer), plane, nullptr,
|
plane, nullptr, std::move(done_writing));
|
||||||
std::move(done_writing));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlTextureBuffer::ViewDoneWriting(const GlTextureView& view) {
|
void GlTextureBuffer::ViewDoneWriting(const GlTextureView& view) {
|
||||||
|
@ -364,7 +360,7 @@ static std::shared_ptr<GpuBufferStorageImageFrame> ConvertToImageFrame(
|
||||||
absl::make_unique<ImageFrame>(image_format, buf->width(), buf->height(),
|
absl::make_unique<ImageFrame>(image_format, buf->width(), buf->height(),
|
||||||
ImageFrame::kGlDefaultAlignmentBoundary);
|
ImageFrame::kGlDefaultAlignmentBoundary);
|
||||||
buf->GetProducerContext()->Run([buf, &output] {
|
buf->GetProducerContext()->Run([buf, &output] {
|
||||||
auto view = buf->GetReadView(internal::types<GlTextureView>{}, nullptr, 0);
|
auto view = buf->GetReadView(internal::types<GlTextureView>{}, 0);
|
||||||
ReadTexture(view, buf->format(), output->MutablePixelData(),
|
ReadTexture(view, buf->format(), output->MutablePixelData(),
|
||||||
output->PixelDataSize());
|
output->PixelDataSize());
|
||||||
});
|
});
|
||||||
|
@ -393,9 +389,8 @@ static std::shared_ptr<GpuBufferStorageCvPixelBuffer> ConvertToCvPixelBuffer(
|
||||||
buf->width(), buf->height(), buf->format());
|
buf->width(), buf->height(), buf->format());
|
||||||
buf->GetProducerContext()->Run([buf, &output] {
|
buf->GetProducerContext()->Run([buf, &output] {
|
||||||
TempGlFramebuffer framebuffer;
|
TempGlFramebuffer framebuffer;
|
||||||
auto src = buf->GetReadView(internal::types<GlTextureView>{}, nullptr, 0);
|
auto src = buf->GetReadView(internal::types<GlTextureView>{}, 0);
|
||||||
auto dst =
|
auto dst = output->GetWriteView(internal::types<GlTextureView>{}, 0);
|
||||||
output->GetWriteView(internal::types<GlTextureView>{}, nullptr, 0);
|
|
||||||
CopyGlTexture(src, dst);
|
CopyGlTexture(src, dst);
|
||||||
glFlush();
|
glFlush();
|
||||||
});
|
});
|
||||||
|
|
|
@ -95,10 +95,8 @@ class GlTextureBuffer
|
||||||
GpuBufferFormat format() const { return format_; }
|
GpuBufferFormat format() const { return format_; }
|
||||||
|
|
||||||
GlTextureView GetReadView(internal::types<GlTextureView>,
|
GlTextureView GetReadView(internal::types<GlTextureView>,
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer,
|
|
||||||
int plane) const override;
|
int plane) const override;
|
||||||
GlTextureView GetWriteView(internal::types<GlTextureView>,
|
GlTextureView GetWriteView(internal::types<GlTextureView>,
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer,
|
|
||||||
int plane) override;
|
int plane) override;
|
||||||
|
|
||||||
// If this texture is going to be used outside of the context that produced
|
// If this texture is going to be used outside of the context that produced
|
||||||
|
|
|
@ -65,8 +65,8 @@ class GlTextureView {
|
||||||
friend class GpuBufferStorageCvPixelBuffer;
|
friend class GpuBufferStorageCvPixelBuffer;
|
||||||
friend class GpuBufferStorageAhwb;
|
friend class GpuBufferStorageAhwb;
|
||||||
GlTextureView(GlContext* context, GLenum target, GLuint name, int width,
|
GlTextureView(GlContext* context, GLenum target, GLuint name, int width,
|
||||||
int height, std::shared_ptr<GpuBuffer> gpu_buffer, int plane,
|
int height, int plane, DetachFn detach,
|
||||||
DetachFn detach, DoneWritingFn done_writing)
|
DoneWritingFn done_writing)
|
||||||
: gl_context_(context),
|
: gl_context_(context),
|
||||||
target_(target),
|
target_(target),
|
||||||
name_(name),
|
name_(name),
|
||||||
|
@ -108,12 +108,8 @@ class ViewProvider<GlTextureView> {
|
||||||
// the same view implement the same signature.
|
// the same view implement the same signature.
|
||||||
// Note that we allow different views to have custom signatures, providing
|
// Note that we allow different views to have custom signatures, providing
|
||||||
// additional view-specific arguments that may be needed.
|
// additional view-specific arguments that may be needed.
|
||||||
virtual GlTextureView GetReadView(types<GlTextureView>,
|
virtual GlTextureView GetReadView(types<GlTextureView>, int plane) const = 0;
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer,
|
virtual GlTextureView GetWriteView(types<GlTextureView>, int plane) = 0;
|
||||||
int plane) const = 0;
|
|
||||||
virtual GlTextureView GetWriteView(types<GlTextureView>,
|
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer,
|
|
||||||
int plane) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
|
@ -106,8 +106,7 @@ class GpuBuffer {
|
||||||
template <class View, class... Args>
|
template <class View, class... Args>
|
||||||
decltype(auto) GetReadView(Args... args) const {
|
decltype(auto) GetReadView(Args... args) const {
|
||||||
return GetViewProviderOrDie<View>(false).GetReadView(
|
return GetViewProviderOrDie<View>(false).GetReadView(
|
||||||
internal::types<View>{}, std::make_shared<GpuBuffer>(*this),
|
internal::types<View>{}, std::forward<Args>(args)...);
|
||||||
std::forward<Args>(args)...);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets a write view of the specified type. The arguments depend on the
|
// Gets a write view of the specified type. The arguments depend on the
|
||||||
|
@ -115,8 +114,7 @@ class GpuBuffer {
|
||||||
template <class View, class... Args>
|
template <class View, class... Args>
|
||||||
decltype(auto) GetWriteView(Args... args) {
|
decltype(auto) GetWriteView(Args... args) {
|
||||||
return GetViewProviderOrDie<View>(true).GetWriteView(
|
return GetViewProviderOrDie<View>(true).GetWriteView(
|
||||||
internal::types<View>{}, std::make_shared<GpuBuffer>(*this),
|
internal::types<View>{}, std::forward<Args>(args)...);
|
||||||
std::forward<Args>(args)...);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempts to access an underlying storage object of the specified type.
|
// Attempts to access an underlying storage object of the specified type.
|
||||||
|
|
|
@ -26,8 +26,7 @@ GpuBufferStorageCvPixelBuffer::GpuBufferStorageCvPixelBuffer(
|
||||||
}
|
}
|
||||||
|
|
||||||
GlTextureView GpuBufferStorageCvPixelBuffer::GetTexture(
|
GlTextureView GpuBufferStorageCvPixelBuffer::GetTexture(
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer, int plane,
|
int plane, GlTextureView::DoneWritingFn done_writing) const {
|
||||||
GlTextureView::DoneWritingFn done_writing) const {
|
|
||||||
CVReturn err;
|
CVReturn err;
|
||||||
auto gl_context = GlContext::GetCurrent();
|
auto gl_context = GlContext::GetCurrent();
|
||||||
CHECK(gl_context);
|
CHECK(gl_context);
|
||||||
|
@ -60,33 +59,30 @@ GlTextureView GpuBufferStorageCvPixelBuffer::GetTexture(
|
||||||
cv_texture.adopt(cv_texture_temp);
|
cv_texture.adopt(cv_texture_temp);
|
||||||
return GlTextureView(
|
return GlTextureView(
|
||||||
gl_context.get(), CVOpenGLESTextureGetTarget(*cv_texture),
|
gl_context.get(), CVOpenGLESTextureGetTarget(*cv_texture),
|
||||||
CVOpenGLESTextureGetName(*cv_texture), width(), height(),
|
CVOpenGLESTextureGetName(*cv_texture), width(), height(), plane,
|
||||||
std::move(gpu_buffer), plane,
|
|
||||||
[cv_texture](mediapipe::GlTextureView&) { /* only retains cv_texture */ },
|
[cv_texture](mediapipe::GlTextureView&) { /* only retains cv_texture */ },
|
||||||
done_writing);
|
done_writing);
|
||||||
#endif // TARGET_OS_OSX
|
#endif // TARGET_OS_OSX
|
||||||
}
|
}
|
||||||
|
|
||||||
GlTextureView GpuBufferStorageCvPixelBuffer::GetReadView(
|
GlTextureView GpuBufferStorageCvPixelBuffer::GetReadView(
|
||||||
internal::types<GlTextureView>, std::shared_ptr<GpuBuffer> gpu_buffer,
|
internal::types<GlTextureView>, int plane) const {
|
||||||
int plane) const {
|
return GetTexture(plane, nullptr);
|
||||||
return GetTexture(std::move(gpu_buffer), plane, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GlTextureView GpuBufferStorageCvPixelBuffer::GetWriteView(
|
GlTextureView GpuBufferStorageCvPixelBuffer::GetWriteView(
|
||||||
internal::types<GlTextureView>, std::shared_ptr<GpuBuffer> gpu_buffer,
|
internal::types<GlTextureView>, int plane) {
|
||||||
int plane) {
|
return GetTexture(plane, [this](const mediapipe::GlTextureView& view) {
|
||||||
return GetTexture(
|
ViewDoneWriting(view);
|
||||||
std::move(gpu_buffer), plane,
|
});
|
||||||
[this](const mediapipe::GlTextureView& view) { ViewDoneWriting(view); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const ImageFrame> GpuBufferStorageCvPixelBuffer::GetReadView(
|
std::shared_ptr<const ImageFrame> GpuBufferStorageCvPixelBuffer::GetReadView(
|
||||||
internal::types<ImageFrame>, std::shared_ptr<GpuBuffer> gpu_buffer) const {
|
internal::types<ImageFrame>) const {
|
||||||
return CreateImageFrameForCVPixelBuffer(**this);
|
return CreateImageFrameForCVPixelBuffer(**this);
|
||||||
}
|
}
|
||||||
std::shared_ptr<ImageFrame> GpuBufferStorageCvPixelBuffer::GetWriteView(
|
std::shared_ptr<ImageFrame> GpuBufferStorageCvPixelBuffer::GetWriteView(
|
||||||
internal::types<ImageFrame>, std::shared_ptr<GpuBuffer> gpu_buffer) {
|
internal::types<ImageFrame>) {
|
||||||
return CreateImageFrameForCVPixelBuffer(**this);
|
return CreateImageFrameForCVPixelBuffer(**this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,9 @@ class ViewProvider<CVPixelBufferRef> {
|
||||||
public:
|
public:
|
||||||
virtual ~ViewProvider() = default;
|
virtual ~ViewProvider() = default;
|
||||||
virtual CFHolder<CVPixelBufferRef> GetReadView(
|
virtual CFHolder<CVPixelBufferRef> GetReadView(
|
||||||
internal::types<CVPixelBufferRef>,
|
internal::types<CVPixelBufferRef>) const = 0;
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer) const = 0;
|
|
||||||
virtual CFHolder<CVPixelBufferRef> GetWriteView(
|
virtual CFHolder<CVPixelBufferRef> GetWriteView(
|
||||||
internal::types<CVPixelBufferRef>,
|
internal::types<CVPixelBufferRef>) = 0;
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -50,37 +48,30 @@ class GpuBufferStorageCvPixelBuffer
|
||||||
CVPixelBufferGetPixelFormatType(**this));
|
CVPixelBufferGetPixelFormatType(**this));
|
||||||
}
|
}
|
||||||
GlTextureView GetReadView(internal::types<GlTextureView>,
|
GlTextureView GetReadView(internal::types<GlTextureView>,
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer,
|
|
||||||
int plane) const override;
|
int plane) const override;
|
||||||
GlTextureView GetWriteView(internal::types<GlTextureView>,
|
GlTextureView GetWriteView(internal::types<GlTextureView>,
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer,
|
|
||||||
int plane) override;
|
int plane) override;
|
||||||
std::shared_ptr<const ImageFrame> GetReadView(
|
std::shared_ptr<const ImageFrame> GetReadView(
|
||||||
internal::types<ImageFrame>,
|
internal::types<ImageFrame>) const override;
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer) const override;
|
|
||||||
std::shared_ptr<ImageFrame> GetWriteView(
|
std::shared_ptr<ImageFrame> GetWriteView(
|
||||||
internal::types<ImageFrame>,
|
internal::types<ImageFrame>) override;
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer) override;
|
|
||||||
CFHolder<CVPixelBufferRef> GetReadView(
|
CFHolder<CVPixelBufferRef> GetReadView(
|
||||||
internal::types<CVPixelBufferRef>,
|
internal::types<CVPixelBufferRef>) const override;
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer) const override;
|
|
||||||
CFHolder<CVPixelBufferRef> GetWriteView(
|
CFHolder<CVPixelBufferRef> GetWriteView(
|
||||||
internal::types<CVPixelBufferRef>,
|
internal::types<CVPixelBufferRef>) override;
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GlTextureView GetTexture(std::shared_ptr<GpuBuffer> gpu_buffer, int plane,
|
GlTextureView GetTexture(int plane,
|
||||||
GlTextureView::DoneWritingFn done_writing) const;
|
GlTextureView::DoneWritingFn done_writing) const;
|
||||||
void ViewDoneWriting(const GlTextureView& view);
|
void ViewDoneWriting(const GlTextureView& view);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline CFHolder<CVPixelBufferRef> GpuBufferStorageCvPixelBuffer::GetReadView(
|
inline CFHolder<CVPixelBufferRef> GpuBufferStorageCvPixelBuffer::GetReadView(
|
||||||
internal::types<CVPixelBufferRef>,
|
internal::types<CVPixelBufferRef>) const {
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer) const {
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline CFHolder<CVPixelBufferRef> GpuBufferStorageCvPixelBuffer::GetWriteView(
|
inline CFHolder<CVPixelBufferRef> GpuBufferStorageCvPixelBuffer::GetWriteView(
|
||||||
internal::types<CVPixelBufferRef>, std::shared_ptr<GpuBuffer> gpu_buffer) {
|
internal::types<CVPixelBufferRef>) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,13 +29,11 @@ class GpuBufferStorageImageFrame
|
||||||
std::shared_ptr<const ImageFrame> image_frame() const { return image_frame_; }
|
std::shared_ptr<const ImageFrame> image_frame() const { return image_frame_; }
|
||||||
std::shared_ptr<ImageFrame> image_frame() { return image_frame_; }
|
std::shared_ptr<ImageFrame> image_frame() { return image_frame_; }
|
||||||
std::shared_ptr<const ImageFrame> GetReadView(
|
std::shared_ptr<const ImageFrame> GetReadView(
|
||||||
internal::types<ImageFrame>,
|
internal::types<ImageFrame>) const override {
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer) const override {
|
|
||||||
return image_frame_;
|
return image_frame_;
|
||||||
}
|
}
|
||||||
std::shared_ptr<ImageFrame> GetWriteView(
|
std::shared_ptr<ImageFrame> GetWriteView(
|
||||||
internal::types<ImageFrame>,
|
internal::types<ImageFrame>) override {
|
||||||
std::shared_ptr<GpuBuffer> gpu_buffer) override {
|
|
||||||
return image_frame_;
|
return image_frame_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,8 @@ class ViewProvider<ImageFrame> {
|
||||||
public:
|
public:
|
||||||
virtual ~ViewProvider() = default;
|
virtual ~ViewProvider() = default;
|
||||||
virtual std::shared_ptr<const ImageFrame> GetReadView(
|
virtual std::shared_ptr<const ImageFrame> GetReadView(
|
||||||
types<ImageFrame>, std::shared_ptr<GpuBuffer> gpu_buffer) const = 0;
|
types<ImageFrame>) const = 0;
|
||||||
virtual std::shared_ptr<ImageFrame> GetWriteView(
|
virtual std::shared_ptr<ImageFrame> GetWriteView(types<ImageFrame>) = 0;
|
||||||
types<ImageFrame>, std::shared_ptr<GpuBuffer> gpu_buffer) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
Loading…
Reference in New Issue
Block a user