Commit f0896290 authored by kevers@chromium.org's avatar kevers@chromium.org

Fix sizing when auto-scaling a missing resource at a non-integer scale factor....

Fix sizing when auto-scaling a missing resource at a non-integer scale factor.  Matches the rounding rules used by UX when scaling resources at non-integer scale factors.

BUG=223928


Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=190970

Review URL: https://chromiumcodereview.appspot.com/12939015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192576 0039d316-1c4b-4281-b951-d872f2087c98
parent 0419d72d
......@@ -86,8 +86,8 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
image = skia::ImageOperations::Resize(
image,
skia::ImageOperations::RESIZE_LANCZOS3,
gfx::ToFlooredInt(image.width() * scale),
gfx::ToFlooredInt(image.height() * scale));
gfx::ToCeiledInt(image.width() * scale),
gfx::ToCeiledInt(image.height() * scale));
// If --highlight-missing-scaled-resources is specified, log the resource
// id and blend the created resource with red.
if (ShouldHighlightMissingScaledResources()) {
......
......@@ -498,6 +498,39 @@ TEST_F(ResourceBundleImageTest, GetImageNamedFallback1x) {
EXPECT_EQ(20, image_rep.pixel_height());
}
#if defined(OS_WIN)
// Tests GetImageNamed() behaves properly when the size of a scaled image
// requires rounding as a result of using a non-integer scale factor.
// Scale factors of 140 and 1805 are Windows specific.
TEST_F(ResourceBundleImageTest, GetImageNamedFallback1xRounding) {
base::FilePath data_path = dir_path().AppendASCII("sample.pak");
base::FilePath data_140P_path = dir_path().AppendASCII("sample_140P.pak");
base::FilePath data_180P_path = dir_path().AppendASCII("sample_180P.pak");
CreateDataPackWithSingleBitmap(data_path, 8, base::StringPiece());
// Mark 140% and 180% images as requiring 1x fallback.
CreateDataPackWithSingleBitmap(data_140P_path, 8, base::StringPiece(
reinterpret_cast<const char*>(kPngScaleChunk),
arraysize(kPngScaleChunk)));
CreateDataPackWithSingleBitmap(data_180P_path, 8, base::StringPiece(
reinterpret_cast<const char*>(kPngScaleChunk),
arraysize(kPngScaleChunk)));
ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak();
resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P);
resource_bundle->AddDataPackFromPath(data_140P_path, SCALE_FACTOR_140P);
resource_bundle->AddDataPackFromPath(data_180P_path, SCALE_FACTOR_180P);
// Non-integer dimensions should be rounded up.
gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
gfx::ImageSkiaRep image_rep =
image_skia->GetRepresentation(ui::SCALE_FACTOR_140P);
EXPECT_EQ(12, image_rep.pixel_width());
image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_180P);
EXPECT_EQ(15, image_rep.pixel_width());
}
#endif
TEST_F(ResourceBundleImageTest, FallbackToNone) {
base::FilePath data_default_path = dir_path().AppendASCII("sample.pak");
......
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