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

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

Issue 277773002: Add ImageSkiaRep::unscaled that tells if the image is for unscaled image. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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/base/resource/resource_bundle_unittest.cc ('k') | ui/gfx/image/image_skia_rep.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 a283117db2415488f3259cb3986fa956c0031a47..3e2873c7c1ebe0117e17c9b7204bfa2714fec115 100644
--- a/ui/gfx/image/image_skia.cc
+++ b/ui/gfx/image/image_skia.cc
@@ -102,6 +102,24 @@ class ImageSkiaStorage : public base::RefCountedThreadSafe<ImageSkiaStorage>,
return (read_only_ && !source_.get()) || CalledOnValidThread();
}
+ // Add a new representation. This checks if the scale of the added image
+ // is not 1.0f, and mark the existing rep as scaled to make
+ // the image high DPI aware.
+ void AddRepresentation(const ImageSkiaRep& image) {
+ if (image.scale() != 1.0f) {
+ for (ImageSkia::ImageSkiaReps::iterator it = image_reps_.begin();
+ it < image_reps_.end();
+ ++it) {
+ if (it->unscaled()) {
+ DCHECK_EQ(1.0f, it->scale());
+ it->SetScaled();
+ break;
+ }
+ }
+ }
+ image_reps_.push_back(image);
+ }
+
// 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
@@ -240,7 +258,7 @@ float ImageSkia::GetMaxSupportedScale() {
// static
ImageSkia ImageSkia::CreateFrom1xBitmap(const SkBitmap& bitmap) {
- return ImageSkia(ImageSkiaRep(bitmap, 1.0f));
+ return ImageSkia(ImageSkiaRep(bitmap, 0.0f));
}
scoped_ptr<ImageSkia> ImageSkia::DeepCopy() const {
@@ -278,7 +296,9 @@ void ImageSkia::AddRepresentation(const ImageSkiaRep& image_rep) {
Init(image_rep);
} else {
CHECK(CanModify());
- storage_->image_reps().push_back(image_rep);
+ // If someone is adding ImageSkia explicitly, check if we should
+ // make the image high DPI aware.
+ storage_->AddRepresentation(image_rep);
}
}
« no previous file with comments | « ui/base/resource/resource_bundle_unittest.cc ('k') | ui/gfx/image/image_skia_rep.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698