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..ab39f2b5415b4787acc4f25ac276815f1e1762f3 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,7 @@ gfx::ImageSkiaRep& NullImageRep() { |
} |
std::vector<float>* g_supported_scales = NULL; |
+ |
} // namespace |
namespace internal { |
@@ -139,7 +143,41 @@ 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 request_scale = scale; |
oshima
2014/05/06 20:59:49
can you use "resource_scale" ?
Jun Mukai
2014/05/06 21:06:27
Done.
|
+ if (ImageSkia::IsDSFScalingInImageSkiaEnabled() && g_supported_scales) { |
+ if (g_supported_scales->back() <= scale) { |
+ request_scale = g_supported_scales->back(); |
+ } else { |
+ for (size_t i = 0; i < g_supported_scales->size(); ++i) { |
+ if ((*g_supported_scales)[i] >= request_scale) { |
+ request_scale = (*g_supported_scales)[i]; |
oshima
2014/05/06 20:59:49
can you make it so that this picks 2.0 for 1.25 an
Jun Mukai
2014/05/06 21:06:27
I think this does so already, this for-loop attemp
Jun Mukai
2014/05/07 00:40:17
Fixed the code so that 1.25 falls back to 1.0. Add
|
+ break; |
+ } |
+ } |
+ } |
+ } |
+ if (ImageSkia::IsDSFScalingInImageSkiaEnabled() && |
+ scale != request_scale) { |
+ std::vector<ImageSkiaRep>::iterator iter = |
+ non_const->FindRepresentation(request_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 +281,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()) |