OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkColorPriv.h" |
9 #include "SkColorShader.h" | 10 #include "SkColorShader.h" |
10 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
11 #include "SkShader.h" | 12 #include "SkShader.h" |
12 #include "SkSurface.h" | 13 #include "SkSurface.h" |
13 #include "SkTemplates.h" | 14 #include "SkTemplates.h" |
14 #include "Test.h" | 15 #include "Test.h" |
15 | 16 |
16 // https://code.google.com/p/chromium/issues/detail?id=448299 | 17 // https://code.google.com/p/chromium/issues/detail?id=448299 |
17 // Giant (inverse) matrix causes overflow when converting/computing using 32.32 | 18 // Giant (inverse) matrix causes overflow when converting/computing using 32.32 |
18 // Before the fix, we would assert (and then crash). | 19 // Before the fix, we would assert (and then crash). |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 227 |
227 SkAutoTUnref<SkShader> gradient( | 228 SkAutoTUnref<SkShader> gradient( |
228 SkGradientShader::CreateLinear(pts, colors, pos, 4, SkShader:
:kClamp_TileMode)); | 229 SkGradientShader::CreateLinear(pts, colors, pos, 4, SkShader:
:kClamp_TileMode)); |
229 | 230 |
230 SkPaint paint; | 231 SkPaint paint; |
231 paint.setShader(gradient); | 232 paint.setShader(gradient); |
232 SkRect r = {0, 83, 1254, 620}; | 233 SkRect r = {0, 83, 1254, 620}; |
233 surface->getCanvas()->drawRect(r, paint); | 234 surface->getCanvas()->drawRect(r, paint); |
234 } | 235 } |
235 | 236 |
| 237 // https://bugs.chromium.org/p/skia/issues/detail?id=5023 |
| 238 // We should still shade pixels for which the radius is exactly 0. |
| 239 static void test_two_point_conical_zero_radius(skiatest::Reporter* reporter) { |
| 240 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(5, 5)); |
| 241 surface->getCanvas()->clear(SK_ColorRED); |
| 242 |
| 243 const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE }; |
| 244 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical( |
| 245 SkPoint::Make(2.5f, 2.5f), 0, |
| 246 SkPoint::Make(3.0f, 3.0f), 10, |
| 247 colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); |
| 248 SkPaint p; |
| 249 p.setShader(shader); |
| 250 surface->getCanvas()->drawPaint(p); |
| 251 |
| 252 // r == 0 for the center pixel. |
| 253 // verify that we draw it (no red bleed) |
| 254 SkPMColor centerPMColor; |
| 255 surface->readPixels(SkImageInfo::MakeN32Premul(1, 1), ¢erPMColor, sizeof
(SkPMColor), 2, 2); |
| 256 REPORTER_ASSERT(reporter, SkGetPackedR32(centerPMColor) == 0); |
| 257 } |
| 258 |
236 DEF_TEST(Gradient, reporter) { | 259 DEF_TEST(Gradient, reporter) { |
237 TestGradientShaders(reporter); | 260 TestGradientShaders(reporter); |
238 TestConstantGradient(reporter); | 261 TestConstantGradient(reporter); |
239 test_big_grad(reporter); | 262 test_big_grad(reporter); |
240 test_nearly_vertical(reporter); | 263 test_nearly_vertical(reporter); |
241 test_linear_fuzz(reporter); | 264 test_linear_fuzz(reporter); |
| 265 test_two_point_conical_zero_radius(reporter); |
242 } | 266 } |
OLD | NEW |