From a55839de51dafe27b4c2b705954444895a842c3c Mon Sep 17 00:00:00 2001 From: Camillo Lugaresi Date: Tue, 22 Nov 2022 18:07:26 -0800 Subject: [PATCH] This storage only needs a "done writing" callback on simulator, so only set it there - When not on simulator, we pass nullptr instead of a do-nothing callback. - The callback is no longer a method, but a function. Only the CVPixelBuffer is captured. PiperOrigin-RevId: 490380248 --- .../gpu/gpu_buffer_storage_cv_pixel_buffer.cc | 45 +++++++++++-------- .../gpu/gpu_buffer_storage_cv_pixel_buffer.h | 1 - 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.cc b/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.cc index f3954a6e4..014cc1c69 100644 --- a/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.cc +++ b/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.cc @@ -70,25 +70,9 @@ GlTextureView GpuBufferStorageCvPixelBuffer::GetReadView( return GetTexture(plane, nullptr); } -GlTextureView GpuBufferStorageCvPixelBuffer::GetWriteView( - internal::types, int plane) { - return GetTexture(plane, [this](const mediapipe::GlTextureView& view) { - ViewDoneWriting(view); - }); -} - -std::shared_ptr GpuBufferStorageCvPixelBuffer::GetReadView( - internal::types) const { - return CreateImageFrameForCVPixelBuffer(**this); -} -std::shared_ptr GpuBufferStorageCvPixelBuffer::GetWriteView( - internal::types) { - return CreateImageFrameForCVPixelBuffer(**this); -} - -void GpuBufferStorageCvPixelBuffer::ViewDoneWriting(const GlTextureView& view) { #if TARGET_IPHONE_SIMULATOR - CVPixelBufferRef pixel_buffer = **this; +static void ViewDoneWritingSimulatorWorkaround(CVPixelBufferRef pixel_buffer, + const GlTextureView& view) { CHECK(pixel_buffer); CVReturn err = CVPixelBufferLockBaseAddress(pixel_buffer, 0); CHECK(err == kCVReturnSuccess) @@ -126,7 +110,30 @@ void GpuBufferStorageCvPixelBuffer::ViewDoneWriting(const GlTextureView& view) { err = CVPixelBufferUnlockBaseAddress(pixel_buffer, 0); CHECK(err == kCVReturnSuccess) << "CVPixelBufferUnlockBaseAddress failed: " << err; -#endif +} +#endif // TARGET_IPHONE_SIMULATOR + +GlTextureView GpuBufferStorageCvPixelBuffer::GetWriteView( + internal::types, int plane) { + return GetTexture(plane, +#if TARGET_IPHONE_SIMULATOR + [pixel_buffer = CFHolder(*this)]( + const mediapipe::GlTextureView& view) { + ViewDoneWritingSimulatorWorkaround(*pixel_buffer, view); + } +#else + nullptr +#endif // TARGET_IPHONE_SIMULATOR + ); +} + +std::shared_ptr GpuBufferStorageCvPixelBuffer::GetReadView( + internal::types) const { + return CreateImageFrameForCVPixelBuffer(**this); +} +std::shared_ptr GpuBufferStorageCvPixelBuffer::GetWriteView( + internal::types) { + return CreateImageFrameForCVPixelBuffer(**this); } static std::shared_ptr ConvertFromImageFrame( diff --git a/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.h b/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.h index a9389ab8a..8723a1087 100644 --- a/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.h +++ b/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.h @@ -63,7 +63,6 @@ class GpuBufferStorageCvPixelBuffer private: GlTextureView GetTexture(int plane, GlTextureView::DoneWritingFn done_writing) const; - void ViewDoneWriting(const GlTextureView& view); }; inline CFHolder GpuBufferStorageCvPixelBuffer::GetReadView(