#ifndef MEDIAPIPE_GPU_GPU_BUFFER_STORAGE_CV_PIXEL_BUFFER_H_ #define MEDIAPIPE_GPU_GPU_BUFFER_STORAGE_CV_PIXEL_BUFFER_H_ #include #include "mediapipe/gpu/gl_texture_view.h" #include "mediapipe/gpu/gpu_buffer_storage.h" #include "mediapipe/gpu/image_frame_view.h" #include "mediapipe/objc/CFHolder.h" namespace mediapipe { class GlContext; namespace internal { template <> class ViewProvider { public: virtual ~ViewProvider() = default; virtual CFHolder GetReadView( internal::types) const = 0; virtual CFHolder GetWriteView( internal::types) = 0; }; } // namespace internal class GpuBufferStorageCvPixelBuffer : public internal::GpuBufferStorageImpl< GpuBufferStorageCvPixelBuffer, internal::ViewProvider, internal::ViewProvider, internal::ViewProvider>, public CFHolder { public: using CFHolder::CFHolder; GpuBufferStorageCvPixelBuffer(int width, int height, GpuBufferFormat format); GpuBufferStorageCvPixelBuffer(const CFHolder& other) : CFHolder(other) {} GpuBufferStorageCvPixelBuffer(CFHolder&& other) : CFHolder(std::move(other)) {} int width() const { return static_cast(CVPixelBufferGetWidth(**this)); } int height() const { return static_cast(CVPixelBufferGetHeight(**this)); } virtual GpuBufferFormat format() const { return GpuBufferFormatForCVPixelFormat( CVPixelBufferGetPixelFormatType(**this)); } GlTextureView GetReadView(internal::types, int plane) const override; GlTextureView GetWriteView(internal::types, int plane) override; std::shared_ptr GetReadView( internal::types) const override; std::shared_ptr GetWriteView( internal::types) override; CFHolder GetReadView( internal::types) const override; CFHolder GetWriteView( internal::types) override; private: GlTextureView GetTexture(int plane, GlTextureView::DoneWritingFn done_writing) const; }; inline CFHolder GpuBufferStorageCvPixelBuffer::GetReadView( internal::types) const { return *this; } inline CFHolder GpuBufferStorageCvPixelBuffer::GetWriteView( internal::types) { return *this; } namespace internal { // These functions enable backward-compatible construction of a GpuBuffer from // CVPixelBufferRef without having to expose that type in the main GpuBuffer // header. std::shared_ptr AsGpuBufferStorage( CFHolder pixel_buffer); std::shared_ptr AsGpuBufferStorage( CVPixelBufferRef pixel_buffer); } // namespace internal } // namespace mediapipe #endif // MEDIAPIPE_GPU_GPU_BUFFER_STORAGE_CV_PIXEL_BUFFER_H_