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

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

Issue 1846513002: Make HasRepresentation() work better for vector images. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@deinline_imageskiastorage
Patch Set: Add DCHECK Created 4 years, 9 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 | « ui/gfx/gfx.gyp ('k') | ui/gfx/image/image_skia_source.h » ('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 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);
}
« no previous file with comments | « ui/gfx/gfx.gyp ('k') | ui/gfx/image/image_skia_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698