0

Handle empty SkBitmap results in WebTestControlHost::OnImageDump().

In some cases, we'll fail to create an SkBitmap (for instance, when
printing via `TestRunner::PrintFrameToBitmap()`. We handle those cases
safely in general, but we missed a check against the color space here.
This CL punts out of image encoding early when it's unnecessary (and
impossible).

Bug: 397018488
Change-Id: If5a43f24312639391d482081671963e151040cf1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6287486
Reviewed-by: Jonathan Hao <phao@chromium.org>
Commit-Queue: Mike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1423778}
This commit is contained in:
Mike West
2025-02-23 23:34:40 -08:00
committed by Chromium LUCI CQ
parent 48792bd8f4
commit d885a8be06

@ -1450,28 +1450,30 @@ void WebTestControlHost::OnImageDump(const std::string& actual_pixel_hash,
if (web_test_runtime_flags().dump_drag_image()) if (web_test_runtime_flags().dump_drag_image())
discard_transparency = false; discard_transparency = false;
gfx::PNGCodec::ColorFormat pixel_format; if (!image.drawsNothing()) {
switch (image.info().colorType()) { gfx::PNGCodec::ColorFormat pixel_format;
case kBGRA_8888_SkColorType: switch (image.info().colorType()) {
pixel_format = gfx::PNGCodec::FORMAT_BGRA; case kBGRA_8888_SkColorType:
break; pixel_format = gfx::PNGCodec::FORMAT_BGRA;
case kRGBA_8888_SkColorType: break;
pixel_format = gfx::PNGCodec::FORMAT_RGBA; case kRGBA_8888_SkColorType:
break; pixel_format = gfx::PNGCodec::FORMAT_RGBA;
default: break;
NOTREACHED(); default:
} NOTREACHED();
}
std::vector<gfx::PNGCodec::Comment> comments; std::vector<gfx::PNGCodec::Comment> comments;
// Used by // Used by
// //third_party/blink/tools/blinkpy/common/read_checksum_from_png.py // //third_party/blink/tools/blinkpy/common/read_checksum_from_png.py
comments.emplace_back("checksum", actual_pixel_hash); comments.emplace_back("checksum", actual_pixel_hash);
std::optional<std::vector<uint8_t>> png = gfx::PNGCodec::Encode( std::optional<std::vector<uint8_t>> png = gfx::PNGCodec::Encode(
static_cast<const unsigned char*>(image.getPixels()), pixel_format, static_cast<const unsigned char*>(image.getPixels()), pixel_format,
gfx::Size(image.width(), image.height()), gfx::Size(image.width(), image.height()),
static_cast<int>(image.rowBytes()), discard_transparency, comments); static_cast<int>(image.rowBytes()), discard_transparency, comments);
if (png) { if (png) {
printer_->PrintImageBlock(png.value()); printer_->PrintImageBlock(png.value());
}
} }
} }
printer_->PrintImageFooter(); printer_->PrintImageFooter();