Commit e5c641c6 authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Add flag which shows visually places where hidpi resources are supported...

Add flag which shows visually places where hidpi resources are supported however a hidpi resource cannot be shown because of missing assets

Bug=131631
Test=manual

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141222 0039d316-1c4b-4281-b951-d872f2087c98
parent 0adfb956
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h" #include "ui/base/layout.h"
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "ui/gfx/skbitmap_operations.h"
namespace ui { namespace ui {
...@@ -43,6 +45,40 @@ const int kMediumFontSizeDelta = 3; ...@@ -43,6 +45,40 @@ const int kMediumFontSizeDelta = 3;
const int kLargeFontSizeDelta = 8; const int kLargeFontSizeDelta = 8;
#endif #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 } // namespace
ResourceBundle* ResourceBundle::g_shared_instance_ = NULL; ResourceBundle* ResourceBundle::g_shared_instance_ = NULL;
...@@ -259,6 +295,8 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) { ...@@ -259,6 +295,8 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
return GetEmptyImage(); return GetEmptyImage();
} }
Create2xResourceIfMissing(image_skia, resource_id);
image = gfx::Image(image_skia); image = gfx::Image(image_skia);
} }
......
...@@ -20,6 +20,13 @@ const char kEnableTouchCalibration[] = "enable-touch-calibration"; ...@@ -20,6 +20,13 @@ const char kEnableTouchCalibration[] = "enable-touch-calibration";
// Enable support for touch events. // Enable support for touch events.
const char kEnableTouchEvents[] = "enable-touch-events"; const char kEnableTouchEvents[] = "enable-touch-events";
// Generates a 2x version of resources for which no 2x version is available or
// the 2x version is of an incorrect size and applies a red mask to the
// resource. Resources for which hidpi is not supported because of software
// reasons will show up pixelated.
const char kHighlightMissing2xResources[] =
"highlight-missing-2x-resources";
// The language file that we want to try to open. Of the form // The language file that we want to try to open. Of the form
// language[-country] where language is the 2 letter code from ISO-639. // language[-country] where language is the 2 letter code from ISO-639.
const char kLang[] = "lang"; const char kLang[] = "lang";
......
...@@ -17,6 +17,7 @@ UI_EXPORT extern const char kDefaultDeviceScaleFactor[]; ...@@ -17,6 +17,7 @@ UI_EXPORT extern const char kDefaultDeviceScaleFactor[];
UI_EXPORT extern const char kEnableTextSubpixelPositioning[]; UI_EXPORT extern const char kEnableTextSubpixelPositioning[];
UI_EXPORT extern const char kEnableTouchCalibration[]; UI_EXPORT extern const char kEnableTouchCalibration[];
UI_EXPORT extern const char kEnableTouchEvents[]; UI_EXPORT extern const char kEnableTouchEvents[];
UI_EXPORT extern const char kHighlightMissing2xResources[];
UI_EXPORT extern const char kLang[]; UI_EXPORT extern const char kLang[];
UI_EXPORT extern const char kLoad2xResources[]; UI_EXPORT extern const char kLoad2xResources[];
UI_EXPORT extern const char kLocalePak[]; UI_EXPORT extern const char kLocalePak[];
......
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