| OLD | NEW |
| 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 Loading... |
| 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 ScopedCanvas scoped(canvas); |
| 92 |
| 91 // Painting at physical device pixels (undo device scale factor). | 93 // Painting at physical device pixels (undo device scale factor). |
| 92 float scale = canvas->SaveAndUnscale(); | 94 const float scale = canvas->UnscaleTheDeviceScaleFactor(); |
| 93 | 95 |
| 94 // Since the drawing from the following Fill() calls assumes the mapped origin | 96 // 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. | 97 // is at (0,0), we need to translate the canvas to the mapped origin. |
| 96 const int left_in_pixels = ToRoundedInt(bounds.x() * scale); | 98 const int left_in_pixels = ToRoundedInt(bounds.x() * scale); |
| 97 const int top_in_pixels = ToRoundedInt(bounds.y() * scale); | 99 const int top_in_pixels = ToRoundedInt(bounds.y() * scale); |
| 98 const int right_in_pixels = ToRoundedInt(bounds.right() * scale); | 100 const int right_in_pixels = ToRoundedInt(bounds.right() * scale); |
| 99 const int bottom_in_pixels = ToRoundedInt(bounds.bottom() * scale); | 101 const int bottom_in_pixels = ToRoundedInt(bounds.bottom() * scale); |
| 100 | 102 |
| 101 const int width_in_pixels = right_in_pixels - left_in_pixels; | 103 const int width_in_pixels = right_in_pixels - left_in_pixels; |
| 102 const int height_in_pixels = bottom_in_pixels - top_in_pixels; | 104 const int height_in_pixels = bottom_in_pixels - top_in_pixels; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 Fill(canvas, image_reps[3], 0, i0h, i3w, height_in_pixels - i0h - i6h, | 158 Fill(canvas, image_reps[3], 0, i0h, i3w, height_in_pixels - i0h - i6h, |
| 157 paint); | 159 paint); |
| 158 Fill(canvas, image_reps[5], width_in_pixels - i5w, i2h, i5w, | 160 Fill(canvas, image_reps[5], width_in_pixels - i5w, i2h, i5w, |
| 159 height_in_pixels - i2h - i8h, paint); | 161 height_in_pixels - i2h - i8h, paint); |
| 160 Fill(canvas, image_reps[6], 0, height_in_pixels - i6h, i6w, i6h, paint); | 162 Fill(canvas, image_reps[6], 0, height_in_pixels - i6h, i6w, i6h, paint); |
| 161 Fill(canvas, image_reps[7], i6w, height_in_pixels - i7h, | 163 Fill(canvas, image_reps[7], i6w, height_in_pixels - i7h, |
| 162 width_in_pixels - i6w - i8w, i7h, paint); | 164 width_in_pixels - i6w - i8w, i7h, paint); |
| 163 Fill(canvas, image_reps[8], width_in_pixels - i8w, height_in_pixels - i8h, | 165 Fill(canvas, image_reps[8], width_in_pixels - i8w, height_in_pixels - i8h, |
| 164 i8w, i8h, paint); | 166 i8w, i8h, paint); |
| 165 } | 167 } |
| 166 | |
| 167 canvas->Restore(); | |
| 168 } | 168 } |
| 169 | 169 |
| 170 // static | 170 // static |
| 171 void NineImagePainter::GetSubsetRegions(const ImageSkia& image, | 171 void NineImagePainter::GetSubsetRegions(const ImageSkia& image, |
| 172 const Insets& insets, | 172 const Insets& insets, |
| 173 std::vector<Rect>* regions) { | 173 std::vector<Rect>* regions) { |
| 174 DCHECK_GE(image.width(), insets.width()); | 174 DCHECK_GE(image.width(), insets.width()); |
| 175 DCHECK_GE(image.height(), insets.height()); | 175 DCHECK_GE(image.height(), insets.height()); |
| 176 | 176 |
| 177 std::vector<Rect> result(9); | 177 std::vector<Rect> result(9); |
| 178 | 178 |
| 179 const int x[] = { | 179 const int x[] = { |
| 180 0, insets.left(), image.width() - insets.right(), image.width()}; | 180 0, insets.left(), image.width() - insets.right(), image.width()}; |
| 181 const int y[] = { | 181 const int y[] = { |
| 182 0, insets.top(), image.height() - insets.bottom(), image.height()}; | 182 0, insets.top(), image.height() - insets.bottom(), image.height()}; |
| 183 | 183 |
| 184 for (size_t j = 0; j < 3; ++j) { | 184 for (size_t j = 0; j < 3; ++j) { |
| 185 for (size_t i = 0; i < 3; ++i) { | 185 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]); | 186 result[i + j * 3] = Rect(x[i], y[j], x[i + 1] - x[i], y[j + 1] - y[j]); |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 result.swap(*regions); | 189 result.swap(*regions); |
| 190 } | 190 } |
| 191 | 191 |
| 192 } // namespace gfx | 192 } // namespace gfx |
| OLD | NEW |