Index: ui/base/resource/resource_bundle.cc |
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc |
index 0071a5a22e871d41974e06be1cafcac6d8daca82..8428f5be522612adb69181f8b91620eeb0ba3905 100644 |
--- a/ui/base/resource/resource_bundle.cc |
+++ b/ui/base/resource/resource_bundle.cc |
@@ -45,7 +45,7 @@ ResourceBundle* g_shared_instance_ = NULL; |
// Returns the actual scale factor of |bitmap| given the image representations |
// which have already been added to |image|. |
// TODO(pkotwicz): Remove this once we are no longer loading 1x resources |
-// as part of 2x data packs. |
+// as part of non 1x data packs. |
ui::ScaleFactor GetActualScaleFactor(const gfx::ImageSkia& image, |
const SkBitmap& bitmap, |
ui::ScaleFactor data_pack_scale_factor) { |
@@ -56,9 +56,9 @@ ui::ScaleFactor GetActualScaleFactor(const gfx::ImageSkia& image, |
static_cast<float>(bitmap.width()) / image.width()); |
} |
-bool ShouldHighlightMissing2xResources() { |
+bool ShouldHighlightMissingScaledResources() { |
return CommandLine::ForCurrentProcess()->HasSwitch( |
- switches::kHighlightMissing2xResources); |
+ switches::kHighlightMissingScaledResources); |
} |
} // namespace |
@@ -84,10 +84,10 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { |
ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
scoped_ptr<SkBitmap> result(rb.LoadBitmap(resource_id_, scale_factor)); |
- gfx::Size size_in_pixel = |
- size_in_dip_.Scale(ui::GetScaleFactorScale(scale_factor)); |
+ float scale = ui::GetScaleFactorScale(scale_factor); |
+ gfx::Size size_in_pixel = size_in_dip_.Scale(scale); |
- if (scale_factor == SCALE_FACTOR_200P && |
+ if (scale_factor != SCALE_FACTOR_100P && |
(!result.get() || |
result->width() != size_in_pixel.width() || |
result->height() != size_in_pixel.height())) { |
@@ -97,39 +97,45 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { |
// the resource id and creates a 2x version of the resource. |
// Blends the created resource with red to make it |
// distinguishable from bitmaps in the resource pak. |
- if (ShouldHighlightMissing2xResources()) { |
- if (!result.get()) |
- LOG(ERROR) << "Missing 2x resource. id=" << resource_id_; |
- else |
- LOG(ERROR) << "Incorrectly sized 2x resource. id=" << resource_id_; |
- |
- SkBitmap bitmap1x = *(rb.LoadBitmap(resource_id_, SCALE_FACTOR_100P)); |
- SkBitmap bitmap2x = skia::ImageOperations::Resize( |
- bitmap1x, |
+ if (ShouldHighlightMissingScaledResources()) { |
+ if (!result.get()) { |
+ LOG(ERROR) << "Missing " << scale << "x resource. id=" |
+ << resource_id_; |
+ } else { |
+ LOG(ERROR) << "Incorrectly sized " << scale << "x resource. id=" |
+ << resource_id_; |
+ } |
+ |
+ scoped_ptr<SkBitmap> bitmap1x( |
+ rb.LoadBitmap(resource_id_, SCALE_FACTOR_100P)); |
+ DCHECK(bitmap1x.get()); |
+ SkBitmap bitmap_scaled = skia::ImageOperations::Resize( |
+ *bitmap1x, |
skia::ImageOperations::RESIZE_LANCZOS3, |
- bitmap1x.width() * 2, bitmap1x.height() * 2); |
+ static_cast<int>(ceil(bitmap1x->width() * scale)), |
huangs
2012/09/17 17:53:45
Reuse size_in_pixel, for consistent rounding.
|
+ static_cast<int>(ceil(bitmap1x->height() * scale))); |
SkBitmap mask; |
mask.setConfig(SkBitmap::kARGB_8888_Config, |
- bitmap2x.width(), |
- bitmap2x.height()); |
+ bitmap_scaled.width(), |
+ bitmap_scaled.height()); |
mask.allocPixels(); |
mask.eraseColor(SK_ColorRED); |
result.reset(new SkBitmap()); |
- *result.get() = SkBitmapOperations::CreateBlendedBitmap(bitmap2x, mask, |
- 0.2); |
- } else if (!result.get() || |
- result->width() == size_in_dip_.width()) { |
- // The 2x resource pack may have the 1x image if its grd file |
+ *result.get() = SkBitmapOperations::CreateBlendedBitmap( |
+ bitmap_scaled, mask, 0.2); |
+ } else if (!result.get() || result->width() == size_in_dip_.width()) { |
+ // The scaled resource pack may have the 1x image if its grd file |
// points to 1x image. Fallback to 1x by returning empty image |
// in this case. This 1x image will be scaled when drawn. |
return gfx::ImageSkiaRep(); |
} |
- // If the size of 2x image isn't exactly 2x of 1x version, |
+ // If the size of scaled image isn't exactly |scale| * 1x version, |
// create ImageSkia as usual. This will end up with |
// corrupted visual representation as the size of image doesn't |
// match the expected size. |
} |
+ DCHECK(result.get()); |
return gfx::ImageSkiaRep(*result.get(), scale_factor); |
} |