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
3 // found in the LICENSE file.
5 #include "cc/layers/video_frame_provider_client_impl.h"
7 #include "cc/base/math_util.h"
8 #include "cc/layers/video_layer_impl.h"
9 #include "media/base/video_frame.h"
14 scoped_refptr
<VideoFrameProviderClientImpl
>
15 VideoFrameProviderClientImpl::Create(
16 VideoFrameProvider
* provider
) {
17 return make_scoped_refptr(
18 new VideoFrameProviderClientImpl(provider
));
21 VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() {}
23 VideoFrameProviderClientImpl::VideoFrameProviderClientImpl(
24 VideoFrameProvider
* provider
)
25 : provider_(provider
) {
26 // This only happens during a commit on the compositor thread while the main
27 // thread is blocked. That makes this a thread-safe call to set the video
28 // frame provider client that does not require a lock. The same is true of
29 // the call to Stop().
30 provider_
->SetVideoFrameProviderClient(this);
32 // This matrix is the default transformation for stream textures, and flips
34 stream_texture_matrix_
= gfx::Transform(
41 void VideoFrameProviderClientImpl::Stop() {
44 provider_
->SetVideoFrameProviderClient(NULL
);
48 scoped_refptr
<media::VideoFrame
>
49 VideoFrameProviderClientImpl::AcquireLockAndCurrentFrame() {
50 provider_lock_
.Acquire(); // Balanced by call to ReleaseLock().
54 return provider_
->GetCurrentFrame();
57 void VideoFrameProviderClientImpl::PutCurrentFrame(
58 const scoped_refptr
<media::VideoFrame
>& frame
) {
59 provider_lock_
.AssertAcquired();
60 provider_
->PutCurrentFrame(frame
);
63 void VideoFrameProviderClientImpl::ReleaseLock() {
64 provider_lock_
.AssertAcquired();
65 provider_lock_
.Release();
68 void VideoFrameProviderClientImpl::StopUsingProvider() {
69 // Block the provider from shutting down until this client is done
71 base::AutoLock
locker(provider_lock_
);
75 void VideoFrameProviderClientImpl::DidReceiveFrame() {
76 if (active_video_layer_
)
77 active_video_layer_
->SetNeedsRedraw();
80 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix
) {
81 stream_texture_matrix_
= gfx::Transform(
82 matrix
[0], matrix
[4], matrix
[8], matrix
[12],
83 matrix
[1], matrix
[5], matrix
[9], matrix
[13],
84 matrix
[2], matrix
[6], matrix
[10], matrix
[14],
85 matrix
[3], matrix
[7], matrix
[11], matrix
[15]);
86 if (active_video_layer_
)
87 active_video_layer_
->SetNeedsRedraw();