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 "SkColorShader.h" | 9 #include "SkColorShader.h" |
10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 const SkScalar pos[] = { 0, 1 }; | 205 const SkScalar pos[] = { 0, 1 }; |
206 SkAutoTUnref<SkShader> gradient( | 206 SkAutoTUnref<SkShader> gradient( |
207 SkGradientShader::CreateLinear(pts, colors, pos, 2, SkShader::kClamp_Til
eMode)); | 207 SkGradientShader::CreateLinear(pts, colors, pos, 2, SkShader::kClamp_Til
eMode)); |
208 | 208 |
209 SkPaint paint; | 209 SkPaint paint; |
210 paint.setShader(gradient); | 210 paint.setShader(gradient); |
211 | 211 |
212 surface->getCanvas()->drawPaint(paint); | 212 surface->getCanvas()->drawPaint(paint); |
213 } | 213 } |
214 | 214 |
| 215 // A linear gradient interval can, due to numerical imprecision (likely in the d
ivide) |
| 216 // finish an interval with the final fx not landing outside of [p0...p1]. |
| 217 // The old code had an assert which this test triggered. |
| 218 // We now explicitly clamp the resulting fx value. |
| 219 static void test_linear_fuzz(skiatest::Reporter* reporter) { |
| 220 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1300, 630)); |
| 221 |
| 222 const SkPoint pts[] = {{ 179.5f, -179.5f }, { 1074.5f, 715.5f }}; |
| 223 const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_C
olorWHITE }; |
| 224 const SkScalar pos[] = {0, 0.200000003f, 0.800000012f, 1 }; |
| 225 |
| 226 |
| 227 SkAutoTUnref<SkShader> gradient( |
| 228 SkGradientShader::CreateLinear(pts, colors, pos, 4, SkShader:
:kClamp_TileMode)); |
| 229 |
| 230 SkPaint paint; |
| 231 paint.setShader(gradient); |
| 232 SkRect r = {0, 83, 1254, 620}; |
| 233 surface->getCanvas()->drawRect(r, paint); |
| 234 } |
| 235 |
215 DEF_TEST(Gradient, reporter) { | 236 DEF_TEST(Gradient, reporter) { |
216 TestGradientShaders(reporter); | 237 TestGradientShaders(reporter); |
217 TestConstantGradient(reporter); | 238 TestConstantGradient(reporter); |
218 test_big_grad(reporter); | 239 test_big_grad(reporter); |
219 test_nearly_vertical(reporter); | 240 test_nearly_vertical(reporter); |
| 241 test_linear_fuzz(reporter); |
220 } | 242 } |
OLD | NEW |