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

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

Issue 2640983002: Rename paint data structures (Closed)
Patch Set: DrawingDisplayItem Created 3 years, 10 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/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 "cc/paint/paint_canvas.h"
13 #include "cc/paint/paint_surface.h"
12 #include "content/public/renderer/render_thread.h" 14 #include "content/public/renderer/render_thread.h"
13 #include "content/renderer/media/media_stream_video_source.h" 15 #include "content/renderer/media/media_stream_video_source.h"
14 #include "content/renderer/media/webrtc_uma_histograms.h" 16 #include "content/renderer/media/webrtc_uma_histograms.h"
15 #include "media/base/limits.h" 17 #include "media/base/limits.h"
16 #include "media/blink/webmediaplayer_impl.h" 18 #include "media/blink/webmediaplayer_impl.h"
17 #include "skia/ext/platform_canvas.h" 19 #include "skia/ext/platform_canvas.h"
18 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" 20 #include "third_party/WebKit/public/platform/WebMediaPlayer.h"
19 #include "third_party/WebKit/public/platform/WebRect.h" 21 #include "third_party/WebKit/public/platform/WebRect.h"
20 #include "third_party/WebKit/public/platform/WebSize.h" 22 #include "third_party/WebKit/public/platform/WebSize.h"
21 #include "third_party/libyuv/include/libyuv.h" 23 #include "third_party/libyuv/include/libyuv.h"
22 #include "third_party/skia/include/core/SkCanvas.h"
23 #include "third_party/skia/include/core/SkSurface.h"
24 24
25 namespace { 25 namespace {
26 const float kMinFramesPerSecond = 1.0; 26 const float kMinFramesPerSecond = 1.0;
27 } // anonymous namespace 27 } // anonymous namespace
28 28
29 namespace content { 29 namespace content {
30 30
31 //static 31 //static
32 std::unique_ptr<HtmlVideoElementCapturerSource> 32 std::unique_ptr<HtmlVideoElementCapturerSource>
33 HtmlVideoElementCapturerSource::CreateFromWebMediaPlayerImpl( 33 HtmlVideoElementCapturerSource::CreateFromWebMediaPlayerImpl(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 << media::VideoCaptureFormat::ToString(params.requested_format); 87 << media::VideoCaptureFormat::ToString(params.requested_format);
88 DCHECK(params.requested_format.IsValid()); 88 DCHECK(params.requested_format.IsValid());
89 DCHECK(thread_checker_.CalledOnValidThread()); 89 DCHECK(thread_checker_.CalledOnValidThread());
90 90
91 running_callback_ = running_callback; 91 running_callback_ = running_callback;
92 if (!web_media_player_ || !web_media_player_->hasVideo()) { 92 if (!web_media_player_ || !web_media_player_->hasVideo()) {
93 running_callback_.Run(false); 93 running_callback_.Run(false);
94 return; 94 return;
95 } 95 }
96 const blink::WebSize resolution = web_media_player_->naturalSize(); 96 const blink::WebSize resolution = web_media_player_->naturalSize();
97 surface_ = 97 surface_ = cc::PaintSurface::MakeRasterN32Premul(resolution.width,
98 SkSurface::MakeRasterN32Premul(resolution.width, resolution.height); 98 resolution.height);
99 if (!surface_) { 99 if (!surface_) {
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),
(...skipping 17 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 SkCanvas* canvas = surface_->getCanvas(); 136 cc::PaintCanvas* canvas = surface_->getCanvas();
137 SkPaint paint; 137 cc::PaintFlags paint;
138 paint.setBlendMode(SkBlendMode::kSrc); 138 paint.setBlendMode(SkBlendMode::kSrc);
139 paint.setFilterQuality(kLow_SkFilterQuality); 139 paint.setFilterQuality(kLow_SkFilterQuality);
140 web_media_player_->paint( 140 web_media_player_->paint(
141 canvas, blink::WebRect(0, 0, resolution.width, resolution.height), 141 canvas, blink::WebRect(0, 0, resolution.width, resolution.height), paint);
142 paint);
143 DCHECK_NE(kUnknown_SkColorType, canvas->imageInfo().colorType()); 142 DCHECK_NE(kUnknown_SkColorType, canvas->imageInfo().colorType());
144 DCHECK_EQ(canvas->imageInfo().width(), resolution.width); 143 DCHECK_EQ(canvas->imageInfo().width(), resolution.width);
145 DCHECK_EQ(canvas->imageInfo().height(), resolution.height); 144 DCHECK_EQ(canvas->imageInfo().height(), resolution.height);
146 145
147 const SkBitmap bitmap = skia::ReadPixels(canvas); 146 const SkBitmap bitmap = skia::ReadPixels(canvas);
148 DCHECK_NE(kUnknown_SkColorType, bitmap.colorType()); 147 DCHECK_NE(kUnknown_SkColorType, bitmap.colorType());
149 DCHECK(!bitmap.drawsNothing()); 148 DCHECK(!bitmap.drawsNothing());
150 DCHECK(bitmap.getPixels()); 149 DCHECK(bitmap.getPixels());
151 if (bitmap.colorType() != kN32_SkColorType) { 150 if (bitmap.colorType() != kN32_SkColorType) {
152 DLOG(ERROR) << "Only supported color type is kN32_SkColorType (ARGB/ABGR)"; 151 DLOG(ERROR) << "Only supported color type is kN32_SkColorType (ARGB/ABGR)";
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 next_capture_time_ = current_time; 195 next_capture_time_ = current_time;
197 } 196 }
198 // Schedule next capture. 197 // Schedule next capture.
199 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 198 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
200 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame, 199 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame,
201 weak_factory_.GetWeakPtr()), 200 weak_factory_.GetWeakPtr()),
202 next_capture_time_ - current_time); 201 next_capture_time_ - current_time);
203 } 202 }
204 203
205 } // namespace content 204 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/html_video_element_capturer_source.h ('k') | content/renderer/media/webmediaplayer_ms.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698