Web MIDI: add MidiScheduler for send() with timestamp
[chromium-blink-merge.git] / cc / layers / video_frame_provider_client_impl.cc
blob68e10dc58edfbffaa3d53cf4466a2a675aad305d
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 return make_scoped_refptr(new VideoFrameProviderClientImpl(provider));
20 VideoFrameProviderClientImpl::VideoFrameProviderClientImpl(
21 VideoFrameProvider* provider)
22 : provider_(provider), active_video_layer_(nullptr), stopped_(false) {
23 // This only happens during a commit on the compositor thread while the main
24 // thread is blocked. That makes this a thread-safe call to set the video
25 // frame provider client that does not require a lock. The same is true of
26 // the call to Stop().
27 provider_->SetVideoFrameProviderClient(this);
29 // This matrix is the default transformation for stream textures, and flips
30 // on the Y axis.
31 stream_texture_matrix_ = gfx::Transform(
32 1.0, 0.0, 0.0, 0.0,
33 0.0, -1.0, 0.0, 1.0,
34 0.0, 0.0, 1.0, 0.0,
35 0.0, 0.0, 0.0, 1.0);
38 VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() {
39 DCHECK(thread_checker_.CalledOnValidThread());
40 DCHECK(stopped_);
43 VideoLayerImpl* VideoFrameProviderClientImpl::ActiveVideoLayer() const {
44 DCHECK(thread_checker_.CalledOnValidThread());
45 return active_video_layer_;
48 void VideoFrameProviderClientImpl::SetActiveVideoLayer(
49 VideoLayerImpl* video_layer) {
50 DCHECK(thread_checker_.CalledOnValidThread());
51 DCHECK(video_layer);
52 active_video_layer_ = video_layer;
55 void VideoFrameProviderClientImpl::Stop() {
56 DCHECK(thread_checker_.CalledOnValidThread());
57 // It's called when the main thread is blocked, so lock isn't needed.
58 if (provider_) {
59 provider_->SetVideoFrameProviderClient(nullptr);
60 provider_ = nullptr;
62 active_video_layer_ = nullptr;
63 stopped_ = true;
66 bool VideoFrameProviderClientImpl::Stopped() const {
67 DCHECK(thread_checker_.CalledOnValidThread());
68 return stopped_;
71 scoped_refptr<media::VideoFrame>
72 VideoFrameProviderClientImpl::AcquireLockAndCurrentFrame() {
73 DCHECK(thread_checker_.CalledOnValidThread());
74 provider_lock_.Acquire(); // Balanced by call to ReleaseLock().
75 if (!provider_)
76 return nullptr;
78 return provider_->GetCurrentFrame();
81 void VideoFrameProviderClientImpl::PutCurrentFrame(
82 const scoped_refptr<media::VideoFrame>& frame) {
83 DCHECK(thread_checker_.CalledOnValidThread());
84 provider_lock_.AssertAcquired();
85 provider_->PutCurrentFrame(frame);
88 void VideoFrameProviderClientImpl::ReleaseLock() {
89 DCHECK(thread_checker_.CalledOnValidThread());
90 provider_lock_.AssertAcquired();
91 provider_lock_.Release();
94 const gfx::Transform& VideoFrameProviderClientImpl::StreamTextureMatrix()
95 const {
96 DCHECK(thread_checker_.CalledOnValidThread());
97 return stream_texture_matrix_;
100 void VideoFrameProviderClientImpl::StopUsingProvider() {
101 // Block the provider from shutting down until this client is done
102 // using the frame.
103 base::AutoLock locker(provider_lock_);
104 provider_ = nullptr;
107 void VideoFrameProviderClientImpl::DidReceiveFrame() {
108 TRACE_EVENT1("cc",
109 "VideoFrameProviderClientImpl::DidReceiveFrame",
110 "active_video_layer",
111 !!active_video_layer_);
112 DCHECK(thread_checker_.CalledOnValidThread());
113 if (active_video_layer_)
114 active_video_layer_->SetNeedsRedraw();
117 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) {
118 DCHECK(thread_checker_.CalledOnValidThread());
119 stream_texture_matrix_ = gfx::Transform(
120 matrix[0], matrix[4], matrix[8], matrix[12],
121 matrix[1], matrix[5], matrix[9], matrix[13],
122 matrix[2], matrix[6], matrix[10], matrix[14],
123 matrix[3], matrix[7], matrix[11], matrix[15]);
124 if (active_video_layer_)
125 active_video_layer_->SetNeedsRedraw();
128 } // namespace cc