Chromium Code Reviews| Index: cc/video_frame_provider_client_impl.cc |
| diff --git a/cc/video_frame_provider_client_impl.cc b/cc/video_frame_provider_client_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2aa5c6f4dff5e48216786bb1da99608fd42bc016 |
| --- /dev/null |
| +++ b/cc/video_frame_provider_client_impl.cc |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/video_frame_provider_client_impl.h" |
| + |
| +#include "cc/math_util.h" |
| +#include "cc/video_layer_impl.h" |
| + |
| +namespace cc { |
| + |
| +// static |
| +scoped_refptr<VideoFrameProviderClientImpl> |
| + VideoFrameProviderClientImpl::Create( |
| + VideoFrameProvider* provider) { |
| + return make_scoped_refptr( |
| + new VideoFrameProviderClientImpl(provider)); |
| +} |
| + |
| +VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() {} |
| + |
| +VideoFrameProviderClientImpl::VideoFrameProviderClientImpl( |
| + VideoFrameProvider* provider) |
| + : provider_(provider) { |
| + // This only happens during a commit on the compositor thread while the main |
|
enne (OOO)
2013/01/17 23:34:55
Can we assert that the main thread is blocked here
jamesr
2013/01/18 01:16:42
Not without plumbing a pointer to the cc::Proxy do
|
| + // thread is blocked. That makes this a thread-safe call to set the video |
| + // frame provider client that does not require a lock. The same is true of |
| + // the call to Stop(). |
| + provider_->SetVideoFrameProviderClient(this); |
| + |
| + // This matrix is the default transformation for stream textures, and flips |
| + // on the Y axis. |
| + stream_texture_matrix_ = gfx::Transform( |
| + 1.0, 0.0, 0.0, 0.0, |
| + 0.0, -1.0, 0.0, 1.0, |
| + 0.0, 0.0, 1.0, 0.0, |
| + 0.0, 0.0, 0.0, 1.0); |
| +} |
| + |
| +void VideoFrameProviderClientImpl::Stop() { |
| + if (!provider_) |
| + return; |
| + provider_->SetVideoFrameProviderClient(0); |
|
danakj
2013/01/18 00:06:13
nit: s/0/NULL/. also on next line.
jamesr
2013/01/18 01:16:42
Done.
|
| + provider_ = 0; |
| +} |
| + |
| +media::VideoFrame* VideoFrameProviderClientImpl::AcquireLockAndCurrentFrame() { |
| + provider_lock_.Acquire(); // Balanced by call to ReleaseLock(). |
| + if (!provider_) |
| + return NULL; |
| + |
| + return provider_->GetCurrentFrame(); |
| +} |
| + |
| +void VideoFrameProviderClientImpl::PutCurrentFrame(media::VideoFrame* frame) { |
| + provider_lock_.AssertAcquired(); |
| + provider_->PutCurrentFrame(frame); |
| +} |
| + |
| +void VideoFrameProviderClientImpl::ReleaseLock() { |
| + provider_lock_.AssertAcquired(); |
| + provider_lock_.Release(); |
| +} |
| + |
| +void VideoFrameProviderClientImpl::StopUsingProvider() { |
| + // Block the provider from shutting down until this client is done |
| + // using the frame. |
| + base::AutoLock locker(provider_lock_); |
| + provider_ = 0; |
| +} |
| + |
| +void VideoFrameProviderClientImpl::DidReceiveFrame() { |
| + if (active_video_layer_) |
| + active_video_layer_->setNeedsRedraw(); |
| +} |
| + |
| +void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) { |
|
enne (OOO)
2013/01/17 23:34:55
What was the issue with the intermittently incorre
|
| + stream_texture_matrix_ = gfx::Transform( |
| + matrix[0], matrix[4], matrix[8], matrix[12], |
| + matrix[1], matrix[5], matrix[9], matrix[13], |
| + matrix[2], matrix[6], matrix[10], matrix[14], |
| + matrix[3], matrix[7], matrix[11], matrix[15]); |
| + if (active_video_layer_) |
| + active_video_layer_->setNeedsRedraw(); |
| +} |
| + |
| +} // namespace cc |