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

Side by Side Diff: content/renderer/media/webrtc/webrtc_video_capturer_adapter.cc

Issue 2758413002: cc/paint: Remove PaintCanvas::peekPixels. (Closed)
Patch Set: update 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/webrtc/webrtc_video_capturer_adapter.h" 5 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/aligned_memory.h" 8 #include "base/memory/aligned_memory.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 const scoped_refptr<media::VideoFrame>& frame, 94 const scoped_refptr<media::VideoFrame>& frame,
95 scoped_refptr<media::VideoFrame>* new_frame, 95 scoped_refptr<media::VideoFrame>* new_frame,
96 base::WaitableEvent* waiter) { 96 base::WaitableEvent* waiter) {
97 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); 97 DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
98 DCHECK(frame->format() == media::PIXEL_FORMAT_ARGB || 98 DCHECK(frame->format() == media::PIXEL_FORMAT_ARGB ||
99 frame->format() == media::PIXEL_FORMAT_XRGB || 99 frame->format() == media::PIXEL_FORMAT_XRGB ||
100 frame->format() == media::PIXEL_FORMAT_I420 || 100 frame->format() == media::PIXEL_FORMAT_I420 ||
101 frame->format() == media::PIXEL_FORMAT_UYVY || 101 frame->format() == media::PIXEL_FORMAT_UYVY ||
102 frame->format() == media::PIXEL_FORMAT_NV12); 102 frame->format() == media::PIXEL_FORMAT_NV12);
103 ScopedWaitableEvent event(waiter); 103 ScopedWaitableEvent event(waiter);
104 sk_sp<cc::PaintSurface> surface = cc::PaintSurface::MakeRasterN32Premul(
105 frame->visible_rect().width(), frame->visible_rect().height());
106 104
107 if (!surface || !provider_) { 105 if (!provider_) {
108 // Return a black frame (yuv = {0, 0x80, 0x80}). 106 // Return a black frame (yuv = {0, 0x80, 0x80}).
109 *new_frame = media::VideoFrame::CreateColorFrame( 107 *new_frame = media::VideoFrame::CreateColorFrame(
110 frame->visible_rect().size(), 0u, 0x80, 0x80, frame->timestamp()); 108 frame->visible_rect().size(), 0u, 0x80, 0x80, frame->timestamp());
111 return; 109 return;
112 } 110 }
113 111
112 SkBitmap bitmap;
113 bitmap.allocPixels(SkImageInfo::MakeN32Premul(
114 frame->visible_rect().width(), frame->visible_rect().height()));
115 cc::SkiaPaintCanvas paint_canvas(bitmap);
116
114 *new_frame = media::VideoFrame::CreateFrame( 117 *new_frame = media::VideoFrame::CreateFrame(
115 media::PIXEL_FORMAT_I420, frame->coded_size(), frame->visible_rect(), 118 media::PIXEL_FORMAT_I420, frame->coded_size(), frame->visible_rect(),
116 frame->natural_size(), frame->timestamp()); 119 frame->natural_size(), frame->timestamp());
117 DCHECK(provider_->ContextGL()); 120 DCHECK(provider_->ContextGL());
118 canvas_video_renderer_->Copy( 121 canvas_video_renderer_->Copy(
119 frame.get(), surface->getCanvas(), 122 frame.get(), &paint_canvas,
120 media::Context3D(provider_->ContextGL(), provider_->GrContext())); 123 media::Context3D(provider_->ContextGL(), provider_->GrContext()));
121 124
122 SkPixmap pixmap; 125 SkPixmap pixmap;
123 const bool result = surface->getCanvas()->peekPixels(&pixmap); 126 const bool result = bitmap.peekPixels(&pixmap);
124 DCHECK(result) << "Error trying to access PaintSurface's pixels"; 127 DCHECK(result) << "Error trying to access SkBitmap's pixels";
125 const uint32 source_pixel_format = 128 const uint32 source_pixel_format =
126 (kN32_SkColorType == kRGBA_8888_SkColorType) ? cricket::FOURCC_ABGR 129 (kN32_SkColorType == kRGBA_8888_SkColorType) ? cricket::FOURCC_ABGR
127 : cricket::FOURCC_ARGB; 130 : cricket::FOURCC_ARGB;
128 libyuv::ConvertToI420( 131 libyuv::ConvertToI420(
129 static_cast<const uint8*>(pixmap.addr(0, 0)), pixmap.getSafeSize64(), 132 static_cast<const uint8*>(pixmap.addr(0, 0)), pixmap.getSafeSize64(),
130 (*new_frame)->visible_data(media::VideoFrame::kYPlane), 133 (*new_frame)->visible_data(media::VideoFrame::kYPlane),
131 (*new_frame)->stride(media::VideoFrame::kYPlane), 134 (*new_frame)->stride(media::VideoFrame::kYPlane),
132 (*new_frame)->visible_data(media::VideoFrame::kUPlane), 135 (*new_frame)->visible_data(media::VideoFrame::kUPlane),
133 (*new_frame)->stride(media::VideoFrame::kUPlane), 136 (*new_frame)->stride(media::VideoFrame::kUPlane),
134 (*new_frame)->visible_data(media::VideoFrame::kVPlane), 137 (*new_frame)->visible_data(media::VideoFrame::kVPlane),
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // just use what is provided. 346 // just use what is provided.
344 // Use the desired format as the best format. 347 // Use the desired format as the best format.
345 best_format->width = desired.width; 348 best_format->width = desired.width;
346 best_format->height = desired.height; 349 best_format->height = desired.height;
347 best_format->fourcc = cricket::FOURCC_I420; 350 best_format->fourcc = cricket::FOURCC_I420;
348 best_format->interval = desired.interval; 351 best_format->interval = desired.interval;
349 return true; 352 return true;
350 } 353 }
351 354
352 } // namespace content 355 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698