Commit 70d0d490 authored by sky's avatar sky Committed by Commit bot

Revert of Changes NineImagePainter to snap to (enclosed) pixel boundaries...

Revert of Changes NineImagePainter to snap to (enclosed) pixel boundaries (patchset #2 id:20001 of https://codereview.chromium.org/604463003/)

Reason for revert:
I'm reverting this as there are two issues:
1. Translate isn't being set correctly.
2. Even with 1 fixed there are problems with scrollbars. I'll investigate after the revert.

Original issue's description:
> Changes NineImagePainter to snap to (enclosed) pixel boundaries
>
> Otherwise the sides may be clipped out.
>
> BUG=417493
> TEST=see bug
> R=ananta@chromium.org
>
> Committed: https://crrev.com/d1ab0241ee29c70bd08531d1f038964664b124b6
> Cr-Commit-Position: refs/heads/master@{#296608}

TBR=ananta@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=417493

Review URL: https://codereview.chromium.org/605893002

Cr-Commit-Position: refs/heads/master@{#296839}
parent 80428d2e
...@@ -13,9 +13,7 @@ ...@@ -13,9 +13,7 @@
#include "third_party/skia/include/effects/SkGradientShader.h" #include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/size_conversions.h" #include "ui/gfx/size_conversions.h"
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
...@@ -348,13 +346,14 @@ void Canvas::DrawImageInt(const ImageSkia& image, ...@@ -348,13 +346,14 @@ void Canvas::DrawImageInt(const ImageSkia& image,
const SkBitmap& bitmap = image_rep.sk_bitmap(); const SkBitmap& bitmap = image_rep.sk_bitmap();
float bitmap_scale = image_rep.scale(); float bitmap_scale = image_rep.scale();
ScopedCanvas scoper(this); canvas_->save();
canvas_->scale(SkFloatToScalar(1.0f / bitmap_scale), canvas_->scale(SkFloatToScalar(1.0f / bitmap_scale),
SkFloatToScalar(1.0f / bitmap_scale)); SkFloatToScalar(1.0f / bitmap_scale));
canvas_->drawBitmap(bitmap, canvas_->drawBitmap(bitmap,
SkFloatToScalar(x * bitmap_scale), SkFloatToScalar(x * bitmap_scale),
SkFloatToScalar(y * bitmap_scale), SkFloatToScalar(y * bitmap_scale),
&paint); &paint);
canvas_->restore();
} }
void Canvas::DrawImageInt(const ImageSkia& image, void Canvas::DrawImageInt(const ImageSkia& image,
...@@ -416,14 +415,13 @@ void Canvas::DrawImageIntInPixel(const ImageSkia& image, ...@@ -416,14 +415,13 @@ void Canvas::DrawImageIntInPixel(const ImageSkia& image,
// Ensure that the direction of the x and y scales is preserved. This is // Ensure that the direction of the x and y scales is preserved. This is
// important for RTL layouts. // important for RTL layouts.
matrix.setScaleX(matrix.getScaleX() > 0 ? 1.0f : -1.0f); matrix.getScaleX() > 0 ? matrix.setScaleX(1.0f) : matrix.setScaleX(-1.0f);
matrix.setScaleY(matrix.getScaleY() > 0 ? 1.0f : -1.0f); matrix.getScaleY() > 0 ? matrix.setScaleY(1.0f) : matrix.setScaleY(-1.0f);
// Floor so that we get consistent rounding. matrix.setTranslateX(SkScalarRoundToInt(matrix.getTranslateX()));
matrix.setTranslateX(SkScalarFloorToScalar(matrix.getTranslateX())); matrix.setTranslateY(SkScalarRoundToInt(matrix.getTranslateY()));
matrix.setTranslateY(SkScalarFloorToScalar(matrix.getTranslateY()));
ScopedCanvas scoper(this); Save();
canvas_->setMatrix(matrix); canvas_->setMatrix(matrix);
...@@ -440,6 +438,9 @@ void Canvas::DrawImageIntInPixel(const ImageSkia& image, ...@@ -440,6 +438,9 @@ void Canvas::DrawImageIntInPixel(const ImageSkia& image,
paint, paint,
image_scale_, image_scale_,
true); true);
// Restore the state of the canvas.
Restore();
} }
void Canvas::DrawImageInPath(const ImageSkia& image, void Canvas::DrawImageInPath(const ImageSkia& image,
......
...@@ -98,29 +98,20 @@ void NineImagePainter::Paint(Canvas* canvas, ...@@ -98,29 +98,20 @@ void NineImagePainter::Paint(Canvas* canvas,
ScopedCanvas scoped_canvas(canvas); ScopedCanvas scoped_canvas(canvas);
canvas->Translate(bounds.OffsetFromOrigin()); canvas->Translate(bounds.OffsetFromOrigin());
SkPaint paint;
paint.setAlpha(alpha);
// Get the current transform from the canvas and apply it to the logical // 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 // bounds passed in. This will give us the pixel bounds which can be used
// to draw the images at the correct locations. // to draw the images at the correct locations.
// We should not scale the bounds by the canvas->image_scale() as that can be // We should not scale the bounds by the canvas->image_scale() as that can be
// different from the real scale in the canvas transform. // 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.
// 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(); SkMatrix matrix = canvas->sk_canvas()->getTotalMatrix();
matrix.setTranslateX(SkIntToScalar(enclosed_rect_in_pixels.x())); SkRect scaled_rect;
matrix.setTranslateY(SkIntToScalar(enclosed_rect_in_pixels.y())); matrix.mapRect(&scaled_rect, RectToSkRect(bounds));
canvas->sk_canvas()->setMatrix(matrix);
const int width_in_pixels = enclosed_rect_in_pixels.width(); int scaled_width = gfx::ToCeiledInt(SkScalarToFloat(scaled_rect.width()));
const int height_in_pixels = enclosed_rect_in_pixels.height(); 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 // 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 // the center first, and extend it out in all directions to the edges of the
...@@ -134,7 +125,7 @@ void NineImagePainter::Paint(Canvas* canvas, ...@@ -134,7 +125,7 @@ void NineImagePainter::Paint(Canvas* canvas,
int i8w = ImageWidthInPixels(images_[8], canvas); int i8w = ImageWidthInPixels(images_[8], canvas);
int i4x = std::min(std::min(i0w, i3w), i6w); 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 i0h = ImageHeightInPixels(images_[0], canvas);
int i1h = ImageHeightInPixels(images_[1], canvas); int i1h = ImageHeightInPixels(images_[1], canvas);
...@@ -144,27 +135,23 @@ void NineImagePainter::Paint(Canvas* canvas, ...@@ -144,27 +135,23 @@ void NineImagePainter::Paint(Canvas* canvas,
int i8h = ImageHeightInPixels(images_[8], canvas); int i8h = ImageHeightInPixels(images_[8], canvas);
int i4y = std::min(std::min(i0h, i1h), i2h); int i4y = std::min(std::min(i0h, i1h), i2h);
int i4h = height_in_pixels - i4y - std::min(std::min(i6h, i7h), i8h); int i4h = scaled_height - i4y - std::min(std::min(i6h, i7h), i8h);
SkPaint paint;
paint.setAlpha(alpha);
if (!images_[4].isNull()) if (!images_[4].isNull())
Fill(canvas, images_[4], i4x, i4y, i4w, i4h, paint); Fill(canvas, images_[4], i4x, i4y, i4w, i4h, paint);
canvas->DrawImageIntInPixel(images_[0], 0, 0, i0w, i0h, canvas->DrawImageIntInPixel(images_[0], 0, 0, i0w, i0h,
0, 0, i0w, i0h, false, paint); 0, 0, i0w, i0h, false, paint);
Fill(canvas, images_[1], i0w, 0, width_in_pixels - i0w - i2w, i1h, paint); Fill(canvas, images_[1], i0w, 0, scaled_width - i0w - i2w, i1h, paint);
canvas->DrawImageIntInPixel(images_[2], 0, 0, i2w, i2h, width_in_pixels - i2w, canvas->DrawImageIntInPixel(images_[2], 0, 0, i2w, i2h, scaled_width - i2w,
0, i2w, i2h, false, paint); 0, i2w, i2h, false, paint);
Fill(canvas, images_[3], 0, i0h, i3w, height_in_pixels - i0h - i6h, paint); Fill(canvas, images_[3], 0, i0h, i3w, scaled_height - i0h - i6h, paint);
Fill(canvas, images_[5], width_in_pixels - i5w, i2h, i5w, Fill(canvas, images_[5], scaled_width - i5w, i2h, i5w,
height_in_pixels - i2h - i8h, paint); scaled_height - i2h - i8h, paint);
canvas->DrawImageIntInPixel(images_[6], 0, 0, i6w, i6h, 0, canvas->DrawImageIntInPixel(images_[6], 0, 0, i6w, i6h, 0,
height_in_pixels - i6h, i6w, i6h, false, paint); scaled_height - i6h, i6w, i6h, false, paint);
Fill(canvas, images_[7], i6w, height_in_pixels - i7h, Fill(canvas, images_[7], i6w, scaled_height - i7h, scaled_width - i6w - i8w,
width_in_pixels - i6w - i8w, i7h, paint); i7h, paint);
canvas->DrawImageIntInPixel(images_[8], 0, 0, i8w, i8h, width_in_pixels - i8w, canvas->DrawImageIntInPixel(images_[8], 0, 0, i8w, i8h, scaled_width - i8w,
height_in_pixels - i8h, i8w, i8h, false, paint); scaled_height - i8h, i8w, i8h, false, paint);
} }
} // namespace gfx } // namespace gfx
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment