Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / layers / video_frame_provider_client_impl.cc
blobed2b90007bf287338d56bbab3805d9973e85d3a6
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 rendering_(false) {
29 // This only happens during a commit on the compositor thread while the main
30 // thread is blocked. That makes this a thread-safe call to set the video
31 // frame provider client that does not require a lock. The same is true of
32 // the call to Stop().
33 provider_->SetVideoFrameProviderClient(this);
35 // This matrix is the default transformation for stream textures, and flips
36 // on the Y axis.
37 stream_texture_matrix_ = gfx::Transform(
38 1.0, 0.0, 0.0, 0.0,
39 0.0, -1.0, 0.0, 1.0,
40 0.0, 0.0, 1.0, 0.0,
41 0.0, 0.0, 0.0, 1.0);
44 VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() {
45 DCHECK(thread_checker_.CalledOnValidThread());
46 DCHECK(stopped_);
49 VideoLayerImpl* VideoFrameProviderClientImpl::ActiveVideoLayer() const {
50 DCHECK(thread_checker_.CalledOnValidThread());
51 return active_video_layer_;
54 void VideoFrameProviderClientImpl::SetActiveVideoLayer(
55 VideoLayerImpl* video_layer) {
56 DCHECK(thread_checker_.CalledOnValidThread());
57 DCHECK(video_layer);
58 active_video_layer_ = video_layer;
61 void VideoFrameProviderClientImpl::Stop() {
62 DCHECK(thread_checker_.CalledOnValidThread());
63 // It's called when the main thread is blocked, so lock isn't needed.
64 if (provider_) {
65 provider_->SetVideoFrameProviderClient(nullptr);
66 provider_ = nullptr;
68 if (rendering_)
69 StopRendering();
70 active_video_layer_ = nullptr;
71 stopped_ = true;
74 bool VideoFrameProviderClientImpl::Stopped() const {
75 DCHECK(thread_checker_.CalledOnValidThread());
76 return stopped_;
79 scoped_refptr<media::VideoFrame>
80 VideoFrameProviderClientImpl::AcquireLockAndCurrentFrame() {
81 DCHECK(thread_checker_.CalledOnValidThread());
82 provider_lock_.Acquire(); // Balanced by call to ReleaseLock().
83 if (!provider_)
84 return nullptr;
86 return provider_->GetCurrentFrame();
89 void VideoFrameProviderClientImpl::PutCurrentFrame() {
90 DCHECK(thread_checker_.CalledOnValidThread());
91 provider_lock_.AssertAcquired();
92 provider_->PutCurrentFrame();
95 void VideoFrameProviderClientImpl::ReleaseLock() {
96 DCHECK(thread_checker_.CalledOnValidThread());
97 provider_lock_.AssertAcquired();
98 provider_lock_.Release();
101 bool VideoFrameProviderClientImpl::HasCurrentFrame() {
102 base::AutoLock locker(provider_lock_);
103 return provider_ && provider_->HasCurrentFrame();
106 const gfx::Transform& VideoFrameProviderClientImpl::StreamTextureMatrix()
107 const {
108 DCHECK(thread_checker_.CalledOnValidThread());
109 return stream_texture_matrix_;
112 void VideoFrameProviderClientImpl::StopUsingProvider() {
113 // Block the provider from shutting down until this client is done
114 // using the frame.
115 base::AutoLock locker(provider_lock_);
116 provider_ = nullptr;
117 if (rendering_)
118 StopRendering();
121 void VideoFrameProviderClientImpl::StartRendering() {
122 DCHECK(thread_checker_.CalledOnValidThread());
123 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::StartRendering");
124 DCHECK(!rendering_);
125 DCHECK(!stopped_);
126 rendering_ = true;
127 client_->AddVideoFrameController(this);
130 void VideoFrameProviderClientImpl::StopRendering() {
131 DCHECK(thread_checker_.CalledOnValidThread());
132 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::StopRendering");
133 DCHECK(rendering_);
134 DCHECK(!stopped_);
135 client_->RemoveVideoFrameController(this);
136 rendering_ = false;
139 void VideoFrameProviderClientImpl::DidReceiveFrame() {
140 TRACE_EVENT1("cc",
141 "VideoFrameProviderClientImpl::DidReceiveFrame",
142 "active_video_layer",
143 !!active_video_layer_);
144 DCHECK(thread_checker_.CalledOnValidThread());
145 if (active_video_layer_)
146 active_video_layer_->SetNeedsRedraw();
149 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) {
150 DCHECK(thread_checker_.CalledOnValidThread());
151 stream_texture_matrix_ = gfx::Transform(
152 matrix[0], matrix[4], matrix[8], matrix[12],
153 matrix[1], matrix[5], matrix[9], matrix[13],
154 matrix[2], matrix[6], matrix[10], matrix[14],
155 matrix[3], matrix[7], matrix[11], matrix[15]);
156 if (active_video_layer_)
157 active_video_layer_->SetNeedsRedraw();
160 void VideoFrameProviderClientImpl::OnBeginFrame(const BeginFrameArgs& args) {
161 DCHECK(thread_checker_.CalledOnValidThread());
162 DCHECK(rendering_);
163 DCHECK(!stopped_);
165 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::OnBeginFrame");
166 base::AutoLock locker(provider_lock_);
168 // We use frame_time + interval here because that is the estimated time at
169 // which a frame returned during this phase will end up being displayed.
170 if (!provider_ ||
171 !provider_->UpdateCurrentFrame(args.frame_time + args.interval,
172 args.frame_time + 2 * args.interval)) {
173 return;
176 DidReceiveFrame();
179 } // namespace cc