Commit 1eb1dbc5 authored by Andres Calderon Jaramillo's avatar Andres Calderon Jaramillo Committed by Commit Bot

cc: Fix target_size in SoftwareImageDecodeCacheUtils::CacheKey.

This CL fixes the computation of the target_size in FromDrawImage() when
the target_size is updated to the size of a mip level. Previously, the
computation rounded down which was inconsistent with the behavior
introduced in https://crrev.com/c/1107049.

Test: the artifact in the referenced bug is no longer present.
Bug: 891316
Change-Id: If8838c1501cbbcedd8261ddf6eac81f21cdca947
Reviewed-on: https://chromium-review.googlesource.com/c/1321774
Commit-Queue: Andres Calderon Jaramillo <andrescj@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607032}
parent 1dd145ed
...@@ -571,6 +571,41 @@ TEST(SoftwareImageDecodeCacheTest, ...@@ -571,6 +571,41 @@ TEST(SoftwareImageDecodeCacheTest,
EXPECT_EQ(100u * 100u * 4u, key.locked_bytes()); EXPECT_EQ(100u * 100u * 4u, key.locked_bytes());
} }
TEST(SoftwareImageDecodeCacheTest, ImageKeyDownscaleMipLevelWithRounding) {
// Tests that, when using a non-zero mip level, the final target size (which
// is the size of the chosen mip level) is as expected if rounding is
// required.
//
// The 97x61 dimensions and the (0.2f, 0.2f) scaling were chosen specifically
// so that:
//
// - The starting target size is 19x12 which means that 2 is the chosen mip
// level.
//
// - Attempting to get the final target size by simply multiplying the
// dimensions of the |src_rect| (97x61) times
// MipMapUtil::GetScaleAdjustmentForLevel() yields 24x15 if we attempt to
// store the result as integers. This is inconsistent with the rounding
// behavior introduced in https://crrev.com/c/1107049 and was the cause of
// https://crbug.com/891316.
PaintImage paint_image = CreatePaintImage(97, 61);
bool is_decomposable = true;
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
kMedium_SkFilterQuality,
CreateMatrix(SkSize::Make(0.2f, 0.2f), is_decomposable),
PaintImage::kDefaultFrameIndex);
auto key = SoftwareImageDecodeCache::CacheKey::FromDrawImage(
draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
EXPECT_FALSE(key.is_nearest_neighbor());
EXPECT_EQ(25, key.target_size().width());
EXPECT_EQ(16, key.target_size().height());
EXPECT_EQ(key.type(), SoftwareImageDecodeCache::CacheKey::kSubrectAndScale);
EXPECT_EQ(25u * 16u * 4u, key.locked_bytes());
}
TEST(SoftwareImageDecodeCacheTest, OriginalDecodesAreEqual) { TEST(SoftwareImageDecodeCacheTest, OriginalDecodesAreEqual) {
PaintImage paint_image = CreatePaintImage(100, 100); PaintImage paint_image = CreatePaintImage(100, 100);
bool is_decomposable = true; bool is_decomposable = true;
......
...@@ -203,14 +203,7 @@ SoftwareImageDecodeCacheUtils::CacheKey::FromDrawImage(const DrawImage& image, ...@@ -203,14 +203,7 @@ SoftwareImageDecodeCacheUtils::CacheKey::FromDrawImage(const DrawImage& image,
} else { } else {
type = kSubrectAndScale; type = kSubrectAndScale;
// Update the target size to be a mip level size. // Update the target size to be a mip level size.
// TODO(vmpstr): MipMapUtil and JPEG decoders disagree on what to do with target_size = MipMapUtil::GetSizeForLevel(src_rect.size(), mip_level);
// odd sizes. If width = 2k + 1, and the mip level is 1, then this will
// return width = k; JPEG decoder, however, will support decoding to width =
// k + 1. We need to figure out what to do in this case.
SkSize mip_scale_adjustment =
MipMapUtil::GetScaleAdjustmentForLevel(src_rect.size(), mip_level);
target_size.set_width(src_rect.width() * mip_scale_adjustment.width());
target_size.set_height(src_rect.height() * mip_scale_adjustment.height());
} }
// If the original image is large, we might want to do a subrect instead if // If the original image is large, we might want to do a subrect instead if
......
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