OLD | NEW |
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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 client_(client), | 25 client_(client), |
26 active_video_layer_(nullptr), | 26 active_video_layer_(nullptr), |
27 stopped_(false), | 27 stopped_(false), |
28 rendering_(false), | 28 rendering_(false), |
29 needs_put_current_frame_(false) { | 29 needs_put_current_frame_(false) { |
30 // This only happens during a commit on the compositor thread while the main | 30 // This only happens during a commit on the compositor thread while the main |
31 // thread is blocked. That makes this a thread-safe call to set the video | 31 // thread is blocked. That makes this a thread-safe call to set the video |
32 // frame provider client that does not require a lock. The same is true of | 32 // frame provider client that does not require a lock. The same is true of |
33 // the call to Stop(). | 33 // the call to Stop(). |
34 provider_->SetVideoFrameProviderClient(this); | 34 provider_->SetVideoFrameProviderClient(this); |
35 | |
36 // This matrix is the default transformation for stream textures, and flips | |
37 // on the Y axis. | |
38 stream_texture_matrix_ = gfx::Transform( | |
39 1.0, 0.0, 0.0, 0.0, | |
40 0.0, -1.0, 0.0, 1.0, | |
41 0.0, 0.0, 1.0, 0.0, | |
42 0.0, 0.0, 0.0, 1.0); | |
43 } | 35 } |
44 | 36 |
45 VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() { | 37 VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() { |
46 DCHECK(thread_checker_.CalledOnValidThread()); | 38 DCHECK(thread_checker_.CalledOnValidThread()); |
47 DCHECK(stopped_); | 39 DCHECK(stopped_); |
48 } | 40 } |
49 | 41 |
50 VideoLayerImpl* VideoFrameProviderClientImpl::ActiveVideoLayer() const { | 42 VideoLayerImpl* VideoFrameProviderClientImpl::ActiveVideoLayer() const { |
51 DCHECK(thread_checker_.CalledOnValidThread()); | 43 DCHECK(thread_checker_.CalledOnValidThread()); |
52 return active_video_layer_; | 44 return active_video_layer_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 DCHECK(thread_checker_.CalledOnValidThread()); | 90 DCHECK(thread_checker_.CalledOnValidThread()); |
99 provider_lock_.AssertAcquired(); | 91 provider_lock_.AssertAcquired(); |
100 provider_lock_.Release(); | 92 provider_lock_.Release(); |
101 } | 93 } |
102 | 94 |
103 bool VideoFrameProviderClientImpl::HasCurrentFrame() { | 95 bool VideoFrameProviderClientImpl::HasCurrentFrame() { |
104 base::AutoLock locker(provider_lock_); | 96 base::AutoLock locker(provider_lock_); |
105 return provider_ && provider_->HasCurrentFrame(); | 97 return provider_ && provider_->HasCurrentFrame(); |
106 } | 98 } |
107 | 99 |
108 const gfx::Transform& VideoFrameProviderClientImpl::StreamTextureMatrix() | |
109 const { | |
110 DCHECK(thread_checker_.CalledOnValidThread()); | |
111 return stream_texture_matrix_; | |
112 } | |
113 | |
114 void VideoFrameProviderClientImpl::StopUsingProvider() { | 100 void VideoFrameProviderClientImpl::StopUsingProvider() { |
115 { | 101 { |
116 // Block the provider from shutting down until this client is done | 102 // Block the provider from shutting down until this client is done |
117 // using the frame. | 103 // using the frame. |
118 base::AutoLock locker(provider_lock_); | 104 base::AutoLock locker(provider_lock_); |
119 provider_ = nullptr; | 105 provider_ = nullptr; |
120 } | 106 } |
121 if (rendering_) | 107 if (rendering_) |
122 StopRendering(); | 108 StopRendering(); |
123 } | 109 } |
(...skipping 20 matching lines...) Expand all Loading... |
144 TRACE_EVENT1("cc", | 130 TRACE_EVENT1("cc", |
145 "VideoFrameProviderClientImpl::DidReceiveFrame", | 131 "VideoFrameProviderClientImpl::DidReceiveFrame", |
146 "active_video_layer", | 132 "active_video_layer", |
147 !!active_video_layer_); | 133 !!active_video_layer_); |
148 DCHECK(thread_checker_.CalledOnValidThread()); | 134 DCHECK(thread_checker_.CalledOnValidThread()); |
149 needs_put_current_frame_ = true; | 135 needs_put_current_frame_ = true; |
150 if (active_video_layer_) | 136 if (active_video_layer_) |
151 active_video_layer_->SetNeedsRedraw(); | 137 active_video_layer_->SetNeedsRedraw(); |
152 } | 138 } |
153 | 139 |
154 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) { | |
155 DCHECK(thread_checker_.CalledOnValidThread()); | |
156 stream_texture_matrix_ = gfx::Transform( | |
157 matrix[0], matrix[4], matrix[8], matrix[12], | |
158 matrix[1], matrix[5], matrix[9], matrix[13], | |
159 matrix[2], matrix[6], matrix[10], matrix[14], | |
160 matrix[3], matrix[7], matrix[11], matrix[15]); | |
161 if (active_video_layer_) | |
162 active_video_layer_->SetNeedsRedraw(); | |
163 } | |
164 | |
165 void VideoFrameProviderClientImpl::OnBeginFrame(const BeginFrameArgs& args) { | 140 void VideoFrameProviderClientImpl::OnBeginFrame(const BeginFrameArgs& args) { |
166 DCHECK(thread_checker_.CalledOnValidThread()); | 141 DCHECK(thread_checker_.CalledOnValidThread()); |
167 DCHECK(rendering_); | 142 DCHECK(rendering_); |
168 DCHECK(!stopped_); | 143 DCHECK(!stopped_); |
169 | 144 |
170 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::OnBeginFrame"); | 145 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::OnBeginFrame"); |
171 { | 146 { |
172 base::AutoLock locker(provider_lock_); | 147 base::AutoLock locker(provider_lock_); |
173 | 148 |
174 // We use frame_time + interval here because that is the estimated time at | 149 // We use frame_time + interval here because that is the estimated time at |
(...skipping 14 matching lines...) Expand all Loading... |
189 DCHECK(thread_checker_.CalledOnValidThread()); | 164 DCHECK(thread_checker_.CalledOnValidThread()); |
190 { | 165 { |
191 base::AutoLock locker(provider_lock_); | 166 base::AutoLock locker(provider_lock_); |
192 if (provider_ && needs_put_current_frame_) | 167 if (provider_ && needs_put_current_frame_) |
193 provider_->PutCurrentFrame(); | 168 provider_->PutCurrentFrame(); |
194 } | 169 } |
195 needs_put_current_frame_ = false; | 170 needs_put_current_frame_ = false; |
196 } | 171 } |
197 | 172 |
198 } // namespace cc | 173 } // namespace cc |
OLD | NEW |