diff --git a/mediapipe/gpu/gl_texture_buffer.cc b/mediapipe/gpu/gl_texture_buffer.cc index 4c2f15a8d..e57195a46 100644 --- a/mediapipe/gpu/gl_texture_buffer.cc +++ b/mediapipe/gpu/gl_texture_buffer.cc @@ -255,9 +255,8 @@ void GlTextureBuffer::WaitForConsumersOnGpu() { // precisely, on only one GL context. } -GlTextureView GlTextureBuffer::GetReadView( - internal::types, std::shared_ptr gpu_buffer, - int plane) const { +GlTextureView GlTextureBuffer::GetReadView(internal::types, + int plane) const { auto gl_context = GlContext::GetCurrent(); CHECK(gl_context); CHECK_EQ(plane, 0); @@ -269,13 +268,11 @@ GlTextureView GlTextureBuffer::GetReadView( DidRead(texture.gl_context()->CreateSyncToken()); }; return GlTextureView(gl_context.get(), target(), name(), width(), height(), - std::move(gpu_buffer), plane, std::move(detach), - nullptr); + plane, std::move(detach), nullptr); } -GlTextureView GlTextureBuffer::GetWriteView( - internal::types, std::shared_ptr gpu_buffer, - int plane) { +GlTextureView GlTextureBuffer::GetWriteView(internal::types, + int plane) { auto gl_context = GlContext::GetCurrent(); CHECK(gl_context); CHECK_EQ(plane, 0); @@ -286,8 +283,7 @@ GlTextureView GlTextureBuffer::GetWriteView( GlTextureView::DoneWritingFn done_writing = [this](const GlTextureView& texture) { ViewDoneWriting(texture); }; return GlTextureView(gl_context.get(), target(), name(), width(), height(), - std::move(gpu_buffer), plane, nullptr, - std::move(done_writing)); + plane, nullptr, std::move(done_writing)); } void GlTextureBuffer::ViewDoneWriting(const GlTextureView& view) { @@ -364,7 +360,7 @@ static std::shared_ptr ConvertToImageFrame( absl::make_unique(image_format, buf->width(), buf->height(), ImageFrame::kGlDefaultAlignmentBoundary); buf->GetProducerContext()->Run([buf, &output] { - auto view = buf->GetReadView(internal::types{}, nullptr, 0); + auto view = buf->GetReadView(internal::types{}, 0); ReadTexture(view, buf->format(), output->MutablePixelData(), output->PixelDataSize()); }); @@ -393,9 +389,8 @@ static std::shared_ptr ConvertToCvPixelBuffer( buf->width(), buf->height(), buf->format()); buf->GetProducerContext()->Run([buf, &output] { TempGlFramebuffer framebuffer; - auto src = buf->GetReadView(internal::types{}, nullptr, 0); - auto dst = - output->GetWriteView(internal::types{}, nullptr, 0); + auto src = buf->GetReadView(internal::types{}, 0); + auto dst = output->GetWriteView(internal::types{}, 0); CopyGlTexture(src, dst); glFlush(); }); diff --git a/mediapipe/gpu/gl_texture_buffer.h b/mediapipe/gpu/gl_texture_buffer.h index 1be24a86b..c7643fd1b 100644 --- a/mediapipe/gpu/gl_texture_buffer.h +++ b/mediapipe/gpu/gl_texture_buffer.h @@ -95,10 +95,8 @@ class GlTextureBuffer GpuBufferFormat format() const { return format_; } GlTextureView GetReadView(internal::types, - std::shared_ptr gpu_buffer, int plane) const override; GlTextureView GetWriteView(internal::types, - std::shared_ptr gpu_buffer, int plane) override; // If this texture is going to be used outside of the context that produced diff --git a/mediapipe/gpu/gl_texture_view.h b/mediapipe/gpu/gl_texture_view.h index d6734ed71..b8ead2708 100644 --- a/mediapipe/gpu/gl_texture_view.h +++ b/mediapipe/gpu/gl_texture_view.h @@ -65,8 +65,8 @@ class GlTextureView { friend class GpuBufferStorageCvPixelBuffer; friend class GpuBufferStorageAhwb; GlTextureView(GlContext* context, GLenum target, GLuint name, int width, - int height, std::shared_ptr gpu_buffer, int plane, - DetachFn detach, DoneWritingFn done_writing) + int height, int plane, DetachFn detach, + DoneWritingFn done_writing) : gl_context_(context), target_(target), name_(name), @@ -108,12 +108,8 @@ class ViewProvider { // the same view implement the same signature. // Note that we allow different views to have custom signatures, providing // additional view-specific arguments that may be needed. - virtual GlTextureView GetReadView(types, - std::shared_ptr gpu_buffer, - int plane) const = 0; - virtual GlTextureView GetWriteView(types, - std::shared_ptr gpu_buffer, - int plane) = 0; + virtual GlTextureView GetReadView(types, int plane) const = 0; + virtual GlTextureView GetWriteView(types, int plane) = 0; }; } // namespace internal diff --git a/mediapipe/gpu/gpu_buffer.h b/mediapipe/gpu/gpu_buffer.h index 45146a322..56507d92f 100644 --- a/mediapipe/gpu/gpu_buffer.h +++ b/mediapipe/gpu/gpu_buffer.h @@ -106,8 +106,7 @@ class GpuBuffer { template decltype(auto) GetReadView(Args... args) const { return GetViewProviderOrDie(false).GetReadView( - internal::types{}, std::make_shared(*this), - std::forward(args)...); + internal::types{}, std::forward(args)...); } // Gets a write view of the specified type. The arguments depend on the @@ -115,8 +114,7 @@ class GpuBuffer { template decltype(auto) GetWriteView(Args... args) { return GetViewProviderOrDie(true).GetWriteView( - internal::types{}, std::make_shared(*this), - std::forward(args)...); + internal::types{}, std::forward(args)...); } // Attempts to access an underlying storage object of the specified type. diff --git a/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.cc b/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.cc index d68ac0db0..f3954a6e4 100644 --- a/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.cc +++ b/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.cc @@ -26,8 +26,7 @@ GpuBufferStorageCvPixelBuffer::GpuBufferStorageCvPixelBuffer( } GlTextureView GpuBufferStorageCvPixelBuffer::GetTexture( - std::shared_ptr gpu_buffer, int plane, - GlTextureView::DoneWritingFn done_writing) const { + int plane, GlTextureView::DoneWritingFn done_writing) const { CVReturn err; auto gl_context = GlContext::GetCurrent(); CHECK(gl_context); @@ -60,33 +59,30 @@ GlTextureView GpuBufferStorageCvPixelBuffer::GetTexture( cv_texture.adopt(cv_texture_temp); return GlTextureView( gl_context.get(), CVOpenGLESTextureGetTarget(*cv_texture), - CVOpenGLESTextureGetName(*cv_texture), width(), height(), - std::move(gpu_buffer), plane, + CVOpenGLESTextureGetName(*cv_texture), width(), height(), plane, [cv_texture](mediapipe::GlTextureView&) { /* only retains cv_texture */ }, done_writing); #endif // TARGET_OS_OSX } GlTextureView GpuBufferStorageCvPixelBuffer::GetReadView( - internal::types, std::shared_ptr gpu_buffer, - int plane) const { - return GetTexture(std::move(gpu_buffer), plane, nullptr); + internal::types, int plane) const { + return GetTexture(plane, nullptr); } GlTextureView GpuBufferStorageCvPixelBuffer::GetWriteView( - internal::types, std::shared_ptr gpu_buffer, - int plane) { - return GetTexture( - std::move(gpu_buffer), plane, - [this](const mediapipe::GlTextureView& view) { ViewDoneWriting(view); }); + internal::types, int plane) { + return GetTexture(plane, [this](const mediapipe::GlTextureView& view) { + ViewDoneWriting(view); + }); } std::shared_ptr GpuBufferStorageCvPixelBuffer::GetReadView( - internal::types, std::shared_ptr gpu_buffer) const { + internal::types) const { return CreateImageFrameForCVPixelBuffer(**this); } std::shared_ptr GpuBufferStorageCvPixelBuffer::GetWriteView( - internal::types, std::shared_ptr gpu_buffer) { + internal::types) { return CreateImageFrameForCVPixelBuffer(**this); } diff --git a/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.h b/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.h index e5bc5de43..a9389ab8a 100644 --- a/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.h +++ b/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.h @@ -19,11 +19,9 @@ class ViewProvider { public: virtual ~ViewProvider() = default; virtual CFHolder GetReadView( - internal::types, - std::shared_ptr gpu_buffer) const = 0; + internal::types) const = 0; virtual CFHolder GetWriteView( - internal::types, - std::shared_ptr gpu_buffer) = 0; + internal::types) = 0; }; } // namespace internal @@ -50,37 +48,30 @@ class GpuBufferStorageCvPixelBuffer CVPixelBufferGetPixelFormatType(**this)); } GlTextureView GetReadView(internal::types, - std::shared_ptr gpu_buffer, int plane) const override; GlTextureView GetWriteView(internal::types, - std::shared_ptr gpu_buffer, int plane) override; std::shared_ptr GetReadView( - internal::types, - std::shared_ptr gpu_buffer) const override; + internal::types) const override; std::shared_ptr GetWriteView( - internal::types, - std::shared_ptr gpu_buffer) override; + internal::types) override; CFHolder GetReadView( - internal::types, - std::shared_ptr gpu_buffer) const override; + internal::types) const override; CFHolder GetWriteView( - internal::types, - std::shared_ptr gpu_buffer) override; + internal::types) override; private: - GlTextureView GetTexture(std::shared_ptr gpu_buffer, int plane, + GlTextureView GetTexture(int plane, GlTextureView::DoneWritingFn done_writing) const; void ViewDoneWriting(const GlTextureView& view); }; inline CFHolder GpuBufferStorageCvPixelBuffer::GetReadView( - internal::types, - std::shared_ptr gpu_buffer) const { + internal::types) const { return *this; } inline CFHolder GpuBufferStorageCvPixelBuffer::GetWriteView( - internal::types, std::shared_ptr gpu_buffer) { + internal::types) { return *this; } diff --git a/mediapipe/gpu/gpu_buffer_storage_image_frame.h b/mediapipe/gpu/gpu_buffer_storage_image_frame.h index 2cea3445e..ab547b9ea 100644 --- a/mediapipe/gpu/gpu_buffer_storage_image_frame.h +++ b/mediapipe/gpu/gpu_buffer_storage_image_frame.h @@ -29,13 +29,11 @@ class GpuBufferStorageImageFrame std::shared_ptr image_frame() const { return image_frame_; } std::shared_ptr image_frame() { return image_frame_; } std::shared_ptr GetReadView( - internal::types, - std::shared_ptr gpu_buffer) const override { + internal::types) const override { return image_frame_; } std::shared_ptr GetWriteView( - internal::types, - std::shared_ptr gpu_buffer) override { + internal::types) override { return image_frame_; } diff --git a/mediapipe/gpu/image_frame_view.h b/mediapipe/gpu/image_frame_view.h index 2fc6f2495..b7e58a824 100644 --- a/mediapipe/gpu/image_frame_view.h +++ b/mediapipe/gpu/image_frame_view.h @@ -12,9 +12,8 @@ class ViewProvider { public: virtual ~ViewProvider() = default; virtual std::shared_ptr GetReadView( - types, std::shared_ptr gpu_buffer) const = 0; - virtual std::shared_ptr GetWriteView( - types, std::shared_ptr gpu_buffer) = 0; + types) const = 0; + virtual std::shared_ptr GetWriteView(types) = 0; }; } // namespace internal