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
This commit is contained in:
Camillo Lugaresi 2022-11-22 18:07:26 -08:00 committed by Copybara-Service
parent 3bbc0e9af9
commit a55839de51
2 changed files with 26 additions and 20 deletions

View File

@ -70,25 +70,9 @@ GlTextureView GpuBufferStorageCvPixelBuffer::GetReadView(
return GetTexture(plane, nullptr);
}
GlTextureView GpuBufferStorageCvPixelBuffer::GetWriteView(
internal::types<GlTextureView>, int plane) {
return GetTexture(plane, [this](const mediapipe::GlTextureView& view) {
ViewDoneWriting(view);
});
}
std::shared_ptr<const ImageFrame> GpuBufferStorageCvPixelBuffer::GetReadView(
internal::types<ImageFrame>) const {
return CreateImageFrameForCVPixelBuffer(**this);
}
std::shared_ptr<ImageFrame> GpuBufferStorageCvPixelBuffer::GetWriteView(
internal::types<ImageFrame>) {
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<GlTextureView>, int plane) {
return GetTexture(plane,
#if TARGET_IPHONE_SIMULATOR
[pixel_buffer = CFHolder<CVPixelBufferRef>(*this)](
const mediapipe::GlTextureView& view) {
ViewDoneWritingSimulatorWorkaround(*pixel_buffer, view);
}
#else
nullptr
#endif // TARGET_IPHONE_SIMULATOR
);
}
std::shared_ptr<const ImageFrame> GpuBufferStorageCvPixelBuffer::GetReadView(
internal::types<ImageFrame>) const {
return CreateImageFrameForCVPixelBuffer(**this);
}
std::shared_ptr<ImageFrame> GpuBufferStorageCvPixelBuffer::GetWriteView(
internal::types<ImageFrame>) {
return CreateImageFrameForCVPixelBuffer(**this);
}
static std::shared_ptr<GpuBufferStorageCvPixelBuffer> ConvertFromImageFrame(

View File

@ -63,7 +63,6 @@ class GpuBufferStorageCvPixelBuffer
private:
GlTextureView GetTexture(int plane,
GlTextureView::DoneWritingFn done_writing) const;
void ViewDoneWriting(const GlTextureView& view);
};
inline CFHolder<CVPixelBufferRef> GpuBufferStorageCvPixelBuffer::GetReadView(