OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "Test.h" | 8 #include "Test.h" |
9 | 9 |
10 #include "SkDashPathEffect.h" | 10 #include "SkDashPathEffect.h" |
11 #include "SkWriteBuffer.h" | 11 #include "SkWriteBuffer.h" |
12 #include "SkStrokeRec.h" | 12 #include "SkStrokeRec.h" |
| 13 #include "SkCanvas.h" |
| 14 #include "SkSurface.h" |
13 | 15 |
14 // crbug.com/348821 was rooted in SkDashPathEffect refusing to flatten and unfla
tten itself when | 16 // crbug.com/348821 was rooted in SkDashPathEffect refusing to flatten and unfla
tten itself when |
15 // the effect is nonsense. Here we test that it fails when passed nonsense para
meters. | 17 // the effect is nonsense. Here we test that it fails when passed nonsense para
meters. |
16 | 18 |
17 DEF_TEST(DashPathEffectTest_crbug_348821, r) { | 19 DEF_TEST(DashPathEffectTest_crbug_348821, r) { |
18 SkScalar intervals[] = { 1.76934361e+36f, 2.80259693e-45f }; // Values from
bug. | 20 SkScalar intervals[] = { 1.76934361e+36f, 2.80259693e-45f }; // Values from
bug. |
19 const int count = 2; | 21 const int count = 2; |
20 SkScalar phase = SK_ScalarInfinity; // Used to force a nonsense effect. | 22 SkScalar phase = SK_ScalarInfinity; // Used to force a nonsense effect. |
21 sk_sp<SkPathEffect> dash(SkDashPathEffect::Make(intervals, count, phase)); | 23 sk_sp<SkPathEffect> dash(SkDashPathEffect::Make(intervals, count, phase)); |
22 | 24 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 SkScalar intervals[2] = { 1, 1 }; | 94 SkScalar intervals[2] = { 1, 1 }; |
93 sk_sp<SkPathEffect> dash(SkDashPathEffect::Make(intervals, 2, 0)); | 95 sk_sp<SkPathEffect> dash(SkDashPathEffect::Make(intervals, 2, 0)); |
94 | 96 |
95 SkPaint paint; | 97 SkPaint paint; |
96 paint.setStyle(SkPaint::kStroke_Style); | 98 paint.setStyle(SkPaint::kStroke_Style); |
97 paint.setPathEffect(dash); | 99 paint.setPathEffect(dash); |
98 | 100 |
99 SkPath fill; | 101 SkPath fill; |
100 paint.getFillPath(path, &fill); | 102 paint.getFillPath(path, &fill); |
101 } | 103 } |
| 104 |
| 105 // Verify that long lines with many dashes don't cause overflows/OOMs. |
| 106 DEF_TEST(DashPathEffectTest_asPoints_limit, r) { |
| 107 sk_sp<SkSurface> surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(25
6, 256))); |
| 108 SkCanvas* canvas = surface->getCanvas(); |
| 109 |
| 110 SkPaint p; |
| 111 p.setStyle(SkPaint::kStroke_Style); |
| 112 // force the bounds to outset by a large amount |
| 113 p.setStrokeWidth(5.0e10f); |
| 114 const SkScalar intervals[] = { 1, 1 }; |
| 115 p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals),
0)); |
| 116 canvas->drawLine(1, 1, 1, 5.0e10f, p); |
| 117 } |
OLD | NEW |