Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: cc/resources/video_resource_updater.cc

Issue 1688033005: Monitor VideoResourceUpdater reusing destructed resource in Debug mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/video_resource_updater.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/video_resource_updater.h" 5 #include "cc/resources/video_resource_updater.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bit_cast.h" 13 #include "base/bit_cast.h"
14 #include "base/single_thread_task_runner.h"
15 #include "base/thread_task_runner_handle.h"
14 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
15 #include "cc/base/math_util.h" 17 #include "cc/base/math_util.h"
16 #include "cc/output/gl_renderer.h" 18 #include "cc/output/gl_renderer.h"
17 #include "cc/resources/resource_provider.h" 19 #include "cc/resources/resource_provider.h"
18 #include "gpu/GLES2/gl2extchromium.h" 20 #include "gpu/GLES2/gl2extchromium.h"
19 #include "gpu/command_buffer/client/gles2_interface.h" 21 #include "gpu/command_buffer/client/gles2_interface.h"
20 #include "media/base/video_frame.h" 22 #include "media/base/video_frame.h"
21 #include "media/renderers/skcanvas_video_renderer.h" 23 #include "media/renderers/skcanvas_video_renderer.h"
22 #include "third_party/khronos/GLES2/gl2.h" 24 #include "third_party/khronos/GLES2/gl2.h"
23 #include "third_party/khronos/GLES2/gl2ext.h" 25 #include "third_party/khronos/GLES2/gl2ext.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 sync_token_.Clear(); 107 sync_token_.Clear();
106 } 108 }
107 } 109 }
108 } 110 }
109 111
110 private: 112 private:
111 gpu::gles2::GLES2Interface* gl_; 113 gpu::gles2::GLES2Interface* gl_;
112 gpu::SyncToken sync_token_; 114 gpu::SyncToken sync_token_;
113 }; 115 };
114 116
117 void OnVideoFrameDestruct(
118 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
119 const base::Closure& task) {
120 task_runner->PostTask(FROM_HERE, task);
miu 2016/02/19 02:47:46 This will introduce an unknown time delay before t
xjz 2016/02/20 00:40:47 Done. Since each VideoFrame can have three resourc
121 }
122
115 } // namespace 123 } // namespace
116 124
117 VideoResourceUpdater::PlaneResource::PlaneResource( 125 VideoResourceUpdater::PlaneResource::PlaneResource(
118 unsigned int resource_id, 126 unsigned int resource_id,
119 const gfx::Size& resource_size, 127 const gfx::Size& resource_size,
120 ResourceFormat resource_format, 128 ResourceFormat resource_format,
121 gpu::Mailbox mailbox) 129 gpu::Mailbox mailbox)
122 : resource_id(resource_id), 130 : resource_id(resource_id),
123 resource_size(resource_size), 131 resource_size(resource_size),
124 resource_format(resource_format), 132 resource_format(resource_format),
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 354 }
347 } 355 }
348 } 356 }
349 357
350 // Check if we need to allocate a new resource. 358 // Check if we need to allocate a new resource.
351 if (resource_it == all_resources_.end()) { 359 if (resource_it == all_resources_.end()) {
352 const bool is_immutable = true; 360 const bool is_immutable = true;
353 resource_it = 361 resource_it =
354 AllocateResource(output_plane_resource_size, output_resource_format, 362 AllocateResource(output_plane_resource_size, output_resource_format,
355 !software_compositor, is_immutable); 363 !software_compositor, is_immutable);
364 if (resource_it != all_resources_.end()) {
365 video_frame->AddDestructionObserver(base::Bind(
366 &OnVideoFrameDestruct, base::ThreadTaskRunnerHandle::Get(),
367 base::Bind(&VideoResourceUpdater::InvalidateResource, AsWeakPtr(),
368 resource_it->resource_id)));
369 }
356 } 370 }
357 if (resource_it == all_resources_.end()) 371 if (resource_it == all_resources_.end())
358 break; 372 break;
359 373
360 ++resource_it->ref_count; 374 ++resource_it->ref_count;
361 plane_resources.push_back(resource_it); 375 plane_resources.push_back(resource_it);
362 } 376 }
363 377
364 if (plane_resources.size() != output_plane_count) { 378 if (plane_resources.size() != output_plane_count) {
365 // Allocation failed, nothing will be returned so restore reference counts. 379 // Allocation failed, nothing will be returned so restore reference counts.
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 if (lost_resource) { 692 if (lost_resource) {
679 resource_it->ref_count = 0; 693 resource_it->ref_count = 0;
680 updater->DeleteResource(resource_it); 694 updater->DeleteResource(resource_it);
681 return; 695 return;
682 } 696 }
683 697
684 --resource_it->ref_count; 698 --resource_it->ref_count;
685 DCHECK_GE(resource_it->ref_count, 0); 699 DCHECK_GE(resource_it->ref_count, 0);
686 } 700 }
687 701
702 // static
703 void VideoResourceUpdater::InvalidateResource(
704 base::WeakPtr<VideoResourceUpdater> updater,
705 ResourceId resource_id) {
706 if (!updater.get()) {
707 return;
708 }
709
710 const ResourceList::iterator resource_it = std::find_if(
711 updater->all_resources_.begin(), updater->all_resources_.end(),
712 [resource_id](const PlaneResource& plane_resource) {
713 return plane_resource.resource_id == resource_id;
714 });
715 if (resource_it == updater->all_resources_.end())
716 return;
717
718 resource_it->ref_count = 0;
719 updater->DeleteResource(resource_it);
720 }
721
688 } // namespace cc 722 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/video_resource_updater.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698