| 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" |
| 11 #include "third_party/skia/include/core/SkScalar.h" | 11 #include "third_party/skia/include/core/SkScalar.h" |
| 12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/geometry/rect_conversions.h" | 13 #include "ui/gfx/geometry/rect_conversions.h" |
| 14 #include "ui/gfx/geometry/safe_integer_conversions.h" | 14 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 15 #include "ui/gfx/image/image_skia_operations.h" | 15 #include "ui/gfx/image/image_skia_operations.h" |
| 16 #include "ui/gfx/insets.h" | 16 #include "ui/gfx/insets.h" |
| 17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 18 #include "ui/gfx/scoped_canvas.h" | 18 #include "ui/gfx/scoped_canvas.h" |
| 19 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
| 20 | 20 |
| 21 namespace gfx { | 21 namespace gfx { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // The following functions width and height of the image in pixels for the | 25 // The following functions width and height of the image in pixels for the |
| 26 // scale factor in the Canvas. | 26 // scale factor in the Canvas. |
| 27 int ImageWidthInPixels(const ImageSkia& i, Canvas* c) { | 27 int ImageWidthInPixels(const ImageSkia& i, Canvas* c) { |
| 28 if (i.isNull()) |
| 29 return 0; |
| 28 return i.GetRepresentation(c->image_scale()).pixel_width(); | 30 return i.GetRepresentation(c->image_scale()).pixel_width(); |
| 29 } | 31 } |
| 30 | 32 |
| 31 int ImageHeightInPixels(const ImageSkia& i, Canvas* c) { | 33 int ImageHeightInPixels(const ImageSkia& i, Canvas* c) { |
| 34 if (i.isNull()) |
| 35 return 0; |
| 32 return i.GetRepresentation(c->image_scale()).pixel_height(); | 36 return i.GetRepresentation(c->image_scale()).pixel_height(); |
| 33 } | 37 } |
| 34 | 38 |
| 35 // Stretches the given image over the specified canvas area. | 39 // Stretches the given image over the specified canvas area. |
| 36 void Fill(Canvas* c, | 40 void Fill(Canvas* c, |
| 37 const ImageSkia& i, | 41 const ImageSkia& i, |
| 38 int x, | 42 int x, |
| 39 int y, | 43 int y, |
| 40 int w, | 44 int w, |
| 41 int h, | 45 int h, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 int i6h = ImageHeightInPixels(images_[6], canvas); | 143 int i6h = ImageHeightInPixels(images_[6], canvas); |
| 140 int i7h = ImageHeightInPixels(images_[7], canvas); | 144 int i7h = ImageHeightInPixels(images_[7], canvas); |
| 141 int i8h = ImageHeightInPixels(images_[8], canvas); | 145 int i8h = ImageHeightInPixels(images_[8], canvas); |
| 142 | 146 |
| 143 int i4y = std::min(std::min(i0h, i1h), i2h); | 147 int i4y = std::min(std::min(i0h, i1h), i2h); |
| 144 int i4h = height_in_pixels - i4y - std::min(std::min(i6h, i7h), i8h); | 148 int i4h = height_in_pixels - i4y - std::min(std::min(i6h, i7h), i8h); |
| 145 | 149 |
| 146 SkPaint paint; | 150 SkPaint paint; |
| 147 paint.setAlpha(alpha); | 151 paint.setAlpha(alpha); |
| 148 | 152 |
| 153 canvas->DrawImageIntInPixel(images_[0], 0, 0, i0w, i0h, |
| 154 0, 0, i0w, i0h, false, paint); |
| 155 |
| 156 if (!images_[1].isNull()) |
| 157 Fill(canvas, images_[1], i0w, 0, width_in_pixels - i0w - i2w, i1h, paint); |
| 158 |
| 159 if (!images_[2].isNull()) { |
| 160 canvas->DrawImageIntInPixel( |
| 161 images_[2], 0, 0, i2w, i2h, width_in_pixels - i2w, |
| 162 0, i2w, i2h, false, paint); |
| 163 } |
| 164 |
| 149 if (!images_[4].isNull()) | 165 if (!images_[4].isNull()) |
| 150 Fill(canvas, images_[4], i4x, i4y, i4w, i4h, paint); | 166 Fill(canvas, images_[4], i4x, i4y, i4w, i4h, paint); |
| 151 canvas->DrawImageIntInPixel(images_[0], 0, 0, i0w, i0h, | 167 |
| 152 0, 0, i0w, i0h, false, paint); | 168 if (!images_[3].isNull()) |
| 153 Fill(canvas, images_[1], i0w, 0, width_in_pixels - i0w - i2w, i1h, paint); | 169 Fill(canvas, images_[3], 0, i0h, i3w, height_in_pixels - i0h - i6h, paint); |
| 154 canvas->DrawImageIntInPixel(images_[2], 0, 0, i2w, i2h, width_in_pixels - i2w, | 170 |
| 155 0, i2w, i2h, false, paint); | 171 if (!images_[5].isNull()) { |
| 156 Fill(canvas, images_[3], 0, i0h, i3w, height_in_pixels - i0h - i6h, paint); | 172 Fill(canvas, images_[5], width_in_pixels - i5w, i2h, i5w, |
| 157 Fill(canvas, images_[5], width_in_pixels - i5w, i2h, i5w, | 173 height_in_pixels - i2h - i8h, paint); |
| 158 height_in_pixels - i2h - i8h, paint); | 174 } |
| 159 canvas->DrawImageIntInPixel(images_[6], 0, 0, i6w, i6h, 0, | 175 |
| 160 height_in_pixels - i6h, i6w, i6h, false, paint); | 176 if (!images_[6].isNull()) { |
| 161 Fill(canvas, images_[7], i6w, height_in_pixels - i7h, | 177 canvas->DrawImageIntInPixel(images_[6], 0, 0, i6w, i6h, 0, |
| 162 width_in_pixels - i6w - i8w, i7h, paint); | 178 height_in_pixels - i6h, i6w, i6h, false, paint); |
| 163 canvas->DrawImageIntInPixel(images_[8], 0, 0, i8w, i8h, width_in_pixels - i8w, | 179 } |
| 164 height_in_pixels - i8h, i8w, i8h, false, paint); | 180 |
| 181 if (!images_[7].isNull()) { |
| 182 Fill(canvas, images_[7], i6w, height_in_pixels - i7h, |
| 183 width_in_pixels - i6w - i8w, i7h, paint); |
| 184 } |
| 185 |
| 186 if (!images_[8].isNull()) { |
| 187 canvas->DrawImageIntInPixel( |
| 188 images_[8], 0, 0, i8w, i8h, width_in_pixels - i8w, |
| 189 height_in_pixels - i8h, i8w, i8h, false, paint); |
| 190 } |
| 165 } | 191 } |
| 166 | 192 |
| 167 } // namespace gfx | 193 } // namespace gfx |
| OLD | NEW |