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

Unified Diff: ui/views/controls/image_view.cc

Issue 73893007: Makes ImageView do a bit more checking before assuming images equal (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 7 years, 1 month 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/views/controls/image_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/image_view.cc
diff --git a/ui/views/controls/image_view.cc b/ui/views/controls/image_view.cc
index fc44a84cfbffba6eb0b8b640e2208315ab25b649..bc2ad8e0d442074488cb4bd88d4eead911d0b0f6 100644
--- a/ui/views/controls/image_view.cc
+++ b/ui/views/controls/image_view.cc
@@ -17,16 +17,19 @@ ImageView::ImageView()
: image_size_set_(false),
horiz_alignment_(CENTER),
vert_alignment_(CENTER),
- interactive_(true) {
+ interactive_(true),
+ last_paint_scale_(0.f),
+ last_painted_bitmap_pixels_(NULL) {
}
ImageView::~ImageView() {
}
void ImageView::SetImage(const gfx::ImageSkia& img) {
- if (image_.BackedBySameObjectAs(img))
+ if (IsImageEqual(img))
return;
+ last_painted_bitmap_pixels_ = NULL;
gfx::Size pref_size(GetPreferredSize());
image_ = img;
if (pref_size != GetPreferredSize())
@@ -82,6 +85,18 @@ gfx::Size ImageView::GetPreferredSize() {
image_.height() + insets.height());
}
+bool ImageView::IsImageEqual(const gfx::ImageSkia& img) const {
+ // Even though we copy ImageSkia in SetImage() the backing store
+ // (ImageSkiaStorage) is not copied and may have changed since the last call
+ // to SetImage(). The expectation is that SetImage() with different pixels is
+ // treated as though the image changed. For this reason we compare not only
+ // the backing store but also the pixels of the last image we painted.
+ return image_.BackedBySameObjectAs(img) &&
+ last_paint_scale_ != 0.0f &&
+ last_painted_bitmap_pixels_ ==
+ img.GetRepresentation(last_paint_scale_).sk_bitmap().getPixels();
+}
+
gfx::Point ImageView::ComputeImageOrigin(const gfx::Size& image_size) const {
gfx::Insets insets = GetInsets();
@@ -114,6 +129,9 @@ gfx::Point ImageView::ComputeImageOrigin(const gfx::Size& image_size) const {
void ImageView::OnPaint(gfx::Canvas* canvas) {
View::OnPaint(canvas);
+ last_paint_scale_ = canvas->image_scale();
+ last_painted_bitmap_pixels_ = NULL;
+
if (image_.isNull())
return;
@@ -131,6 +149,8 @@ void ImageView::OnPaint(gfx::Canvas* canvas) {
} else {
canvas->DrawImageInt(image_, image_bounds.x(), image_bounds.y());
}
+ last_painted_bitmap_pixels_ =
+ image_.GetRepresentation(last_paint_scale_).sk_bitmap().getPixels();
}
void ImageView::GetAccessibleState(ui::AccessibleViewState* state) {
« no previous file with comments | « ui/views/controls/image_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698