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

Unified Diff: ui/gfx/image/image_skia.cc

Issue 263253003: Allows arbitrary scale factor in ImageSkia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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/gfx/image/image_skia_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0283969faed0b556d86b83118da813d723bae58e 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,16 @@ gfx::ImageSkiaRep& NullImageRep() {
}
std::vector<float>* g_supported_scales = NULL;
+
+bool IsImageSkiaScaling() {
oshima 2014/05/06 18:52:27 how about IsDSFScalingInImageSkiaEnabled ?
Jun Mukai 2014/05/06 19:56:49 Done.
+#if defined(OS_WIN)
+ return true;
+#else
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kAllowArbitraryScaleFactorInImageSkia);
+#endif
+}
+
} // namespace
namespace internal {
@@ -139,7 +152,28 @@ 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;
+ if (IsImageSkiaScaling() && scale != 1.0f && scale != 2.0f) {
oshima 2014/05/06 18:52:27 can you use g_supported_scales?
Jun Mukai 2014/05/06 19:56:49 Well, that's still unclear to me. What is g_suppor
Jun Mukai 2014/05/06 20:42:42 Chatted offline and I was wrong. g_supported_scale
+ std::vector<ImageSkiaRep>::iterator iter =
+ non_const->FindRepresentation(
+ (scale < 1.0f) ? 1.0f : 2.0f, 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() &&
« no previous file with comments | « no previous file | ui/gfx/image/image_skia_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698