[go: nahoru, domu]

Avoid memcpy after converting YUV to RGB pixels for video frames

This CL avoids using "canvas->drawImage()" in PaintCanvasVideoRenderer::Paint().
Most of the time (when the video isn't rotated etc), all that's necessary is to
convert YUV to RGB pixels. But the drawImage() call will first create a
temporary SkBitmap, copy the frame into that, and then redundantly memcpy() the
bitmap to the resulting canvas.

The memcpy() is very expensive and results in a lot of dropped frames when
playing back 8K video. A single 8K frame is 145MiB, so at 60fps we'd be copying
8.24GiB/s, which uses up most of the RAM bandwidth.

With this change, I can playback 8K video at 60fps with only 49% dropped frames
when I was getting 76% dropped before.

The remaining bottleneck is in ConvertVideoFrameToRGBPixels(): if I remove that
function, I can playback 8K video at 75fps with zero dropped frames (but with no
video :P), so the current plan is to try to parallelize that function after
landing this CL.

BUG=1001207

Change-Id: I0f69988e224d28cd06973beedf00d461ebd5e67e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1788320
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Khushal <khushalsagar@chromium.org>
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#696919}
diff --git a/cc/paint/paint_canvas.h b/cc/paint/paint_canvas.h
index a8201032..ff5a69b 100644
--- a/cc/paint/paint_canvas.h
+++ b/cc/paint/paint_canvas.h
@@ -50,6 +50,10 @@
   // recording or not, so could be simplified or removed.
   virtual SkImageInfo imageInfo() const = 0;
 
+  virtual void* accessTopLayerPixels(SkImageInfo* info,
+                                     size_t* rowBytes,
+                                     SkIPoint* origin = nullptr) = 0;
+
   // TODO(enne): It would be nice to get rid of flush() entirely, as it
   // doesn't really make sense for recording.  However, this gets used by
   // PaintCanvasVideoRenderer which takes a PaintCanvas to paint both