summaryrefslogtreecommitdiffstats
path: root/ui/base/resource
diff options
context:
space:
mode:
authorkevers@chromium.org <kevers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-27 17:43:30 +0000
committerkevers@chromium.org <kevers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-27 17:43:30 +0000
commitd1d46d8ee555df27cf50e63bd82e48458da89902 (patch)
tree468be565f2bbe4e1f608a722cf5af08ff9593553 /ui/base/resource
parent9ee4d3a2fdc6accd37343d148e5c5149c1b7d045 (diff)
downloadchromium_src-d1d46d8ee555df27cf50e63bd82e48458da89902.zip
chromium_src-d1d46d8ee555df27cf50e63bd82e48458da89902.tar.gz
chromium_src-d1d46d8ee555df27cf50e63bd82e48458da89902.tar.bz2
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 Review URL: https://chromiumcodereview.appspot.com/12939015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190970 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/resource')
-rw-r--r--ui/base/resource/resource_bundle.cc4
-rw-r--r--ui/base/resource/resource_bundle_unittest.cc30
2 files changed, 32 insertions, 2 deletions
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index 3c03ee8..c1687f8 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -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()) {
diff --git a/ui/base/resource/resource_bundle_unittest.cc b/ui/base/resource/resource_bundle_unittest.cc
index ab1c2094..c6f4910 100644
--- a/ui/base/resource/resource_bundle_unittest.cc
+++ b/ui/base/resource/resource_bundle_unittest.cc
@@ -498,6 +498,36 @@ TEST_F(ResourceBundleImageTest, GetImageNamedFallback1x) {
EXPECT_EQ(20, image_rep.pixel_height());
}
+// Tests GetImageNamed() behaves properly when the size of a scaled image
+// requires rounding as a result of using a non-integer scale factor.
+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());
+}
+
TEST_F(ResourceBundleImageTest, FallbackToNone) {
base::FilePath data_default_path = dir_path().AppendASCII("sample.pak");