Chromium Code Reviews| Index: ui/base/resource/resource_bundle.cc |
| diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc |
| index 417fd2bb11b35ac47b340ff38f7dc02904f2f6b6..60b51f1946a514b12f1592ee9b01c71286ac95c2 100644 |
| --- a/ui/base/resource/resource_bundle.cc |
| +++ b/ui/base/resource/resource_bundle.cc |
| @@ -17,6 +17,7 @@ |
| #include "base/synchronization/lock.h" |
| #include "base/utf_string_conversions.h" |
| #include "build/build_config.h" |
| +#include "skia/ext/image_operations.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/layout.h" |
| @@ -27,6 +28,7 @@ |
| #include "ui/gfx/codec/png_codec.h" |
| #include "ui/gfx/image/image_skia.h" |
| #include "ui/gfx/screen.h" |
| +#include "ui/gfx/skbitmap_operations.h" |
| namespace ui { |
| @@ -43,6 +45,33 @@ const int kMediumFontSizeDelta = 3; |
| const int kLargeFontSizeDelta = 8; |
| #endif |
| +// Creates a 2x resource if the 2x resource is missing from |image| or is the |
| +// incorrect size. Blends the created resource with red to make it |
| +// distinguishable from bitmaps in the resource pak. |
| +void Create2xResourceIfMissing(gfx::ImageSkia image) { |
| + CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + if (command_line->HasSwitch( |
| + switches::kHighlightMissing2xResources) && |
| + command_line->HasSwitch(switches::kLoad2xResources) && |
| + !image.HasBitmapForScale(2.0f)) { |
| + float bitmap_scale; |
|
sky
2012/06/08 03:01:21
Why don't you also log.
|
| + SkBitmap bitmap = image.GetBitmapForScale(2.0f, &bitmap_scale); |
| + SkBitmap bitmap2x = skia::ImageOperations::Resize(bitmap, |
| + skia::ImageOperations::RESIZE_LANCZOS3, |
| + image.width() * 2, image.height() * 2); |
| + |
| + SkBitmap mask; |
| + mask.setConfig(SkBitmap::kARGB_8888_Config, |
| + bitmap2x.width(), |
| + bitmap2x.height()); |
| + mask.allocPixels(); |
| + mask.eraseColor(SK_ColorRED); |
| + SkBitmap result = SkBitmapOperations::CreateBlendedBitmap(bitmap2x, mask, |
| + 0.2); |
| + image.AddBitmapForScale(result, 2.0f); |
| + } |
| +} |
| + |
| } // namespace |
| ResourceBundle* ResourceBundle::g_shared_instance_ = NULL; |
| @@ -259,6 +288,8 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) { |
| return GetEmptyImage(); |
| } |
| + Create2xResourceIfMissing(image_skia); |
| + |
| image = gfx::Image(image_skia); |
| } |