Commit e59fb34a authored by Darwin Huang's avatar Darwin Huang Committed by Commit Bot

Async Clipboard: Use faster image/png encoding.

Before this CL, navigator.clipboard.read image/png encoding used fZLibLevel = 6.

Use fZLibLevel = 1 instead of the default fZLibLevel = 6. fZLibLevel = 6 is slower,
and inconsistent with DataTransfer[1], which already uses fZLibLevel = 1.

When testing using https://www.photopea.com/clipboard_img.html , which provides
a 8000x4000 px bitmap of random pixels, navigator.clipboard.read took:
* 4.10 (4.07 to 4.13) seconds over 3 trials with fZLibLevel = 6
* 3.98 (3.95 to 4.00) seconds over 3 trials with fZLibLevel = 1
* 1.53 (1.50 to 1.56) seconds over 3 trials with fZLibLevel = 0

Switching from fZLibLevel 6 to fZLibLevel 1 should enable a 3% speed-up in
Async Clipboard performance, and not cause any change in behavior for
DataTransfer (which would occur with fZLibLevel 0). The trade off is that
this may cause encoded image/png images to be slightly larger, but this
should be acceptable for clipboard content.

[1]: https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/clipboard/data_object_item.cc?l=141

Bug: 1004867
Change-Id: Ie557b211bbe70e19009c5d67fca310cc970101cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824063
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699650}
parent faaa1c44
...@@ -33,6 +33,7 @@ class ClipboardImageReader final : public ClipboardReader { ...@@ -33,6 +33,7 @@ class ClipboardImageReader final : public ClipboardReader {
Vector<uint8_t> png_data; Vector<uint8_t> png_data;
SkPngEncoder::Options options; SkPngEncoder::Options options;
options.fZLibLevel = 1;
if (!ImageEncoder::Encode(&png_data, pixmap, options)) if (!ImageEncoder::Encode(&png_data, pixmap, options))
return nullptr; return nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment