Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: ui/base/resource/resource_bundle.cc

Issue 10494013: Add flag which shows missing 2x resources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/base/ui_base_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..205ee6dc22c47b63508142910713ee19a7d1668e 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,40 @@ const int kMediumFontSizeDelta = 3;
const int kLargeFontSizeDelta = 8;
#endif
+// If 2x resource is missing from |image| or is the incorrect size,
+// logs 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.
+void Create2xResourceIfMissing(gfx::ImageSkia image, int idr) {
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(
+ switches::kHighlightMissing2xResources) &&
+ command_line->HasSwitch(switches::kLoad2xResources) &&
+ !image.HasBitmapForScale(2.0f)) {
+ float bitmap_scale;
+ SkBitmap bitmap = image.GetBitmapForScale(2.0f, &bitmap_scale);
+
+ if (bitmap_scale == 1.0f)
+ LOG(INFO) << "Missing 2x resource with id " << idr;
+ else
+ LOG(INFO) << "Incorrectly sized 2x resource with id " << idr;
+
+ 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 +295,8 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
return GetEmptyImage();
}
+ Create2xResourceIfMissing(image_skia, resource_id);
+
image = gfx::Image(image_skia);
}
« no previous file with comments | « no previous file | ui/base/ui_base_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698