Skip to content

Commit

Permalink
GpuMemoryBufferVideoFramePool: Parameterize usage
Browse files Browse the repository at this point in the history
Current use of GpuMemoryBufferVideoFramePool is to create GMB-backed
frames that are populated by writing using the CPU, and so the
gfx::BufferUsage is hard-coded to gfx::BufferUsage::
SCANOUT_CPU_READ_WRITE. For one copy canvas capture, out CPU access
to the GMBs will be read-only, so we'll want to use the
usage SCANOUT_VEA_CPU_READ, which is what is currently used by
video capture frames.

Also update macOS-GMB support to allow SCANOUT_VEA_CPU_READ, since
that configuration is valid (and is already in use, just not in a way
that hits this path).

Bug: 1207111
Change-Id: I82e1a0d16c92748db8a8dc1ed118bcebec723be4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2942208
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: ccameron <ccameron@chromium.org>
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Reviewed-by: Dan Sanders <sandersd@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#891790}
  • Loading branch information
ccameron-chromium authored and Chromium LUCI CQ committed Jun 11, 2021
1 parent 21659cc commit 742c88c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gpu/ipc/common/gpu_memory_buffer_support.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ bool GpuMemoryBufferSupport::IsNativeGpuMemoryBufferConfigurationSupported(
case gfx::BufferUsage::SCANOUT_CPU_READ_WRITE:
case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE:
case gfx::BufferUsage::SCANOUT_FRONT_RENDERING:
case gfx::BufferUsage::SCANOUT_VEA_CPU_READ:
return format == gfx::BufferFormat::BGRA_8888 ||
format == gfx::BufferFormat::RGBA_8888 ||
format == gfx::BufferFormat::BGRX_8888 ||
Expand All @@ -100,7 +101,6 @@ bool GpuMemoryBufferSupport::IsNativeGpuMemoryBufferConfigurationSupported(
case gfx::BufferUsage::PROTECTED_SCANOUT_VDA_WRITE:
case gfx::BufferUsage::SCANOUT_CAMERA_READ_WRITE:
case gfx::BufferUsage::CAMERA_AND_CPU_READ_WRITE:
case gfx::BufferUsage::SCANOUT_VEA_CPU_READ:
case gfx::BufferUsage::VEA_READ_CAMERA_AND_CPU_READ_WRITE:
return false;
}
Expand Down
24 changes: 14 additions & 10 deletions media/video/gpu_memory_buffer_video_frame_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class GpuMemoryBufferVideoFramePool::PoolImpl
// and prone to leakage. Switch this to pass around std::unique_ptr
// such that callers own resources explicitly.
struct FrameResources {
explicit FrameResources(const gfx::Size& size) : size(size) {}
explicit FrameResources(const gfx::Size& size, gfx::BufferUsage usage)
: size(size), usage(usage) {}
void MarkUsed() {
is_used_ = true;
last_use_time_ = base::TimeTicks();
Expand All @@ -133,6 +134,7 @@ class GpuMemoryBufferVideoFramePool::PoolImpl
base::TimeTicks last_use_time() const { return last_use_time_; }

const gfx::Size size;
const gfx::BufferUsage usage;
PlaneResource plane_resources[VideoFrame::kMaxPlanes];
// The sync token used to recycle or destroy the resources. It is set when
// the resources are returned from the VideoFrame (via
Expand Down Expand Up @@ -192,16 +194,18 @@ class GpuMemoryBufferVideoFramePool::PoolImpl
// Return true if |resources| can be used to represent a frame for
// specific |format| and |size|.
static bool AreFrameResourcesCompatible(const FrameResources* resources,
const gfx::Size& size) {
return size == resources->size;
const gfx::Size& size,
gfx::BufferUsage usage) {
return size == resources->size && usage == resources->usage;
}

// Get the resources needed for a frame out of the pool, or create them if
// necessary.
// This also drops the LRU resources that can't be reuse for this frame.
FrameResources* GetOrCreateFrameResources(
const gfx::Size& size,
GpuVideoAcceleratorFactories::OutputFormat format);
GpuVideoAcceleratorFactories::OutputFormat format,
gfx::BufferUsage usage);

// Calls the FrameReadyCB of the first entry in |frame_copy_requests_|, with
// the provided |video_frame|, then deletes the entry from
Expand Down Expand Up @@ -865,7 +869,7 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::StartCopy() {
? nullptr
: GetOrCreateFrameResources(
CodedSize(request.video_frame.get(), output_format_),
output_format_);
output_format_, gfx::BufferUsage::SCANOUT_CPU_READ_WRITE);
if (!frame_resources) {
std::move(request.frame_ready_cb).Run(std::move(request.video_frame));
frame_copy_requests_.pop_front();
Expand Down Expand Up @@ -1214,14 +1218,15 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::SetTickClockForTesting(
GpuMemoryBufferVideoFramePool::PoolImpl::FrameResources*
GpuMemoryBufferVideoFramePool::PoolImpl::GetOrCreateFrameResources(
const gfx::Size& size,
GpuVideoAcceleratorFactories::OutputFormat format) {
GpuVideoAcceleratorFactories::OutputFormat format,
gfx::BufferUsage usage) {
DCHECK(media_task_runner_->BelongsToCurrentThread());

auto it = resources_pool_.begin();
while (it != resources_pool_.end()) {
FrameResources* frame_resources = *it;
if (!frame_resources->is_used()) {
if (AreFrameResourcesCompatible(frame_resources, size)) {
if (AreFrameResourcesCompatible(frame_resources, size, usage)) {
frame_resources->MarkUsed();
return frame_resources;
} else {
Expand All @@ -1235,7 +1240,7 @@ GpuMemoryBufferVideoFramePool::PoolImpl::GetOrCreateFrameResources(
}

// Create the resources.
FrameResources* frame_resources = new FrameResources(size);
FrameResources* frame_resources = new FrameResources(size, usage);
resources_pool_.push_back(frame_resources);
for (size_t i = 0; i < NumGpuMemoryBuffers(output_format_); i++) {
PlaneResource& plane_resource = frame_resources->plane_resources[i];
Expand All @@ -1247,8 +1252,7 @@ GpuMemoryBufferVideoFramePool::PoolImpl::GetOrCreateFrameResources(

const gfx::BufferFormat buffer_format = GpuMemoryBufferFormat(format, i);
plane_resource.gpu_memory_buffer = gpu_factories_->CreateGpuMemoryBuffer(
plane_resource.size, buffer_format,
gfx::BufferUsage::SCANOUT_CPU_READ_WRITE);
plane_resource.size, buffer_format, usage);
}
return frame_resources;
}
Expand Down

0 comments on commit 742c88c

Please sign in to comment.