Commit c80fc114 authored by Daniele Castagna's avatar Daniele Castagna Committed by Commit Bot

Reland "media: Use BindOnce everywhere in GMBVFP."

Changes the use of Bind and Closure to BindOnce and OnceClosure in
GpuMemoryBufferVideoFramePool.

It additionally introduces a trampoline in MailboxHoldersReleased so
that if the callback is called on media_thread it can skip going trough
the message loop.
Previous the callback would be bound to the media_thread loop.

Two DCHECKs have also be added to check thread expectations.

TBR=dalecurtis, mcasas

Change-Id: I871e5505691b53a1871d2bd3e8a79ab1b75d2e69
Reviewed-on: https://chromium-review.googlesource.com/966583Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Commit-Queue: Daniele Castagna <dcastagna@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543727}
parent eb8d3afd
......@@ -699,10 +699,9 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::CopyVideoFrameToGpuMemoryBuffers(
++copies;
}
const base::Closure copies_done =
base::Bind(&PoolImpl::OnCopiesDone, this, video_frame, frame_resources);
const base::RepeatingClosure barrier =
base::BarrierClosure(copies, copies_done);
const base::RepeatingClosure barrier = base::BarrierClosure(
copies, base::BindOnce(&PoolImpl::OnCopiesDone, this, video_frame,
frame_resources));
// Map the buffers.
for (size_t i = 0; i < NumGpuMemoryBuffers(output_format_); i++) {
......@@ -840,25 +839,24 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::
for (size_t i = 0; i < NumGpuMemoryBuffers(output_format_); i++)
mailbox_holders[i].sync_token = sync_token;
auto release_mailbox_callback = BindToCurrentLoop(
base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources));
VideoPixelFormat frame_format = VideoFormat(output_format_);
// Create the VideoFrame backed by native textures.
gfx::Size visible_size = video_frame->visible_rect().size();
scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTextures(
frame_format, mailbox_holders, release_mailbox_callback, coded_size,
frame_format, mailbox_holders, VideoFrame::ReleaseMailboxCB(), coded_size,
gfx::Rect(visible_size), video_frame->natural_size(),
video_frame->timestamp());
if (!frame) {
frame_resources->MarkUnused(tick_clock_->NowTicks());
release_mailbox_callback.Run(gpu::SyncToken());
MailboxHoldersReleased(frame_resources, gpu::SyncToken());
std::move(frame_copy_requests_.front().frame_ready_cb).Run(video_frame);
frame_copy_requests_.pop_front();
return;
}
frame->SetReleaseMailboxCB(
base::BindOnce(&PoolImpl::MailboxHoldersReleased, this, frame_resources));
frame->set_color_space(video_frame->ColorSpace());
......@@ -913,6 +911,7 @@ GpuMemoryBufferVideoFramePool::PoolImpl::~PoolImpl() {
}
void GpuMemoryBufferVideoFramePool::PoolImpl::Shutdown() {
DCHECK(media_task_runner_->BelongsToCurrentThread());
// Clients don't care about copies once shutdown has started, so abort them.
Abort();
......@@ -941,6 +940,7 @@ GpuMemoryBufferVideoFramePool::PoolImpl::FrameResources*
GpuMemoryBufferVideoFramePool::PoolImpl::GetOrCreateFrameResources(
const gfx::Size& size,
GpuVideoAcceleratorFactories::OutputFormat format) {
DCHECK(media_task_runner_->BelongsToCurrentThread());
auto it = resources_pool_.begin();
while (it != resources_pool_.end()) {
......@@ -1019,7 +1019,13 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::DeleteFrameResources(
void GpuMemoryBufferVideoFramePool::PoolImpl::MailboxHoldersReleased(
FrameResources* frame_resources,
const gpu::SyncToken& release_sync_token) {
DCHECK(media_task_runner_->BelongsToCurrentThread());
if (!media_task_runner_->BelongsToCurrentThread()) {
media_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&PoolImpl::MailboxHoldersReleased, this,
frame_resources, release_sync_token));
return;
}
if (in_shutdown_) {
DeleteFrameResources(gpu_factories_, frame_resources);
delete frame_resources;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment