Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: content/renderer/media_capture_from_element/html_video_element_capturer_source.cc

Issue 2764633002: cc/paint: Remove cc::PaintSurface. (Closed)
Patch Set: more stuff Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/renderer/media_capture_from_element/html_video_element_capture r_source.h" 5 #include "content/renderer/media_capture_from_element/html_video_element_capture r_source.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "cc/paint/paint_canvas.h" 12 #include "cc/paint/skia_paint_canvas.h"
13 #include "cc/paint/paint_surface.h"
14 #include "content/public/renderer/render_thread.h" 13 #include "content/public/renderer/render_thread.h"
15 #include "content/renderer/media/media_stream_video_source.h" 14 #include "content/renderer/media/media_stream_video_source.h"
16 #include "content/renderer/media/webrtc_uma_histograms.h" 15 #include "content/renderer/media/webrtc_uma_histograms.h"
17 #include "media/base/limits.h" 16 #include "media/base/limits.h"
18 #include "media/blink/webmediaplayer_impl.h" 17 #include "media/blink/webmediaplayer_impl.h"
19 #include "skia/ext/platform_canvas.h" 18 #include "skia/ext/platform_canvas.h"
20 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" 19 #include "third_party/WebKit/public/platform/WebMediaPlayer.h"
21 #include "third_party/WebKit/public/platform/WebRect.h" 20 #include "third_party/WebKit/public/platform/WebRect.h"
22 #include "third_party/WebKit/public/platform/WebSize.h" 21 #include "third_party/WebKit/public/platform/WebSize.h"
23 #include "third_party/libyuv/include/libyuv.h" 22 #include "third_party/libyuv/include/libyuv.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 << media::VideoCaptureFormat::ToString(params.requested_format); 86 << media::VideoCaptureFormat::ToString(params.requested_format);
88 DCHECK(params.requested_format.IsValid()); 87 DCHECK(params.requested_format.IsValid());
89 DCHECK(thread_checker_.CalledOnValidThread()); 88 DCHECK(thread_checker_.CalledOnValidThread());
90 89
91 running_callback_ = running_callback; 90 running_callback_ = running_callback;
92 if (!web_media_player_ || !web_media_player_->hasVideo()) { 91 if (!web_media_player_ || !web_media_player_->hasVideo()) {
93 running_callback_.Run(false); 92 running_callback_.Run(false);
94 return; 93 return;
95 } 94 }
96 const blink::WebSize resolution = web_media_player_->naturalSize(); 95 const blink::WebSize resolution = web_media_player_->naturalSize();
97 surface_ = cc::PaintSurface::MakeRasterN32Premul(resolution.width, 96
98 resolution.height); 97 canvas_ = cc::SkiaPaintCanvas::CreateRasterZeroed(
99 if (!surface_) { 98 SkImageInfo::MakeN32Premul(resolution.width, resolution.height));
99 if (!canvas_) {
100 running_callback_.Run(false); 100 running_callback_.Run(false);
101 return; 101 return;
102 } 102 }
103 103
104 new_frame_callback_ = new_frame_callback; 104 new_frame_callback_ = new_frame_callback;
105 // Force |capture_frame_rate_| to be in between k{Min,Max}FramesPerSecond. 105 // Force |capture_frame_rate_| to be in between k{Min,Max}FramesPerSecond.
106 capture_frame_rate_ = 106 capture_frame_rate_ =
107 std::max(kMinFramesPerSecond, 107 std::max(kMinFramesPerSecond,
108 std::min(static_cast<float>(media::limits::kMaxFramesPerSecond), 108 std::min(static_cast<float>(media::limits::kMaxFramesPerSecond),
109 params.requested_format.frame_rate)); 109 params.requested_format.frame_rate));
(...skipping 16 matching lines...) Expand all
126 DVLOG(3) << __func__; 126 DVLOG(3) << __func__;
127 TRACE_EVENT0("video", "HtmlVideoElementCapturerSource::sendNewFrame"); 127 TRACE_EVENT0("video", "HtmlVideoElementCapturerSource::sendNewFrame");
128 DCHECK(thread_checker_.CalledOnValidThread()); 128 DCHECK(thread_checker_.CalledOnValidThread());
129 129
130 if (!web_media_player_ || new_frame_callback_.is_null()) 130 if (!web_media_player_ || new_frame_callback_.is_null())
131 return; 131 return;
132 132
133 const base::TimeTicks current_time = base::TimeTicks::Now(); 133 const base::TimeTicks current_time = base::TimeTicks::Now();
134 const blink::WebSize resolution = web_media_player_->naturalSize(); 134 const blink::WebSize resolution = web_media_player_->naturalSize();
135 135
136 cc::PaintCanvas* canvas = surface_->getCanvas();
137 cc::PaintFlags flags; 136 cc::PaintFlags flags;
138 flags.setBlendMode(SkBlendMode::kSrc); 137 flags.setBlendMode(SkBlendMode::kSrc);
139 flags.setFilterQuality(kLow_SkFilterQuality); 138 flags.setFilterQuality(kLow_SkFilterQuality);
140 web_media_player_->paint( 139 web_media_player_->paint(
141 canvas, blink::WebRect(0, 0, resolution.width, resolution.height), flags); 140 canvas_.get(), blink::WebRect(0, 0, resolution.width, resolution.height),
142 DCHECK_NE(kUnknown_SkColorType, canvas->imageInfo().colorType()); 141 flags);
143 DCHECK_EQ(canvas->imageInfo().width(), resolution.width); 142 DCHECK_NE(kUnknown_SkColorType, canvas_->imageInfo().colorType());
144 DCHECK_EQ(canvas->imageInfo().height(), resolution.height); 143 DCHECK_EQ(canvas_->imageInfo().width(), resolution.width);
144 DCHECK_EQ(canvas_->imageInfo().height(), resolution.height);
145 145
146 SkBitmap bitmap; 146 SkBitmap bitmap;
147 bitmap.setInfo(canvas->imageInfo()); 147 bitmap.setInfo(canvas_->imageInfo());
148 canvas->readPixels(&bitmap, 0, 0); 148 canvas_->readPixels(&bitmap, 0, 0);
149 149
150 DCHECK_NE(kUnknown_SkColorType, bitmap.colorType()); 150 DCHECK_NE(kUnknown_SkColorType, bitmap.colorType());
151 DCHECK(!bitmap.drawsNothing()); 151 DCHECK(!bitmap.drawsNothing());
152 DCHECK(bitmap.getPixels()); 152 DCHECK(bitmap.getPixels());
153 if (bitmap.colorType() != kN32_SkColorType) { 153 if (bitmap.colorType() != kN32_SkColorType) {
154 DLOG(ERROR) << "Only supported color type is kN32_SkColorType (ARGB/ABGR)"; 154 DLOG(ERROR) << "Only supported color type is kN32_SkColorType (ARGB/ABGR)";
155 return; 155 return;
156 } 156 }
157 157
158 scoped_refptr<media::VideoFrame> frame = frame_pool_.CreateFrame( 158 scoped_refptr<media::VideoFrame> frame = frame_pool_.CreateFrame(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 next_capture_time_ = current_time; 198 next_capture_time_ = current_time;
199 } 199 }
200 // Schedule next capture. 200 // Schedule next capture.
201 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 201 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
202 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame, 202 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame,
203 weak_factory_.GetWeakPtr()), 203 weak_factory_.GetWeakPtr()),
204 next_capture_time_ - current_time); 204 next_capture_time_ - current_time);
205 } 205 }
206 206
207 } // namespace content 207 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698