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 | 13 |
14 // crbug.com/348821 was rooted in SkDashPathEffect refusing to flatten and unfla
tten itself when | 14 // crbug.com/348821 was rooted in SkDashPathEffect refusing to flatten and unfla
tten itself when |
15 // fInitialDashLength < 0 (a signal the effect is nonsense). Here we test that
it flattens. | 15 // fInitialDashLength < 0 (a signal the effect is nonsense). Here we test that
it flattens. |
16 | 16 |
17 DEF_TEST(DashPathEffectTest_crbug_348821, r) { | 17 DEF_TEST(DashPathEffectTest_crbug_348821, r) { |
18 SkScalar intervals[] = { 1.76934361e+36f, 2.80259693e-45f }; // Values from
bug. | 18 SkScalar intervals[] = { 1.76934361e+36f, 2.80259693e-45f }; // Values from
bug. |
19 const int count = 2; | 19 const int count = 2; |
20 SkScalar phase = SK_ScalarInfinity; // Used to force the bad fInitialDashLe
ngth = -1 path. | 20 SkScalar phase = SK_ScalarInfinity; // Used to force the bad fInitialDashLe
ngth = -1 path. |
21 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, coun
t, phase)); | 21 SkAutoTUnref<SkPathEffect> dash(SkDashPathEffect::Create(intervals, count, p
hase)); |
22 | 22 |
23 // nullptr -> refuses to work with flattening framework. | 23 // nullptr -> refuses to work with flattening framework. |
24 REPORTER_ASSERT(r, dash->getFactory() != nullptr); | 24 REPORTER_ASSERT(r, dash->getFactory() != nullptr); |
25 | 25 |
26 SkWriteBuffer buffer; | 26 SkWriteBuffer buffer; |
27 buffer.writeFlattenable(dash); | 27 buffer.writeFlattenable(dash); |
28 REPORTER_ASSERT(r, buffer.bytesWritten() > 12); // We'd write 12 if broken,
>=40 if not. | 28 REPORTER_ASSERT(r, buffer.bytesWritten() > 12); // We'd write 12 if broken,
>=40 if not. |
29 } | 29 } |
30 | 30 |
31 // Test out the asPoint culling behavior. | 31 // Test out the asPoint culling behavior. |
32 DEF_TEST(DashPathEffectTest_asPoints, r) { | 32 DEF_TEST(DashPathEffectTest_asPoints, r) { |
33 | 33 |
34 const SkScalar intervals[] = { 1.0f, 1.0f }; | 34 const SkScalar intervals[] = { 1.0f, 1.0f }; |
35 const int count = 2; | 35 const int count = 2; |
36 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, coun
t, 0.0f)); | 36 SkAutoTUnref<SkPathEffect> dash(SkDashPathEffect::Create(intervals, count, 0
.0f)); |
37 | 37 |
38 SkRect cull = SkRect::MakeWH(1.0f, 1.0f); | 38 SkRect cull = SkRect::MakeWH(1.0f, 1.0f); |
39 | 39 |
40 const struct { | 40 const struct { |
41 SkPoint fPts[2]; | 41 SkPoint fPts[2]; |
42 bool fExpectedResult; | 42 bool fExpectedResult; |
43 } testCases[] = { | 43 } testCases[] = { |
44 { { { -5.0f, 0.5f }, { -4.0f, 0.5f } }, false }, // off to the left | 44 { { { -5.0f, 0.5f }, { -4.0f, 0.5f } }, false }, // off to the left |
45 { { { 4.0f, 0.5f }, { 5.0f, 0.5f } }, false }, // off to the right | 45 { { { 4.0f, 0.5f }, { 5.0f, 0.5f } }, false }, // off to the right |
46 { { { 0.5f, 4.0f }, { 0.5f, 5.0f } }, false }, // off the bottom | 46 { { { 0.5f, 4.0f }, { 0.5f, 5.0f } }, false }, // off the bottom |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 if (i < 2) { | 80 if (i < 2) { |
81 REPORTER_ASSERT(r, actualResult == testCases[j].fExpectedRes
ult); | 81 REPORTER_ASSERT(r, actualResult == testCases[j].fExpectedRes
ult); |
82 } else { | 82 } else { |
83 // On the third pass all the lines should be outside the tra
nslated cull rect | 83 // On the third pass all the lines should be outside the tra
nslated cull rect |
84 REPORTER_ASSERT(r, !actualResult); | 84 REPORTER_ASSERT(r, !actualResult); |
85 } | 85 } |
86 } | 86 } |
87 } | 87 } |
88 } | 88 } |
89 } | 89 } |
OLD | NEW |