summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authordanakj <danakj@chromium.org>2015-10-30 12:25:16 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-30 19:26:44 +0000
commitda76437a9d701587d08a93bbc4f37dd796f21124 (patch)
tree0d1fab5784eef99d99ae3ad917fcf18dfbf9382a /ui
parent591eec3d9a017ce11b7f07ad7805ac294cdee2e2 (diff)
downloadchromium_src-da76437a9d701587d08a93bbc4f37dd796f21124.zip
chromium_src-da76437a9d701587d08a93bbc4f37dd796f21124.tar.gz
chromium_src-da76437a9d701587d08a93bbc4f37dd796f21124.tar.bz2
gfx: Rename canvas SaveAndUnscale to UnscaleTheDeviceScaleFactor.
This changes the method to only do the unscaling. Callers use a ScopedCanvas instead. Then they don't need to call Restore() themselves. R=pkasting, sky Review URL: https://codereview.chromium.org/1425163002 Cr-Commit-Position: refs/heads/master@{#357172}
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/canvas.cc11
-rw-r--r--ui/gfx/canvas.h10
-rw-r--r--ui/gfx/nine_image_painter.cc9
-rw-r--r--ui/gfx/scoped_canvas.h6
4 files changed, 15 insertions, 21 deletions
diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc
index 2465cfae..b81f995 100644
--- a/ui/gfx/canvas.cc
+++ b/ui/gfx/canvas.cc
@@ -175,17 +175,16 @@ void Canvas::DrawDashedRect(const Rect& rect, SkColor color) {
paint);
}
-void Canvas::Save() {
- canvas_->save();
-}
-
-float Canvas::SaveAndUnscale() {
- Save();
+float Canvas::UndoDeviceScaleFactor() {
SkScalar scale_factor = 1.0f / image_scale_;
canvas_->scale(scale_factor, scale_factor);
return image_scale_;
}
+void Canvas::Save() {
+ canvas_->save();
+}
+
void Canvas::SaveLayerAlpha(uint8 alpha) {
canvas_->saveLayerAlpha(NULL, alpha);
}
diff --git a/ui/gfx/canvas.h b/ui/gfx/canvas.h
index 8183dfa..fd6e3c7 100644
--- a/ui/gfx/canvas.h
+++ b/ui/gfx/canvas.h
@@ -165,15 +165,15 @@ class GFX_EXPORT Canvas {
// Draws a dashed rectangle of the specified color.
void DrawDashedRect(const Rect& rect, SkColor color);
+ // Unscales by the image scale factor (aka device scale factor), and returns
+ // that factor. This is useful when callers want to draw directly in the
+ // native scale.
+ float UndoDeviceScaleFactor();
+
// Saves a copy of the drawing state onto a stack, operating on this copy
// until a balanced call to Restore() is made.
void Save();
- // Saves the drawing state, unscales by the image scale factor, and returns
- // that factor. This is useful when callers want to draw directly in the
- // native scale.
- float SaveAndUnscale();
-
// As with Save(), except draws to a layer that is blended with the canvas
// at the specified alpha once Restore() is called.
// |layer_bounds| are the bounds of the layer relative to the current
diff --git a/ui/gfx/nine_image_painter.cc b/ui/gfx/nine_image_painter.cc
index 040678d..49be5ee 100644
--- a/ui/gfx/nine_image_painter.cc
+++ b/ui/gfx/nine_image_painter.cc
@@ -88,8 +88,11 @@ void NineImagePainter::Paint(Canvas* canvas,
if (IsEmpty())
return;
- // Painting at physical device pixels (undo device scale factor).
- float scale = canvas->SaveAndUnscale();
+ ScopedCanvas scoped_canvas(canvas);
+
+ // Painting and doing layout at physical device pixels to avoid cracks or
+ // overlap.
+ const float scale = canvas->UndoDeviceScaleFactor();
// Since the drawing from the following Fill() calls assumes the mapped origin
// is at (0,0), we need to translate the canvas to the mapped origin.
@@ -163,8 +166,6 @@ void NineImagePainter::Paint(Canvas* canvas,
Fill(canvas, image_reps[8], width_in_pixels - i8w, height_in_pixels - i8h,
i8w, i8h, paint);
}
-
- canvas->Restore();
}
// static
diff --git a/ui/gfx/scoped_canvas.h b/ui/gfx/scoped_canvas.h
index 2e59a07..7701f7c 100644
--- a/ui/gfx/scoped_canvas.h
+++ b/ui/gfx/scoped_canvas.h
@@ -20,12 +20,6 @@ class ScopedCanvas {
if (canvas_)
canvas_->Restore();
}
- void SetCanvas(gfx::Canvas* canvas) {
- if (canvas_)
- canvas_->Restore();
- canvas_ = canvas;
- canvas_->Save();
- }
private:
gfx::Canvas* canvas_;