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

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

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years 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/html_video_element_capturer_source.h" 5 #include "content/renderer/media/html_video_element_capturer_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 "content/public/renderer/render_thread.h" 12 #include "content/public/renderer/render_thread.h"
13 #include "content/renderer/media/media_stream_video_source.h" 13 #include "content/renderer/media/media_stream_video_source.h"
14 #include "content/renderer/media/webrtc_uma_histograms.h" 14 #include "content/renderer/media/webrtc_uma_histograms.h"
15 #include "media/base/limits.h" 15 #include "media/base/limits.h"
16 #include "media/blink/webmediaplayer_impl.h" 16 #include "media/blink/webmediaplayer_impl.h"
17 #include "skia/ext/cdl_surface.h"
17 #include "skia/ext/platform_canvas.h" 18 #include "skia/ext/platform_canvas.h"
18 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" 19 #include "third_party/WebKit/public/platform/WebMediaPlayer.h"
19 #include "third_party/WebKit/public/platform/WebRect.h" 20 #include "third_party/WebKit/public/platform/WebRect.h"
20 #include "third_party/WebKit/public/platform/WebSize.h" 21 #include "third_party/WebKit/public/platform/WebSize.h"
21 #include "third_party/libyuv/include/libyuv.h" 22 #include "third_party/libyuv/include/libyuv.h"
22 #include "third_party/skia/include/core/SkCanvas.h" 23 #include "third_party/skia/include/core/SkCanvas.h"
23 #include "third_party/skia/include/core/SkSurface.h" 24 #include "third_party/skia/include/core/SkSurface.h"
24 25
25 namespace { 26 namespace {
26 const float kMinFramesPerSecond = 1.0; 27 const float kMinFramesPerSecond = 1.0;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 DCHECK(params.requested_format.IsValid()); 89 DCHECK(params.requested_format.IsValid());
89 DCHECK(thread_checker_.CalledOnValidThread()); 90 DCHECK(thread_checker_.CalledOnValidThread());
90 91
91 running_callback_ = running_callback; 92 running_callback_ = running_callback;
92 if (!web_media_player_ || !web_media_player_->hasVideo()) { 93 if (!web_media_player_ || !web_media_player_->hasVideo()) {
93 running_callback_.Run(false); 94 running_callback_.Run(false);
94 return; 95 return;
95 } 96 }
96 const blink::WebSize resolution = web_media_player_->naturalSize(); 97 const blink::WebSize resolution = web_media_player_->naturalSize();
97 surface_ = 98 surface_ =
98 SkSurface::MakeRasterN32Premul(resolution.width, resolution.height); 99 CdlSurface::MakeRasterN32Premul(resolution.width, resolution.height);
99 if (!surface_) { 100 if (!surface_) {
100 running_callback_.Run(false); 101 running_callback_.Run(false);
101 return; 102 return;
102 } 103 }
103 104
104 new_frame_callback_ = new_frame_callback; 105 new_frame_callback_ = new_frame_callback;
105 // Force |capture_frame_rate_| to be in between k{Min,Max}FramesPerSecond. 106 // Force |capture_frame_rate_| to be in between k{Min,Max}FramesPerSecond.
106 capture_frame_rate_ = 107 capture_frame_rate_ =
107 std::max(kMinFramesPerSecond, 108 std::max(kMinFramesPerSecond,
108 std::min(static_cast<float>(media::limits::kMaxFramesPerSecond), 109 std::min(static_cast<float>(media::limits::kMaxFramesPerSecond),
(...skipping 17 matching lines...) Expand all
126 DVLOG(3) << __func__; 127 DVLOG(3) << __func__;
127 TRACE_EVENT0("video", "HtmlVideoElementCapturerSource::sendNewFrame"); 128 TRACE_EVENT0("video", "HtmlVideoElementCapturerSource::sendNewFrame");
128 DCHECK(thread_checker_.CalledOnValidThread()); 129 DCHECK(thread_checker_.CalledOnValidThread());
129 130
130 if (!web_media_player_ || new_frame_callback_.is_null()) 131 if (!web_media_player_ || new_frame_callback_.is_null())
131 return; 132 return;
132 133
133 const base::TimeTicks current_time = base::TimeTicks::Now(); 134 const base::TimeTicks current_time = base::TimeTicks::Now();
134 const blink::WebSize resolution = web_media_player_->naturalSize(); 135 const blink::WebSize resolution = web_media_player_->naturalSize();
135 136
136 SkCanvas* canvas = surface_->getCanvas(); 137 CdlCanvas* canvas = surface_->getCanvas();
137 SkPaint paint; 138 CdlPaint paint;
138 paint.setBlendMode(SkBlendMode::kSrc); 139 paint.setBlendMode(SkBlendMode::kSrc);
139 paint.setFilterQuality(kLow_SkFilterQuality); 140 paint.setFilterQuality(kLow_SkFilterQuality);
140 web_media_player_->paint( 141 web_media_player_->paint(
141 canvas, blink::WebRect(0, 0, resolution.width, resolution.height), 142 canvas, blink::WebRect(0, 0, resolution.width, resolution.height), paint);
142 paint); 143 DCHECK_NE(kUnknown_SkColorType, GetSkCanvas(canvas)->imageInfo().colorType());
143 DCHECK_NE(kUnknown_SkColorType, canvas->imageInfo().colorType()); 144 DCHECK_EQ(GetSkCanvas(canvas)->imageInfo().width(), resolution.width);
144 DCHECK_EQ(canvas->imageInfo().width(), resolution.width); 145 DCHECK_EQ(GetSkCanvas(canvas)->imageInfo().height(), resolution.height);
145 DCHECK_EQ(canvas->imageInfo().height(), resolution.height);
146 146
147 const SkBitmap bitmap = skia::ReadPixels(canvas); 147 const SkBitmap bitmap = skia::ReadPixels(canvas);
148 DCHECK_NE(kUnknown_SkColorType, bitmap.colorType()); 148 DCHECK_NE(kUnknown_SkColorType, bitmap.colorType());
149 DCHECK(!bitmap.drawsNothing()); 149 DCHECK(!bitmap.drawsNothing());
150 DCHECK(bitmap.getPixels()); 150 DCHECK(bitmap.getPixels());
151 if (bitmap.colorType() != kN32_SkColorType) { 151 if (bitmap.colorType() != kN32_SkColorType) {
152 DLOG(ERROR) << "Only supported color type is kN32_SkColorType (ARGB/ABGR)"; 152 DLOG(ERROR) << "Only supported color type is kN32_SkColorType (ARGB/ABGR)";
153 return; 153 return;
154 } 154 }
155 155
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 next_capture_time_ = current_time; 196 next_capture_time_ = current_time;
197 } 197 }
198 // Schedule next capture. 198 // Schedule next capture.
199 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 199 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
200 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame, 200 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame,
201 weak_factory_.GetWeakPtr()), 201 weak_factory_.GetWeakPtr()),
202 next_capture_time_ - current_time); 202 next_capture_time_ - current_time);
203 } 203 }
204 204
205 } // namespace content 205 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/html_video_element_capturer_source.h ('k') | content/renderer/media/image_capture_frame_grabber.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698