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

Unified Diff: ui/gfx/nine_image_painter.cc

Issue 605893002: Revert of Changes NineImagePainter to snap to (enclosed) pixel boundaries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/canvas.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/nine_image_painter.cc
diff --git a/ui/gfx/nine_image_painter.cc b/ui/gfx/nine_image_painter.cc
index 0377846582dc2c333938cee3d482256aff9d7a02..24a3e3b3627f422f9ea4ce67346edeb7d64b0380 100644
--- a/ui/gfx/nine_image_painter.cc
+++ b/ui/gfx/nine_image_painter.cc
@@ -98,29 +98,20 @@
ScopedCanvas scoped_canvas(canvas);
canvas->Translate(bounds.OffsetFromOrigin());
+ SkPaint paint;
+ paint.setAlpha(alpha);
+
// Get the current transform from the canvas and apply it to the logical
// bounds passed in. This will give us the pixel bounds which can be used
// to draw the images at the correct locations.
// We should not scale the bounds by the canvas->image_scale() as that can be
// different from the real scale in the canvas transform.
- SkRect bounds_in_pixels;
- if (!canvas->sk_canvas()->getTotalMatrix().mapRect(&bounds_in_pixels,
- RectToSkRect(bounds)))
- return; // Invalid transform.
+ SkMatrix matrix = canvas->sk_canvas()->getTotalMatrix();
+ SkRect scaled_rect;
+ matrix.mapRect(&scaled_rect, RectToSkRect(bounds));
- // It's often the case that |bounds| corresponds to the bounds of a View, say
- // a button. We use enclosed rect, in pixels coordinates, to ensure the
- // complete image can be seen. Without this clipping on all sides can happen.
- const gfx::Rect enclosed_rect_in_pixels(
- ToEnclosedRect(SkRectToRectF(bounds_in_pixels)));
-
- SkMatrix matrix = canvas->sk_canvas()->getTotalMatrix();
- matrix.setTranslateX(SkIntToScalar(enclosed_rect_in_pixels.x()));
- matrix.setTranslateY(SkIntToScalar(enclosed_rect_in_pixels.y()));
- canvas->sk_canvas()->setMatrix(matrix);
-
- const int width_in_pixels = enclosed_rect_in_pixels.width();
- const int height_in_pixels = enclosed_rect_in_pixels.height();
+ int scaled_width = gfx::ToCeiledInt(SkScalarToFloat(scaled_rect.width()));
+ int scaled_height = gfx::ToCeiledInt(SkScalarToFloat(scaled_rect.height()));
// In case the corners and edges don't all have the same width/height, we draw
// the center first, and extend it out in all directions to the edges of the
@@ -134,7 +125,7 @@
int i8w = ImageWidthInPixels(images_[8], canvas);
int i4x = std::min(std::min(i0w, i3w), i6w);
- int i4w = width_in_pixels - i4x - std::min(std::min(i2w, i5w), i8w);
+ int i4w = scaled_width - i4x - std::min(std::min(i2w, i5w), i8w);
int i0h = ImageHeightInPixels(images_[0], canvas);
int i1h = ImageHeightInPixels(images_[1], canvas);
@@ -144,27 +135,23 @@
int i8h = ImageHeightInPixels(images_[8], canvas);
int i4y = std::min(std::min(i0h, i1h), i2h);
- int i4h = height_in_pixels - i4y - std::min(std::min(i6h, i7h), i8h);
-
- SkPaint paint;
- paint.setAlpha(alpha);
-
+ int i4h = scaled_height - i4y - std::min(std::min(i6h, i7h), i8h);
if (!images_[4].isNull())
Fill(canvas, images_[4], i4x, i4y, i4w, i4h, paint);
canvas->DrawImageIntInPixel(images_[0], 0, 0, i0w, i0h,
0, 0, i0w, i0h, false, paint);
- Fill(canvas, images_[1], i0w, 0, width_in_pixels - i0w - i2w, i1h, paint);
- canvas->DrawImageIntInPixel(images_[2], 0, 0, i2w, i2h, width_in_pixels - i2w,
+ Fill(canvas, images_[1], i0w, 0, scaled_width - i0w - i2w, i1h, paint);
+ canvas->DrawImageIntInPixel(images_[2], 0, 0, i2w, i2h, scaled_width - i2w,
0, i2w, i2h, false, paint);
- Fill(canvas, images_[3], 0, i0h, i3w, height_in_pixels - i0h - i6h, paint);
- Fill(canvas, images_[5], width_in_pixels - i5w, i2h, i5w,
- height_in_pixels - i2h - i8h, paint);
+ Fill(canvas, images_[3], 0, i0h, i3w, scaled_height - i0h - i6h, paint);
+ Fill(canvas, images_[5], scaled_width - i5w, i2h, i5w,
+ scaled_height - i2h - i8h, paint);
canvas->DrawImageIntInPixel(images_[6], 0, 0, i6w, i6h, 0,
- height_in_pixels - i6h, i6w, i6h, false, paint);
- Fill(canvas, images_[7], i6w, height_in_pixels - i7h,
- width_in_pixels - i6w - i8w, i7h, paint);
- canvas->DrawImageIntInPixel(images_[8], 0, 0, i8w, i8h, width_in_pixels - i8w,
- height_in_pixels - i8h, i8w, i8h, false, paint);
+ scaled_height - i6h, i6w, i6h, false, paint);
+ Fill(canvas, images_[7], i6w, scaled_height - i7h, scaled_width - i6w - i8w,
+ i7h, paint);
+ canvas->DrawImageIntInPixel(images_[8], 0, 0, i8w, i8h, scaled_width - i8w,
+ scaled_height - i8h, i8w, i8h, false, paint);
}
} // namespace gfx
« no previous file with comments | « ui/gfx/canvas.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698