Commit bb986efb authored by Chisoon Jeong's avatar Chisoon Jeong Committed by Commit Bot

Call bitmapDraw() for dithering if necessary for converting color type.

This change performs bitmapDraw() only if dithering is necessary to avoid
bitmapDraw() call that causes less responsiveness on low performance ARM
devices.

Canvas' bitmapDraw() was performed on a webOS ARM device on decoding image
for images that don't need dithering when converting its color type.

For example converting color type between RGBA8888 and BGRA8888,
which is related endian, dithering is not necessary.
Therefor these cases can be processed by SkPixmap's readPixels() that is
more efficient than Canvas' bitmapDraw() for responsiveness of webpage.

Change-Id: Ib33c062519b16429a83445bafa376f2540030425
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1763523Reviewed-by: default avatarFlorin Malita <fmalita@chromium.org>
Reviewed-by: default avatarBrian Osman <brianosman@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691909}
parent aaa06af6
......@@ -35,6 +35,7 @@
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkImageInfo.h"
namespace blink {
......@@ -220,18 +221,27 @@ bool DecodingImageGenerator::GetPixels(const SkImageInfo& dst_info,
// Convert the color type to the requested one if necessary
if (decoded && target_info.colorType() != dst_info.colorType()) {
auto canvas = SkCanvas::MakeRasterDirect(dst_info, pixels, row_bytes);
DCHECK(canvas);
SkPaint paint;
if (dst_info.colorType() == kARGB_4444_SkColorType ||
dst_info.colorType() == kRGB_565_SkColorType) {
// Convert the color type by readPixels if dithering is not necessary
// (readPixels is potentially cheaper than a full-blown drawBitmap).
if (SkColorTypeBytesPerPixel(target_info.colorType()) <=
SkColorTypeBytesPerPixel(dst_info.colorType())) {
decoded = SkPixmap{target_info, memory, adjusted_row_bytes}.readPixels(
SkPixmap{dst_info, pixels, row_bytes});
DCHECK(decoded);
} else { // Do dithering by drawBitmap() if dithering is necessary
auto canvas = SkCanvas::MakeRasterDirect(dst_info, pixels, row_bytes);
DCHECK(canvas);
SkPaint paint;
paint.setDither(true);
paint.setBlendMode(SkBlendMode::kSrc);
SkBitmap bitmap;
decoded = bitmap.installPixels(target_info, memory, adjusted_row_bytes);
DCHECK(decoded);
canvas->drawBitmap(bitmap, 0, 0, &paint);
}
paint.setBlendMode(SkBlendMode::kSrc);
SkBitmap bitmap;
decoded = bitmap.installPixels(target_info, memory, adjusted_row_bytes);
DCHECK(decoded);
canvas->drawBitmap(bitmap, 0, 0, &paint);
}
return decoded;
}
......
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