| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_family.h" | 5 #include "ui/gfx/image/image_family.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "skia/ext/image_operations.h" | 9 #include "skia/ext/image_operations.h" |
| 10 #include "ui/gfx/geometry/size.h" | 10 #include "ui/gfx/geometry/size.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 SkBitmap bitmap = image->AsBitmap(); | 129 SkBitmap bitmap = image->AsBitmap(); |
| 130 SkBitmap resized_bitmap = skia::ImageOperations::Resize( | 130 SkBitmap resized_bitmap = skia::ImageOperations::Resize( |
| 131 bitmap, skia::ImageOperations::RESIZE_LANCZOS3, width, height); | 131 bitmap, skia::ImageOperations::RESIZE_LANCZOS3, width, height); |
| 132 return gfx::Image::CreateFrom1xBitmap(resized_bitmap); | 132 return gfx::Image::CreateFrom1xBitmap(resized_bitmap); |
| 133 } | 133 } |
| 134 | 134 |
| 135 gfx::Image ImageFamily::CreateExact(const gfx::Size& size) const { | 135 gfx::Image ImageFamily::CreateExact(const gfx::Size& size) const { |
| 136 return CreateExact(size.width(), size.height()); | 136 return CreateExact(size.width(), size.height()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void ImageFamily::DisableThreadChecking() { |
| 140 for (auto& item : map_) |
| 141 item.second.DisableThreadChecking(); |
| 142 } |
| 143 |
| 144 void ImageFamily::DetachFromThread() { |
| 145 for (auto& item : map_) |
| 146 item.second.DetachFromThread(); |
| 147 } |
| 148 |
| 139 const gfx::Image* ImageFamily::GetWithExactAspect(float aspect, | 149 const gfx::Image* ImageFamily::GetWithExactAspect(float aspect, |
| 140 int width) const { | 150 int width) const { |
| 141 // Find the two images of given aspect ratio on either side of |width|. | 151 // Find the two images of given aspect ratio on either side of |width|. |
| 142 std::map<MapKey, gfx::Image>::const_iterator greater_or_equal = | 152 std::map<MapKey, gfx::Image>::const_iterator greater_or_equal = |
| 143 map_.lower_bound(MapKey(aspect, width)); | 153 map_.lower_bound(MapKey(aspect, width)); |
| 144 if (greater_or_equal != map_.end() && | 154 if (greater_or_equal != map_.end() && |
| 145 greater_or_equal->first.aspect() == aspect) { | 155 greater_or_equal->first.aspect() == aspect) { |
| 146 // We have found the smallest image of the same size or greater. | 156 // We have found the smallest image of the same size or greater. |
| 147 return &greater_or_equal->second; | 157 return &greater_or_equal->second; |
| 148 } | 158 } |
| 149 | 159 |
| 150 DCHECK(greater_or_equal != map_.begin()); | 160 DCHECK(greater_or_equal != map_.begin()); |
| 151 std::map<MapKey, gfx::Image>::const_iterator less_than = greater_or_equal; | 161 std::map<MapKey, gfx::Image>::const_iterator less_than = greater_or_equal; |
| 152 --less_than; | 162 --less_than; |
| 153 // This must be true because there must be at least one image with |aspect|. | 163 // This must be true because there must be at least one image with |aspect|. |
| 154 DCHECK_EQ(less_than->first.aspect(), aspect); | 164 DCHECK_EQ(less_than->first.aspect(), aspect); |
| 155 // We have found the largest image smaller than desired. | 165 // We have found the largest image smaller than desired. |
| 156 return &less_than->second; | 166 return &less_than->second; |
| 157 } | 167 } |
| 158 | 168 |
| 159 } // namespace gfx | 169 } // namespace gfx |
| OLD | NEW |