Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/image/image_skia.h" | 5 #include "ui/gfx/image/image_skia.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| 11 #include "base/command_line.h" | |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
| 15 #include "ui/gfx/geometry/size_conversions.h" | |
| 14 #include "ui/gfx/image/image_skia_operations.h" | 16 #include "ui/gfx/image/image_skia_operations.h" |
| 15 #include "ui/gfx/image/image_skia_source.h" | 17 #include "ui/gfx/image/image_skia_source.h" |
| 16 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 17 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
| 18 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
| 21 #include "ui/gfx/switches.h" | |
| 19 | 22 |
| 20 namespace gfx { | 23 namespace gfx { |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 // static | 26 // static |
| 24 gfx::ImageSkiaRep& NullImageRep() { | 27 gfx::ImageSkiaRep& NullImageRep() { |
| 25 CR_DEFINE_STATIC_LOCAL(ImageSkiaRep, null_image_rep, ()); | 28 CR_DEFINE_STATIC_LOCAL(ImageSkiaRep, null_image_rep, ()); |
| 26 return null_image_rep; | 29 return null_image_rep; |
| 27 } | 30 } |
| 28 | 31 |
| 29 std::vector<float>* g_supported_scales = NULL; | 32 std::vector<float>* g_supported_scales = NULL; |
| 33 | |
| 34 bool IsImageSkiaScaling() { | |
|
oshima
2014/05/06 18:52:27
how about IsDSFScalingInImageSkiaEnabled ?
Jun Mukai
2014/05/06 19:56:49
Done.
| |
| 35 #if defined(OS_WIN) | |
| 36 return true; | |
| 37 #else | |
| 38 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 39 switches::kAllowArbitraryScaleFactorInImageSkia); | |
| 40 #endif | |
| 41 } | |
| 42 | |
| 30 } // namespace | 43 } // namespace |
| 31 | 44 |
| 32 namespace internal { | 45 namespace internal { |
| 33 namespace { | 46 namespace { |
| 34 | 47 |
| 35 class Matcher { | 48 class Matcher { |
| 36 public: | 49 public: |
| 37 explicit Matcher(float scale) : scale_(scale) { | 50 explicit Matcher(float scale) : scale_(scale) { |
| 38 } | 51 } |
| 39 | 52 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 if (diff < smallest_diff && !it->is_null()) { | 145 if (diff < smallest_diff && !it->is_null()) { |
| 133 closest_iter = it; | 146 closest_iter = it; |
| 134 smallest_diff = diff; | 147 smallest_diff = diff; |
| 135 } | 148 } |
| 136 } | 149 } |
| 137 | 150 |
| 138 if (fetch_new_image && source_.get()) { | 151 if (fetch_new_image && source_.get()) { |
| 139 DCHECK(CalledOnValidThread()) << | 152 DCHECK(CalledOnValidThread()) << |
| 140 "An ImageSkia with the source must be accessed by the same thread."; | 153 "An ImageSkia with the source must be accessed by the same thread."; |
| 141 | 154 |
| 142 ImageSkiaRep image = source_->GetImageForScale(scale); | 155 ImageSkiaRep image; |
| 156 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
| |
| 157 std::vector<ImageSkiaRep>::iterator iter = | |
| 158 non_const->FindRepresentation( | |
| 159 (scale < 1.0f) ? 1.0f : 2.0f, fetch_new_image); | |
| 160 | |
| 161 DCHECK(iter != non_const->image_reps().end()); | |
| 162 SkBitmap scaled_image; | |
| 163 gfx::Size unscaled_size(iter->pixel_width(), iter->pixel_height()); | |
| 164 gfx::Size scaled_size = ToCeiledSize( | |
| 165 gfx::ScaleSize(unscaled_size, scale / iter->scale())); | |
| 166 | |
| 167 image = ImageSkiaRep(skia::ImageOperations::Resize( | |
| 168 iter->sk_bitmap(), | |
| 169 skia::ImageOperations::RESIZE_LANCZOS3, | |
| 170 scaled_size.width(), | |
| 171 scaled_size.height()), scale); | |
| 172 DCHECK_EQ(image.pixel_width(), scaled_size.width()); | |
| 173 DCHECK_EQ(image.pixel_height(), scaled_size.height()); | |
| 174 } else { | |
| 175 image = source_->GetImageForScale(scale); | |
| 176 } | |
| 143 | 177 |
| 144 // If the source returned the new image, store it. | 178 // If the source returned the new image, store it. |
| 145 if (!image.is_null() && | 179 if (!image.is_null() && |
| 146 std::find_if(image_reps_.begin(), image_reps_.end(), | 180 std::find_if(image_reps_.begin(), image_reps_.end(), |
| 147 Matcher(image.scale())) == image_reps_.end()) { | 181 Matcher(image.scale())) == image_reps_.end()) { |
| 148 non_const->image_reps().push_back(image); | 182 non_const->image_reps().push_back(image); |
| 149 } | 183 } |
| 150 | 184 |
| 151 // If the result image's scale isn't same as the expected scale, create | 185 // If the result image's scale isn't same as the expected scale, create |
| 152 // null ImageSkiaRep with the |scale| so that the next lookup will | 186 // null ImageSkiaRep with the |scale| so that the next lookup will |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 bool ImageSkia::CanModify() const { | 450 bool ImageSkia::CanModify() const { |
| 417 return !storage_.get() || storage_->CanModify(); | 451 return !storage_.get() || storage_->CanModify(); |
| 418 } | 452 } |
| 419 | 453 |
| 420 void ImageSkia::DetachStorageFromThread() { | 454 void ImageSkia::DetachStorageFromThread() { |
| 421 if (storage_.get()) | 455 if (storage_.get()) |
| 422 storage_->DetachFromThread(); | 456 storage_->DetachFromThread(); |
| 423 } | 457 } |
| 424 | 458 |
| 425 } // namespace gfx | 459 } // namespace gfx |
| OLD | NEW |