Remove shared_ptr from SimplePool definition
This makes the types more explicit and will help with factoring out platform-specific code. PiperOrigin-RevId: 488775470
This commit is contained in:
parent
a67069156e
commit
3c71c64be1
|
@ -90,8 +90,8 @@ std::string CvPixelBufferPoolWrapper::GetDebugString() const {
|
|||
|
||||
void CvPixelBufferPoolWrapper::Flush() { CVPixelBufferPoolFlush(*pool_, 0); }
|
||||
|
||||
GpuBufferMultiPool::SimplePool GpuBufferMultiPool::MakeSimplePool(
|
||||
const GpuBufferMultiPool::BufferSpec& spec) {
|
||||
std::shared_ptr<GpuBufferMultiPool::SimplePool>
|
||||
GpuBufferMultiPool::MakeSimplePool(const GpuBufferMultiPool::BufferSpec& spec) {
|
||||
return std::make_shared<CvPixelBufferPoolWrapper>(spec,
|
||||
kMaxInactiveBufferAge);
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ void GpuBufferMultiPool::FlushTextureCaches() {
|
|||
#define FORCE_CONTIGUOUS_PIXEL_BUFFER_ON_IPHONE_SIMULATOR 0
|
||||
|
||||
GpuBuffer GpuBufferMultiPool::GetBufferFromSimplePool(
|
||||
BufferSpec spec, const GpuBufferMultiPool::SimplePool& pool) {
|
||||
BufferSpec spec, GpuBufferMultiPool::SimplePool& pool) {
|
||||
#if TARGET_IPHONE_SIMULATOR && FORCE_CONTIGUOUS_PIXEL_BUFFER_ON_IPHONE_SIMULATOR
|
||||
// On the simulator, syncing the texture with the pixelbuffer does not work,
|
||||
// and we have to use glReadPixels. Since GL_UNPACK_ROW_LENGTH is not
|
||||
|
@ -134,14 +134,14 @@ GpuBuffer GpuBufferMultiPool::GetBufferFromSimplePool(
|
|||
// pool to give us contiguous data.
|
||||
return GetBufferWithoutPool(spec);
|
||||
#else
|
||||
return pool->GetBuffer([this]() { FlushTextureCaches(); });
|
||||
return pool.GetBuffer([this]() { FlushTextureCaches(); });
|
||||
#endif // TARGET_IPHONE_SIMULATOR
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
GpuBufferMultiPool::SimplePool GpuBufferMultiPool::MakeSimplePool(
|
||||
const BufferSpec& spec) {
|
||||
std::shared_ptr<GpuBufferMultiPool::SimplePool>
|
||||
GpuBufferMultiPool::MakeSimplePool(const BufferSpec& spec) {
|
||||
return GlTextureBufferPool::Create(spec.width, spec.height, spec.format,
|
||||
kKeepCount);
|
||||
}
|
||||
|
@ -152,16 +152,16 @@ GpuBuffer GpuBufferMultiPool::GetBufferWithoutPool(const BufferSpec& spec) {
|
|||
}
|
||||
|
||||
GpuBuffer GpuBufferMultiPool::GetBufferFromSimplePool(
|
||||
BufferSpec spec, const GpuBufferMultiPool::SimplePool& pool) {
|
||||
return GpuBuffer(pool->GetBuffer());
|
||||
BufferSpec spec, GpuBufferMultiPool::SimplePool& pool) {
|
||||
return GpuBuffer(pool.GetBuffer());
|
||||
}
|
||||
|
||||
#endif // MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER
|
||||
|
||||
GpuBufferMultiPool::SimplePool GpuBufferMultiPool::RequestPool(
|
||||
std::shared_ptr<GpuBufferMultiPool::SimplePool> GpuBufferMultiPool::RequestPool(
|
||||
const BufferSpec& spec) {
|
||||
SimplePool pool;
|
||||
std::vector<SimplePool> evicted;
|
||||
std::shared_ptr<SimplePool> pool;
|
||||
std::vector<std::shared_ptr<SimplePool>> evicted;
|
||||
{
|
||||
absl::MutexLock lock(&mutex_);
|
||||
pool =
|
||||
|
@ -180,10 +180,10 @@ GpuBufferMultiPool::SimplePool GpuBufferMultiPool::RequestPool(
|
|||
GpuBuffer GpuBufferMultiPool::GetBuffer(int width, int height,
|
||||
GpuBufferFormat format) {
|
||||
BufferSpec key(width, height, format);
|
||||
SimplePool pool = RequestPool(key);
|
||||
std::shared_ptr<SimplePool> pool = RequestPool(key);
|
||||
if (pool) {
|
||||
// Note: we release our multipool lock before accessing the simple pool.
|
||||
return GetBufferFromSimplePool(key, pool);
|
||||
return GetBufferFromSimplePool(key, *pool);
|
||||
} else {
|
||||
return GetBufferWithoutPool(key);
|
||||
}
|
||||
|
|
|
@ -83,22 +83,23 @@ class GpuBufferMultiPool {
|
|||
|
||||
private:
|
||||
#if MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER
|
||||
using SimplePool = std::shared_ptr<CvPixelBufferPoolWrapper>;
|
||||
using SimplePool = CvPixelBufferPoolWrapper;
|
||||
#else
|
||||
using SimplePool = std::shared_ptr<GlTextureBufferPool>;
|
||||
using SimplePool = GlTextureBufferPool;
|
||||
#endif // MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER
|
||||
|
||||
SimplePool MakeSimplePool(const BufferSpec& spec);
|
||||
std::shared_ptr<SimplePool> MakeSimplePool(const BufferSpec& spec);
|
||||
// Requests a simple buffer pool for the given spec. This may return nullptr
|
||||
// if we have not yet reached a sufficient number of requests to allocate a
|
||||
// pool, in which case the caller should invoke GetBufferWithoutPool instead
|
||||
// of GetBufferFromSimplePool.
|
||||
SimplePool RequestPool(const BufferSpec& spec);
|
||||
GpuBuffer GetBufferFromSimplePool(BufferSpec spec, const SimplePool& pool);
|
||||
std::shared_ptr<SimplePool> RequestPool(const BufferSpec& spec);
|
||||
GpuBuffer GetBufferFromSimplePool(BufferSpec spec, SimplePool& pool);
|
||||
GpuBuffer GetBufferWithoutPool(const BufferSpec& spec);
|
||||
|
||||
absl::Mutex mutex_;
|
||||
mediapipe::ResourceCache<BufferSpec, SimplePool, absl::Hash<BufferSpec>>
|
||||
mediapipe::ResourceCache<BufferSpec, std::shared_ptr<SimplePool>,
|
||||
absl::Hash<BufferSpec>>
|
||||
cache_ ABSL_GUARDED_BY(mutex_);
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
|
Loading…
Reference in New Issue
Block a user