Chromium Code Reviews| Index: ui/gfx/image/image_skia.cc |
| diff --git a/ui/gfx/image/image_skia.cc b/ui/gfx/image/image_skia.cc |
| index 20349b4baf14c71cd7fd7200697b559abc4fcf84..aede1290f0865c3c2c74a23d0db52660462f4ae3 100644 |
| --- a/ui/gfx/image/image_skia.cc |
| +++ b/ui/gfx/image/image_skia.cc |
| @@ -41,6 +41,17 @@ std::vector<float>* g_supported_scales = NULL; |
| // the image to 1.25. |
| const float kFallbackToSmallerScaleDiff = 0.20f; |
| +// Maps to the closest supported scale. Returns an exact match, a smaller |
| +// scale within 0.2 units, the nearest larger scale, or the min/max |
| +// supported scale. |
| +float MapToSupportedScale(float scale) { |
| + for (float supported_scale : *g_supported_scales) { |
| + if (supported_scale + kFallbackToSmallerScaleDiff >= scale) |
| + return supported_scale; |
| + } |
| + return g_supported_scales->back(); |
| +} |
| + |
| } // namespace |
| namespace internal { |
| @@ -219,18 +230,8 @@ std::vector<ImageSkiaRep>::iterator ImageSkiaStorage::FindRepresentation( |
| ImageSkiaRep image; |
| float resource_scale = scale; |
| - if (!HasRepresentationAtAllScales() && 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 >= scale) { |
| - resource_scale = (*g_supported_scales)[i]; |
| - break; |
| - } |
| - } |
| - } |
| - } |
| + if (!HasRepresentationAtAllScales() && g_supported_scales) |
| + resource_scale = MapToSupportedScale(scale); |
| if (scale != resource_scale) { |
| std::vector<ImageSkiaRep>::iterator iter = |
| FindRepresentation(resource_scale, fetch_new_image); |
| @@ -481,6 +482,18 @@ void ImageSkia::EnsureRepsForSupportedScales() const { |
| } |
| } |
| +void ImageSkia::RemoveUnsupportedRepresentationsForScale(float scale) { |
| + std::vector<float> scales_to_remove; |
|
oshima
2017/05/26 20:01:05
image reps returns the vector by value, so you can
khmel
2017/05/26 20:13:55
Good point, done.
|
| + for (const ImageSkiaRep& image_rep_to_test : image_reps()) { |
| + const float test_scale = image_rep_to_test.scale(); |
| + if (test_scale != scale && MapToSupportedScale(test_scale) == scale) |
| + scales_to_remove.push_back(test_scale); |
| + } |
| + |
| + for (float scale_to_remove : scales_to_remove) |
| + RemoveRepresentation(scale_to_remove); |
| +} |
| + |
| void ImageSkia::Init(const ImageSkiaRep& image_rep) { |
| // TODO(pkotwicz): The image should be null whenever image rep is null. |
| if (image_rep.sk_bitmap().empty()) { |