Chromium Code Reviews| Index: cc/resources/video_resource_updater.cc |
| diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc |
| index 46dbbc95e4e0cc6999f121afe6f9f7dff515444a..d1c0f546460f4d1be52a5428ace3b333d06fec6a 100644 |
| --- a/cc/resources/video_resource_updater.cc |
| +++ b/cc/resources/video_resource_updater.cc |
| @@ -23,6 +23,11 @@ |
| #include "third_party/khronos/GLES2/gl2ext.h" |
| #include "ui/gfx/geometry/size_conversions.h" |
| +#if !defined(NDEBUG) |
| +#include "base/single_thread_task_runner.h" |
| +#include "base/thread_task_runner_handle.h" |
| +#endif |
| + |
| namespace cc { |
| namespace { |
| @@ -112,6 +117,14 @@ class SyncTokenClientImpl : public media::VideoFrame::SyncTokenClient { |
| gpu::SyncToken sync_token_; |
| }; |
| +#if !defined(NDEBUG) |
| +void OnVideoFrameDestruct( |
| + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| + const base::Closure& task) { |
| + task_runner->PostTask(FROM_HERE, task); |
| +} |
| +#endif |
| + |
| } // namespace |
| VideoResourceUpdater::PlaneResource::PlaneResource( |
| @@ -125,6 +138,9 @@ VideoResourceUpdater::PlaneResource::PlaneResource( |
| mailbox(mailbox), |
| ref_count(0), |
| frame_ptr(nullptr), |
| +#if !defined(NDEBUG) |
| + destructed(false), |
| +#endif |
| plane_index(0u) { |
| } |
| @@ -135,9 +151,17 @@ bool VideoResourceUpdater::PlaneResourceMatchesUniqueID( |
| const PlaneResource& plane_resource, |
| const media::VideoFrame* video_frame, |
| size_t plane_index) { |
| - return plane_resource.frame_ptr == video_frame && |
| - plane_resource.plane_index == plane_index && |
| - plane_resource.timestamp == video_frame->timestamp(); |
| + bool matched = plane_resource.frame_ptr == video_frame && |
| + plane_resource.plane_index == plane_index && |
| + plane_resource.timestamp == video_frame->timestamp(); |
| +#if !defined(NDEBUG) |
| + if ((plane_index == 0) && matched) { |
| + DCHECK(plane_resource.destructed == false) |
|
miu
2016/03/09 01:59:49
nit: DCHECK(!plane_resource.destructed)
xjz
2016/03/10 01:51:44
Done.
|
| + << "ERROR: reused the destructed resource." |
| + << " timestamp = " << plane_resource.timestamp; |
| + } |
| +#endif |
| + return matched; |
| } |
| void VideoResourceUpdater::SetPlaneResourceUniqueId( |
| @@ -147,6 +171,9 @@ void VideoResourceUpdater::SetPlaneResourceUniqueId( |
| plane_resource->frame_ptr = video_frame; |
| plane_resource->plane_index = plane_index; |
| plane_resource->timestamp = video_frame->timestamp(); |
| +#if !defined(NDEBUG) |
| + plane_resource->destructed = false; |
| +#endif |
| } |
| VideoFrameExternalResources::VideoFrameExternalResources() |
| @@ -394,6 +421,14 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( |
| // by software. |
| video_renderer_->Copy(video_frame, &canvas, media::Context3D()); |
| SetPlaneResourceUniqueId(video_frame.get(), 0, &plane_resource); |
| +#if !defined(NDEBUG) |
| + // Add VideoFrame destructor callback. |
| + video_frame->AddDestructionObserver(base::Bind( |
| + &OnVideoFrameDestruct, base::ThreadTaskRunnerHandle::Get(), |
| + base::Bind(&VideoResourceUpdater::MarkOldResource, AsWeakPtr(), |
| + static_cast<void*>(video_frame.get()), |
| + video_frame->timestamp()))); |
| +#endif |
| } |
| external_resources.software_resources.push_back(plane_resource.resource_id); |
| @@ -489,6 +524,16 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( |
| resource_provider_->CopyToResource(plane_resource.resource_id, pixels, |
| resource_size_pixels); |
| SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource); |
| +#if !defined(NDEBUG) |
| + // Add VideoFrame destructor callback. |
| + if (i == 0) { |
| + video_frame->AddDestructionObserver(base::Bind( |
| + &OnVideoFrameDestruct, base::ThreadTaskRunnerHandle::Get(), |
| + base::Bind(&VideoResourceUpdater::MarkOldResource, AsWeakPtr(), |
| + static_cast<void*>(video_frame.get()), |
| + video_frame->timestamp()))); |
| + } |
| +#endif |
| } |
| if (plane_resource.resource_format == LUMINANCE_F16) { |
| @@ -693,4 +738,26 @@ void VideoResourceUpdater::RecycleResource( |
| DCHECK_GE(resource_it->ref_count, 0); |
| } |
| +#if !defined(NDEBUG) |
| +// static |
| +void VideoResourceUpdater::MarkOldResource( |
| + base::WeakPtr<VideoResourceUpdater> updater, |
| + const void* video_frame_ptr, |
| + base::TimeDelta timestamp) { |
| + if (!updater.get()) |
|
miu
2016/03/09 01:59:49
nit: if (!updater)
xjz
2016/03/10 01:51:44
Done.
|
| + return; |
| + const ResourceList::iterator resource_it = std::find_if( |
| + updater->all_resources_.begin(), updater->all_resources_.end(), |
| + [video_frame_ptr, timestamp](const PlaneResource& plane_resource) { |
| + return plane_resource.frame_ptr == video_frame_ptr && |
| + plane_resource.timestamp == timestamp && |
| + plane_resource.plane_index == 0; |
| + }); |
| + if (resource_it == updater->all_resources_.end()) |
| + return; |
| + |
| + resource_it->destructed = true; |
| +} |
| +#endif |
| + |
| } // namespace cc |