Index: ui/gfx/image/image_skia.cc |
diff --git a/ui/gfx/image/image_skia.cc b/ui/gfx/image/image_skia.cc |
index ba2cad2af08f01198a2b47df3e70de1db6c35aa8..c7c930db137ad5592391490abc5f0a83cdf655ff 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,45 @@ 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 = FindRepresentation( |
+ resource_scale, fetch_new_image); |
+ |
+ DCHECK(iter != image_reps_.end()); |
+ |
+ if (!iter->unscaled()) { |
+ 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()); |
+ } |
oshima
2014/05/09 16:10:30
This currently works without the following because
Jun Mukai
2014/05/12 05:23:24
Done.
|
+ } else { |
+ image = source_->GetImageForScale(scale); |
+ } |
// If the source returned the new image, store it. |
if (!image.is_null() && |
@@ -243,6 +291,17 @@ ImageSkia ImageSkia::CreateFrom1xBitmap(const SkBitmap& bitmap) { |
return ImageSkia(ImageSkiaRep(bitmap, 0.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()) |