Commit 7b6750e8 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[imagebitmap] Remove another use of ArrayBuffer

In this CL we remove another use of ArrayBuffer in image_bitmap.cc,
similar to https://crrev.com/c/1835659. However, this time it cannot
be avoided to create a SkPixmap object, due to scaling and color
settings. Therefore we still create the SkPixmap object to call
scalePixels and setColorSpace on it, but then we only use info()
and rowBytes() from it to create the SkImage from the initially
allocated SkData.


R=jbroman@chromium.org

Bug: chromium:1008840
Change-Id: I82ad357db16f11139e799fbee4423a777d5c2a33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1916476
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#716302}
parent 8eb27642
......@@ -341,10 +341,6 @@ scoped_refptr<StaticBitmapImage> GetImageWithAlphaDisposition(
return StaticBitmapImage::Create(std::move(dst_pixels), info);
}
void freePixels(const void*, void* pixels) {
static_cast<Uint8Array*>(pixels)->Release();
}
scoped_refptr<StaticBitmapImage> ScaleImage(
scoped_refptr<StaticBitmapImage>&& image,
const ImageBitmap::ParsedOptions& parsed_options) {
......@@ -380,27 +376,22 @@ scoped_refptr<StaticBitmapImage> ScaleImage(
// Avoid sRGB transfer function by setting the color space to nullptr.
if (image_info.colorSpace()->isSRGB())
image_info = image_info.makeColorSpace(nullptr);
scoped_refptr<ArrayBuffer> resized_buffer =
ArrayBuffer::CreateOrNull(image_info.computeMinByteSize(), 1);
if (!resized_buffer)
return nullptr;
scoped_refptr<Uint8Array> resized_pixels = Uint8Array::Create(
std::move(resized_buffer), 0, image_info.computeMinByteSize());
if (!resized_pixels)
sk_sp<SkData> image_pixels =
TryAllocateSkData(image_info.computeMinByteSize());
if (!image_pixels) {
return nullptr;
SkPixmap resized_pixmap(image_info, resized_pixels->Data(),
}
SkPixmap resized_pixmap(image_info, image_pixels->data(),
image_info.minRowBytes());
sk_image->scalePixels(resized_pixmap, parsed_options.resize_quality);
// Tag the resized Pixmap with the correct color space.
resized_pixmap.setColorSpace(GetSkImageInfo(image).refColorSpace());
Uint8Array* pixels = resized_pixels.get();
if (pixels) {
pixels->AddRef();
resized_pixels = nullptr;
}
resized_sk_image =
SkImage::MakeFromRaster(resized_pixmap, freePixels, pixels);
SkImage::MakeRasterData(resized_pixmap.info(), std::move(image_pixels),
resized_pixmap.rowBytes());
}
if (!resized_sk_image)
......
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