OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/video_frame_provider_client_impl.h" | 5 #include "cc/layers/video_frame_provider_client_impl.h" |
6 | 6 |
7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
9 #include "cc/layers/video_layer_impl.h" | 9 #include "cc/layers/video_layer_impl.h" |
10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
14 // static | 14 // static |
15 scoped_refptr<VideoFrameProviderClientImpl> | 15 scoped_refptr<VideoFrameProviderClientImpl> |
16 VideoFrameProviderClientImpl::Create( | 16 VideoFrameProviderClientImpl::Create(VideoFrameProvider* provider) { |
17 VideoFrameProvider* provider) { | 17 return make_scoped_refptr(new VideoFrameProviderClientImpl(provider)); |
18 return make_scoped_refptr( | |
19 new VideoFrameProviderClientImpl(provider)); | |
20 } | 18 } |
21 | 19 |
22 VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() {} | |
23 | |
24 VideoFrameProviderClientImpl::VideoFrameProviderClientImpl( | 20 VideoFrameProviderClientImpl::VideoFrameProviderClientImpl( |
25 VideoFrameProvider* provider) | 21 VideoFrameProvider* provider) |
26 : active_video_layer_(nullptr), provider_(provider) { | 22 : provider_(provider), active_video_layer_(nullptr), stopped_(false) { |
27 // This only happens during a commit on the compositor thread while the main | 23 // This only happens during a commit on the compositor thread while the main |
28 // thread is blocked. That makes this a thread-safe call to set the video | 24 // thread is blocked. That makes this a thread-safe call to set the video |
29 // frame provider client that does not require a lock. The same is true of | 25 // frame provider client that does not require a lock. The same is true of |
30 // the call to Stop(). | 26 // the call to Stop(). |
31 provider_->SetVideoFrameProviderClient(this); | 27 provider_->SetVideoFrameProviderClient(this); |
32 | 28 |
33 // This matrix is the default transformation for stream textures, and flips | 29 // This matrix is the default transformation for stream textures, and flips |
34 // on the Y axis. | 30 // on the Y axis. |
35 stream_texture_matrix_ = gfx::Transform( | 31 stream_texture_matrix_ = gfx::Transform( |
36 1.0, 0.0, 0.0, 0.0, | 32 1.0, 0.0, 0.0, 0.0, |
37 0.0, -1.0, 0.0, 1.0, | 33 0.0, -1.0, 0.0, 1.0, |
38 0.0, 0.0, 1.0, 0.0, | 34 0.0, 0.0, 1.0, 0.0, |
39 0.0, 0.0, 0.0, 1.0); | 35 0.0, 0.0, 0.0, 1.0); |
40 } | 36 } |
41 | 37 |
42 void VideoFrameProviderClientImpl::SetActiveVideoLayer( | 38 VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() { |
43 VideoLayerImpl* video_layer) { | 39 DCHECK(Stopped()); |
40 } | |
41 | |
42 void VideoFrameProviderClientImpl::Start(VideoLayerImpl* active_video_layer) { | |
44 DCHECK(thread_checker_.CalledOnValidThread()); | 43 DCHECK(thread_checker_.CalledOnValidThread()); |
45 DCHECK(video_layer); | 44 DCHECK(active_video_layer); |
46 active_video_layer_ = video_layer; | 45 active_video_layer_ = active_video_layer; |
46 } | |
47 | |
48 bool VideoFrameProviderClientImpl::Started() const { | |
49 DCHECK(thread_checker_.CalledOnValidThread()); | |
50 return !!active_video_layer_; | |
47 } | 51 } |
48 | 52 |
49 void VideoFrameProviderClientImpl::Stop() { | 53 void VideoFrameProviderClientImpl::Stop() { |
54 DCHECK(thread_checker_.CalledOnValidThread()); | |
50 // It's called when the main thread is blocked, so lock isn't needed. | 55 // It's called when the main thread is blocked, so lock isn't needed. |
51 if (!provider_) | 56 if (provider_) { |
52 return; | 57 provider_->SetVideoFrameProviderClient(nullptr); |
53 DCHECK(thread_checker_.CalledOnValidThread()); | 58 provider_ = nullptr; |
54 provider_->SetVideoFrameProviderClient(nullptr); | 59 } |
55 provider_ = nullptr; | 60 active_video_layer_ = nullptr; |
61 stopped_ = true; | |
56 } | 62 } |
57 | 63 |
58 bool VideoFrameProviderClientImpl::Stopped() { | 64 bool VideoFrameProviderClientImpl::Stopped() const { |
59 DCHECK(thread_checker_.CalledOnValidThread()); | 65 DCHECK(thread_checker_.CalledOnValidThread()); |
60 // |provider_| is changed while the main thread is blocked, and not changed | 66 return stopped_; |
61 // thereafter, so lock isn't needed. | |
62 return !provider_; | |
63 } | 67 } |
64 | 68 |
65 scoped_refptr<media::VideoFrame> | 69 scoped_refptr<media::VideoFrame> |
66 VideoFrameProviderClientImpl::AcquireLockAndCurrentFrame() { | 70 VideoFrameProviderClientImpl::AcquireLockAndCurrentFrame() { |
67 DCHECK(thread_checker_.CalledOnValidThread()); | 71 DCHECK(thread_checker_.CalledOnValidThread()); |
68 provider_lock_.Acquire(); // Balanced by call to ReleaseLock(). | 72 provider_lock_.Acquire(); // Balanced by call to ReleaseLock(). |
69 if (!provider_) | 73 if (!provider_) |
70 return nullptr; | 74 return nullptr; |
71 | 75 |
72 return provider_->GetCurrentFrame(); | 76 return provider_->GetCurrentFrame(); |
73 } | 77 } |
74 | 78 |
75 void VideoFrameProviderClientImpl::PutCurrentFrame( | 79 void VideoFrameProviderClientImpl::PutCurrentFrame( |
76 const scoped_refptr<media::VideoFrame>& frame) { | 80 const scoped_refptr<media::VideoFrame>& frame) { |
77 DCHECK(thread_checker_.CalledOnValidThread()); | 81 DCHECK(thread_checker_.CalledOnValidThread()); |
78 provider_lock_.AssertAcquired(); | 82 provider_lock_.AssertAcquired(); |
79 provider_->PutCurrentFrame(frame); | 83 provider_->PutCurrentFrame(frame); |
80 } | 84 } |
81 | 85 |
82 void VideoFrameProviderClientImpl::ReleaseLock() { | 86 void VideoFrameProviderClientImpl::ReleaseLock() { |
83 DCHECK(thread_checker_.CalledOnValidThread()); | 87 DCHECK(thread_checker_.CalledOnValidThread()); |
84 provider_lock_.AssertAcquired(); | 88 provider_lock_.AssertAcquired(); |
85 provider_lock_.Release(); | 89 provider_lock_.Release(); |
86 } | 90 } |
87 | 91 |
88 void VideoFrameProviderClientImpl::StopUsingProvider() { | 92 void VideoFrameProviderClientImpl::StopUsingProvider() { |
89 // Block the provider from shutting down until this client is done | 93 // Block the provider from shutting down until the frame controller and it's |
danakj
2015/03/24 17:38:01
this is the only mention of a frame controller, i
sunnyps
2015/03/24 19:43:38
Done.
| |
90 // using the frame. | 94 // layer is done using the frame. |
91 base::AutoLock locker(provider_lock_); | 95 base::AutoLock locker(provider_lock_); |
92 provider_ = nullptr; | 96 provider_ = nullptr; |
93 } | 97 } |
94 | 98 |
95 void VideoFrameProviderClientImpl::DidReceiveFrame() { | 99 void VideoFrameProviderClientImpl::DidReceiveFrame() { |
96 TRACE_EVENT1("cc", | |
97 "VideoFrameProviderClientImpl::DidReceiveFrame", | |
98 "active_video_layer", | |
99 !!active_video_layer_); | |
100 DCHECK(thread_checker_.CalledOnValidThread()); | 100 DCHECK(thread_checker_.CalledOnValidThread()); |
101 TRACE_EVENT1("cc", "VideoFrameProviderClientImpl::DidReceiveFrame", "Started", | |
102 Started()); | |
101 if (active_video_layer_) | 103 if (active_video_layer_) |
102 active_video_layer_->SetNeedsRedraw(); | 104 active_video_layer_->SetNeedsRedraw(); |
103 } | 105 } |
104 | 106 |
105 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) { | 107 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) { |
106 DCHECK(thread_checker_.CalledOnValidThread()); | 108 DCHECK(thread_checker_.CalledOnValidThread()); |
107 stream_texture_matrix_ = gfx::Transform( | 109 stream_texture_matrix_ = gfx::Transform( |
108 matrix[0], matrix[4], matrix[8], matrix[12], | 110 matrix[0], matrix[4], matrix[8], matrix[12], |
109 matrix[1], matrix[5], matrix[9], matrix[13], | 111 matrix[1], matrix[5], matrix[9], matrix[13], |
110 matrix[2], matrix[6], matrix[10], matrix[14], | 112 matrix[2], matrix[6], matrix[10], matrix[14], |
111 matrix[3], matrix[7], matrix[11], matrix[15]); | 113 matrix[3], matrix[7], matrix[11], matrix[15]); |
112 if (active_video_layer_) | 114 if (active_video_layer_) |
113 active_video_layer_->SetNeedsRedraw(); | 115 active_video_layer_->SetNeedsRedraw(); |
114 } | 116 } |
115 | 117 |
116 } // namespace cc | 118 } // namespace cc |
OLD | NEW |