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

Side by Side Diff: ui/gfx/nine_image_painter.cc

Issue 1425163002: gfx: Rename canvas SaveAndUnscale to UnscaleTheDeviceScaleFactor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ninepatchscale
Patch Set: scopedunscale: . Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « ui/gfx/canvas.cc ('k') | ui/gfx/scoped_canvas.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/nine_image_painter.h" 5 #include "ui/gfx/nine_image_painter.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "third_party/skia/include/core/SkPaint.h" 9 #include "third_party/skia/include/core/SkPaint.h"
10 #include "third_party/skia/include/core/SkRect.h" 10 #include "third_party/skia/include/core/SkRect.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // When no alpha value is specified, use default value of 100% opacity. 81 // When no alpha value is specified, use default value of 100% opacity.
82 Paint(canvas, bounds, std::numeric_limits<uint8>::max()); 82 Paint(canvas, bounds, std::numeric_limits<uint8>::max());
83 } 83 }
84 84
85 void NineImagePainter::Paint(Canvas* canvas, 85 void NineImagePainter::Paint(Canvas* canvas,
86 const Rect& bounds, 86 const Rect& bounds,
87 const uint8 alpha) { 87 const uint8 alpha) {
88 if (IsEmpty()) 88 if (IsEmpty())
89 return; 89 return;
90 90
91 // Painting at physical device pixels (undo device scale factor). 91 ScopedCanvas scoped_canvas(canvas);
92 float scale = canvas->SaveAndUnscale(); 92
93 // Painting and doing layout at physical device pixels to avoid cracks or
94 // overlap.
95 const float scale = canvas->UndoDeviceScaleFactor();
93 96
94 // Since the drawing from the following Fill() calls assumes the mapped origin 97 // Since the drawing from the following Fill() calls assumes the mapped origin
95 // is at (0,0), we need to translate the canvas to the mapped origin. 98 // is at (0,0), we need to translate the canvas to the mapped origin.
96 const int left_in_pixels = ToRoundedInt(bounds.x() * scale); 99 const int left_in_pixels = ToRoundedInt(bounds.x() * scale);
97 const int top_in_pixels = ToRoundedInt(bounds.y() * scale); 100 const int top_in_pixels = ToRoundedInt(bounds.y() * scale);
98 const int right_in_pixels = ToRoundedInt(bounds.right() * scale); 101 const int right_in_pixels = ToRoundedInt(bounds.right() * scale);
99 const int bottom_in_pixels = ToRoundedInt(bounds.bottom() * scale); 102 const int bottom_in_pixels = ToRoundedInt(bounds.bottom() * scale);
100 103
101 const int width_in_pixels = right_in_pixels - left_in_pixels; 104 const int width_in_pixels = right_in_pixels - left_in_pixels;
102 const int height_in_pixels = bottom_in_pixels - top_in_pixels; 105 const int height_in_pixels = bottom_in_pixels - top_in_pixels;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 Fill(canvas, image_reps[3], 0, i0h, i3w, height_in_pixels - i0h - i6h, 159 Fill(canvas, image_reps[3], 0, i0h, i3w, height_in_pixels - i0h - i6h,
157 paint); 160 paint);
158 Fill(canvas, image_reps[5], width_in_pixels - i5w, i2h, i5w, 161 Fill(canvas, image_reps[5], width_in_pixels - i5w, i2h, i5w,
159 height_in_pixels - i2h - i8h, paint); 162 height_in_pixels - i2h - i8h, paint);
160 Fill(canvas, image_reps[6], 0, height_in_pixels - i6h, i6w, i6h, paint); 163 Fill(canvas, image_reps[6], 0, height_in_pixels - i6h, i6w, i6h, paint);
161 Fill(canvas, image_reps[7], i6w, height_in_pixels - i7h, 164 Fill(canvas, image_reps[7], i6w, height_in_pixels - i7h,
162 width_in_pixels - i6w - i8w, i7h, paint); 165 width_in_pixels - i6w - i8w, i7h, paint);
163 Fill(canvas, image_reps[8], width_in_pixels - i8w, height_in_pixels - i8h, 166 Fill(canvas, image_reps[8], width_in_pixels - i8w, height_in_pixels - i8h,
164 i8w, i8h, paint); 167 i8w, i8h, paint);
165 } 168 }
166
167 canvas->Restore();
168 } 169 }
169 170
170 // static 171 // static
171 void NineImagePainter::GetSubsetRegions(const ImageSkia& image, 172 void NineImagePainter::GetSubsetRegions(const ImageSkia& image,
172 const Insets& insets, 173 const Insets& insets,
173 std::vector<Rect>* regions) { 174 std::vector<Rect>* regions) {
174 DCHECK_GE(image.width(), insets.width()); 175 DCHECK_GE(image.width(), insets.width());
175 DCHECK_GE(image.height(), insets.height()); 176 DCHECK_GE(image.height(), insets.height());
176 177
177 std::vector<Rect> result(9); 178 std::vector<Rect> result(9);
178 179
179 const int x[] = { 180 const int x[] = {
180 0, insets.left(), image.width() - insets.right(), image.width()}; 181 0, insets.left(), image.width() - insets.right(), image.width()};
181 const int y[] = { 182 const int y[] = {
182 0, insets.top(), image.height() - insets.bottom(), image.height()}; 183 0, insets.top(), image.height() - insets.bottom(), image.height()};
183 184
184 for (size_t j = 0; j < 3; ++j) { 185 for (size_t j = 0; j < 3; ++j) {
185 for (size_t i = 0; i < 3; ++i) { 186 for (size_t i = 0; i < 3; ++i) {
186 result[i + j * 3] = Rect(x[i], y[j], x[i + 1] - x[i], y[j + 1] - y[j]); 187 result[i + j * 3] = Rect(x[i], y[j], x[i + 1] - x[i], y[j + 1] - y[j]);
187 } 188 }
188 } 189 }
189 result.swap(*regions); 190 result.swap(*regions);
190 } 191 }
191 192
192 } // namespace gfx 193 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas.cc ('k') | ui/gfx/scoped_canvas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698