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

Side by Side Diff: media/renderers/skcanvas_video_renderer.cc

Issue 1719533002: Modify YUV codecs to match Skia's API change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to Patch Set 3 Created 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/renderers/skcanvas_video_renderer.h" 5 #include "media/renderers/skcanvas_video_renderer.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "gpu/GLES2/gl2extchromium.h" 10 #include "gpu/GLES2/gl2extchromium.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 void* pixels, 216 void* pixels,
217 size_t row_bytes, 217 size_t row_bytes,
218 SkPMColor ctable[], 218 SkPMColor ctable[],
219 int* ctable_count) override { 219 int* ctable_count) override {
220 // If skia couldn't do the YUV conversion on GPU, we will on CPU. 220 // If skia couldn't do the YUV conversion on GPU, we will on CPU.
221 SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels(frame_.get(), pixels, 221 SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels(frame_.get(), pixels,
222 row_bytes); 222 row_bytes);
223 return true; 223 return true;
224 } 224 }
225 225
226 bool onGetYUV8Planes(SkISize sizes[3], 226 bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* color_space) const
227 void* planes[3], 227 override {
Noel Gordon 2016/03/03 01:25:28 Style nit: chromium line limits /meh causing an ov
msarett 2016/03/04 19:49:08 Done.
228 size_t row_bytes[3],
229 SkYUVColorSpace* color_space) override {
230 if (!media::IsYuvPlanar(frame_->format()) || 228 if (!media::IsYuvPlanar(frame_->format()) ||
231 // TODO(rileya): Skia currently doesn't support YUVA conversion. Remove 229 // TODO(rileya): Skia currently doesn't support YUVA conversion. Remove
232 // this case once it does. As-is we will fall back on the pure-software 230 // this case once it does. As-is we will fall back on the pure-software
233 // path in this case. 231 // path in this case.
234 frame_->format() == PIXEL_FORMAT_YV12A) { 232 frame_->format() == PIXEL_FORMAT_YV12A) {
235 return false; 233 return false;
236 } 234 }
237 235
238 if (color_space) { 236 if (color_space) {
239 if (CheckColorSpace(frame_.get(), COLOR_SPACE_JPEG)) 237 if (CheckColorSpace(frame_.get(), COLOR_SPACE_JPEG))
240 *color_space = kJPEG_SkYUVColorSpace; 238 *color_space = kJPEG_SkYUVColorSpace;
241 else if (CheckColorSpace(frame_.get(), COLOR_SPACE_HD_REC709)) 239 else if (CheckColorSpace(frame_.get(), COLOR_SPACE_HD_REC709))
242 *color_space = kRec709_SkYUVColorSpace; 240 *color_space = kRec709_SkYUVColorSpace;
243 else 241 else
244 *color_space = kRec601_SkYUVColorSpace; 242 *color_space = kRec601_SkYUVColorSpace;
245 } 243 }
246 244
247 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; 245 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane;
248 ++plane) { 246 ++plane) {
249 if (sizes) { 247 const gfx::Size size =
250 const gfx::Size size = 248 VideoFrame::PlaneSize(frame_->format(), plane,
251 VideoFrame::PlaneSize(frame_->format(), plane, 249 gfx::Size(frame_->visible_rect().width(),
252 gfx::Size(frame_->visible_rect().width(), 250 frame_->visible_rect().height()));
253 frame_->visible_rect().height())); 251 sizeInfo->fSizes[plane].set(size.width(), size.height());
254 sizes[plane].set(size.width(), size.height()); 252 sizeInfo->fWidthBytes[plane] = size.width();
253 }
254
255 return true;
256 }
257
258 bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override
259 {
Noel Gordon 2016/03/03 01:25:28 Style nit: chromium & line limits & weird readabil
msarett 2016/03/04 19:49:08 Done.
260 DCHECK(media::IsYuvPlanar(frame_->format()) &&
261 frame_->format() != PIXEL_FORMAT_YV12A);
262
Noel Gordon 2016/03/03 01:25:28 Optional: store or ref frame->format() into a loca
msarett 2016/03/04 19:49:08 Done.
263 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane;
264 ++plane) {
265 const gfx::Size size =
266 VideoFrame::PlaneSize(frame_->format(), plane,
267 gfx::Size(frame_->visible_rect().width(),
268 frame_->visible_rect().height()));
269 if (size.width() != sizeInfo.fSizes[plane].width() ||
270 size.height() != sizeInfo.fSizes[plane].height()) {
271 return false;
255 } 272 }
256 if (row_bytes && planes) {
257 size_t offset;
258 const int y_shift =
259 (frame_->format() == media::PIXEL_FORMAT_YV16) ? 0 : 1;
260 if (plane == VideoFrame::kYPlane) {
261 offset = (frame_->stride(VideoFrame::kYPlane) *
262 frame_->visible_rect().y()) +
263 frame_->visible_rect().x();
264 } else {
265 offset = (frame_->stride(VideoFrame::kUPlane) *
266 (frame_->visible_rect().y() >> y_shift)) +
267 (frame_->visible_rect().x() >> 1);
268 }
269 273
270 // Copy the frame to the supplied memory. 274 size_t offset;
271 // TODO: Find a way (API change?) to avoid this copy. 275 const int y_shift =
272 char* out_line = static_cast<char*>(planes[plane]); 276 (frame_->format() == media::PIXEL_FORMAT_YV16) ? 0 : 1;
273 int out_line_stride = row_bytes[plane]; 277 if (plane == VideoFrame::kYPlane) {
274 uint8_t* in_line = frame_->data(plane) + offset; 278 offset = (frame_->stride(VideoFrame::kYPlane) *
275 int in_line_stride = frame_->stride(plane); 279 frame_->visible_rect().y()) +
276 int plane_height = sizes[plane].height(); 280 frame_->visible_rect().x();
277 if (in_line_stride == out_line_stride) { 281 } else {
278 memcpy(out_line, in_line, plane_height * in_line_stride); 282 offset = (frame_->stride(VideoFrame::kUPlane) *
279 } else { 283 (frame_->visible_rect().y() >> y_shift)) +
280 // Different line padding so need to copy one line at a time. 284 (frame_->visible_rect().x() >> 1);
281 int bytes_to_copy_per_line = out_line_stride < in_line_stride 285 }
282 ? out_line_stride 286
283 : in_line_stride; 287 // Copy the frame to the supplied memory.
284 for (int line_no = 0; line_no < plane_height; line_no++) { 288 // TODO: Find a way (API change?) to avoid this copy.
285 memcpy(out_line, in_line, bytes_to_copy_per_line); 289 char* out_line = static_cast<char*>(planes[plane]);
286 in_line += in_line_stride; 290 int out_line_stride = sizeInfo.fWidthBytes[plane];
287 out_line += out_line_stride; 291 uint8_t* in_line = frame_->data(plane) + offset;
288 } 292 int in_line_stride = frame_->stride(plane);
293 int plane_height = sizeInfo.fSizes[plane].height();
294 if (in_line_stride == out_line_stride) {
295 memcpy(out_line, in_line, plane_height * in_line_stride);
296 } else {
297 // Different line padding so need to copy one line at a time.
298 int bytes_to_copy_per_line = out_line_stride < in_line_stride
299 ? out_line_stride
300 : in_line_stride;
301 for (int line_no = 0; line_no < plane_height; line_no++) {
302 memcpy(out_line, in_line, bytes_to_copy_per_line);
303 in_line += in_line_stride;
304 out_line += out_line_stride;
289 } 305 }
290 } 306 }
291 } 307 }
292 return true; 308 return true;
293 } 309 }
294 310
295 private: 311 private:
296 scoped_refptr<VideoFrame> frame_; 312 scoped_refptr<VideoFrame> frame_;
297 313
298 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoImageGenerator); 314 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoImageGenerator);
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 } 675 }
660 676
661 void SkCanvasVideoRenderer::ResetCache() { 677 void SkCanvasVideoRenderer::ResetCache() {
662 DCHECK(thread_checker_.CalledOnValidThread()); 678 DCHECK(thread_checker_.CalledOnValidThread());
663 // Clear cached values. 679 // Clear cached values.
664 last_image_ = nullptr; 680 last_image_ = nullptr;
665 last_timestamp_ = kNoTimestamp(); 681 last_timestamp_ = kNoTimestamp();
666 } 682 }
667 683
668 } // namespace media 684 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698