Index: ui/gfx/image/image_skia.cc |
diff --git a/ui/gfx/image/image_skia.cc b/ui/gfx/image/image_skia.cc |
index 58fb8d1e95f9054f975fa5120a431d836915c9aa..8a1a2c99555c6f46bae55fd1a3ef3e0d5c9d4053 100644 |
--- a/ui/gfx/image/image_skia.cc |
+++ b/ui/gfx/image/image_skia.cc |
@@ -92,6 +92,11 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>, |
// the image high DPI aware. |
void AddRepresentation(const ImageSkiaRep& image); |
+ // Returns whether the underlying image source can provide a representation at |
+ // any scale. In this case, the caller is guaranteed that |
+ // FindRepresentation(..., true) will always succeed. |
+ bool HasRepresentationAtAllScales() const; |
+ |
// Returns the iterator of the image rep whose density best matches |
// |scale|. If the image for the |scale| doesn't exist in the storage and |
// |storage| is set, it fetches new image by calling |
@@ -160,6 +165,10 @@ bool ImageSkiaStorage::CanRead() const { |
} |
void ImageSkiaStorage::AddRepresentation(const ImageSkiaRep& image) { |
+ // Explicitly adding a representation makes no sense for images that |
+ // inherently have representations at all scales already. |
+ DCHECK(!HasRepresentationAtAllScales()); |
+ |
if (image.scale() != 1.0f) { |
for (ImageSkia::ImageSkiaReps::iterator it = image_reps_.begin(); |
it < image_reps_.end(); ++it) { |
@@ -173,6 +182,10 @@ void ImageSkiaStorage::AddRepresentation(const ImageSkiaRep& image) { |
image_reps_.push_back(image); |
} |
+bool ImageSkiaStorage::HasRepresentationAtAllScales() const { |
+ return source_ && source_->HasRepresentationAtAllScales(); |
+} |
+ |
std::vector<ImageSkiaRep>::iterator ImageSkiaStorage::FindRepresentation( |
float scale, |
bool fetch_new_image) const { |
@@ -379,6 +392,14 @@ bool ImageSkia::HasRepresentation(float scale) const { |
return false; |
CHECK(CanRead()); |
+ // This check is not only faster than FindRepresentation(), it's important for |
+ // getting the right answer in cases of image types that are not based on |
+ // discrete preset underlying representations, which otherwise might report |
+ // "false" for this if GetRepresentation() has not yet been called for this |
+ // |scale|. |
+ if (storage_->HasRepresentationAtAllScales()) |
+ return true; |
+ |
ImageSkiaReps::iterator it = storage_->FindRepresentation(scale, false); |
return (it != storage_->image_reps().end() && it->scale() == scale); |
} |