| Index: ui/gfx/image/image_skia.cc
|
| diff --git a/ui/gfx/image/image_skia.cc b/ui/gfx/image/image_skia.cc
|
| index a283117db2415488f3259cb3986fa956c0031a47..e4123f1310dc581f4aab789daca790074226d673 100644
|
| --- a/ui/gfx/image/image_skia.cc
|
| +++ b/ui/gfx/image/image_skia.cc
|
| @@ -8,14 +8,17 @@
|
| #include <cmath>
|
| #include <limits>
|
|
|
| +#include "base/command_line.h"
|
| #include "base/logging.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/threading/non_thread_safe.h"
|
| +#include "ui/gfx/geometry/size_conversions.h"
|
| #include "ui/gfx/image/image_skia_operations.h"
|
| #include "ui/gfx/image/image_skia_source.h"
|
| #include "ui/gfx/rect.h"
|
| #include "ui/gfx/size.h"
|
| #include "ui/gfx/skia_util.h"
|
| +#include "ui/gfx/switches.h"
|
|
|
| namespace gfx {
|
| namespace {
|
| @@ -27,6 +30,13 @@ gfx::ImageSkiaRep& NullImageRep() {
|
| }
|
|
|
| std::vector<float>* g_supported_scales = NULL;
|
| +
|
| +// The difference to fall back to the smaller scale factor rather than the
|
| +// larger one. For example, assume 1.25 is requested but only 1.0 and 2.0 are
|
| +// supported. In that case, not fall back to 2.0 but 1.0, and then expand
|
| +// the image to 1.25.
|
| +const float kFallbackToSmallerScaleDiff = 0.25f;
|
| +
|
| } // namespace
|
|
|
| namespace internal {
|
| @@ -139,7 +149,42 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
|
| DCHECK(CalledOnValidThread()) <<
|
| "An ImageSkia with the source must be accessed by the same thread.";
|
|
|
| - ImageSkiaRep image = source_->GetImageForScale(scale);
|
| + ImageSkiaRep image;
|
| + float resource_scale = scale;
|
| + if (ImageSkia::IsDSFScalingInImageSkiaEnabled() && g_supported_scales) {
|
| + if (g_supported_scales->back() <= scale) {
|
| + resource_scale = g_supported_scales->back();
|
| + } else {
|
| + for (size_t i = 0; i < g_supported_scales->size(); ++i) {
|
| + if ((*g_supported_scales)[i] + kFallbackToSmallerScaleDiff >=
|
| + resource_scale) {
|
| + resource_scale = (*g_supported_scales)[i];
|
| + break;
|
| + }
|
| + }
|
| + }
|
| + }
|
| + if (ImageSkia::IsDSFScalingInImageSkiaEnabled() &&
|
| + scale != resource_scale) {
|
| + std::vector<ImageSkiaRep>::iterator iter =
|
| + non_const->FindRepresentation(resource_scale, fetch_new_image);
|
| +
|
| + DCHECK(iter != non_const->image_reps().end());
|
| + SkBitmap scaled_image;
|
| + gfx::Size unscaled_size(iter->pixel_width(), iter->pixel_height());
|
| + gfx::Size scaled_size = ToCeiledSize(
|
| + gfx::ScaleSize(unscaled_size, scale / iter->scale()));
|
| +
|
| + image = ImageSkiaRep(skia::ImageOperations::Resize(
|
| + iter->sk_bitmap(),
|
| + skia::ImageOperations::RESIZE_LANCZOS3,
|
| + scaled_size.width(),
|
| + scaled_size.height()), scale);
|
| + DCHECK_EQ(image.pixel_width(), scaled_size.width());
|
| + DCHECK_EQ(image.pixel_height(), scaled_size.height());
|
| + } else {
|
| + image = source_->GetImageForScale(scale);
|
| + }
|
|
|
| // If the source returned the new image, store it.
|
| if (!image.is_null() &&
|
| @@ -243,6 +288,17 @@ ImageSkia ImageSkia::CreateFrom1xBitmap(const SkBitmap& bitmap) {
|
| return ImageSkia(ImageSkiaRep(bitmap, 1.0f));
|
| }
|
|
|
| +bool ImageSkia::IsDSFScalingInImageSkiaEnabled() {
|
| + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
| +#if defined(OS_WIN)
|
| + return !command_line->HasSwitch(
|
| + switches::kDisallowArbitraryScaleFactorInImageSkia);
|
| +#else
|
| + return command_line->HasSwitch(
|
| + switches::kAllowArbitraryScaleFactorInImageSkia);
|
| +#endif
|
| +}
|
| +
|
| scoped_ptr<ImageSkia> ImageSkia::DeepCopy() const {
|
| ImageSkia* copy = new ImageSkia;
|
| if (isNull())
|
|
|