Internal change
PiperOrigin-RevId: 537381138
This commit is contained in:
parent
09bad328ad
commit
b69f93fca6
|
@ -211,6 +211,14 @@ GlTexture GlCalculatorHelper::CreateDestinationTexture(int width, int height,
|
||||||
return MapGpuBuffer(gpu_buffer, gpu_buffer.GetWriteView<GlTextureView>(0));
|
return MapGpuBuffer(gpu_buffer, gpu_buffer.GetWriteView<GlTextureView>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GlTexture GlCalculatorHelper::CreateDestinationTexture(
|
||||||
|
const ImageFrame& image_frame) {
|
||||||
|
// TODO: ensure buffer pool is used when creating textures out of
|
||||||
|
// ImageFrame.
|
||||||
|
GpuBuffer gpu_buffer = GpuBufferCopyingImageFrame(image_frame);
|
||||||
|
return MapGpuBuffer(gpu_buffer, gpu_buffer.GetWriteView<GlTextureView>(0));
|
||||||
|
}
|
||||||
|
|
||||||
GlTexture GlCalculatorHelper::CreateSourceTexture(
|
GlTexture GlCalculatorHelper::CreateSourceTexture(
|
||||||
const mediapipe::Image& image) {
|
const mediapipe::Image& image) {
|
||||||
return CreateSourceTexture(image.GetGpuBuffer());
|
return CreateSourceTexture(image.GetGpuBuffer());
|
||||||
|
|
|
@ -135,6 +135,12 @@ class GlCalculatorHelper {
|
||||||
// This is deprecated because: 1) it encourages the use of GlTexture as a
|
// This is deprecated because: 1) it encourages the use of GlTexture as a
|
||||||
// long-lived object; 2) it requires copying the ImageFrame's contents,
|
// long-lived object; 2) it requires copying the ImageFrame's contents,
|
||||||
// which may not always be necessary.
|
// which may not always be necessary.
|
||||||
|
//
|
||||||
|
// WARNING: do NOT use as a destination texture which will be sent to
|
||||||
|
// downstream calculators as it may lead to synchronization issues. The result
|
||||||
|
// is meant to be a short-lived object, local to a single calculator and
|
||||||
|
// single GL thread. Use `CreateDestinationTexture` instead, if you need a
|
||||||
|
// destination texture.
|
||||||
ABSL_DEPRECATED("Use `GpuBufferWithImageFrame`.")
|
ABSL_DEPRECATED("Use `GpuBufferWithImageFrame`.")
|
||||||
GlTexture CreateSourceTexture(const ImageFrame& image_frame);
|
GlTexture CreateSourceTexture(const ImageFrame& image_frame);
|
||||||
|
|
||||||
|
@ -156,6 +162,14 @@ class GlCalculatorHelper {
|
||||||
int output_width, int output_height,
|
int output_width, int output_height,
|
||||||
GpuBufferFormat format = GpuBufferFormat::kBGRA32);
|
GpuBufferFormat format = GpuBufferFormat::kBGRA32);
|
||||||
|
|
||||||
|
// Creates a destination texture copying and uploading passed image frame.
|
||||||
|
//
|
||||||
|
// WARNING: mind that this functions creates a new texture every time and
|
||||||
|
// doesn't use MediaPipe's gpu buffer pool.
|
||||||
|
// TODO: ensure buffer pool is used when creating textures out of
|
||||||
|
// ImageFrame.
|
||||||
|
GlTexture CreateDestinationTexture(const ImageFrame& image_frame);
|
||||||
|
|
||||||
// The OpenGL name of the output framebuffer.
|
// The OpenGL name of the output framebuffer.
|
||||||
GLuint framebuffer() const;
|
GLuint framebuffer() const;
|
||||||
|
|
||||||
|
@ -196,7 +210,7 @@ class GlCalculatorHelper {
|
||||||
// This class should be the main way to interface with GL memory within a single
|
// This class should be the main way to interface with GL memory within a single
|
||||||
// calculator. This is the preferred way to utilize the memory pool inside of
|
// calculator. This is the preferred way to utilize the memory pool inside of
|
||||||
// the helper, because GlTexture manages efficiently releasing memory back into
|
// the helper, because GlTexture manages efficiently releasing memory back into
|
||||||
// the pool. A GPU backed Image can be extracted from the unerlying
|
// the pool. A GPU backed Image can be extracted from the underlying
|
||||||
// memory.
|
// memory.
|
||||||
class GlTexture {
|
class GlTexture {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -71,11 +71,10 @@ absl::Status ImageFrameToGpuBufferCalculator::Process(CalculatorContext* cc) {
|
||||||
#else
|
#else
|
||||||
const auto& input = cc->Inputs().Index(0).Get<ImageFrame>();
|
const auto& input = cc->Inputs().Index(0).Get<ImageFrame>();
|
||||||
helper_.RunInGlContext([this, &input, &cc]() {
|
helper_.RunInGlContext([this, &input, &cc]() {
|
||||||
auto src = helper_.CreateSourceTexture(input);
|
GlTexture dst = helper_.CreateDestinationTexture(input);
|
||||||
auto output = src.GetFrame<GpuBuffer>();
|
std::unique_ptr<GpuBuffer> output = dst.GetFrame<GpuBuffer>();
|
||||||
glFlush();
|
|
||||||
cc->Outputs().Index(0).Add(output.release(), cc->InputTimestamp());
|
cc->Outputs().Index(0).Add(output.release(), cc->InputTimestamp());
|
||||||
src.Release();
|
dst.Release();
|
||||||
});
|
});
|
||||||
#endif // MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER
|
#endif // MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user