Commit 27c4613d authored by Nathan Zabriskie's avatar Nathan Zabriskie Committed by Commit Bot

Update ImageDataBuffer for OOPR compatability

Currently ImageDataBuffer ctor uses PaintImage::GetSkImage which will
be deprecated as we move to enable OOPR for Canvas2D. This CL updates
the ctor to be OOPR/non OOPR agnostic by using new calls to
PaintImage::GetSwSkImage and PaintImage::readPixels which will work in
both modes.

Bug: 1018894
Change-Id: Iaf5a9af5b4384fd040a75c3db3cc6ffe8a68d736
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2366036
Commit-Queue: Khushal <khushalsagar@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802445}
parent 88c83a45
...@@ -51,30 +51,36 @@ namespace blink { ...@@ -51,30 +51,36 @@ namespace blink {
ImageDataBuffer::ImageDataBuffer(scoped_refptr<StaticBitmapImage> image) { ImageDataBuffer::ImageDataBuffer(scoped_refptr<StaticBitmapImage> image) {
if (!image) if (!image)
return; return;
retained_image_ = image->PaintImageForCurrentFrame().GetSkImage(); PaintImage paint_image = image->PaintImageForCurrentFrame();
if (!retained_image_) if (!paint_image || paint_image.IsPaintWorklet())
return; return;
SkImageInfo paint_image_info = paint_image.GetSkImageInfo();
if (paint_image_info.isEmpty())
return;
#if defined(MEMORY_SANITIZER) #if defined(MEMORY_SANITIZER)
// Test if retained_image has an initialized pixmap. // Test if software SKImage has an initialized pixmap.
SkPixmap pixmap; SkPixmap pixmap;
if (retained_image_->peekPixels(&pixmap)) if (!paint_image.IsTextureBacked() &&
paint_image.GetSwSkImage()->peekPixels(&pixmap)) {
MSAN_CHECK_MEM_IS_INITIALIZED(pixmap.addr(), pixmap.computeByteSize()); MSAN_CHECK_MEM_IS_INITIALIZED(pixmap.addr(), pixmap.computeByteSize());
}
#endif #endif
if (retained_image_->isTextureBacked() || if (paint_image.IsTextureBacked() || paint_image.IsLazyGenerated() ||
retained_image_->isLazyGenerated() || paint_image_info.alphaType() != kUnpremul_SkAlphaType) {
retained_image_->alphaType() != kUnpremul_SkAlphaType) {
// Unpremul is handled upfront, using readPixels, which will correctly clamp // Unpremul is handled upfront, using readPixels, which will correctly clamp
// premul color values that would otherwise cause overflows in the skia // premul color values that would otherwise cause overflows in the skia
// encoder unpremul logic. // encoder unpremul logic.
SkColorType colorType = retained_image_->colorType(); SkColorType colorType = paint_image.GetColorType();
if (colorType == kRGBA_8888_SkColorType || if (colorType == kRGBA_8888_SkColorType ||
colorType == kBGRA_8888_SkColorType) colorType == kBGRA_8888_SkColorType)
colorType = kN32_SkColorType; // Work around for bug with JPEG encoder colorType = kN32_SkColorType; // Work around for bug with JPEG encoder
const SkImageInfo info = const SkImageInfo info =
SkImageInfo::Make(retained_image_->width(), retained_image_->height(), SkImageInfo::Make(paint_image_info.width(), paint_image_info.height(),
retained_image_->colorType(), kUnpremul_SkAlphaType, paint_image_info.colorType(), kUnpremul_SkAlphaType,
retained_image_->refColorSpace()); paint_image_info.refColorSpace());
const size_t rowBytes = info.minRowBytes(); const size_t rowBytes = info.minRowBytes();
size_t size = info.computeByteSize(rowBytes); size_t size = info.computeByteSize(rowBytes);
if (SkImageInfo::ByteSizeOverflowed(size)) if (SkImageInfo::ByteSizeOverflowed(size))
...@@ -82,13 +88,15 @@ ImageDataBuffer::ImageDataBuffer(scoped_refptr<StaticBitmapImage> image) { ...@@ -82,13 +88,15 @@ ImageDataBuffer::ImageDataBuffer(scoped_refptr<StaticBitmapImage> image) {
sk_sp<SkData> data = SkData::MakeUninitialized(size); sk_sp<SkData> data = SkData::MakeUninitialized(size);
pixmap_ = {info, data->writable_data(), info.minRowBytes()}; pixmap_ = {info, data->writable_data(), info.minRowBytes()};
if (!retained_image_->readPixels(pixmap_, 0, 0)) { if (!paint_image.readPixels(info, pixmap_.writable_addr(), rowBytes, 0,
0)) {
pixmap_.reset(); pixmap_.reset();
return; return;
} }
MSAN_CHECK_MEM_IS_INITIALIZED(pixmap_.addr(), pixmap_.computeByteSize()); MSAN_CHECK_MEM_IS_INITIALIZED(pixmap_.addr(), pixmap_.computeByteSize());
retained_image_ = SkImage::MakeRasterData(info, std::move(data), rowBytes); retained_image_ = SkImage::MakeRasterData(info, std::move(data), rowBytes);
} else { } else {
retained_image_ = paint_image.GetSwSkImage();
if (!retained_image_->peekPixels(&pixmap_)) if (!retained_image_->peekPixels(&pixmap_))
return; return;
MSAN_CHECK_MEM_IS_INITIALIZED(pixmap_.addr(), pixmap_.computeByteSize()); MSAN_CHECK_MEM_IS_INITIALIZED(pixmap_.addr(), pixmap_.computeByteSize());
......
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