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

Side by Side Diff: content/renderer/media_recorder/video_track_recorder.cc

Issue 2781823002: Revert of cc/paint: Remove cc::PaintSurface. (Closed)
Patch Set: Created 3 years, 8 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_recorder/video_track_recorder.h" 5 #include "content/renderer/media_recorder/video_track_recorder.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/sys_info.h" 13 #include "base/sys_info.h"
14 #include "base/task_runner_util.h" 14 #include "base/task_runner_util.h"
15 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
19 #include "cc/paint/skia_paint_canvas.h" 19 #include "cc/paint/paint_canvas.h"
20 #include "cc/paint/paint_surface.h"
20 #include "content/renderer/media/renderer_gpu_video_accelerator_factories.h" 21 #include "content/renderer/media/renderer_gpu_video_accelerator_factories.h"
21 #include "content/renderer/render_thread_impl.h" 22 #include "content/renderer/render_thread_impl.h"
22 #include "media/base/bind_to_current_loop.h" 23 #include "media/base/bind_to_current_loop.h"
23 #include "media/base/video_frame.h" 24 #include "media/base/video_frame.h"
24 #include "media/base/video_util.h" 25 #include "media/base/video_util.h"
25 #include "media/filters/context_3d.h" 26 #include "media/filters/context_3d.h"
26 #include "media/renderers/skcanvas_video_renderer.h" 27 #include "media/renderers/skcanvas_video_renderer.h"
27 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" 28 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h"
28 #include "skia/ext/platform_canvas.h" 29 #include "skia/ext/platform_canvas.h"
29 #include "third_party/libyuv/include/libyuv.h" 30 #include "third_party/libyuv/include/libyuv.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 235
235 // This callback should be exercised on IO thread. 236 // This callback should be exercised on IO thread.
236 const OnEncodedVideoCB on_encoded_video_callback_; 237 const OnEncodedVideoCB on_encoded_video_callback_;
237 238
238 // Target bitrate for video encoding. If 0, a standard bitrate is used. 239 // Target bitrate for video encoding. If 0, a standard bitrate is used.
239 const int32_t bits_per_second_; 240 const int32_t bits_per_second_;
240 241
241 // Used to retrieve incoming opaque VideoFrames (i.e. VideoFrames backed by 242 // Used to retrieve incoming opaque VideoFrames (i.e. VideoFrames backed by
242 // textures). Created on-demand on |main_task_runner_|. 243 // textures). Created on-demand on |main_task_runner_|.
243 std::unique_ptr<media::SkCanvasVideoRenderer> video_renderer_; 244 std::unique_ptr<media::SkCanvasVideoRenderer> video_renderer_;
244 std::unique_ptr<cc::PaintCanvas> canvas_; 245 sk_sp<cc::PaintSurface> surface_;
245 246
246 DISALLOW_COPY_AND_ASSIGN(Encoder); 247 DISALLOW_COPY_AND_ASSIGN(Encoder);
247 }; 248 };
248 249
249 void VideoTrackRecorder::Encoder::StartFrameEncode( 250 void VideoTrackRecorder::Encoder::StartFrameEncode(
250 const scoped_refptr<VideoFrame>& video_frame, 251 const scoped_refptr<VideoFrame>& video_frame,
251 base::TimeTicks capture_timestamp) { 252 base::TimeTicks capture_timestamp) {
252 // Cache the thread sending frames on first frame arrival. 253 // Cache the thread sending frames on first frame arrival.
253 if (!origin_task_runner_.get()) 254 if (!origin_task_runner_.get())
254 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 255 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 305
305 frame = media::VideoFrame::CreateFrame( 306 frame = media::VideoFrame::CreateFrame(
306 media::PIXEL_FORMAT_I420, video_frame->coded_size(), 307 media::PIXEL_FORMAT_I420, video_frame->coded_size(),
307 video_frame->visible_rect(), video_frame->natural_size(), 308 video_frame->visible_rect(), video_frame->natural_size(),
308 video_frame->timestamp()); 309 video_frame->timestamp());
309 310
310 const SkImageInfo info = SkImageInfo::MakeN32( 311 const SkImageInfo info = SkImageInfo::MakeN32(
311 frame->visible_rect().width(), frame->visible_rect().height(), 312 frame->visible_rect().width(), frame->visible_rect().height(),
312 kOpaque_SkAlphaType); 313 kOpaque_SkAlphaType);
313 314
314 SkBitmap bitmap;
315 // Create |surface_| if it doesn't exist or incoming resolution has changed. 315 // Create |surface_| if it doesn't exist or incoming resolution has changed.
316 if (!canvas_ || canvas_->imageInfo().width() != info.width() || 316 if (!surface_ || surface_->width() != info.width() ||
317 canvas_->imageInfo().height() != info.height()) { 317 surface_->height() != info.height()) {
318 bitmap.allocPixels(info); 318 surface_ = cc::PaintSurface::MakeRaster(info);
319 canvas_ = base::MakeUnique<cc::SkiaPaintCanvas>(bitmap);
320 } 319 }
321 if (!video_renderer_) 320 if (!video_renderer_)
322 video_renderer_.reset(new media::SkCanvasVideoRenderer); 321 video_renderer_.reset(new media::SkCanvasVideoRenderer);
323 322
324 DCHECK(context_provider->ContextGL()); 323 DCHECK(context_provider->ContextGL());
325 video_renderer_->Copy(video_frame.get(), canvas_.get(), 324 video_renderer_->Copy(video_frame.get(), surface_->getCanvas(),
326 media::Context3D(context_provider->ContextGL(), 325 media::Context3D(context_provider->ContextGL(),
327 context_provider->GrContext())); 326 context_provider->GrContext()));
328 327
329 SkPixmap pixmap; 328 SkPixmap pixmap;
330 if (!bitmap.peekPixels(&pixmap)) { 329 if (!cc::ToPixmap(surface_->getCanvas(), &pixmap)) {
331 DLOG(ERROR) << "Error trying to map PaintSurface's pixels"; 330 DLOG(ERROR) << "Error trying to map PaintSurface's pixels";
332 return; 331 return;
333 } 332 }
334 // TODO(mcasas): Use the incoming frame's rotation when 333 // TODO(mcasas): Use the incoming frame's rotation when
335 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6069 is closed. 334 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6069 is closed.
336 const libyuv::RotationMode source_rotation = libyuv::kRotate0; 335 const libyuv::RotationMode source_rotation = libyuv::kRotate0;
337 const uint32 source_pixel_format = 336 const uint32 source_pixel_format =
338 (kN32_SkColorType == kRGBA_8888_SkColorType) ? libyuv::FOURCC_ABGR 337 (kN32_SkColorType == kRGBA_8888_SkColorType) ? libyuv::FOURCC_ABGR
339 : libyuv::FOURCC_ARGB; 338 : libyuv::FOURCC_ARGB;
340 if (libyuv::ConvertToI420(static_cast<uint8*>(pixmap.writable_addr()), 339 if (libyuv::ConvertToI420(static_cast<uint8*>(pixmap.writable_addr()),
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), 1335 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_),
1337 false); 1336 false);
1338 } 1337 }
1339 1338
1340 bool VideoTrackRecorder::CanEncodeAlphaChannelForTesting() { 1339 bool VideoTrackRecorder::CanEncodeAlphaChannelForTesting() {
1341 DCHECK(encoder_); 1340 DCHECK(encoder_);
1342 return encoder_->CanEncodeAlphaChannel(); 1341 return encoder_->CanEncodeAlphaChannel();
1343 } 1342 }
1344 1343
1345 } // namespace content 1344 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698