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..c86cf2875884c411881ee3707b7da0361202fe88 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_image_(NULL) { |
} |
ImageView::~ImageView() { |
} |
void ImageView::SetImage(const gfx::ImageSkia& img) { |
- if (image_.BackedBySameObjectAs(img)) |
+ if (IsImageEqual(img)) |
pkotwicz
2013/11/15 20:57:09
Can you please add a comment (in the code) as to w
sky
2013/11/15 22:19:13
I placed the comment in IsImageEqual.
|
return; |
+ last_painted_image_ = NULL; |
gfx::Size pref_size(GetPreferredSize()); |
image_ = img; |
if (pref_size != GetPreferredSize()) |
@@ -82,6 +85,13 @@ gfx::Size ImageView::GetPreferredSize() { |
image_.height() + insets.height()); |
} |
+bool ImageView::IsImageEqual(const gfx::ImageSkia& img) const { |
+ return image_.BackedBySameObjectAs(img) && |
+ last_paint_scale_ != 0.0f && |
+ last_painted_image_ == |
+ img.GetRepresentation(last_paint_scale_).sk_bitmap().getPixels(); |
+} |
+ |
gfx::Point ImageView::ComputeImageOrigin(const gfx::Size& image_size) const { |
gfx::Insets insets = GetInsets(); |
@@ -114,6 +124,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_image_ = NULL; |
+ |
if (image_.isNull()) |
return; |
@@ -131,6 +144,8 @@ void ImageView::OnPaint(gfx::Canvas* canvas) { |
} else { |
canvas->DrawImageInt(image_, image_bounds.x(), image_bounds.y()); |
} |
+ last_painted_image_ = |
+ image_.GetRepresentation(last_paint_scale_).sk_bitmap().getPixels(); |
} |
void ImageView::GetAccessibleState(ui::AccessibleViewState* state) { |