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

Unified Diff: ui/gfx/canvas.cc

Issue 604463003: Changes NineImagePainter to snap to (enclosed) pixel boundaries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment 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 | « no previous file | ui/gfx/nine_image_painter.cc » ('j') | ui/gfx/nine_image_painter.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/canvas.cc
diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc
index 6ea067eb696ca04b86a44bf4ce2473a22a810bd5..7ce7c4725ecb39041d534c57fdb26ea3abca8f4b 100644
--- a/ui/gfx/canvas.cc
+++ b/ui/gfx/canvas.cc
@@ -13,7 +13,9 @@
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rect_conversions.h"
+#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/rect.h"
+#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/size_conversions.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/transform.h"
@@ -346,14 +348,13 @@ void Canvas::DrawImageInt(const ImageSkia& image,
const SkBitmap& bitmap = image_rep.sk_bitmap();
float bitmap_scale = image_rep.scale();
- canvas_->save();
+ ScopedCanvas scoper(this);
canvas_->scale(SkFloatToScalar(1.0f / bitmap_scale),
SkFloatToScalar(1.0f / bitmap_scale));
canvas_->drawBitmap(bitmap,
SkFloatToScalar(x * bitmap_scale),
SkFloatToScalar(y * bitmap_scale),
&paint);
- canvas_->restore();
}
void Canvas::DrawImageInt(const ImageSkia& image,
@@ -415,13 +416,14 @@ void Canvas::DrawImageIntInPixel(const ImageSkia& image,
// Ensure that the direction of the x and y scales is preserved. This is
// important for RTL layouts.
- matrix.getScaleX() > 0 ? matrix.setScaleX(1.0f) : matrix.setScaleX(-1.0f);
- matrix.getScaleY() > 0 ? matrix.setScaleY(1.0f) : matrix.setScaleY(-1.0f);
+ matrix.setScaleX(matrix.getScaleX() > 0 ? 1.0f : -1.0f);
+ matrix.setScaleY(matrix.getScaleY() > 0 ? 1.0f : -1.0f);
- matrix.setTranslateX(SkScalarRoundToInt(matrix.getTranslateX()));
- matrix.setTranslateY(SkScalarRoundToInt(matrix.getTranslateY()));
+ // Floor so that we get consistent rounding.
+ matrix.setTranslateX(SkScalarFloorToScalar(matrix.getTranslateX()));
+ matrix.setTranslateY(SkScalarFloorToScalar(matrix.getTranslateY()));
- Save();
+ ScopedCanvas scoper(this);
canvas_->setMatrix(matrix);
@@ -438,9 +440,6 @@ void Canvas::DrawImageIntInPixel(const ImageSkia& image,
paint,
image_scale_,
true);
-
- // Restore the state of the canvas.
- Restore();
}
void Canvas::DrawImageInPath(const ImageSkia& image,
« no previous file with comments | « no previous file | ui/gfx/nine_image_painter.cc » ('j') | ui/gfx/nine_image_painter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698