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

Side by Side Diff: cc/layers/video_frame_provider_client_impl.cc

Issue 1033563002: cc: Various code safety improvements in video compositing code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 5 years, 9 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
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/layers/video_frame_provider_client_impl.h" 5 #include "cc/layers/video_frame_provider_client_impl.h"
6 6
7 #include "base/trace_event/trace_event.h" 7 #include "base/trace_event/trace_event.h"
8 #include "cc/base/math_util.h" 8 #include "cc/base/math_util.h"
9 #include "cc/layers/video_layer_impl.h" 9 #include "cc/layers/video_layer_impl.h"
10 #include "media/base/video_frame.h" 10 #include "media/base/video_frame.h"
11 11
12 namespace cc { 12 namespace cc {
13 13
14 // static 14 // static
15 scoped_refptr<VideoFrameProviderClientImpl> 15 scoped_refptr<VideoFrameProviderClientImpl>
16 VideoFrameProviderClientImpl::Create( 16 VideoFrameProviderClientImpl::Create(VideoFrameProvider* provider) {
17 VideoFrameProvider* provider) { 17 return make_scoped_refptr(new VideoFrameProviderClientImpl(provider));
18 return make_scoped_refptr(
19 new VideoFrameProviderClientImpl(provider));
20 } 18 }
21 19
22 VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() {}
23
24 VideoFrameProviderClientImpl::VideoFrameProviderClientImpl( 20 VideoFrameProviderClientImpl::VideoFrameProviderClientImpl(
25 VideoFrameProvider* provider) 21 VideoFrameProvider* provider)
26 : active_video_layer_(nullptr), provider_(provider) { 22 : provider_(provider), active_video_layer_(nullptr), stopped_(false) {
27 // This only happens during a commit on the compositor thread while the main 23 // This only happens during a commit on the compositor thread while the main
28 // thread is blocked. That makes this a thread-safe call to set the video 24 // thread is blocked. That makes this a thread-safe call to set the video
29 // frame provider client that does not require a lock. The same is true of 25 // frame provider client that does not require a lock. The same is true of
30 // the call to Stop(). 26 // the call to Stop().
31 provider_->SetVideoFrameProviderClient(this); 27 provider_->SetVideoFrameProviderClient(this);
32 28
33 // This matrix is the default transformation for stream textures, and flips 29 // This matrix is the default transformation for stream textures, and flips
34 // on the Y axis. 30 // on the Y axis.
35 stream_texture_matrix_ = gfx::Transform( 31 stream_texture_matrix_ = gfx::Transform(
36 1.0, 0.0, 0.0, 0.0, 32 1.0, 0.0, 0.0, 0.0,
37 0.0, -1.0, 0.0, 1.0, 33 0.0, -1.0, 0.0, 1.0,
38 0.0, 0.0, 1.0, 0.0, 34 0.0, 0.0, 1.0, 0.0,
39 0.0, 0.0, 0.0, 1.0); 35 0.0, 0.0, 0.0, 1.0);
40 } 36 }
41 37
38 VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() {
39 DCHECK(thread_checker_.CalledOnValidThread());
40 DCHECK(stopped_);
41 }
42
43 VideoLayerImpl* VideoFrameProviderClientImpl::ActiveVideoLayer() const {
44 DCHECK(thread_checker_.CalledOnValidThread());
45 return active_video_layer_;
46 }
47
42 void VideoFrameProviderClientImpl::SetActiveVideoLayer( 48 void VideoFrameProviderClientImpl::SetActiveVideoLayer(
43 VideoLayerImpl* video_layer) { 49 VideoLayerImpl* video_layer) {
44 DCHECK(thread_checker_.CalledOnValidThread()); 50 DCHECK(thread_checker_.CalledOnValidThread());
45 DCHECK(video_layer); 51 DCHECK(video_layer);
46 active_video_layer_ = video_layer; 52 active_video_layer_ = video_layer;
47 } 53 }
48 54
49 void VideoFrameProviderClientImpl::Stop() { 55 void VideoFrameProviderClientImpl::Stop() {
56 DCHECK(thread_checker_.CalledOnValidThread());
50 // It's called when the main thread is blocked, so lock isn't needed. 57 // It's called when the main thread is blocked, so lock isn't needed.
51 if (!provider_) 58 if (provider_) {
52 return; 59 provider_->SetVideoFrameProviderClient(nullptr);
53 DCHECK(thread_checker_.CalledOnValidThread()); 60 provider_ = nullptr;
54 provider_->SetVideoFrameProviderClient(nullptr); 61 }
55 provider_ = nullptr; 62 active_video_layer_ = nullptr;
63 stopped_ = true;
56 } 64 }
57 65
58 bool VideoFrameProviderClientImpl::Stopped() { 66 bool VideoFrameProviderClientImpl::Stopped() const {
59 DCHECK(thread_checker_.CalledOnValidThread()); 67 DCHECK(thread_checker_.CalledOnValidThread());
60 // |provider_| is changed while the main thread is blocked, and not changed 68 return stopped_;
61 // thereafter, so lock isn't needed.
62 return !provider_;
63 } 69 }
64 70
65 scoped_refptr<media::VideoFrame> 71 scoped_refptr<media::VideoFrame>
66 VideoFrameProviderClientImpl::AcquireLockAndCurrentFrame() { 72 VideoFrameProviderClientImpl::AcquireLockAndCurrentFrame() {
67 DCHECK(thread_checker_.CalledOnValidThread()); 73 DCHECK(thread_checker_.CalledOnValidThread());
68 provider_lock_.Acquire(); // Balanced by call to ReleaseLock(). 74 provider_lock_.Acquire(); // Balanced by call to ReleaseLock().
69 if (!provider_) 75 if (!provider_)
70 return nullptr; 76 return nullptr;
71 77
72 return provider_->GetCurrentFrame(); 78 return provider_->GetCurrentFrame();
73 } 79 }
74 80
75 void VideoFrameProviderClientImpl::PutCurrentFrame( 81 void VideoFrameProviderClientImpl::PutCurrentFrame(
76 const scoped_refptr<media::VideoFrame>& frame) { 82 const scoped_refptr<media::VideoFrame>& frame) {
77 DCHECK(thread_checker_.CalledOnValidThread()); 83 DCHECK(thread_checker_.CalledOnValidThread());
78 provider_lock_.AssertAcquired(); 84 provider_lock_.AssertAcquired();
79 provider_->PutCurrentFrame(frame); 85 provider_->PutCurrentFrame(frame);
80 } 86 }
81 87
82 void VideoFrameProviderClientImpl::ReleaseLock() { 88 void VideoFrameProviderClientImpl::ReleaseLock() {
83 DCHECK(thread_checker_.CalledOnValidThread()); 89 DCHECK(thread_checker_.CalledOnValidThread());
84 provider_lock_.AssertAcquired(); 90 provider_lock_.AssertAcquired();
85 provider_lock_.Release(); 91 provider_lock_.Release();
86 } 92 }
87 93
94 const gfx::Transform& VideoFrameProviderClientImpl::StreamTextureMatrix()
95 const {
96 DCHECK(thread_checker_.CalledOnValidThread());
97 return stream_texture_matrix_;
98 }
99
88 void VideoFrameProviderClientImpl::StopUsingProvider() { 100 void VideoFrameProviderClientImpl::StopUsingProvider() {
89 // Block the provider from shutting down until this client is done 101 // Block the provider from shutting down until this client is done
90 // using the frame. 102 // using the frame.
91 base::AutoLock locker(provider_lock_); 103 base::AutoLock locker(provider_lock_);
92 provider_ = nullptr; 104 provider_ = nullptr;
93 } 105 }
94 106
95 void VideoFrameProviderClientImpl::DidReceiveFrame() { 107 void VideoFrameProviderClientImpl::DidReceiveFrame() {
96 TRACE_EVENT1("cc", 108 TRACE_EVENT1("cc",
97 "VideoFrameProviderClientImpl::DidReceiveFrame", 109 "VideoFrameProviderClientImpl::DidReceiveFrame",
98 "active_video_layer", 110 "active_video_layer",
99 !!active_video_layer_); 111 !!active_video_layer_);
100 DCHECK(thread_checker_.CalledOnValidThread()); 112 DCHECK(thread_checker_.CalledOnValidThread());
101 if (active_video_layer_) 113 if (active_video_layer_)
102 active_video_layer_->SetNeedsRedraw(); 114 active_video_layer_->SetNeedsRedraw();
103 } 115 }
104 116
105 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) { 117 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) {
106 DCHECK(thread_checker_.CalledOnValidThread()); 118 DCHECK(thread_checker_.CalledOnValidThread());
107 stream_texture_matrix_ = gfx::Transform( 119 stream_texture_matrix_ = gfx::Transform(
108 matrix[0], matrix[4], matrix[8], matrix[12], 120 matrix[0], matrix[4], matrix[8], matrix[12],
109 matrix[1], matrix[5], matrix[9], matrix[13], 121 matrix[1], matrix[5], matrix[9], matrix[13],
110 matrix[2], matrix[6], matrix[10], matrix[14], 122 matrix[2], matrix[6], matrix[10], matrix[14],
111 matrix[3], matrix[7], matrix[11], matrix[15]); 123 matrix[3], matrix[7], matrix[11], matrix[15]);
112 if (active_video_layer_) 124 if (active_video_layer_)
113 active_video_layer_->SetNeedsRedraw(); 125 active_video_layer_->SetNeedsRedraw();
114 } 126 }
115 127
116 } // namespace cc 128 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698