Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / cc / layers / video_frame_provider_client_impl.cc
blob3ca39efda389cb4c2b00092b5872f3c8094d3524
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 "base/trace_event/trace_event.h"
8 #include "cc/base/math_util.h"
9 #include "cc/layers/video_layer_impl.h"
10 #include "media/base/video_frame.h"
12 namespace cc {
14 // static
15 scoped_refptr<VideoFrameProviderClientImpl>
16 VideoFrameProviderClientImpl::Create(VideoFrameProvider* provider,
17 VideoFrameControllerClient* client) {
18 return make_scoped_refptr(new VideoFrameProviderClientImpl(provider, client));
21 VideoFrameProviderClientImpl::VideoFrameProviderClientImpl(
22 VideoFrameProvider* provider,
23 VideoFrameControllerClient* client)
24 : provider_(provider),
25 client_(client),
26 active_video_layer_(nullptr),
27 stopped_(false) {
28 // This only happens during a commit on the compositor thread while the main
29 // thread is blocked. That makes this a thread-safe call to set the video
30 // frame provider client that does not require a lock. The same is true of
31 // the call to Stop().
32 provider_->SetVideoFrameProviderClient(this);
34 // This matrix is the default transformation for stream textures, and flips
35 // on the Y axis.
36 stream_texture_matrix_ = gfx::Transform(
37 1.0, 0.0, 0.0, 0.0,
38 0.0, -1.0, 0.0, 1.0,
39 0.0, 0.0, 1.0, 0.0,
40 0.0, 0.0, 0.0, 1.0);
43 VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() {
44 DCHECK(thread_checker_.CalledOnValidThread());
45 DCHECK(stopped_);
48 VideoLayerImpl* VideoFrameProviderClientImpl::ActiveVideoLayer() const {
49 DCHECK(thread_checker_.CalledOnValidThread());
50 return active_video_layer_;
53 void VideoFrameProviderClientImpl::SetActiveVideoLayer(
54 VideoLayerImpl* video_layer) {
55 DCHECK(thread_checker_.CalledOnValidThread());
56 DCHECK(video_layer);
57 active_video_layer_ = video_layer;
60 void VideoFrameProviderClientImpl::Stop() {
61 DCHECK(thread_checker_.CalledOnValidThread());
62 // It's called when the main thread is blocked, so lock isn't needed.
63 if (provider_) {
64 provider_->SetVideoFrameProviderClient(nullptr);
65 provider_ = nullptr;
67 client_->RemoveVideoFrameController(this);
68 active_video_layer_ = nullptr;
69 stopped_ = true;
72 bool VideoFrameProviderClientImpl::Stopped() const {
73 DCHECK(thread_checker_.CalledOnValidThread());
74 return stopped_;
77 scoped_refptr<media::VideoFrame>
78 VideoFrameProviderClientImpl::AcquireLockAndCurrentFrame() {
79 DCHECK(thread_checker_.CalledOnValidThread());
80 provider_lock_.Acquire(); // Balanced by call to ReleaseLock().
81 if (!provider_)
82 return nullptr;
84 return provider_->GetCurrentFrame();
87 void VideoFrameProviderClientImpl::PutCurrentFrame() {
88 DCHECK(thread_checker_.CalledOnValidThread());
89 provider_lock_.AssertAcquired();
90 provider_->PutCurrentFrame();
93 void VideoFrameProviderClientImpl::ReleaseLock() {
94 DCHECK(thread_checker_.CalledOnValidThread());
95 provider_lock_.AssertAcquired();
96 provider_lock_.Release();
99 const gfx::Transform& VideoFrameProviderClientImpl::StreamTextureMatrix()
100 const {
101 DCHECK(thread_checker_.CalledOnValidThread());
102 return stream_texture_matrix_;
105 void VideoFrameProviderClientImpl::StopUsingProvider() {
106 // Block the provider from shutting down until this client is done
107 // using the frame.
108 base::AutoLock locker(provider_lock_);
109 provider_ = nullptr;
112 void VideoFrameProviderClientImpl::StartRendering() {
113 // TODO(dalecurtis, sunnyps): Hook this method up to control when to start
114 // observing vsync intervals. http://crbug.com/336733
117 void VideoFrameProviderClientImpl::StopRendering() {
118 // TODO(dalecurtis, sunnyps): Hook this method up to control when to stop
119 // observing vsync intervals. http://crbug.com/336733
122 void VideoFrameProviderClientImpl::DidReceiveFrame() {
123 TRACE_EVENT1("cc",
124 "VideoFrameProviderClientImpl::DidReceiveFrame",
125 "active_video_layer",
126 !!active_video_layer_);
127 DCHECK(thread_checker_.CalledOnValidThread());
128 if (active_video_layer_)
129 active_video_layer_->SetNeedsRedraw();
132 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) {
133 DCHECK(thread_checker_.CalledOnValidThread());
134 stream_texture_matrix_ = gfx::Transform(
135 matrix[0], matrix[4], matrix[8], matrix[12],
136 matrix[1], matrix[5], matrix[9], matrix[13],
137 matrix[2], matrix[6], matrix[10], matrix[14],
138 matrix[3], matrix[7], matrix[11], matrix[15]);
139 if (active_video_layer_)
140 active_video_layer_->SetNeedsRedraw();
143 void VideoFrameProviderClientImpl::OnBeginFrame(const BeginFrameArgs& args) {
144 DCHECK(thread_checker_.CalledOnValidThread());
145 NOTIMPLEMENTED();
148 } // namespace cc