bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkCanvas.h" |
| 9 | #include "include/core/SkPath.h" |
| 10 | #include "include/core/SkSurface.h" |
| 11 | #include "include/effects/SkDashPathEffect.h" |
| 12 | #include "include/pathops/SkPathOps.h" |
| 13 | #include "src/core/SkClipOpPriv.h" |
| 14 | #include "src/core/SkRectPriv.h" |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 15 | #include "src/gpu/geometry/GrStyledShape.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "tests/Test.h" |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 17 | |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 18 | #include <initializer_list> |
| 19 | #include <functional> |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 20 | #include <utility> |
| 21 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 22 | uint32_t GrStyledShape::testingOnly_getOriginalGenerationID() const { |
Brian Salomon | da6d072 | 2018-01-03 13:54:35 -0500 | [diff] [blame] | 23 | if (const auto* lp = this->originalPathForListeners()) { |
| 24 | return lp->getGenerationID(); |
| 25 | } |
| 26 | return SkPath().getGenerationID(); |
Brian Osman | f6f7cf6 | 2017-09-25 16:49:55 -0400 | [diff] [blame] | 27 | } |
| 28 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 29 | bool GrStyledShape::testingOnly_isPath() const { |
Michael Ludwig | f38b711 | 2020-04-30 13:47:00 -0400 | [diff] [blame] | 30 | return fShape.isPath(); |
Brian Osman | b379dcd | 2017-10-04 15:44:05 -0400 | [diff] [blame] | 31 | } |
| 32 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 33 | bool GrStyledShape::testingOnly_isNonVolatilePath() const { |
Michael Ludwig | f38b711 | 2020-04-30 13:47:00 -0400 | [diff] [blame] | 34 | return fShape.isPath() && !fShape.path().isVolatile(); |
Brian Salomon | da6d072 | 2018-01-03 13:54:35 -0500 | [diff] [blame] | 35 | } |
| 36 | |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 37 | using Key = SkTArray<uint32_t>; |
| 38 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 39 | static bool make_key(Key* key, const GrStyledShape& shape) { |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 40 | int size = shape.unstyledKeySize(); |
| 41 | if (size <= 0) { |
| 42 | key->reset(0); |
| 43 | return false; |
| 44 | } |
| 45 | SkASSERT(size); |
| 46 | key->reset(size); |
| 47 | shape.writeUnstyledKey(key->begin()); |
| 48 | return true; |
| 49 | } |
| 50 | |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 51 | static bool paths_fill_same(const SkPath& a, const SkPath& b) { |
| 52 | SkPath pathXor; |
| 53 | Op(a, b, SkPathOp::kXOR_SkPathOp, &pathXor); |
| 54 | return pathXor.isEmpty(); |
| 55 | } |
| 56 | |
bsalomon | 9fb4203 | 2016-05-13 09:23:38 -0700 | [diff] [blame] | 57 | static bool test_bounds_by_rasterizing(const SkPath& path, const SkRect& bounds) { |
bsalomon | 164fd9f | 2016-08-26 06:45:06 -0700 | [diff] [blame] | 58 | // We test the bounds by rasterizing the path into a kRes by kRes grid. The bounds is |
| 59 | // mapped to the range kRes/4 to 3*kRes/4 in x and y. A difference clip is used to avoid |
| 60 | // rendering within the bounds (with a tolerance). Then we render the path and check that |
| 61 | // everything got clipped out. |
bsalomon | 9fb4203 | 2016-05-13 09:23:38 -0700 | [diff] [blame] | 62 | static constexpr int kRes = 2000; |
| 63 | // This tolerance is in units of 1/kRes fractions of the bounds width/height. |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 64 | static constexpr int kTol = 2; |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 65 | static_assert(kRes % 4 == 0); |
bsalomon | 9fb4203 | 2016-05-13 09:23:38 -0700 | [diff] [blame] | 66 | SkImageInfo info = SkImageInfo::MakeA8(kRes, kRes); |
| 67 | sk_sp<SkSurface> surface = SkSurface::MakeRaster(info); |
| 68 | surface->getCanvas()->clear(0x0); |
| 69 | SkRect clip = SkRect::MakeXYWH(kRes/4, kRes/4, kRes/2, kRes/2); |
| 70 | SkMatrix matrix; |
| 71 | matrix.setRectToRect(bounds, clip, SkMatrix::kFill_ScaleToFit); |
| 72 | clip.outset(SkIntToScalar(kTol), SkIntToScalar(kTol)); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 73 | surface->getCanvas()->clipRect(clip, kDifference_SkClipOp); |
bsalomon | 9fb4203 | 2016-05-13 09:23:38 -0700 | [diff] [blame] | 74 | surface->getCanvas()->concat(matrix); |
| 75 | SkPaint whitePaint; |
| 76 | whitePaint.setColor(SK_ColorWHITE); |
| 77 | surface->getCanvas()->drawPath(path, whitePaint); |
| 78 | SkPixmap pixmap; |
| 79 | surface->getCanvas()->peekPixels(&pixmap); |
| 80 | #if defined(SK_BUILD_FOR_WIN) |
| 81 | // The static constexpr version in #else causes cl.exe to crash. |
| 82 | const uint8_t* kZeros = reinterpret_cast<uint8_t*>(calloc(kRes, 1)); |
| 83 | #else |
| 84 | static constexpr uint8_t kZeros[kRes] = {0}; |
| 85 | #endif |
bsalomon | 164fd9f | 2016-08-26 06:45:06 -0700 | [diff] [blame] | 86 | for (int y = 0; y < kRes; ++y) { |
bsalomon | 9fb4203 | 2016-05-13 09:23:38 -0700 | [diff] [blame] | 87 | const uint8_t* row = pixmap.addr8(0, y); |
| 88 | if (0 != memcmp(kZeros, row, kRes)) { |
| 89 | return false; |
| 90 | } |
| 91 | } |
| 92 | #ifdef SK_BUILD_FOR_WIN |
| 93 | free(const_cast<uint8_t*>(kZeros)); |
| 94 | #endif |
| 95 | return true; |
| 96 | } |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 97 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 98 | static bool can_interchange_winding_and_even_odd_fill(const GrStyledShape& shape) { |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 99 | SkPath path; |
| 100 | shape.asPath(&path); |
| 101 | if (shape.style().hasNonDashPathEffect()) { |
| 102 | return false; |
| 103 | } |
| 104 | const SkStrokeRec::Style strokeRecStyle = shape.style().strokeRec().getStyle(); |
| 105 | return strokeRecStyle == SkStrokeRec::kStroke_Style || |
| 106 | strokeRecStyle == SkStrokeRec::kHairline_Style || |
| 107 | (shape.style().isSimpleFill() && path.isConvex()); |
| 108 | } |
| 109 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 110 | static void check_equivalence(skiatest::Reporter* r, const GrStyledShape& a, const GrStyledShape& b, |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 111 | const Key& keyA, const Key& keyB) { |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 112 | // GrStyledShape only respects the input winding direction and start point for rrect shapes |
| 113 | // when there is a path effect. Thus, if there are two GrStyledShapes representing the same |
| 114 | // rrect but one has a path effect in its style and the other doesn't then asPath() and the |
| 115 | // unstyled key will differ. GrStyledShape will have canonicalized the direction and start point |
| 116 | // for the shape without the path effect. If *both* have path effects then they should have both |
| 117 | // preserved the direction and starting point. |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 118 | |
| 119 | // The asRRect() output params are all initialized just to silence compiler warnings about |
| 120 | // uninitialized variables. |
| 121 | SkRRect rrectA = SkRRect::MakeEmpty(), rrectB = SkRRect::MakeEmpty(); |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 122 | SkPathDirection dirA = SkPathDirection::kCW, dirB = SkPathDirection::kCW; |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 123 | unsigned startA = ~0U, startB = ~0U; |
| 124 | bool invertedA = true, invertedB = true; |
| 125 | |
| 126 | bool aIsRRect = a.asRRect(&rrectA, &dirA, &startA, &invertedA); |
| 127 | bool bIsRRect = b.asRRect(&rrectB, &dirB, &startB, &invertedB); |
| 128 | bool aHasPE = a.style().hasPathEffect(); |
| 129 | bool bHasPE = b.style().hasPathEffect(); |
| 130 | bool allowSameRRectButDiffStartAndDir = (aIsRRect && bIsRRect) && (aHasPE != bHasPE); |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 131 | // GrStyledShape will close paths with simple fill style. |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 132 | bool allowedClosednessDiff = (a.style().isSimpleFill() != b.style().isSimpleFill()); |
| 133 | SkPath pathA, pathB; |
| 134 | a.asPath(&pathA); |
| 135 | b.asPath(&pathB); |
| 136 | |
| 137 | // Having a dash path effect can allow 'a' but not 'b' to turn a inverse fill type into a |
| 138 | // non-inverse fill type (or vice versa). |
| 139 | bool ignoreInversenessDifference = false; |
| 140 | if (pathA.isInverseFillType() != pathB.isInverseFillType()) { |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 141 | const GrStyledShape* s1 = pathA.isInverseFillType() ? &a : &b; |
| 142 | const GrStyledShape* s2 = pathA.isInverseFillType() ? &b : &a; |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 143 | bool canDropInverse1 = s1->style().isDashed(); |
| 144 | bool canDropInverse2 = s2->style().isDashed(); |
| 145 | ignoreInversenessDifference = (canDropInverse1 != canDropInverse2); |
| 146 | } |
| 147 | bool ignoreWindingVsEvenOdd = false; |
Mike Reed | cf0e3c6 | 2019-12-03 16:26:15 -0500 | [diff] [blame] | 148 | if (SkPathFillType_ConvertToNonInverse(pathA.getFillType()) != |
| 149 | SkPathFillType_ConvertToNonInverse(pathB.getFillType())) { |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 150 | bool aCanChange = can_interchange_winding_and_even_odd_fill(a); |
| 151 | bool bCanChange = can_interchange_winding_and_even_odd_fill(b); |
| 152 | if (aCanChange != bCanChange) { |
| 153 | ignoreWindingVsEvenOdd = true; |
| 154 | } |
| 155 | } |
| 156 | if (allowSameRRectButDiffStartAndDir) { |
| 157 | REPORTER_ASSERT(r, rrectA == rrectB); |
| 158 | REPORTER_ASSERT(r, paths_fill_same(pathA, pathB)); |
| 159 | REPORTER_ASSERT(r, ignoreInversenessDifference || invertedA == invertedB); |
| 160 | } else { |
| 161 | SkPath pA = pathA; |
| 162 | SkPath pB = pathB; |
| 163 | REPORTER_ASSERT(r, a.inverseFilled() == pA.isInverseFillType()); |
| 164 | REPORTER_ASSERT(r, b.inverseFilled() == pB.isInverseFillType()); |
| 165 | if (ignoreInversenessDifference) { |
Mike Reed | cf0e3c6 | 2019-12-03 16:26:15 -0500 | [diff] [blame] | 166 | pA.setFillType(SkPathFillType_ConvertToNonInverse(pathA.getFillType())); |
| 167 | pB.setFillType(SkPathFillType_ConvertToNonInverse(pathB.getFillType())); |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 168 | } |
| 169 | if (ignoreWindingVsEvenOdd) { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 170 | pA.setFillType(pA.isInverseFillType() ? SkPathFillType::kInverseEvenOdd |
| 171 | : SkPathFillType::kEvenOdd); |
| 172 | pB.setFillType(pB.isInverseFillType() ? SkPathFillType::kInverseEvenOdd |
| 173 | : SkPathFillType::kEvenOdd); |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 174 | } |
| 175 | if (!ignoreInversenessDifference && !ignoreWindingVsEvenOdd) { |
| 176 | REPORTER_ASSERT(r, keyA == keyB); |
| 177 | } else { |
| 178 | REPORTER_ASSERT(r, keyA != keyB); |
| 179 | } |
| 180 | if (allowedClosednessDiff) { |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 181 | // GrStyledShape will close paths with simple fill style. Make the non-filled path |
| 182 | // closed so that the comparision will succeed. Make sure both are closed before |
| 183 | // comparing. |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 184 | pA.close(); |
| 185 | pB.close(); |
| 186 | } |
| 187 | REPORTER_ASSERT(r, pA == pB); |
| 188 | REPORTER_ASSERT(r, aIsRRect == bIsRRect); |
| 189 | if (aIsRRect) { |
| 190 | REPORTER_ASSERT(r, rrectA == rrectB); |
| 191 | REPORTER_ASSERT(r, dirA == dirB); |
| 192 | REPORTER_ASSERT(r, startA == startB); |
| 193 | REPORTER_ASSERT(r, ignoreInversenessDifference || invertedA == invertedB); |
| 194 | } |
| 195 | } |
| 196 | REPORTER_ASSERT(r, a.isEmpty() == b.isEmpty()); |
| 197 | REPORTER_ASSERT(r, allowedClosednessDiff || a.knownToBeClosed() == b.knownToBeClosed()); |
| 198 | // closedness can affect convexity. |
| 199 | REPORTER_ASSERT(r, allowedClosednessDiff || a.knownToBeConvex() == b.knownToBeConvex()); |
| 200 | if (a.knownToBeConvex()) { |
| 201 | REPORTER_ASSERT(r, pathA.isConvex()); |
| 202 | } |
| 203 | if (b.knownToBeConvex()) { |
| 204 | REPORTER_ASSERT(r, pathB.isConvex()); |
| 205 | } |
| 206 | REPORTER_ASSERT(r, a.bounds() == b.bounds()); |
| 207 | REPORTER_ASSERT(r, a.segmentMask() == b.segmentMask()); |
| 208 | // Init these to suppress warnings. |
| 209 | SkPoint pts[4] {{0, 0,}, {0, 0}, {0, 0}, {0, 0}} ; |
| 210 | bool invertedLine[2] {true, true}; |
| 211 | REPORTER_ASSERT(r, a.asLine(pts, &invertedLine[0]) == b.asLine(pts + 2, &invertedLine[1])); |
| 212 | // mayBeInverseFilledAfterStyling() is allowed to differ if one has a arbitrary PE and the other |
| 213 | // doesn't (since the PE can set any fill type on its output path). |
| 214 | // Moreover, dash style explicitly ignores inverseness. So if one is dashed but not the other |
| 215 | // then they may disagree about inverseness. |
| 216 | if (a.style().hasNonDashPathEffect() == b.style().hasNonDashPathEffect() && |
| 217 | a.style().isDashed() == b.style().isDashed()) { |
| 218 | REPORTER_ASSERT(r, a.mayBeInverseFilledAfterStyling() == |
| 219 | b.mayBeInverseFilledAfterStyling()); |
| 220 | } |
| 221 | if (a.asLine(nullptr, nullptr)) { |
| 222 | REPORTER_ASSERT(r, pts[2] == pts[0] && pts[3] == pts[1]); |
| 223 | REPORTER_ASSERT(r, ignoreInversenessDifference || invertedLine[0] == invertedLine[1]); |
| 224 | REPORTER_ASSERT(r, invertedLine[0] == a.inverseFilled()); |
| 225 | REPORTER_ASSERT(r, invertedLine[1] == b.inverseFilled()); |
| 226 | } |
| 227 | REPORTER_ASSERT(r, ignoreInversenessDifference || a.inverseFilled() == b.inverseFilled()); |
| 228 | } |
| 229 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 230 | static void check_original_path_ids(skiatest::Reporter* r, const GrStyledShape& base, |
| 231 | const GrStyledShape& pe, const GrStyledShape& peStroke, |
| 232 | const GrStyledShape& full) { |
Brian Salomon | da6d072 | 2018-01-03 13:54:35 -0500 | [diff] [blame] | 233 | bool baseIsNonVolatilePath = base.testingOnly_isNonVolatilePath(); |
Brian Osman | b379dcd | 2017-10-04 15:44:05 -0400 | [diff] [blame] | 234 | bool peIsPath = pe.testingOnly_isPath(); |
| 235 | bool peStrokeIsPath = peStroke.testingOnly_isPath(); |
| 236 | bool fullIsPath = full.testingOnly_isPath(); |
| 237 | |
| 238 | REPORTER_ASSERT(r, peStrokeIsPath == fullIsPath); |
| 239 | |
| 240 | uint32_t baseID = base.testingOnly_getOriginalGenerationID(); |
| 241 | uint32_t peID = pe.testingOnly_getOriginalGenerationID(); |
| 242 | uint32_t peStrokeID = peStroke.testingOnly_getOriginalGenerationID(); |
| 243 | uint32_t fullID = full.testingOnly_getOriginalGenerationID(); |
| 244 | |
| 245 | // All empty paths have the same gen ID |
| 246 | uint32_t emptyID = SkPath().getGenerationID(); |
| 247 | |
| 248 | // If we started with a real path, then our genID should match that path's gen ID (and not be |
Brian Salomon | da6d072 | 2018-01-03 13:54:35 -0500 | [diff] [blame] | 249 | // empty). If we started with a simple shape or a volatile path, our original path should have |
| 250 | // been reset. |
| 251 | REPORTER_ASSERT(r, baseIsNonVolatilePath == (baseID != emptyID)); |
Brian Osman | b379dcd | 2017-10-04 15:44:05 -0400 | [diff] [blame] | 252 | |
| 253 | // For the derived shapes, if they're simple types, their original paths should have been reset |
| 254 | REPORTER_ASSERT(r, peIsPath || (peID == emptyID)); |
| 255 | REPORTER_ASSERT(r, peStrokeIsPath || (peStrokeID == emptyID)); |
| 256 | REPORTER_ASSERT(r, fullIsPath || (fullID == emptyID)); |
| 257 | |
| 258 | if (!peIsPath) { |
| 259 | // If the path effect produces a simple shape, then there are no unbroken chains to test |
| 260 | return; |
| 261 | } |
| 262 | |
| 263 | // From here on, we know that the path effect produced a shape that was a "real" path |
| 264 | |
Brian Salomon | da6d072 | 2018-01-03 13:54:35 -0500 | [diff] [blame] | 265 | if (baseIsNonVolatilePath) { |
Brian Osman | b379dcd | 2017-10-04 15:44:05 -0400 | [diff] [blame] | 266 | REPORTER_ASSERT(r, baseID == peID); |
| 267 | } |
| 268 | |
| 269 | if (peStrokeIsPath) { |
| 270 | REPORTER_ASSERT(r, peID == peStrokeID); |
| 271 | REPORTER_ASSERT(r, peStrokeID == fullID); |
| 272 | } |
| 273 | |
Brian Salomon | da6d072 | 2018-01-03 13:54:35 -0500 | [diff] [blame] | 274 | if (baseIsNonVolatilePath && peStrokeIsPath) { |
Brian Osman | b379dcd | 2017-10-04 15:44:05 -0400 | [diff] [blame] | 275 | REPORTER_ASSERT(r, baseID == peStrokeID); |
| 276 | REPORTER_ASSERT(r, baseID == fullID); |
| 277 | } |
| 278 | } |
| 279 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 280 | void test_inversions(skiatest::Reporter* r, const GrStyledShape& shape, const Key& shapeKey) { |
| 281 | GrStyledShape preserve = GrStyledShape::MakeFilled( |
| 282 | shape, GrStyledShape::FillInversion::kPreserve); |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 283 | Key preserveKey; |
| 284 | make_key(&preserveKey, preserve); |
| 285 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 286 | GrStyledShape flip = GrStyledShape::MakeFilled(shape, GrStyledShape::FillInversion::kFlip); |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 287 | Key flipKey; |
| 288 | make_key(&flipKey, flip); |
| 289 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 290 | GrStyledShape inverted = GrStyledShape::MakeFilled( |
| 291 | shape, GrStyledShape::FillInversion::kForceInverted); |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 292 | Key invertedKey; |
| 293 | make_key(&invertedKey, inverted); |
| 294 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 295 | GrStyledShape noninverted = GrStyledShape::MakeFilled( |
| 296 | shape, GrStyledShape::FillInversion::kForceNoninverted); |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 297 | Key noninvertedKey; |
| 298 | make_key(&noninvertedKey, noninverted); |
| 299 | |
| 300 | if (invertedKey.count() || noninvertedKey.count()) { |
| 301 | REPORTER_ASSERT(r, invertedKey != noninvertedKey); |
| 302 | } |
| 303 | if (shape.style().isSimpleFill()) { |
| 304 | check_equivalence(r, shape, preserve, shapeKey, preserveKey); |
| 305 | } |
| 306 | if (shape.inverseFilled()) { |
| 307 | check_equivalence(r, preserve, inverted, preserveKey, invertedKey); |
| 308 | check_equivalence(r, flip, noninverted, flipKey, noninvertedKey); |
| 309 | } else { |
| 310 | check_equivalence(r, preserve, noninverted, preserveKey, noninvertedKey); |
| 311 | check_equivalence(r, flip, inverted, flipKey, invertedKey); |
| 312 | } |
| 313 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 314 | GrStyledShape doubleFlip = GrStyledShape::MakeFilled(flip, GrStyledShape::FillInversion::kFlip); |
Brian Salomon | 4f40caf | 2017-09-01 09:00:45 -0400 | [diff] [blame] | 315 | Key doubleFlipKey; |
| 316 | make_key(&doubleFlipKey, doubleFlip); |
| 317 | // It can be the case that the double flip has no key but preserve does. This happens when the |
| 318 | // original shape has an inherited style key. That gets dropped on the first inversion flip. |
| 319 | if (preserveKey.count() && !doubleFlipKey.count()) { |
| 320 | preserveKey.reset(); |
| 321 | } |
| 322 | check_equivalence(r, preserve, doubleFlip, preserveKey, doubleFlipKey); |
| 323 | } |
| 324 | |
bsalomon | 9fb4203 | 2016-05-13 09:23:38 -0700 | [diff] [blame] | 325 | namespace { |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 326 | /** |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 327 | * Geo is a factory for creating a GrStyledShape from another representation. It also answers some |
| 328 | * questions about expected behavior for GrStyledShape given the inputs. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 329 | */ |
| 330 | class Geo { |
| 331 | public: |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 332 | virtual ~Geo() {} |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 333 | virtual GrStyledShape makeShape(const SkPaint&) const = 0; |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 334 | virtual SkPath path() const = 0; |
| 335 | // These functions allow tests to check for special cases where style gets |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 336 | // applied by GrStyledShape in its constructor (without calling GrStyledShape::applyStyle). |
| 337 | // These unfortunately rely on knowing details of GrStyledShape's implementation. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 338 | // These predicates are factored out here to avoid littering the rest of the |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 339 | // test code with GrStyledShape implementation details. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 340 | virtual bool fillChangesGeom() const { return false; } |
| 341 | virtual bool strokeIsConvertedToFill() const { return false; } |
| 342 | virtual bool strokeAndFillIsConvertedToFill(const SkPaint&) const { return false; } |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 343 | // Is this something we expect GrStyledShape to recognize as something simpler than a path. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 344 | virtual bool isNonPath(const SkPaint& paint) const { return true; } |
| 345 | }; |
| 346 | |
| 347 | class RectGeo : public Geo { |
| 348 | public: |
| 349 | RectGeo(const SkRect& rect) : fRect(rect) {} |
| 350 | |
| 351 | SkPath path() const override { |
| 352 | SkPath path; |
| 353 | path.addRect(fRect); |
| 354 | return path; |
| 355 | } |
| 356 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 357 | GrStyledShape makeShape(const SkPaint& paint) const override { |
| 358 | return GrStyledShape(fRect, paint); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | bool strokeAndFillIsConvertedToFill(const SkPaint& paint) const override { |
| 362 | SkASSERT(paint.getStyle() == SkPaint::kStrokeAndFill_Style); |
Michael Ludwig | f38b711 | 2020-04-30 13:47:00 -0400 | [diff] [blame] | 363 | // Converted to an outset rectangle or round rect |
| 364 | return (paint.getStrokeJoin() == SkPaint::kMiter_Join && |
| 365 | paint.getStrokeMiter() >= SK_ScalarSqrt2) || |
| 366 | paint.getStrokeJoin() == SkPaint::kRound_Join; |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | private: |
| 370 | SkRect fRect; |
| 371 | }; |
| 372 | |
| 373 | class RRectGeo : public Geo { |
| 374 | public: |
| 375 | RRectGeo(const SkRRect& rrect) : fRRect(rrect) {} |
| 376 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 377 | GrStyledShape makeShape(const SkPaint& paint) const override { |
| 378 | return GrStyledShape(fRRect, paint); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | SkPath path() const override { |
| 382 | SkPath path; |
| 383 | path.addRRect(fRRect); |
| 384 | return path; |
| 385 | } |
| 386 | |
| 387 | bool strokeAndFillIsConvertedToFill(const SkPaint& paint) const override { |
| 388 | SkASSERT(paint.getStyle() == SkPaint::kStrokeAndFill_Style); |
| 389 | if (fRRect.isRect()) { |
| 390 | return RectGeo(fRRect.rect()).strokeAndFillIsConvertedToFill(paint); |
| 391 | } |
| 392 | return false; |
| 393 | } |
| 394 | |
| 395 | private: |
| 396 | SkRRect fRRect; |
| 397 | }; |
| 398 | |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 399 | class ArcGeo : public Geo { |
| 400 | public: |
| 401 | ArcGeo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter) |
| 402 | : fOval(oval) |
| 403 | , fStartAngle(startAngle) |
| 404 | , fSweepAngle(sweepAngle) |
| 405 | , fUseCenter(useCenter) {} |
| 406 | |
| 407 | SkPath path() const override { |
| 408 | SkPath path; |
| 409 | SkPathPriv::CreateDrawArcPath(&path, fOval, fStartAngle, fSweepAngle, fUseCenter, false); |
| 410 | return path; |
| 411 | } |
| 412 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 413 | GrStyledShape makeShape(const SkPaint& paint) const override { |
| 414 | return GrStyledShape::MakeArc(fOval, fStartAngle, fSweepAngle, fUseCenter, GrStyle(paint)); |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 415 | } |
| 416 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 417 | // GrStyledShape specializes when created from arc params but it doesn't recognize arcs from |
| 418 | // SkPath. |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 419 | bool isNonPath(const SkPaint& paint) const override { return false; } |
| 420 | |
| 421 | private: |
| 422 | SkRect fOval; |
| 423 | SkScalar fStartAngle; |
| 424 | SkScalar fSweepAngle; |
| 425 | bool fUseCenter; |
| 426 | }; |
| 427 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 428 | class PathGeo : public Geo { |
| 429 | public: |
| 430 | enum class Invert { kNo, kYes }; |
| 431 | |
| 432 | PathGeo(const SkPath& path, Invert invert) : fPath(path) { |
| 433 | SkASSERT(!path.isInverseFillType()); |
| 434 | if (Invert::kYes == invert) { |
Mike Reed | cf0e3c6 | 2019-12-03 16:26:15 -0500 | [diff] [blame] | 435 | if (fPath.getFillType() == SkPathFillType::kEvenOdd) { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 436 | fPath.setFillType(SkPathFillType::kInverseEvenOdd); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 437 | } else { |
Mike Reed | cf0e3c6 | 2019-12-03 16:26:15 -0500 | [diff] [blame] | 438 | SkASSERT(fPath.getFillType() == SkPathFillType::kWinding); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 439 | fPath.setFillType(SkPathFillType::kInverseWinding); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 444 | GrStyledShape makeShape(const SkPaint& paint) const override { |
| 445 | return GrStyledShape(fPath, paint); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | SkPath path() const override { return fPath; } |
| 449 | |
| 450 | bool fillChangesGeom() const override { |
| 451 | // unclosed rects get closed. Lines get turned into empty geometry |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 452 | return this->isUnclosedRect() || fPath.isLine(nullptr); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | bool strokeIsConvertedToFill() const override { |
| 456 | return this->isAxisAlignedLine(); |
| 457 | } |
| 458 | |
| 459 | bool strokeAndFillIsConvertedToFill(const SkPaint& paint) const override { |
| 460 | SkASSERT(paint.getStyle() == SkPaint::kStrokeAndFill_Style); |
| 461 | if (this->isAxisAlignedLine()) { |
| 462 | // The fill is ignored (zero area) and the stroke is converted to a rrect. |
| 463 | return true; |
| 464 | } |
| 465 | SkRect rect; |
| 466 | unsigned start; |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 467 | SkPathDirection dir; |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 468 | if (SkPathPriv::IsSimpleClosedRect(fPath, &rect, &dir, &start)) { |
| 469 | return RectGeo(rect).strokeAndFillIsConvertedToFill(paint); |
| 470 | } |
| 471 | return false; |
| 472 | } |
| 473 | |
| 474 | bool isNonPath(const SkPaint& paint) const override { |
| 475 | return fPath.isLine(nullptr) || fPath.isEmpty(); |
| 476 | } |
| 477 | |
| 478 | private: |
| 479 | bool isAxisAlignedLine() const { |
| 480 | SkPoint pts[2]; |
| 481 | if (!fPath.isLine(pts)) { |
| 482 | return false; |
| 483 | } |
| 484 | return pts[0].fX == pts[1].fX || pts[0].fY == pts[1].fY; |
| 485 | } |
| 486 | |
| 487 | bool isUnclosedRect() const { |
| 488 | bool closed; |
| 489 | return fPath.isRect(nullptr, &closed, nullptr) && !closed; |
| 490 | } |
| 491 | |
| 492 | SkPath fPath; |
| 493 | }; |
| 494 | |
| 495 | class RRectPathGeo : public PathGeo { |
| 496 | public: |
| 497 | enum class RRectForStroke { kNo, kYes }; |
| 498 | |
| 499 | RRectPathGeo(const SkPath& path, const SkRRect& equivalentRRect, RRectForStroke rrectForStroke, |
| 500 | Invert invert) |
| 501 | : PathGeo(path, invert) |
| 502 | , fRRect(equivalentRRect) |
| 503 | , fRRectForStroke(rrectForStroke) {} |
| 504 | |
| 505 | RRectPathGeo(const SkPath& path, const SkRect& equivalentRect, RRectForStroke rrectForStroke, |
| 506 | Invert invert) |
| 507 | : RRectPathGeo(path, SkRRect::MakeRect(equivalentRect), rrectForStroke, invert) {} |
| 508 | |
| 509 | bool isNonPath(const SkPaint& paint) const override { |
| 510 | if (SkPaint::kFill_Style == paint.getStyle() || RRectForStroke::kYes == fRRectForStroke) { |
| 511 | return true; |
| 512 | } |
| 513 | return false; |
| 514 | } |
| 515 | |
| 516 | const SkRRect& rrect() const { return fRRect; } |
| 517 | |
| 518 | private: |
| 519 | SkRRect fRRect; |
| 520 | RRectForStroke fRRectForStroke; |
| 521 | }; |
| 522 | |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 523 | class TestCase { |
| 524 | public: |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 525 | TestCase(const Geo& geo, const SkPaint& paint, skiatest::Reporter* r, |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 526 | SkScalar scale = SK_Scalar1) |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 527 | : fBase(new GrStyledShape(geo.makeShape(paint))) { |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 528 | this->init(r, scale); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 531 | template <typename... ShapeArgs> |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 532 | TestCase(skiatest::Reporter* r, ShapeArgs... shapeArgs) |
| 533 | : fBase(new GrStyledShape(shapeArgs...)) { |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 534 | this->init(r, SK_Scalar1); |
| 535 | } |
| 536 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 537 | TestCase(const GrStyledShape& shape, skiatest::Reporter* r, SkScalar scale = SK_Scalar1) |
| 538 | : fBase(new GrStyledShape(shape)) { |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 539 | this->init(r, scale); |
| 540 | } |
| 541 | |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 542 | struct SelfExpectations { |
| 543 | bool fPEHasEffect; |
| 544 | bool fPEHasValidKey; |
| 545 | bool fStrokeApplies; |
| 546 | }; |
| 547 | |
| 548 | void testExpectations(skiatest::Reporter* reporter, SelfExpectations expectations) const; |
| 549 | |
| 550 | enum ComparisonExpecation { |
| 551 | kAllDifferent_ComparisonExpecation, |
| 552 | kSameUpToPE_ComparisonExpecation, |
| 553 | kSameUpToStroke_ComparisonExpecation, |
| 554 | kAllSame_ComparisonExpecation, |
| 555 | }; |
| 556 | |
| 557 | void compare(skiatest::Reporter*, const TestCase& that, ComparisonExpecation) const; |
| 558 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 559 | const GrStyledShape& baseShape() const { return *fBase; } |
| 560 | const GrStyledShape& appliedPathEffectShape() const { return *fAppliedPE; } |
| 561 | const GrStyledShape& appliedFullStyleShape() const { return *fAppliedFull; } |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 562 | |
| 563 | // The returned array's count will be 0 if the key shape has no key. |
| 564 | const Key& baseKey() const { return fBaseKey; } |
| 565 | const Key& appliedPathEffectKey() const { return fAppliedPEKey; } |
| 566 | const Key& appliedFullStyleKey() const { return fAppliedFullKey; } |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 567 | const Key& appliedPathEffectThenStrokeKey() const { return fAppliedPEThenStrokeKey; } |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 568 | |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 569 | private: |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 570 | static void CheckBounds(skiatest::Reporter* r, const GrStyledShape& shape, |
| 571 | const SkRect& bounds) { |
bsalomon | 9fb4203 | 2016-05-13 09:23:38 -0700 | [diff] [blame] | 572 | SkPath path; |
| 573 | shape.asPath(&path); |
| 574 | // If the bounds are empty, the path ought to be as well. |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 575 | if (bounds.fLeft > bounds.fRight || bounds.fTop > bounds.fBottom) { |
bsalomon | 9fb4203 | 2016-05-13 09:23:38 -0700 | [diff] [blame] | 576 | REPORTER_ASSERT(r, path.isEmpty()); |
| 577 | return; |
| 578 | } |
| 579 | if (path.isEmpty()) { |
| 580 | return; |
| 581 | } |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 582 | // The bounds API explicitly calls out that it does not consider inverseness. |
| 583 | SkPath p = path; |
Mike Reed | cf0e3c6 | 2019-12-03 16:26:15 -0500 | [diff] [blame] | 584 | p.setFillType(SkPathFillType_ConvertToNonInverse(path.getFillType())); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 585 | REPORTER_ASSERT(r, test_bounds_by_rasterizing(p, bounds)); |
bsalomon | 9fb4203 | 2016-05-13 09:23:38 -0700 | [diff] [blame] | 586 | } |
| 587 | |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 588 | void init(skiatest::Reporter* r, SkScalar scale) { |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 589 | fAppliedPE.reset(new GrStyledShape); |
| 590 | fAppliedPEThenStroke.reset(new GrStyledShape); |
| 591 | fAppliedFull.reset(new GrStyledShape); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 592 | |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 593 | *fAppliedPE = fBase->applyStyle(GrStyle::Apply::kPathEffectOnly, scale); |
| 594 | *fAppliedPEThenStroke = |
| 595 | fAppliedPE->applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, scale); |
| 596 | *fAppliedFull = fBase->applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, scale); |
| 597 | |
| 598 | make_key(&fBaseKey, *fBase); |
| 599 | make_key(&fAppliedPEKey, *fAppliedPE); |
| 600 | make_key(&fAppliedPEThenStrokeKey, *fAppliedPEThenStroke); |
| 601 | make_key(&fAppliedFullKey, *fAppliedFull); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 602 | |
Brian Osman | f6f7cf6 | 2017-09-25 16:49:55 -0400 | [diff] [blame] | 603 | // All shapes should report the same "original" path, so that path renderers can get to it |
| 604 | // if necessary. |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 605 | check_original_path_ids(r, *fBase, *fAppliedPE, *fAppliedPEThenStroke, *fAppliedFull); |
Brian Osman | f6f7cf6 | 2017-09-25 16:49:55 -0400 | [diff] [blame] | 606 | |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 607 | // Applying the path effect and then the stroke should always be the same as applying |
| 608 | // both in one go. |
| 609 | REPORTER_ASSERT(r, fAppliedPEThenStrokeKey == fAppliedFullKey); |
| 610 | SkPath a, b; |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 611 | fAppliedPEThenStroke->asPath(&a); |
| 612 | fAppliedFull->asPath(&b); |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 613 | // If the output of the path effect is a rrect then it is possible for a and b to be |
| 614 | // different paths that fill identically. The reason is that fAppliedFull will do this: |
| 615 | // base -> apply path effect -> rrect_as_path -> stroke -> stroked_rrect_as_path |
| 616 | // fAppliedPEThenStroke will have converted the rrect_as_path back to a rrect. However, |
| 617 | // now that there is no longer a path effect, the direction and starting index get |
| 618 | // canonicalized before the stroke. |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 619 | if (fAppliedPE->asRRect(nullptr, nullptr, nullptr, nullptr)) { |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 620 | REPORTER_ASSERT(r, paths_fill_same(a, b)); |
| 621 | } else { |
| 622 | REPORTER_ASSERT(r, a == b); |
| 623 | } |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 624 | REPORTER_ASSERT(r, fAppliedFull->isEmpty() == fAppliedPEThenStroke->isEmpty()); |
bsalomon | 7c73a53 | 2016-05-11 15:15:56 -0700 | [diff] [blame] | 625 | |
| 626 | SkPath path; |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 627 | fBase->asPath(&path); |
| 628 | REPORTER_ASSERT(r, path.isEmpty() == fBase->isEmpty()); |
| 629 | REPORTER_ASSERT(r, path.getSegmentMasks() == fBase->segmentMask()); |
| 630 | fAppliedPE->asPath(&path); |
| 631 | REPORTER_ASSERT(r, path.isEmpty() == fAppliedPE->isEmpty()); |
| 632 | REPORTER_ASSERT(r, path.getSegmentMasks() == fAppliedPE->segmentMask()); |
| 633 | fAppliedFull->asPath(&path); |
| 634 | REPORTER_ASSERT(r, path.isEmpty() == fAppliedFull->isEmpty()); |
| 635 | REPORTER_ASSERT(r, path.getSegmentMasks() == fAppliedFull->segmentMask()); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 636 | |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 637 | CheckBounds(r, *fBase, fBase->bounds()); |
| 638 | CheckBounds(r, *fAppliedPE, fAppliedPE->bounds()); |
| 639 | CheckBounds(r, *fAppliedPEThenStroke, fAppliedPEThenStroke->bounds()); |
| 640 | CheckBounds(r, *fAppliedFull, fAppliedFull->bounds()); |
| 641 | SkRect styledBounds = fBase->styledBounds(); |
| 642 | CheckBounds(r, *fAppliedFull, styledBounds); |
| 643 | styledBounds = fAppliedPE->styledBounds(); |
| 644 | CheckBounds(r, *fAppliedFull, styledBounds); |
bsalomon | 9fb4203 | 2016-05-13 09:23:38 -0700 | [diff] [blame] | 645 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 646 | // Check that the same path is produced when style is applied by GrStyledShape and GrStyle. |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 647 | SkPath preStyle; |
| 648 | SkPath postPathEffect; |
| 649 | SkPath postAllStyle; |
| 650 | |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 651 | fBase->asPath(&preStyle); |
bsalomon | 1a0b9ed | 2016-05-06 11:07:03 -0700 | [diff] [blame] | 652 | SkStrokeRec postPEStrokeRec(SkStrokeRec::kFill_InitStyle); |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 653 | if (fBase->style().applyPathEffectToPath(&postPathEffect, &postPEStrokeRec, preStyle, |
| 654 | scale)) { |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 655 | // run postPathEffect through GrStyledShape to get any geometry reductions that would |
| 656 | // have occurred to fAppliedPE. |
| 657 | GrStyledShape(postPathEffect, GrStyle(postPEStrokeRec, nullptr)) |
| 658 | .asPath(&postPathEffect); |
bsalomon | 1a0b9ed | 2016-05-06 11:07:03 -0700 | [diff] [blame] | 659 | |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 660 | SkPath testPath; |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 661 | fAppliedPE->asPath(&testPath); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 662 | REPORTER_ASSERT(r, testPath == postPathEffect); |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 663 | REPORTER_ASSERT(r, postPEStrokeRec.hasEqualEffect(fAppliedPE->style().strokeRec())); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 664 | } |
| 665 | SkStrokeRec::InitStyle fillOrHairline; |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 666 | if (fBase->style().applyToPath(&postAllStyle, &fillOrHairline, preStyle, scale)) { |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 667 | SkPath testPath; |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 668 | fAppliedFull->asPath(&testPath); |
| 669 | if (fBase->style().hasPathEffect()) { |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 670 | // Because GrStyledShape always does two-stage application when there is a path |
| 671 | // effect there may be a reduction/canonicalization step between the path effect and |
bsalomon | 1b28c1a | 2016-06-20 12:28:17 -0700 | [diff] [blame] | 672 | // strokerec not reflected in postAllStyle since it applied both the path effect |
| 673 | // and strokerec without analyzing the intermediate path. |
| 674 | REPORTER_ASSERT(r, paths_fill_same(postAllStyle, testPath)); |
| 675 | } else { |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 676 | // Make sure that postAllStyle sees any reductions/canonicalizations that |
| 677 | // GrStyledShape would apply. |
| 678 | GrStyledShape(postAllStyle, GrStyle(fillOrHairline)).asPath(&postAllStyle); |
bsalomon | 1b28c1a | 2016-06-20 12:28:17 -0700 | [diff] [blame] | 679 | REPORTER_ASSERT(r, testPath == postAllStyle); |
| 680 | } |
| 681 | |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 682 | if (fillOrHairline == SkStrokeRec::kFill_InitStyle) { |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 683 | REPORTER_ASSERT(r, fAppliedFull->style().isSimpleFill()); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 684 | } else { |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 685 | REPORTER_ASSERT(r, fAppliedFull->style().isSimpleHairline()); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 686 | } |
| 687 | } |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 688 | test_inversions(r, *fBase, fBaseKey); |
| 689 | test_inversions(r, *fAppliedPE, fAppliedPEKey); |
| 690 | test_inversions(r, *fAppliedFull, fAppliedFullKey); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 693 | std::unique_ptr<GrStyledShape> fBase; |
| 694 | std::unique_ptr<GrStyledShape> fAppliedPE; |
| 695 | std::unique_ptr<GrStyledShape> fAppliedPEThenStroke; |
| 696 | std::unique_ptr<GrStyledShape> fAppliedFull; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 697 | |
| 698 | Key fBaseKey; |
| 699 | Key fAppliedPEKey; |
| 700 | Key fAppliedPEThenStrokeKey; |
| 701 | Key fAppliedFullKey; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 702 | }; |
| 703 | |
| 704 | void TestCase::testExpectations(skiatest::Reporter* reporter, SelfExpectations expectations) const { |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 705 | // The base's key should always be valid (unless the path is volatile) |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 706 | REPORTER_ASSERT(reporter, fBaseKey.count()); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 707 | if (expectations.fPEHasEffect) { |
| 708 | REPORTER_ASSERT(reporter, fBaseKey != fAppliedPEKey); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 709 | REPORTER_ASSERT(reporter, expectations.fPEHasValidKey == SkToBool(fAppliedPEKey.count())); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 710 | REPORTER_ASSERT(reporter, fBaseKey != fAppliedFullKey); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 711 | REPORTER_ASSERT(reporter, expectations.fPEHasValidKey == SkToBool(fAppliedFullKey.count())); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 712 | if (expectations.fStrokeApplies && expectations.fPEHasValidKey) { |
| 713 | REPORTER_ASSERT(reporter, fAppliedPEKey != fAppliedFullKey); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 714 | REPORTER_ASSERT(reporter, SkToBool(fAppliedFullKey.count())); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 715 | } |
| 716 | } else { |
| 717 | REPORTER_ASSERT(reporter, fBaseKey == fAppliedPEKey); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 718 | SkPath a, b; |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 719 | fBase->asPath(&a); |
| 720 | fAppliedPE->asPath(&b); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 721 | REPORTER_ASSERT(reporter, a == b); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 722 | if (expectations.fStrokeApplies) { |
| 723 | REPORTER_ASSERT(reporter, fBaseKey != fAppliedFullKey); |
| 724 | } else { |
| 725 | REPORTER_ASSERT(reporter, fBaseKey == fAppliedFullKey); |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 730 | void TestCase::compare(skiatest::Reporter* r, const TestCase& that, |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 731 | ComparisonExpecation expectation) const { |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 732 | SkPath a, b; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 733 | switch (expectation) { |
| 734 | case kAllDifferent_ComparisonExpecation: |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 735 | REPORTER_ASSERT(r, fBaseKey != that.fBaseKey); |
| 736 | REPORTER_ASSERT(r, fAppliedPEKey != that.fAppliedPEKey); |
| 737 | REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 738 | break; |
| 739 | case kSameUpToPE_ComparisonExpecation: |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 740 | check_equivalence(r, *fBase, *that.fBase, fBaseKey, that.fBaseKey); |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 741 | REPORTER_ASSERT(r, fAppliedPEKey != that.fAppliedPEKey); |
| 742 | REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 743 | break; |
| 744 | case kSameUpToStroke_ComparisonExpecation: |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 745 | check_equivalence(r, *fBase, *that.fBase, fBaseKey, that.fBaseKey); |
| 746 | check_equivalence(r, *fAppliedPE, *that.fAppliedPE, fAppliedPEKey, that.fAppliedPEKey); |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 747 | REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 748 | break; |
| 749 | case kAllSame_ComparisonExpecation: |
Brian Salomon | c8cdad7 | 2018-04-16 09:46:09 -0400 | [diff] [blame] | 750 | check_equivalence(r, *fBase, *that.fBase, fBaseKey, that.fBaseKey); |
| 751 | check_equivalence(r, *fAppliedPE, *that.fAppliedPE, fAppliedPEKey, that.fAppliedPEKey); |
| 752 | check_equivalence(r, *fAppliedFull, *that.fAppliedFull, fAppliedFullKey, |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 753 | that.fAppliedFullKey); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 754 | break; |
| 755 | } |
| 756 | } |
| 757 | } // namespace |
| 758 | |
| 759 | static sk_sp<SkPathEffect> make_dash() { |
| 760 | static const SkScalar kIntervals[] = { 0.25, 3.f, 0.5, 2.f }; |
| 761 | static const SkScalar kPhase = 0.75; |
| 762 | return SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), kPhase); |
| 763 | } |
| 764 | |
| 765 | static sk_sp<SkPathEffect> make_null_dash() { |
| 766 | static const SkScalar kNullIntervals[] = {0, 0, 0, 0, 0, 0}; |
| 767 | return SkDashPathEffect::Make(kNullIntervals, SK_ARRAY_COUNT(kNullIntervals), 0.f); |
| 768 | } |
| 769 | |
Mike Klein | 4334428 | 2017-08-16 11:56:22 -0400 | [diff] [blame] | 770 | // We make enough TestCases, and they're large enough, that on Google3 builds we exceed |
| 771 | // the maximum stack frame limit. make_TestCase() moves those temporaries over to the heap. |
| 772 | template <typename... Args> |
| 773 | static std::unique_ptr<TestCase> make_TestCase(Args&&... args) { |
| 774 | return std::unique_ptr<TestCase>{ new TestCase(std::forward<Args>(args)...) }; |
| 775 | } |
| 776 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 777 | static void test_basic(skiatest::Reporter* reporter, const Geo& geo) { |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 778 | sk_sp<SkPathEffect> dashPE = make_dash(); |
| 779 | |
| 780 | TestCase::SelfExpectations expectations; |
| 781 | SkPaint fill; |
| 782 | |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 783 | TestCase fillCase(geo, fill, reporter); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 784 | expectations.fPEHasEffect = false; |
| 785 | expectations.fPEHasValidKey = false; |
| 786 | expectations.fStrokeApplies = false; |
| 787 | fillCase.testExpectations(reporter, expectations); |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 788 | // Test that another GrStyledShape instance built from the same primitive is the same. |
Mike Klein | 4334428 | 2017-08-16 11:56:22 -0400 | [diff] [blame] | 789 | make_TestCase(geo, fill, reporter) |
| 790 | ->compare(reporter, fillCase, TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 791 | |
| 792 | SkPaint stroke2RoundBevel; |
| 793 | stroke2RoundBevel.setStyle(SkPaint::kStroke_Style); |
| 794 | stroke2RoundBevel.setStrokeCap(SkPaint::kRound_Cap); |
| 795 | stroke2RoundBevel.setStrokeJoin(SkPaint::kBevel_Join); |
| 796 | stroke2RoundBevel.setStrokeWidth(2.f); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 797 | TestCase stroke2RoundBevelCase(geo, stroke2RoundBevel, reporter); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 798 | expectations.fPEHasValidKey = true; |
| 799 | expectations.fPEHasEffect = false; |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 800 | expectations.fStrokeApplies = !geo.strokeIsConvertedToFill(); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 801 | stroke2RoundBevelCase.testExpectations(reporter, expectations); |
Mike Klein | 4334428 | 2017-08-16 11:56:22 -0400 | [diff] [blame] | 802 | make_TestCase(geo, stroke2RoundBevel, reporter) |
| 803 | ->compare(reporter, stroke2RoundBevelCase, TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 804 | |
| 805 | SkPaint stroke2RoundBevelDash = stroke2RoundBevel; |
| 806 | stroke2RoundBevelDash.setPathEffect(make_dash()); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 807 | TestCase stroke2RoundBevelDashCase(geo, stroke2RoundBevelDash, reporter); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 808 | expectations.fPEHasValidKey = true; |
| 809 | expectations.fPEHasEffect = true; |
| 810 | expectations.fStrokeApplies = true; |
| 811 | stroke2RoundBevelDashCase.testExpectations(reporter, expectations); |
Mike Klein | 4334428 | 2017-08-16 11:56:22 -0400 | [diff] [blame] | 812 | make_TestCase(geo, stroke2RoundBevelDash, reporter) |
| 813 | ->compare(reporter, stroke2RoundBevelDashCase, TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 814 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 815 | if (geo.fillChangesGeom() || geo.strokeIsConvertedToFill()) { |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 816 | fillCase.compare(reporter, stroke2RoundBevelCase, |
| 817 | TestCase::kAllDifferent_ComparisonExpecation); |
| 818 | fillCase.compare(reporter, stroke2RoundBevelDashCase, |
| 819 | TestCase::kAllDifferent_ComparisonExpecation); |
| 820 | } else { |
| 821 | fillCase.compare(reporter, stroke2RoundBevelCase, |
| 822 | TestCase::kSameUpToStroke_ComparisonExpecation); |
| 823 | fillCase.compare(reporter, stroke2RoundBevelDashCase, |
| 824 | TestCase::kSameUpToPE_ComparisonExpecation); |
| 825 | } |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 826 | if (geo.strokeIsConvertedToFill()) { |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 827 | stroke2RoundBevelCase.compare(reporter, stroke2RoundBevelDashCase, |
| 828 | TestCase::kAllDifferent_ComparisonExpecation); |
| 829 | } else { |
| 830 | stroke2RoundBevelCase.compare(reporter, stroke2RoundBevelDashCase, |
| 831 | TestCase::kSameUpToPE_ComparisonExpecation); |
| 832 | } |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 833 | |
bsalomon | f0cf355 | 2016-05-05 08:28:30 -0700 | [diff] [blame] | 834 | // Stroke and fill cases |
| 835 | SkPaint stroke2RoundBevelAndFill = stroke2RoundBevel; |
| 836 | stroke2RoundBevelAndFill.setStyle(SkPaint::kStrokeAndFill_Style); |
| 837 | TestCase stroke2RoundBevelAndFillCase(geo, stroke2RoundBevelAndFill, reporter); |
| 838 | expectations.fPEHasValidKey = true; |
| 839 | expectations.fPEHasEffect = false; |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 840 | expectations.fStrokeApplies = !geo.strokeIsConvertedToFill(); |
bsalomon | f0cf355 | 2016-05-05 08:28:30 -0700 | [diff] [blame] | 841 | stroke2RoundBevelAndFillCase.testExpectations(reporter, expectations); |
Mike Klein | 4334428 | 2017-08-16 11:56:22 -0400 | [diff] [blame] | 842 | make_TestCase(geo, stroke2RoundBevelAndFill, reporter)->compare( |
| 843 | reporter, stroke2RoundBevelAndFillCase, TestCase::kAllSame_ComparisonExpecation); |
bsalomon | f0cf355 | 2016-05-05 08:28:30 -0700 | [diff] [blame] | 844 | |
| 845 | SkPaint stroke2RoundBevelAndFillDash = stroke2RoundBevelDash; |
| 846 | stroke2RoundBevelAndFillDash.setStyle(SkPaint::kStrokeAndFill_Style); |
| 847 | TestCase stroke2RoundBevelAndFillDashCase(geo, stroke2RoundBevelAndFillDash, reporter); |
| 848 | expectations.fPEHasValidKey = true; |
bsalomon | a058786 | 2016-06-09 06:03:38 -0700 | [diff] [blame] | 849 | expectations.fPEHasEffect = false; |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 850 | expectations.fStrokeApplies = !geo.strokeIsConvertedToFill(); |
bsalomon | f0cf355 | 2016-05-05 08:28:30 -0700 | [diff] [blame] | 851 | stroke2RoundBevelAndFillDashCase.testExpectations(reporter, expectations); |
Mike Klein | 4334428 | 2017-08-16 11:56:22 -0400 | [diff] [blame] | 852 | make_TestCase(geo, stroke2RoundBevelAndFillDash, reporter)->compare( |
bsalomon | f0cf355 | 2016-05-05 08:28:30 -0700 | [diff] [blame] | 853 | reporter, stroke2RoundBevelAndFillDashCase, TestCase::kAllSame_ComparisonExpecation); |
bsalomon | a058786 | 2016-06-09 06:03:38 -0700 | [diff] [blame] | 854 | stroke2RoundBevelAndFillDashCase.compare(reporter, stroke2RoundBevelAndFillCase, |
| 855 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | f0cf355 | 2016-05-05 08:28:30 -0700 | [diff] [blame] | 856 | |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 857 | SkPaint hairline; |
| 858 | hairline.setStyle(SkPaint::kStroke_Style); |
| 859 | hairline.setStrokeWidth(0.f); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 860 | TestCase hairlineCase(geo, hairline, reporter); |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 861 | // Since hairline style doesn't change the SkPath data, it is keyed identically to fill (except |
| 862 | // in the line and unclosed rect cases). |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 863 | if (geo.fillChangesGeom()) { |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 864 | hairlineCase.compare(reporter, fillCase, TestCase::kAllDifferent_ComparisonExpecation); |
| 865 | } else { |
| 866 | hairlineCase.compare(reporter, fillCase, TestCase::kAllSame_ComparisonExpecation); |
| 867 | } |
bsalomon | 9ad5d7c | 2016-05-04 08:44:15 -0700 | [diff] [blame] | 868 | REPORTER_ASSERT(reporter, hairlineCase.baseShape().style().isSimpleHairline()); |
| 869 | REPORTER_ASSERT(reporter, hairlineCase.appliedFullStyleShape().style().isSimpleHairline()); |
| 870 | REPORTER_ASSERT(reporter, hairlineCase.appliedPathEffectShape().style().isSimpleHairline()); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 871 | |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 872 | } |
| 873 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 874 | static void test_scale(skiatest::Reporter* reporter, const Geo& geo) { |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 875 | sk_sp<SkPathEffect> dashPE = make_dash(); |
| 876 | |
| 877 | static const SkScalar kS1 = 1.f; |
| 878 | static const SkScalar kS2 = 2.f; |
| 879 | |
| 880 | SkPaint fill; |
| 881 | TestCase fillCase1(geo, fill, reporter, kS1); |
| 882 | TestCase fillCase2(geo, fill, reporter, kS2); |
| 883 | // Scale doesn't affect fills. |
| 884 | fillCase1.compare(reporter, fillCase2, TestCase::kAllSame_ComparisonExpecation); |
| 885 | |
| 886 | SkPaint hairline; |
| 887 | hairline.setStyle(SkPaint::kStroke_Style); |
| 888 | hairline.setStrokeWidth(0.f); |
| 889 | TestCase hairlineCase1(geo, hairline, reporter, kS1); |
| 890 | TestCase hairlineCase2(geo, hairline, reporter, kS2); |
| 891 | // Scale doesn't affect hairlines. |
| 892 | hairlineCase1.compare(reporter, hairlineCase2, TestCase::kAllSame_ComparisonExpecation); |
| 893 | |
| 894 | SkPaint stroke; |
| 895 | stroke.setStyle(SkPaint::kStroke_Style); |
| 896 | stroke.setStrokeWidth(2.f); |
| 897 | TestCase strokeCase1(geo, stroke, reporter, kS1); |
| 898 | TestCase strokeCase2(geo, stroke, reporter, kS2); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 899 | // Scale affects the stroke |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 900 | if (geo.strokeIsConvertedToFill()) { |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 901 | REPORTER_ASSERT(reporter, !strokeCase1.baseShape().style().applies()); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 902 | strokeCase1.compare(reporter, strokeCase2, TestCase::kAllSame_ComparisonExpecation); |
| 903 | } else { |
| 904 | strokeCase1.compare(reporter, strokeCase2, TestCase::kSameUpToStroke_ComparisonExpecation); |
| 905 | } |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 906 | |
| 907 | SkPaint strokeDash = stroke; |
| 908 | strokeDash.setPathEffect(make_dash()); |
| 909 | TestCase strokeDashCase1(geo, strokeDash, reporter, kS1); |
| 910 | TestCase strokeDashCase2(geo, strokeDash, reporter, kS2); |
| 911 | // Scale affects the dash and the stroke. |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 912 | strokeDashCase1.compare(reporter, strokeDashCase2, |
| 913 | TestCase::kSameUpToPE_ComparisonExpecation); |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 914 | |
| 915 | // Stroke and fill cases |
| 916 | SkPaint strokeAndFill = stroke; |
| 917 | strokeAndFill.setStyle(SkPaint::kStrokeAndFill_Style); |
| 918 | TestCase strokeAndFillCase1(geo, strokeAndFill, reporter, kS1); |
| 919 | TestCase strokeAndFillCase2(geo, strokeAndFill, reporter, kS2); |
bsalomon | a058786 | 2016-06-09 06:03:38 -0700 | [diff] [blame] | 920 | SkPaint strokeAndFillDash = strokeDash; |
| 921 | strokeAndFillDash.setStyle(SkPaint::kStrokeAndFill_Style); |
| 922 | // Dash is ignored for stroke and fill |
| 923 | TestCase strokeAndFillDashCase1(geo, strokeAndFillDash, reporter, kS1); |
| 924 | TestCase strokeAndFillDashCase2(geo, strokeAndFillDash, reporter, kS2); |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 925 | // Scale affects the stroke, but check to make sure this didn't become a simpler shape (e.g. |
| 926 | // stroke-and-filled rect can become a rect), in which case the scale shouldn't matter and the |
| 927 | // geometries should agree. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 928 | if (geo.strokeAndFillIsConvertedToFill(strokeAndFillDash)) { |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 929 | REPORTER_ASSERT(reporter, !strokeAndFillCase1.baseShape().style().applies()); |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 930 | strokeAndFillCase1.compare(reporter, strokeAndFillCase2, |
| 931 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 932 | strokeAndFillDashCase1.compare(reporter, strokeAndFillDashCase2, |
| 933 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 934 | } else { |
| 935 | strokeAndFillCase1.compare(reporter, strokeAndFillCase2, |
| 936 | TestCase::kSameUpToStroke_ComparisonExpecation); |
| 937 | } |
bsalomon | a058786 | 2016-06-09 06:03:38 -0700 | [diff] [blame] | 938 | strokeAndFillDashCase1.compare(reporter, strokeAndFillCase1, |
| 939 | TestCase::kAllSame_ComparisonExpecation); |
| 940 | strokeAndFillDashCase2.compare(reporter, strokeAndFillCase2, |
| 941 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 942 | } |
| 943 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 944 | template <typename T> |
| 945 | static void test_stroke_param_impl(skiatest::Reporter* reporter, const Geo& geo, |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 946 | std::function<void(SkPaint*, T)> setter, T a, T b, |
| 947 | bool paramAffectsStroke, |
| 948 | bool paramAffectsDashAndStroke) { |
| 949 | // Set the stroke width so that we don't get hairline. However, call the setter afterward so |
| 950 | // that it can override the stroke width. |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 951 | SkPaint strokeA; |
| 952 | strokeA.setStyle(SkPaint::kStroke_Style); |
| 953 | strokeA.setStrokeWidth(2.f); |
| 954 | setter(&strokeA, a); |
| 955 | SkPaint strokeB; |
| 956 | strokeB.setStyle(SkPaint::kStroke_Style); |
| 957 | strokeB.setStrokeWidth(2.f); |
| 958 | setter(&strokeB, b); |
| 959 | |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 960 | TestCase strokeACase(geo, strokeA, reporter); |
| 961 | TestCase strokeBCase(geo, strokeB, reporter); |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 962 | if (paramAffectsStroke) { |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 963 | // If stroking is immediately incorporated into a geometric transformation then the base |
| 964 | // shapes will differ. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 965 | if (geo.strokeIsConvertedToFill()) { |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 966 | strokeACase.compare(reporter, strokeBCase, |
| 967 | TestCase::kAllDifferent_ComparisonExpecation); |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 968 | } else { |
| 969 | strokeACase.compare(reporter, strokeBCase, |
| 970 | TestCase::kSameUpToStroke_ComparisonExpecation); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 971 | } |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 972 | } else { |
| 973 | strokeACase.compare(reporter, strokeBCase, TestCase::kAllSame_ComparisonExpecation); |
| 974 | } |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 975 | |
bsalomon | f0cf355 | 2016-05-05 08:28:30 -0700 | [diff] [blame] | 976 | SkPaint strokeAndFillA = strokeA; |
| 977 | SkPaint strokeAndFillB = strokeB; |
| 978 | strokeAndFillA.setStyle(SkPaint::kStrokeAndFill_Style); |
| 979 | strokeAndFillB.setStyle(SkPaint::kStrokeAndFill_Style); |
| 980 | TestCase strokeAndFillACase(geo, strokeAndFillA, reporter); |
| 981 | TestCase strokeAndFillBCase(geo, strokeAndFillB, reporter); |
| 982 | if (paramAffectsStroke) { |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 983 | // If stroking is immediately incorporated into a geometric transformation then the base |
| 984 | // shapes will differ. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 985 | if (geo.strokeAndFillIsConvertedToFill(strokeAndFillA) || |
| 986 | geo.strokeAndFillIsConvertedToFill(strokeAndFillB)) { |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 987 | strokeAndFillACase.compare(reporter, strokeAndFillBCase, |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 988 | TestCase::kAllDifferent_ComparisonExpecation); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 989 | } else { |
| 990 | strokeAndFillACase.compare(reporter, strokeAndFillBCase, |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 991 | TestCase::kSameUpToStroke_ComparisonExpecation); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 992 | } |
bsalomon | f0cf355 | 2016-05-05 08:28:30 -0700 | [diff] [blame] | 993 | } else { |
| 994 | strokeAndFillACase.compare(reporter, strokeAndFillBCase, |
| 995 | TestCase::kAllSame_ComparisonExpecation); |
| 996 | } |
| 997 | |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 998 | // Make sure stroking params don't affect fill style. |
| 999 | SkPaint fillA = strokeA, fillB = strokeB; |
| 1000 | fillA.setStyle(SkPaint::kFill_Style); |
| 1001 | fillB.setStyle(SkPaint::kFill_Style); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 1002 | TestCase fillACase(geo, fillA, reporter); |
| 1003 | TestCase fillBCase(geo, fillB, reporter); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1004 | fillACase.compare(reporter, fillBCase, TestCase::kAllSame_ComparisonExpecation); |
| 1005 | |
| 1006 | // Make sure just applying the dash but not stroke gives the same key for both stroking |
| 1007 | // variations. |
| 1008 | SkPaint dashA = strokeA, dashB = strokeB; |
| 1009 | dashA.setPathEffect(make_dash()); |
| 1010 | dashB.setPathEffect(make_dash()); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 1011 | TestCase dashACase(geo, dashA, reporter); |
| 1012 | TestCase dashBCase(geo, dashB, reporter); |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 1013 | if (paramAffectsDashAndStroke) { |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 1014 | dashACase.compare(reporter, dashBCase, TestCase::kSameUpToStroke_ComparisonExpecation); |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 1015 | } else { |
| 1016 | dashACase.compare(reporter, dashBCase, TestCase::kAllSame_ComparisonExpecation); |
| 1017 | } |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1020 | template <typename T> |
| 1021 | static void test_stroke_param(skiatest::Reporter* reporter, const Geo& geo, |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 1022 | std::function<void(SkPaint*, T)> setter, T a, T b) { |
| 1023 | test_stroke_param_impl(reporter, geo, setter, a, b, true, true); |
| 1024 | }; |
| 1025 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1026 | static void test_stroke_cap(skiatest::Reporter* reporter, const Geo& geo) { |
| 1027 | SkPaint hairline; |
| 1028 | hairline.setStrokeWidth(0); |
| 1029 | hairline.setStyle(SkPaint::kStroke_Style); |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1030 | GrStyledShape shape = geo.makeShape(hairline); |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 1031 | // The cap should only affect shapes that may be open. |
| 1032 | bool affectsStroke = !shape.knownToBeClosed(); |
| 1033 | // Dashing adds ends that need caps. |
| 1034 | bool affectsDashAndStroke = true; |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1035 | test_stroke_param_impl<SkPaint::Cap>( |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 1036 | reporter, |
| 1037 | geo, |
| 1038 | [](SkPaint* p, SkPaint::Cap c) { p->setStrokeCap(c);}, |
| 1039 | SkPaint::kButt_Cap, SkPaint::kRound_Cap, |
| 1040 | affectsStroke, |
| 1041 | affectsDashAndStroke); |
| 1042 | }; |
| 1043 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1044 | static bool shape_known_not_to_have_joins(const GrStyledShape& shape) { |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 1045 | return shape.asLine(nullptr, nullptr) || shape.isEmpty(); |
| 1046 | } |
| 1047 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1048 | static void test_stroke_join(skiatest::Reporter* reporter, const Geo& geo) { |
| 1049 | SkPaint hairline; |
| 1050 | hairline.setStrokeWidth(0); |
| 1051 | hairline.setStyle(SkPaint::kStroke_Style); |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1052 | GrStyledShape shape = geo.makeShape(hairline); |
| 1053 | // GrStyledShape recognizes certain types don't have joins and will prevent the join type from |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 1054 | // affecting the style key. |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1055 | // Dashing doesn't add additional joins. However, GrStyledShape currently loses track of this |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 1056 | // after applying the dash. |
| 1057 | bool affectsStroke = !shape_known_not_to_have_joins(shape); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1058 | test_stroke_param_impl<SkPaint::Join>( |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 1059 | reporter, |
| 1060 | geo, |
| 1061 | [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);}, |
| 1062 | SkPaint::kRound_Join, SkPaint::kBevel_Join, |
| 1063 | affectsStroke, true); |
| 1064 | }; |
| 1065 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1066 | static void test_miter_limit(skiatest::Reporter* reporter, const Geo& geo) { |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 1067 | auto setMiterJoinAndLimit = [](SkPaint* p, SkScalar miter) { |
| 1068 | p->setStrokeJoin(SkPaint::kMiter_Join); |
| 1069 | p->setStrokeMiter(miter); |
| 1070 | }; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1071 | |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 1072 | auto setOtherJoinAndLimit = [](SkPaint* p, SkScalar miter) { |
| 1073 | p->setStrokeJoin(SkPaint::kRound_Join); |
| 1074 | p->setStrokeMiter(miter); |
| 1075 | }; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1076 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1077 | SkPaint hairline; |
| 1078 | hairline.setStrokeWidth(0); |
| 1079 | hairline.setStyle(SkPaint::kStroke_Style); |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1080 | GrStyledShape shape = geo.makeShape(hairline); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 1081 | bool mayHaveJoins = !shape_known_not_to_have_joins(shape); |
| 1082 | |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 1083 | // The miter limit should affect stroked and dashed-stroked cases when the join type is |
| 1084 | // miter. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1085 | test_stroke_param_impl<SkScalar>( |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 1086 | reporter, |
| 1087 | geo, |
| 1088 | setMiterJoinAndLimit, |
| 1089 | 0.5f, 0.75f, |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 1090 | mayHaveJoins, |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 1091 | true); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1092 | |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 1093 | // The miter limit should not affect stroked and dashed-stroked cases when the join type is |
| 1094 | // not miter. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1095 | test_stroke_param_impl<SkScalar>( |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 1096 | reporter, |
| 1097 | geo, |
| 1098 | setOtherJoinAndLimit, |
| 1099 | 0.5f, 0.75f, |
| 1100 | false, |
| 1101 | false); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1104 | static void test_dash_fill(skiatest::Reporter* reporter, const Geo& geo) { |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1105 | // A dash with no stroke should have no effect |
| 1106 | using DashFactoryFn = sk_sp<SkPathEffect>(*)(); |
| 1107 | for (DashFactoryFn md : {&make_dash, &make_null_dash}) { |
| 1108 | SkPaint dashFill; |
| 1109 | dashFill.setPathEffect((*md)()); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 1110 | TestCase dashFillCase(geo, dashFill, reporter); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1111 | |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 1112 | TestCase fillCase(geo, SkPaint(), reporter); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1113 | dashFillCase.compare(reporter, fillCase, TestCase::kAllSame_ComparisonExpecation); |
| 1114 | } |
| 1115 | } |
| 1116 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1117 | void test_null_dash(skiatest::Reporter* reporter, const Geo& geo) { |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1118 | SkPaint fill; |
| 1119 | SkPaint stroke; |
| 1120 | stroke.setStyle(SkPaint::kStroke_Style); |
| 1121 | stroke.setStrokeWidth(1.f); |
| 1122 | SkPaint dash; |
| 1123 | dash.setStyle(SkPaint::kStroke_Style); |
| 1124 | dash.setStrokeWidth(1.f); |
| 1125 | dash.setPathEffect(make_dash()); |
| 1126 | SkPaint nullDash; |
| 1127 | nullDash.setStyle(SkPaint::kStroke_Style); |
| 1128 | nullDash.setStrokeWidth(1.f); |
| 1129 | nullDash.setPathEffect(make_null_dash()); |
| 1130 | |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 1131 | TestCase fillCase(geo, fill, reporter); |
| 1132 | TestCase strokeCase(geo, stroke, reporter); |
| 1133 | TestCase dashCase(geo, dash, reporter); |
| 1134 | TestCase nullDashCase(geo, nullDash, reporter); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1135 | |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 1136 | // We expect the null dash to be ignored so nullDashCase should match strokeCase, always. |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1137 | nullDashCase.compare(reporter, strokeCase, TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 1138 | // Check whether the fillCase or strokeCase/nullDashCase would undergo a geometric tranformation |
| 1139 | // on construction in order to determine how to compare the fill and stroke. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1140 | if (geo.fillChangesGeom() || geo.strokeIsConvertedToFill()) { |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 1141 | nullDashCase.compare(reporter, fillCase, TestCase::kAllDifferent_ComparisonExpecation); |
| 1142 | } else { |
| 1143 | nullDashCase.compare(reporter, fillCase, TestCase::kSameUpToStroke_ComparisonExpecation); |
| 1144 | } |
| 1145 | // In the null dash case we may immediately convert to a fill, but not for the normal dash case. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1146 | if (geo.strokeIsConvertedToFill()) { |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 1147 | nullDashCase.compare(reporter, dashCase, TestCase::kAllDifferent_ComparisonExpecation); |
| 1148 | } else { |
| 1149 | nullDashCase.compare(reporter, dashCase, TestCase::kSameUpToPE_ComparisonExpecation); |
| 1150 | } |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1153 | void test_path_effect_makes_rrect(skiatest::Reporter* reporter, const Geo& geo) { |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1154 | /** |
| 1155 | * This path effect takes any input path and turns it into a rrect. It passes through stroke |
| 1156 | * info. |
| 1157 | */ |
| 1158 | class RRectPathEffect : SkPathEffect { |
| 1159 | public: |
| 1160 | static const SkRRect& RRect() { |
| 1161 | static const SkRRect kRRect = SkRRect::MakeRectXY(SkRect::MakeWH(12, 12), 3, 5); |
| 1162 | return kRRect; |
| 1163 | } |
| 1164 | |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 1165 | static sk_sp<SkPathEffect> Make() { return sk_sp<SkPathEffect>(new RRectPathEffect); } |
| 1166 | Factory getFactory() const override { return nullptr; } |
Mike Klein | 4fee323 | 2018-10-18 17:27:16 -0400 | [diff] [blame] | 1167 | const char* getTypeName() const override { return nullptr; } |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 1168 | |
| 1169 | protected: |
| 1170 | bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, |
| 1171 | const SkRect* cullR) const override { |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1172 | dst->reset(); |
| 1173 | dst->addRRect(RRect()); |
| 1174 | return true; |
| 1175 | } |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 1176 | |
| 1177 | SkRect onComputeFastBounds(const SkRect& src) const override { |
| 1178 | return RRect().getBounds(); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1179 | } |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 1180 | |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1181 | private: |
| 1182 | RRectPathEffect() {} |
| 1183 | }; |
| 1184 | |
| 1185 | SkPaint fill; |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 1186 | TestCase fillGeoCase(geo, fill, reporter); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1187 | |
| 1188 | SkPaint pe; |
| 1189 | pe.setPathEffect(RRectPathEffect::Make()); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 1190 | TestCase geoPECase(geo, pe, reporter); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1191 | |
| 1192 | SkPaint peStroke; |
| 1193 | peStroke.setPathEffect(RRectPathEffect::Make()); |
| 1194 | peStroke.setStrokeWidth(2.f); |
| 1195 | peStroke.setStyle(SkPaint::kStroke_Style); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 1196 | TestCase geoPEStrokeCase(geo, peStroke, reporter); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1197 | |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 1198 | // Check whether constructing the filled case would cause the base shape to have a different |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1199 | // geometry (because of a geometric transformation upon initial GrStyledShape construction). |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1200 | if (geo.fillChangesGeom()) { |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 1201 | fillGeoCase.compare(reporter, geoPECase, TestCase::kAllDifferent_ComparisonExpecation); |
| 1202 | fillGeoCase.compare(reporter, geoPEStrokeCase, |
| 1203 | TestCase::kAllDifferent_ComparisonExpecation); |
| 1204 | } else { |
| 1205 | fillGeoCase.compare(reporter, geoPECase, TestCase::kSameUpToPE_ComparisonExpecation); |
| 1206 | fillGeoCase.compare(reporter, geoPEStrokeCase, TestCase::kSameUpToPE_ComparisonExpecation); |
| 1207 | } |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1208 | geoPECase.compare(reporter, geoPEStrokeCase, |
| 1209 | TestCase::kSameUpToStroke_ComparisonExpecation); |
| 1210 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1211 | TestCase rrectFillCase(reporter, RRectPathEffect::RRect(), fill); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1212 | SkPaint stroke = peStroke; |
| 1213 | stroke.setPathEffect(nullptr); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1214 | TestCase rrectStrokeCase(reporter, RRectPathEffect::RRect(), stroke); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1215 | |
| 1216 | SkRRect rrect; |
| 1217 | // Applying the path effect should make a SkRRect shape. There is no further stroking in the |
| 1218 | // geoPECase, so the full style should be the same as just the PE. |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1219 | REPORTER_ASSERT(reporter, geoPECase.appliedPathEffectShape().asRRect(&rrect, nullptr, nullptr, |
| 1220 | nullptr)); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1221 | REPORTER_ASSERT(reporter, rrect == RRectPathEffect::RRect()); |
| 1222 | REPORTER_ASSERT(reporter, geoPECase.appliedPathEffectKey() == rrectFillCase.baseKey()); |
| 1223 | |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1224 | REPORTER_ASSERT(reporter, geoPECase.appliedFullStyleShape().asRRect(&rrect, nullptr, nullptr, |
| 1225 | nullptr)); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1226 | REPORTER_ASSERT(reporter, rrect == RRectPathEffect::RRect()); |
| 1227 | REPORTER_ASSERT(reporter, geoPECase.appliedFullStyleKey() == rrectFillCase.baseKey()); |
| 1228 | |
| 1229 | // In the PE+stroke case applying the full style should be the same as just stroking the rrect. |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1230 | REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectShape().asRRect(&rrect, nullptr, |
| 1231 | nullptr, nullptr)); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1232 | REPORTER_ASSERT(reporter, rrect == RRectPathEffect::RRect()); |
| 1233 | REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectKey() == rrectFillCase.baseKey()); |
| 1234 | |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1235 | REPORTER_ASSERT(reporter, !geoPEStrokeCase.appliedFullStyleShape().asRRect(&rrect, nullptr, |
| 1236 | nullptr, nullptr)); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1237 | REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleKey() == |
| 1238 | rrectStrokeCase.appliedFullStyleKey()); |
| 1239 | } |
| 1240 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1241 | void test_unknown_path_effect(skiatest::Reporter* reporter, const Geo& geo) { |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1242 | /** |
| 1243 | * This path effect just adds two lineTos to the input path. |
| 1244 | */ |
| 1245 | class AddLineTosPathEffect : SkPathEffect { |
| 1246 | public: |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 1247 | static sk_sp<SkPathEffect> Make() { return sk_sp<SkPathEffect>(new AddLineTosPathEffect); } |
| 1248 | Factory getFactory() const override { return nullptr; } |
Mike Klein | 4fee323 | 2018-10-18 17:27:16 -0400 | [diff] [blame] | 1249 | const char* getTypeName() const override { return nullptr; } |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 1250 | |
| 1251 | protected: |
| 1252 | bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, |
| 1253 | const SkRect* cullR) const override { |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1254 | *dst = src; |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 1255 | // To avoid triggering data-based keying of paths with few verbs we add many segments. |
| 1256 | for (int i = 0; i < 100; ++i) { |
| 1257 | dst->lineTo(SkIntToScalar(i), SkIntToScalar(i)); |
| 1258 | } |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1259 | return true; |
| 1260 | } |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 1261 | SkRect onComputeFastBounds(const SkRect& src) const override { |
| 1262 | SkRect dst = src; |
| 1263 | SkRectPriv::GrowToInclude(&dst, {0, 0}); |
| 1264 | SkRectPriv::GrowToInclude(&dst, {100, 100}); |
| 1265 | return dst; |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1266 | } |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1267 | private: |
| 1268 | AddLineTosPathEffect() {} |
| 1269 | }; |
| 1270 | |
bsalomon | 9ad5d7c | 2016-05-04 08:44:15 -0700 | [diff] [blame] | 1271 | // This path effect should make the keys invalid when it is applied. We only produce a path |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1272 | // effect key for dash path effects. So the only way another arbitrary path effect can produce |
| 1273 | // a styled result with a key is to produce a non-path shape that has a purely geometric key. |
| 1274 | SkPaint peStroke; |
| 1275 | peStroke.setPathEffect(AddLineTosPathEffect::Make()); |
| 1276 | peStroke.setStrokeWidth(2.f); |
| 1277 | peStroke.setStyle(SkPaint::kStroke_Style); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 1278 | TestCase geoPEStrokeCase(geo, peStroke, reporter); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 1279 | TestCase::SelfExpectations expectations; |
| 1280 | expectations.fPEHasEffect = true; |
| 1281 | expectations.fPEHasValidKey = false; |
| 1282 | expectations.fStrokeApplies = true; |
| 1283 | geoPEStrokeCase.testExpectations(reporter, expectations); |
| 1284 | } |
| 1285 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1286 | void test_make_hairline_path_effect(skiatest::Reporter* reporter, const Geo& geo) { |
bsalomon | 9ad5d7c | 2016-05-04 08:44:15 -0700 | [diff] [blame] | 1287 | /** |
| 1288 | * This path effect just changes the stroke rec to hairline. |
| 1289 | */ |
| 1290 | class MakeHairlinePathEffect : SkPathEffect { |
| 1291 | public: |
bsalomon | 9ad5d7c | 2016-05-04 08:44:15 -0700 | [diff] [blame] | 1292 | static sk_sp<SkPathEffect> Make() { |
| 1293 | return sk_sp<SkPathEffect>(new MakeHairlinePathEffect); |
| 1294 | } |
| 1295 | Factory getFactory() const override { return nullptr; } |
Mike Klein | 4fee323 | 2018-10-18 17:27:16 -0400 | [diff] [blame] | 1296 | const char* getTypeName() const override { return nullptr; } |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 1297 | |
| 1298 | protected: |
| 1299 | bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec* strokeRec, |
| 1300 | const SkRect* cullR) const override { |
| 1301 | *dst = src; |
| 1302 | strokeRec->setHairlineStyle(); |
| 1303 | return true; |
| 1304 | } |
bsalomon | 9ad5d7c | 2016-05-04 08:44:15 -0700 | [diff] [blame] | 1305 | private: |
| 1306 | MakeHairlinePathEffect() {} |
| 1307 | }; |
| 1308 | |
| 1309 | SkPaint fill; |
| 1310 | SkPaint pe; |
| 1311 | pe.setPathEffect(MakeHairlinePathEffect::Make()); |
| 1312 | |
| 1313 | TestCase peCase(geo, pe, reporter); |
| 1314 | |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 1315 | SkPath a, b, c; |
bsalomon | 9ad5d7c | 2016-05-04 08:44:15 -0700 | [diff] [blame] | 1316 | peCase.baseShape().asPath(&a); |
| 1317 | peCase.appliedPathEffectShape().asPath(&b); |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 1318 | peCase.appliedFullStyleShape().asPath(&c); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1319 | if (geo.isNonPath(pe)) { |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 1320 | // RRect types can have a change in start index or direction after the PE is applied. This |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1321 | // is because once the PE is applied, GrStyledShape may canonicalize the dir and index since |
| 1322 | // it is not germane to the styling any longer. |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 1323 | // Instead we just check that the paths would fill the same both before and after styling. |
| 1324 | REPORTER_ASSERT(reporter, paths_fill_same(a, b)); |
| 1325 | REPORTER_ASSERT(reporter, paths_fill_same(a, c)); |
bsalomon | 9ad5d7c | 2016-05-04 08:44:15 -0700 | [diff] [blame] | 1326 | } else { |
bsalomon | a4817af | 2016-06-23 11:48:26 -0700 | [diff] [blame] | 1327 | // The base shape cannot perform canonicalization on the path's fill type because of an |
| 1328 | // unknown path effect. However, after the path effect is applied the resulting hairline |
| 1329 | // shape will canonicalize the path fill type since hairlines (and stroking in general) |
| 1330 | // don't distinguish between even/odd and non-zero winding. |
| 1331 | a.setFillType(b.getFillType()); |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 1332 | REPORTER_ASSERT(reporter, a == b); |
| 1333 | REPORTER_ASSERT(reporter, a == c); |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 1334 | // If the resulting path is small enough then it will have a key. |
| 1335 | REPORTER_ASSERT(reporter, paths_fill_same(a, b)); |
| 1336 | REPORTER_ASSERT(reporter, paths_fill_same(a, c)); |
bsalomon | aa84064 | 2016-09-23 12:09:16 -0700 | [diff] [blame] | 1337 | REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey().empty()); |
| 1338 | REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey().empty()); |
bsalomon | 9ad5d7c | 2016-05-04 08:44:15 -0700 | [diff] [blame] | 1339 | } |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 1340 | REPORTER_ASSERT(reporter, peCase.appliedPathEffectShape().style().isSimpleHairline()); |
| 1341 | REPORTER_ASSERT(reporter, peCase.appliedFullStyleShape().style().isSimpleHairline()); |
bsalomon | 9ad5d7c | 2016-05-04 08:44:15 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1344 | void test_volatile_path(skiatest::Reporter* reporter, const Geo& geo) { |
| 1345 | SkPath vPath = geo.path(); |
bsalomon | 4eeccc9 | 2016-04-27 13:30:25 -0700 | [diff] [blame] | 1346 | vPath.setIsVolatile(true); |
| 1347 | |
| 1348 | SkPaint dashAndStroke; |
| 1349 | dashAndStroke.setPathEffect(make_dash()); |
| 1350 | dashAndStroke.setStrokeWidth(2.f); |
| 1351 | dashAndStroke.setStyle(SkPaint::kStroke_Style); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1352 | TestCase volatileCase(reporter, vPath, dashAndStroke); |
bsalomon | 4eeccc9 | 2016-04-27 13:30:25 -0700 | [diff] [blame] | 1353 | // We expect a shape made from a volatile path to have a key iff the shape is recognized |
bsalomon | aa84064 | 2016-09-23 12:09:16 -0700 | [diff] [blame] | 1354 | // as a specialized geometry. |
| 1355 | if (geo.isNonPath(dashAndStroke)) { |
bsalomon | 4eeccc9 | 2016-04-27 13:30:25 -0700 | [diff] [blame] | 1356 | REPORTER_ASSERT(reporter, SkToBool(volatileCase.baseKey().count())); |
| 1357 | // In this case all the keys should be identical to the non-volatile case. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1358 | TestCase nonVolatileCase(reporter, geo.path(), dashAndStroke); |
bsalomon | 4eeccc9 | 2016-04-27 13:30:25 -0700 | [diff] [blame] | 1359 | volatileCase.compare(reporter, nonVolatileCase, TestCase::kAllSame_ComparisonExpecation); |
| 1360 | } else { |
| 1361 | // None of the keys should be valid. |
| 1362 | REPORTER_ASSERT(reporter, !SkToBool(volatileCase.baseKey().count())); |
| 1363 | REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedPathEffectKey().count())); |
| 1364 | REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedFullStyleKey().count())); |
| 1365 | REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedPathEffectThenStrokeKey().count())); |
| 1366 | } |
| 1367 | } |
| 1368 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1369 | void test_path_effect_makes_empty_shape(skiatest::Reporter* reporter, const Geo& geo) { |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1370 | /** |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1371 | * This path effect returns an empty path (possibly inverted) |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1372 | */ |
| 1373 | class EmptyPathEffect : SkPathEffect { |
| 1374 | public: |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 1375 | static sk_sp<SkPathEffect> Make(bool invert) { |
| 1376 | return sk_sp<SkPathEffect>(new EmptyPathEffect(invert)); |
| 1377 | } |
| 1378 | Factory getFactory() const override { return nullptr; } |
Mike Klein | 4fee323 | 2018-10-18 17:27:16 -0400 | [diff] [blame] | 1379 | const char* getTypeName() const override { return nullptr; } |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 1380 | protected: |
| 1381 | bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, |
| 1382 | const SkRect* cullR) const override { |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1383 | dst->reset(); |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1384 | if (fInvert) { |
| 1385 | dst->toggleInverseFillType(); |
| 1386 | } |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1387 | return true; |
| 1388 | } |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 1389 | SkRect onComputeFastBounds(const SkRect& src) const override { |
| 1390 | return { 0, 0, 0, 0 }; |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1391 | } |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1392 | private: |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1393 | bool fInvert; |
| 1394 | EmptyPathEffect(bool invert) : fInvert(invert) {} |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1395 | }; |
| 1396 | |
| 1397 | SkPath emptyPath; |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1398 | GrStyledShape emptyShape(emptyPath); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1399 | Key emptyKey; |
| 1400 | make_key(&emptyKey, emptyShape); |
bsalomon | 7c73a53 | 2016-05-11 15:15:56 -0700 | [diff] [blame] | 1401 | REPORTER_ASSERT(reporter, emptyShape.isEmpty()); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1402 | |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1403 | emptyPath.toggleInverseFillType(); |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1404 | GrStyledShape invertedEmptyShape(emptyPath); |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1405 | Key invertedEmptyKey; |
| 1406 | make_key(&invertedEmptyKey, invertedEmptyShape); |
| 1407 | REPORTER_ASSERT(reporter, invertedEmptyShape.isEmpty()); |
| 1408 | |
| 1409 | REPORTER_ASSERT(reporter, invertedEmptyKey != emptyKey); |
| 1410 | |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1411 | SkPaint pe; |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1412 | pe.setPathEffect(EmptyPathEffect::Make(false)); |
| 1413 | TestCase geoPECase(geo, pe, reporter); |
| 1414 | REPORTER_ASSERT(reporter, geoPECase.appliedFullStyleKey() == emptyKey); |
| 1415 | REPORTER_ASSERT(reporter, geoPECase.appliedPathEffectKey() == emptyKey); |
| 1416 | REPORTER_ASSERT(reporter, geoPECase.appliedPathEffectThenStrokeKey() == emptyKey); |
| 1417 | REPORTER_ASSERT(reporter, geoPECase.appliedPathEffectShape().isEmpty()); |
| 1418 | REPORTER_ASSERT(reporter, geoPECase.appliedFullStyleShape().isEmpty()); |
| 1419 | REPORTER_ASSERT(reporter, !geoPECase.appliedPathEffectShape().inverseFilled()); |
| 1420 | REPORTER_ASSERT(reporter, !geoPECase.appliedFullStyleShape().inverseFilled()); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1421 | |
| 1422 | SkPaint peStroke; |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1423 | peStroke.setPathEffect(EmptyPathEffect::Make(false)); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1424 | peStroke.setStrokeWidth(2.f); |
| 1425 | peStroke.setStyle(SkPaint::kStroke_Style); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 1426 | TestCase geoPEStrokeCase(geo, peStroke, reporter); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1427 | REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleKey() == emptyKey); |
| 1428 | REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectKey() == emptyKey); |
| 1429 | REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectThenStrokeKey() == emptyKey); |
bsalomon | 7c73a53 | 2016-05-11 15:15:56 -0700 | [diff] [blame] | 1430 | REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectShape().isEmpty()); |
| 1431 | REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleShape().isEmpty()); |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1432 | REPORTER_ASSERT(reporter, !geoPEStrokeCase.appliedPathEffectShape().inverseFilled()); |
| 1433 | REPORTER_ASSERT(reporter, !geoPEStrokeCase.appliedFullStyleShape().inverseFilled()); |
| 1434 | pe.setPathEffect(EmptyPathEffect::Make(true)); |
| 1435 | |
| 1436 | TestCase geoPEInvertCase(geo, pe, reporter); |
| 1437 | REPORTER_ASSERT(reporter, geoPEInvertCase.appliedFullStyleKey() == invertedEmptyKey); |
| 1438 | REPORTER_ASSERT(reporter, geoPEInvertCase.appliedPathEffectKey() == invertedEmptyKey); |
| 1439 | REPORTER_ASSERT(reporter, geoPEInvertCase.appliedPathEffectThenStrokeKey() == invertedEmptyKey); |
| 1440 | REPORTER_ASSERT(reporter, geoPEInvertCase.appliedPathEffectShape().isEmpty()); |
| 1441 | REPORTER_ASSERT(reporter, geoPEInvertCase.appliedFullStyleShape().isEmpty()); |
| 1442 | REPORTER_ASSERT(reporter, geoPEInvertCase.appliedPathEffectShape().inverseFilled()); |
| 1443 | REPORTER_ASSERT(reporter, geoPEInvertCase.appliedFullStyleShape().inverseFilled()); |
| 1444 | |
| 1445 | peStroke.setPathEffect(EmptyPathEffect::Make(true)); |
| 1446 | TestCase geoPEInvertStrokeCase(geo, peStroke, reporter); |
| 1447 | REPORTER_ASSERT(reporter, geoPEInvertStrokeCase.appliedFullStyleKey() == invertedEmptyKey); |
| 1448 | REPORTER_ASSERT(reporter, geoPEInvertStrokeCase.appliedPathEffectKey() == invertedEmptyKey); |
| 1449 | REPORTER_ASSERT(reporter, |
| 1450 | geoPEInvertStrokeCase.appliedPathEffectThenStrokeKey() == invertedEmptyKey); |
| 1451 | REPORTER_ASSERT(reporter, geoPEInvertStrokeCase.appliedPathEffectShape().isEmpty()); |
| 1452 | REPORTER_ASSERT(reporter, geoPEInvertStrokeCase.appliedFullStyleShape().isEmpty()); |
| 1453 | REPORTER_ASSERT(reporter, geoPEInvertStrokeCase.appliedPathEffectShape().inverseFilled()); |
| 1454 | REPORTER_ASSERT(reporter, geoPEInvertStrokeCase.appliedFullStyleShape().inverseFilled()); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1457 | void test_path_effect_fails(skiatest::Reporter* reporter, const Geo& geo) { |
bsalomon | d672384 | 2016-06-07 12:20:15 -0700 | [diff] [blame] | 1458 | /** |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 1459 | * This path effect always fails to apply. |
bsalomon | d672384 | 2016-06-07 12:20:15 -0700 | [diff] [blame] | 1460 | */ |
| 1461 | class FailurePathEffect : SkPathEffect { |
| 1462 | public: |
bsalomon | d672384 | 2016-06-07 12:20:15 -0700 | [diff] [blame] | 1463 | static sk_sp<SkPathEffect> Make() { return sk_sp<SkPathEffect>(new FailurePathEffect); } |
| 1464 | Factory getFactory() const override { return nullptr; } |
Mike Klein | 4fee323 | 2018-10-18 17:27:16 -0400 | [diff] [blame] | 1465 | const char* getTypeName() const override { return nullptr; } |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 1466 | protected: |
| 1467 | bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, |
| 1468 | const SkRect* cullR) const override { |
| 1469 | return false; |
| 1470 | } |
bsalomon | d672384 | 2016-06-07 12:20:15 -0700 | [diff] [blame] | 1471 | private: |
| 1472 | FailurePathEffect() {} |
| 1473 | }; |
| 1474 | |
| 1475 | SkPaint fill; |
| 1476 | TestCase fillCase(geo, fill, reporter); |
| 1477 | |
| 1478 | SkPaint pe; |
| 1479 | pe.setPathEffect(FailurePathEffect::Make()); |
| 1480 | TestCase peCase(geo, pe, reporter); |
| 1481 | |
| 1482 | SkPaint stroke; |
| 1483 | stroke.setStrokeWidth(2.f); |
| 1484 | stroke.setStyle(SkPaint::kStroke_Style); |
| 1485 | TestCase strokeCase(geo, stroke, reporter); |
| 1486 | |
| 1487 | SkPaint peStroke = stroke; |
| 1488 | peStroke.setPathEffect(FailurePathEffect::Make()); |
| 1489 | TestCase peStrokeCase(geo, peStroke, reporter); |
| 1490 | |
| 1491 | // In general the path effect failure can cause some of the TestCase::compare() tests to fail |
| 1492 | // for at least two reasons: 1) We will initially treat the shape as unkeyable because of the |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1493 | // path effect, but then when the path effect fails we can key it. 2) GrStyledShape will change |
| 1494 | // its mind about whether a unclosed rect is actually rect. The path effect initially bars us |
| 1495 | // from closing it but after the effect fails we can (for the fill+pe case). This causes |
| 1496 | // different routes through GrStyledShape to have equivalent but different representations of |
| 1497 | // the path (closed or not) but that fill the same. |
bsalomon | d672384 | 2016-06-07 12:20:15 -0700 | [diff] [blame] | 1498 | SkPath a; |
| 1499 | SkPath b; |
| 1500 | fillCase.appliedPathEffectShape().asPath(&a); |
| 1501 | peCase.appliedPathEffectShape().asPath(&b); |
| 1502 | REPORTER_ASSERT(reporter, paths_fill_same(a, b)); |
| 1503 | |
| 1504 | fillCase.appliedFullStyleShape().asPath(&a); |
| 1505 | peCase.appliedFullStyleShape().asPath(&b); |
| 1506 | REPORTER_ASSERT(reporter, paths_fill_same(a, b)); |
| 1507 | |
| 1508 | strokeCase.appliedPathEffectShape().asPath(&a); |
| 1509 | peStrokeCase.appliedPathEffectShape().asPath(&b); |
| 1510 | REPORTER_ASSERT(reporter, paths_fill_same(a, b)); |
| 1511 | |
| 1512 | strokeCase.appliedFullStyleShape().asPath(&a); |
| 1513 | peStrokeCase.appliedFullStyleShape().asPath(&b); |
| 1514 | REPORTER_ASSERT(reporter, paths_fill_same(a, b)); |
| 1515 | } |
| 1516 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1517 | DEF_TEST(GrStyledShape_empty_shape, reporter) { |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1518 | SkPath emptyPath; |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1519 | SkPath invertedEmptyPath; |
| 1520 | invertedEmptyPath.toggleInverseFillType(); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1521 | SkPaint fill; |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1522 | TestCase fillEmptyCase(reporter, emptyPath, fill); |
bsalomon | 7c73a53 | 2016-05-11 15:15:56 -0700 | [diff] [blame] | 1523 | REPORTER_ASSERT(reporter, fillEmptyCase.baseShape().isEmpty()); |
| 1524 | REPORTER_ASSERT(reporter, fillEmptyCase.appliedPathEffectShape().isEmpty()); |
| 1525 | REPORTER_ASSERT(reporter, fillEmptyCase.appliedFullStyleShape().isEmpty()); |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1526 | REPORTER_ASSERT(reporter, !fillEmptyCase.baseShape().inverseFilled()); |
| 1527 | REPORTER_ASSERT(reporter, !fillEmptyCase.appliedPathEffectShape().inverseFilled()); |
| 1528 | REPORTER_ASSERT(reporter, !fillEmptyCase.appliedFullStyleShape().inverseFilled()); |
| 1529 | TestCase fillInvertedEmptyCase(reporter, invertedEmptyPath, fill); |
| 1530 | REPORTER_ASSERT(reporter, fillInvertedEmptyCase.baseShape().isEmpty()); |
| 1531 | REPORTER_ASSERT(reporter, fillInvertedEmptyCase.appliedPathEffectShape().isEmpty()); |
| 1532 | REPORTER_ASSERT(reporter, fillInvertedEmptyCase.appliedFullStyleShape().isEmpty()); |
| 1533 | REPORTER_ASSERT(reporter, fillInvertedEmptyCase.baseShape().inverseFilled()); |
| 1534 | REPORTER_ASSERT(reporter, fillInvertedEmptyCase.appliedPathEffectShape().inverseFilled()); |
| 1535 | REPORTER_ASSERT(reporter, fillInvertedEmptyCase.appliedFullStyleShape().inverseFilled()); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1536 | |
| 1537 | Key emptyKey(fillEmptyCase.baseKey()); |
| 1538 | REPORTER_ASSERT(reporter, emptyKey.count()); |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1539 | Key inverseEmptyKey(fillInvertedEmptyCase.baseKey()); |
| 1540 | REPORTER_ASSERT(reporter, inverseEmptyKey.count()); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1541 | TestCase::SelfExpectations expectations; |
| 1542 | expectations.fStrokeApplies = false; |
| 1543 | expectations.fPEHasEffect = false; |
| 1544 | // This will test whether applying style preserves emptiness |
| 1545 | fillEmptyCase.testExpectations(reporter, expectations); |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1546 | fillInvertedEmptyCase.testExpectations(reporter, expectations); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1547 | |
| 1548 | // Stroking an empty path should have no effect |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1549 | SkPaint stroke; |
| 1550 | stroke.setStrokeWidth(2.f); |
| 1551 | stroke.setStyle(SkPaint::kStroke_Style); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1552 | stroke.setStrokeJoin(SkPaint::kRound_Join); |
| 1553 | stroke.setStrokeCap(SkPaint::kRound_Cap); |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1554 | TestCase strokeEmptyCase(reporter, emptyPath, stroke); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1555 | strokeEmptyCase.compare(reporter, fillEmptyCase, TestCase::kAllSame_ComparisonExpecation); |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1556 | TestCase strokeInvertedEmptyCase(reporter, invertedEmptyPath, stroke); |
| 1557 | strokeInvertedEmptyCase.compare(reporter, fillInvertedEmptyCase, |
| 1558 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1559 | |
| 1560 | // Dashing and stroking an empty path should have no effect |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1561 | SkPaint dashAndStroke; |
| 1562 | dashAndStroke.setPathEffect(make_dash()); |
| 1563 | dashAndStroke.setStrokeWidth(2.f); |
| 1564 | dashAndStroke.setStyle(SkPaint::kStroke_Style); |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1565 | TestCase dashAndStrokeEmptyCase(reporter, emptyPath, dashAndStroke); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1566 | dashAndStrokeEmptyCase.compare(reporter, fillEmptyCase, |
| 1567 | TestCase::kAllSame_ComparisonExpecation); |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1568 | TestCase dashAndStrokeInvertexEmptyCase(reporter, invertedEmptyPath, dashAndStroke); |
| 1569 | // Dashing ignores inverseness so this is equivalent to the non-inverted empty fill. |
| 1570 | dashAndStrokeInvertexEmptyCase.compare(reporter, fillEmptyCase, |
| 1571 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 5e410b4 | 2016-04-28 09:30:46 -0700 | [diff] [blame] | 1572 | |
Michael Ludwig | f38b711 | 2020-04-30 13:47:00 -0400 | [diff] [blame] | 1573 | // A shape made from an empty rrect should behave the same as an empty path when filled and |
| 1574 | // when stroked. The shape is closed so it does not produce caps when stroked. When dashed there |
| 1575 | // is no path to dash along, making it equivalent as well. |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1576 | SkRRect emptyRRect = SkRRect::MakeEmpty(); |
bsalomon | 5e410b4 | 2016-04-28 09:30:46 -0700 | [diff] [blame] | 1577 | REPORTER_ASSERT(reporter, emptyRRect.getType() == SkRRect::kEmpty_Type); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1578 | |
| 1579 | TestCase fillEmptyRRectCase(reporter, emptyRRect, fill); |
| 1580 | fillEmptyRRectCase.compare(reporter, fillEmptyCase, TestCase::kAllSame_ComparisonExpecation); |
| 1581 | |
| 1582 | TestCase strokeEmptyRRectCase(reporter, emptyRRect, stroke); |
| 1583 | strokeEmptyRRectCase.compare(reporter, strokeEmptyCase, |
Michael Ludwig | f38b711 | 2020-04-30 13:47:00 -0400 | [diff] [blame] | 1584 | TestCase::kAllSame_ComparisonExpecation); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1585 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1586 | TestCase dashAndStrokeEmptyRRectCase(reporter, emptyRRect, dashAndStroke); |
bsalomon | 5e410b4 | 2016-04-28 09:30:46 -0700 | [diff] [blame] | 1587 | dashAndStrokeEmptyRRectCase.compare(reporter, fillEmptyCase, |
| 1588 | TestCase::kAllSame_ComparisonExpecation); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1589 | |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1590 | static constexpr SkPathDirection kDir = SkPathDirection::kCCW; |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1591 | static constexpr int kStart = 0; |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1592 | |
| 1593 | TestCase fillInvertedEmptyRRectCase(reporter, emptyRRect, kDir, kStart, true, GrStyle(fill)); |
| 1594 | fillInvertedEmptyRRectCase.compare(reporter, fillInvertedEmptyCase, |
| 1595 | TestCase::kAllSame_ComparisonExpecation); |
| 1596 | |
| 1597 | TestCase strokeInvertedEmptyRRectCase(reporter, emptyRRect, kDir, kStart, true, |
| 1598 | GrStyle(stroke)); |
| 1599 | strokeInvertedEmptyRRectCase.compare(reporter, strokeInvertedEmptyCase, |
Michael Ludwig | f38b711 | 2020-04-30 13:47:00 -0400 | [diff] [blame] | 1600 | TestCase::kAllSame_ComparisonExpecation); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1601 | |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1602 | TestCase dashAndStrokeEmptyInvertedRRectCase(reporter, emptyRRect, kDir, kStart, true, |
| 1603 | GrStyle(dashAndStroke)); |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1604 | dashAndStrokeEmptyInvertedRRectCase.compare(reporter, fillEmptyCase, |
| 1605 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 5e410b4 | 2016-04-28 09:30:46 -0700 | [diff] [blame] | 1606 | |
| 1607 | // Same for a rect. |
| 1608 | SkRect emptyRect = SkRect::MakeEmpty(); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1609 | TestCase fillEmptyRectCase(reporter, emptyRect, fill); |
| 1610 | fillEmptyRectCase.compare(reporter, fillEmptyCase, TestCase::kAllSame_ComparisonExpecation); |
| 1611 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1612 | TestCase dashAndStrokeEmptyRectCase(reporter, emptyRect, dashAndStroke); |
bsalomon | 5e410b4 | 2016-04-28 09:30:46 -0700 | [diff] [blame] | 1613 | dashAndStrokeEmptyRectCase.compare(reporter, fillEmptyCase, |
| 1614 | TestCase::kAllSame_ComparisonExpecation); |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 1615 | |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1616 | TestCase dashAndStrokeEmptyInvertedRectCase(reporter, SkRRect::MakeRect(emptyRect), kDir, |
| 1617 | kStart, true, GrStyle(dashAndStroke)); |
| 1618 | // Dashing ignores inverseness so this is equivalent to the non-inverted empty fill. |
| 1619 | dashAndStrokeEmptyInvertedRectCase.compare(reporter, fillEmptyCase, |
| 1620 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1623 | // rect and oval types have rrect start indices that collapse to the same point. Here we select the |
| 1624 | // canonical point in these cases. |
| 1625 | unsigned canonicalize_rrect_start(int s, const SkRRect& rrect) { |
| 1626 | switch (rrect.getType()) { |
| 1627 | case SkRRect::kRect_Type: |
| 1628 | return (s + 1) & 0b110; |
| 1629 | case SkRRect::kOval_Type: |
| 1630 | return s & 0b110; |
| 1631 | default: |
| 1632 | return s; |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | void test_rrect(skiatest::Reporter* r, const SkRRect& rrect) { |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1637 | enum Style { |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1638 | kFill, |
| 1639 | kStroke, |
| 1640 | kHairline, |
| 1641 | kStrokeAndFill |
| 1642 | }; |
| 1643 | |
| 1644 | // SkStrokeRec has no default cons., so init with kFill before calling the setters below. |
| 1645 | SkStrokeRec strokeRecs[4] { SkStrokeRec::kFill_InitStyle, SkStrokeRec::kFill_InitStyle, |
| 1646 | SkStrokeRec::kFill_InitStyle, SkStrokeRec::kFill_InitStyle}; |
| 1647 | strokeRecs[kFill].setFillStyle(); |
| 1648 | strokeRecs[kStroke].setStrokeStyle(2.f); |
| 1649 | strokeRecs[kHairline].setHairlineStyle(); |
| 1650 | strokeRecs[kStrokeAndFill].setStrokeStyle(3.f, true); |
bsalomon | 487f8d3 | 2016-07-20 07:15:44 -0700 | [diff] [blame] | 1651 | // Use a bevel join to avoid complications of stroke+filled rects becoming filled rects before |
| 1652 | // applyStyle() is called. |
| 1653 | strokeRecs[kStrokeAndFill].setStrokeParams(SkPaint::kButt_Cap, SkPaint::kBevel_Join, 1.f); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1654 | sk_sp<SkPathEffect> dashEffect = make_dash(); |
| 1655 | |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1656 | static constexpr Style kStyleCnt = static_cast<Style>(SK_ARRAY_COUNT(strokeRecs)); |
| 1657 | |
| 1658 | auto index = [](bool inverted, |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1659 | SkPathDirection dir, |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1660 | unsigned start, |
| 1661 | Style style, |
| 1662 | bool dash) -> int { |
| 1663 | return inverted * (2 * 8 * kStyleCnt * 2) + |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1664 | (int)dir * ( 8 * kStyleCnt * 2) + |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1665 | start * ( kStyleCnt * 2) + |
| 1666 | style * ( 2) + |
| 1667 | dash; |
| 1668 | }; |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1669 | static const SkPathDirection kSecondDirection = static_cast<SkPathDirection>(1); |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1670 | const int cnt = index(true, kSecondDirection, 7, static_cast<Style>(kStyleCnt - 1), true) + 1; |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1671 | SkAutoTArray<GrStyledShape> shapes(cnt); |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1672 | for (bool inverted : {false, true}) { |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1673 | for (SkPathDirection dir : {SkPathDirection::kCW, SkPathDirection::kCCW}) { |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1674 | for (unsigned start = 0; start < 8; ++start) { |
| 1675 | for (Style style : {kFill, kStroke, kHairline, kStrokeAndFill}) { |
| 1676 | for (bool dash : {false, true}) { |
Robert Phillips | f809c1e | 2017-01-13 11:02:42 -0500 | [diff] [blame] | 1677 | sk_sp<SkPathEffect> pe = dash ? dashEffect : nullptr; |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1678 | shapes[index(inverted, dir, start, style, dash)] = |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1679 | GrStyledShape(rrect, dir, start, SkToBool(inverted), |
Robert Phillips | f809c1e | 2017-01-13 11:02:42 -0500 | [diff] [blame] | 1680 | GrStyle(strokeRecs[style], std::move(pe))); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1681 | } |
| 1682 | } |
| 1683 | } |
| 1684 | } |
| 1685 | } |
| 1686 | |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1687 | // Get the keys for some example shape instances that we'll use for comparision against the |
| 1688 | // rest. |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1689 | static constexpr SkPathDirection kExamplesDir = SkPathDirection::kCW; |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1690 | static constexpr unsigned kExamplesStart = 0; |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1691 | const GrStyledShape& exampleFillCase = shapes[index(false, kExamplesDir, kExamplesStart, kFill, |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1692 | false)]; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1693 | Key exampleFillCaseKey; |
| 1694 | make_key(&exampleFillCaseKey, exampleFillCase); |
| 1695 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1696 | const GrStyledShape& exampleStrokeAndFillCase = shapes[index(false, kExamplesDir, |
| 1697 | kExamplesStart, kStrokeAndFill, false)]; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1698 | Key exampleStrokeAndFillCaseKey; |
| 1699 | make_key(&exampleStrokeAndFillCaseKey, exampleStrokeAndFillCase); |
| 1700 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1701 | const GrStyledShape& exampleInvFillCase = shapes[index(true, kExamplesDir, |
| 1702 | kExamplesStart, kFill, false)]; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1703 | Key exampleInvFillCaseKey; |
| 1704 | make_key(&exampleInvFillCaseKey, exampleInvFillCase); |
| 1705 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1706 | const GrStyledShape& exampleInvStrokeAndFillCase = shapes[index(true, kExamplesDir, |
| 1707 | kExamplesStart, kStrokeAndFill, |
| 1708 | false)]; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1709 | Key exampleInvStrokeAndFillCaseKey; |
| 1710 | make_key(&exampleInvStrokeAndFillCaseKey, exampleInvStrokeAndFillCase); |
| 1711 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1712 | const GrStyledShape& exampleStrokeCase = shapes[index(false, kExamplesDir, kExamplesStart, |
| 1713 | kStroke, false)]; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1714 | Key exampleStrokeCaseKey; |
| 1715 | make_key(&exampleStrokeCaseKey, exampleStrokeCase); |
| 1716 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1717 | const GrStyledShape& exampleInvStrokeCase = shapes[index(true, kExamplesDir, kExamplesStart, |
| 1718 | kStroke, false)]; |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1719 | Key exampleInvStrokeCaseKey; |
| 1720 | make_key(&exampleInvStrokeCaseKey, exampleInvStrokeCase); |
| 1721 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1722 | const GrStyledShape& exampleHairlineCase = shapes[index(false, kExamplesDir, kExamplesStart, |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1723 | kHairline, false)]; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1724 | Key exampleHairlineCaseKey; |
| 1725 | make_key(&exampleHairlineCaseKey, exampleHairlineCase); |
| 1726 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1727 | const GrStyledShape& exampleInvHairlineCase = shapes[index(true, kExamplesDir, kExamplesStart, |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1728 | kHairline, false)]; |
| 1729 | Key exampleInvHairlineCaseKey; |
| 1730 | make_key(&exampleInvHairlineCaseKey, exampleInvHairlineCase); |
| 1731 | |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1732 | // These are dummy initializations to suppress warnings. |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1733 | SkRRect queryRR = SkRRect::MakeEmpty(); |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1734 | SkPathDirection queryDir = SkPathDirection::kCW; |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1735 | unsigned queryStart = ~0U; |
| 1736 | bool queryInverted = true; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1737 | |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1738 | REPORTER_ASSERT(r, exampleFillCase.asRRect(&queryRR, &queryDir, &queryStart, &queryInverted)); |
| 1739 | REPORTER_ASSERT(r, queryRR == rrect); |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1740 | REPORTER_ASSERT(r, SkPathDirection::kCW == queryDir); |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1741 | REPORTER_ASSERT(r, 0 == queryStart); |
| 1742 | REPORTER_ASSERT(r, !queryInverted); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1743 | |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1744 | REPORTER_ASSERT(r, exampleInvFillCase.asRRect(&queryRR, &queryDir, &queryStart, |
| 1745 | &queryInverted)); |
| 1746 | REPORTER_ASSERT(r, queryRR == rrect); |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1747 | REPORTER_ASSERT(r, SkPathDirection::kCW == queryDir); |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1748 | REPORTER_ASSERT(r, 0 == queryStart); |
| 1749 | REPORTER_ASSERT(r, queryInverted); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1750 | |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1751 | REPORTER_ASSERT(r, exampleStrokeAndFillCase.asRRect(&queryRR, &queryDir, &queryStart, |
| 1752 | &queryInverted)); |
| 1753 | REPORTER_ASSERT(r, queryRR == rrect); |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1754 | REPORTER_ASSERT(r, SkPathDirection::kCW == queryDir); |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1755 | REPORTER_ASSERT(r, 0 == queryStart); |
| 1756 | REPORTER_ASSERT(r, !queryInverted); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1757 | |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1758 | REPORTER_ASSERT(r, exampleInvStrokeAndFillCase.asRRect(&queryRR, &queryDir, &queryStart, |
| 1759 | &queryInverted)); |
| 1760 | REPORTER_ASSERT(r, queryRR == rrect); |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1761 | REPORTER_ASSERT(r, SkPathDirection::kCW == queryDir); |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1762 | REPORTER_ASSERT(r, 0 == queryStart); |
| 1763 | REPORTER_ASSERT(r, queryInverted); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1764 | |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1765 | REPORTER_ASSERT(r, exampleHairlineCase.asRRect(&queryRR, &queryDir, &queryStart, |
| 1766 | &queryInverted)); |
| 1767 | REPORTER_ASSERT(r, queryRR == rrect); |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1768 | REPORTER_ASSERT(r, SkPathDirection::kCW == queryDir); |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1769 | REPORTER_ASSERT(r, 0 == queryStart); |
| 1770 | REPORTER_ASSERT(r, !queryInverted); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1771 | |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1772 | REPORTER_ASSERT(r, exampleInvHairlineCase.asRRect(&queryRR, &queryDir, &queryStart, |
| 1773 | &queryInverted)); |
| 1774 | REPORTER_ASSERT(r, queryRR == rrect); |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1775 | REPORTER_ASSERT(r, SkPathDirection::kCW == queryDir); |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1776 | REPORTER_ASSERT(r, 0 == queryStart); |
| 1777 | REPORTER_ASSERT(r, queryInverted); |
| 1778 | |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1779 | REPORTER_ASSERT(r, exampleStrokeCase.asRRect(&queryRR, &queryDir, &queryStart, &queryInverted)); |
| 1780 | REPORTER_ASSERT(r, queryRR == rrect); |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1781 | REPORTER_ASSERT(r, SkPathDirection::kCW == queryDir); |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1782 | REPORTER_ASSERT(r, 0 == queryStart); |
| 1783 | REPORTER_ASSERT(r, !queryInverted); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1784 | |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1785 | REPORTER_ASSERT(r, exampleInvStrokeCase.asRRect(&queryRR, &queryDir, &queryStart, |
| 1786 | &queryInverted)); |
| 1787 | REPORTER_ASSERT(r, queryRR == rrect); |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1788 | REPORTER_ASSERT(r, SkPathDirection::kCW == queryDir); |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1789 | REPORTER_ASSERT(r, 0 == queryStart); |
| 1790 | REPORTER_ASSERT(r, queryInverted); |
| 1791 | |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1792 | // Remember that the key reflects the geometry before styling is applied. |
| 1793 | REPORTER_ASSERT(r, exampleFillCaseKey != exampleInvFillCaseKey); |
| 1794 | REPORTER_ASSERT(r, exampleFillCaseKey == exampleStrokeAndFillCaseKey); |
| 1795 | REPORTER_ASSERT(r, exampleFillCaseKey != exampleInvStrokeAndFillCaseKey); |
| 1796 | REPORTER_ASSERT(r, exampleFillCaseKey == exampleStrokeCaseKey); |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1797 | REPORTER_ASSERT(r, exampleFillCaseKey != exampleInvStrokeCaseKey); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1798 | REPORTER_ASSERT(r, exampleFillCaseKey == exampleHairlineCaseKey); |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1799 | REPORTER_ASSERT(r, exampleFillCaseKey != exampleInvHairlineCaseKey); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1800 | REPORTER_ASSERT(r, exampleInvStrokeAndFillCaseKey == exampleInvFillCaseKey); |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1801 | REPORTER_ASSERT(r, exampleInvStrokeAndFillCaseKey == exampleInvStrokeCaseKey); |
| 1802 | REPORTER_ASSERT(r, exampleInvStrokeAndFillCaseKey == exampleInvHairlineCaseKey); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1803 | |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1804 | for (bool inverted : {false, true}) { |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1805 | for (SkPathDirection dir : {SkPathDirection::kCW, SkPathDirection::kCCW}) { |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1806 | for (unsigned start = 0; start < 8; ++start) { |
| 1807 | for (bool dash : {false, true}) { |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1808 | const GrStyledShape& fillCase = shapes[index(inverted, dir, start, kFill, |
| 1809 | dash)]; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1810 | Key fillCaseKey; |
| 1811 | make_key(&fillCaseKey, fillCase); |
| 1812 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1813 | const GrStyledShape& strokeAndFillCase = shapes[index(inverted, dir, start, |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1814 | kStrokeAndFill, dash)]; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1815 | Key strokeAndFillCaseKey; |
| 1816 | make_key(&strokeAndFillCaseKey, strokeAndFillCase); |
| 1817 | |
| 1818 | // Both fill and stroke-and-fill shapes must respect the inverseness and both |
| 1819 | // ignore dashing. |
| 1820 | REPORTER_ASSERT(r, !fillCase.style().pathEffect()); |
| 1821 | REPORTER_ASSERT(r, !strokeAndFillCase.style().pathEffect()); |
| 1822 | TestCase a(fillCase, r); |
| 1823 | TestCase b(inverted ? exampleInvFillCase : exampleFillCase, r); |
| 1824 | TestCase c(strokeAndFillCase, r); |
| 1825 | TestCase d(inverted ? exampleInvStrokeAndFillCase |
| 1826 | : exampleStrokeAndFillCase, r); |
| 1827 | a.compare(r, b, TestCase::kAllSame_ComparisonExpecation); |
| 1828 | c.compare(r, d, TestCase::kAllSame_ComparisonExpecation); |
| 1829 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1830 | const GrStyledShape& strokeCase = shapes[index(inverted, dir, start, kStroke, |
| 1831 | dash)]; |
| 1832 | const GrStyledShape& hairlineCase = shapes[index(inverted, dir, start, |
| 1833 | kHairline, dash)]; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1834 | |
| 1835 | TestCase e(strokeCase, r); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1836 | TestCase g(hairlineCase, r); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1837 | |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1838 | // Both hairline and stroke shapes must respect the dashing. |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1839 | if (dash) { |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1840 | // Dashing always ignores the inverseness. skbug.com/5421 |
| 1841 | TestCase f(exampleStrokeCase, r); |
| 1842 | TestCase h(exampleHairlineCase, r); |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1843 | unsigned expectedStart = canonicalize_rrect_start(start, rrect); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1844 | REPORTER_ASSERT(r, strokeCase.style().pathEffect()); |
| 1845 | REPORTER_ASSERT(r, hairlineCase.style().pathEffect()); |
| 1846 | |
bsalomon | cadb5a2 | 2016-06-10 18:28:06 -0700 | [diff] [blame] | 1847 | REPORTER_ASSERT(r, strokeCase.asRRect(&queryRR, &queryDir, &queryStart, |
| 1848 | &queryInverted)); |
| 1849 | REPORTER_ASSERT(r, queryRR == rrect); |
| 1850 | REPORTER_ASSERT(r, queryDir == dir); |
| 1851 | REPORTER_ASSERT(r, queryStart == expectedStart); |
| 1852 | REPORTER_ASSERT(r, !queryInverted); |
| 1853 | REPORTER_ASSERT(r, hairlineCase.asRRect(&queryRR, &queryDir, &queryStart, |
| 1854 | &queryInverted)); |
| 1855 | REPORTER_ASSERT(r, queryRR == rrect); |
| 1856 | REPORTER_ASSERT(r, queryDir == dir); |
| 1857 | REPORTER_ASSERT(r, queryStart == expectedStart); |
| 1858 | REPORTER_ASSERT(r, !queryInverted); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1859 | |
| 1860 | // The pre-style case for the dash will match the non-dash example iff the |
| 1861 | // dir and start match (dir=cw, start=0). |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1862 | if (0 == expectedStart && SkPathDirection::kCW == dir) { |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1863 | e.compare(r, f, TestCase::kSameUpToPE_ComparisonExpecation); |
| 1864 | g.compare(r, h, TestCase::kSameUpToPE_ComparisonExpecation); |
| 1865 | } else { |
| 1866 | e.compare(r, f, TestCase::kAllDifferent_ComparisonExpecation); |
| 1867 | g.compare(r, h, TestCase::kAllDifferent_ComparisonExpecation); |
| 1868 | } |
| 1869 | } else { |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 1870 | TestCase f(inverted ? exampleInvStrokeCase : exampleStrokeCase, r); |
| 1871 | TestCase h(inverted ? exampleInvHairlineCase : exampleHairlineCase, r); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 1872 | REPORTER_ASSERT(r, !strokeCase.style().pathEffect()); |
| 1873 | REPORTER_ASSERT(r, !hairlineCase.style().pathEffect()); |
| 1874 | e.compare(r, f, TestCase::kAllSame_ComparisonExpecation); |
| 1875 | g.compare(r, h, TestCase::kAllSame_ComparisonExpecation); |
| 1876 | } |
| 1877 | } |
| 1878 | } |
| 1879 | } |
| 1880 | } |
| 1881 | } |
| 1882 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1883 | DEF_TEST(GrStyledShape_lines, r) { |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 1884 | static constexpr SkPoint kA { 1, 1}; |
| 1885 | static constexpr SkPoint kB { 5, -9}; |
| 1886 | static constexpr SkPoint kC {-3, 17}; |
| 1887 | |
| 1888 | SkPath lineAB; |
| 1889 | lineAB.moveTo(kA); |
| 1890 | lineAB.lineTo(kB); |
| 1891 | |
| 1892 | SkPath lineBA; |
| 1893 | lineBA.moveTo(kB); |
| 1894 | lineBA.lineTo(kA); |
| 1895 | |
| 1896 | SkPath lineAC; |
| 1897 | lineAC.moveTo(kB); |
| 1898 | lineAC.lineTo(kC); |
| 1899 | |
| 1900 | SkPath invLineAB = lineAB; |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 1901 | invLineAB.setFillType(SkPathFillType::kInverseEvenOdd); |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 1902 | |
| 1903 | SkPaint fill; |
| 1904 | SkPaint stroke; |
| 1905 | stroke.setStyle(SkPaint::kStroke_Style); |
| 1906 | stroke.setStrokeWidth(2.f); |
| 1907 | SkPaint hairline; |
| 1908 | hairline.setStyle(SkPaint::kStroke_Style); |
| 1909 | hairline.setStrokeWidth(0.f); |
| 1910 | SkPaint dash = stroke; |
| 1911 | dash.setPathEffect(make_dash()); |
| 1912 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1913 | TestCase fillAB(r, lineAB, fill); |
| 1914 | TestCase fillEmpty(r, SkPath(), fill); |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 1915 | fillAB.compare(r, fillEmpty, TestCase::kAllSame_ComparisonExpecation); |
| 1916 | REPORTER_ASSERT(r, !fillAB.baseShape().asLine(nullptr, nullptr)); |
| 1917 | |
Brian Salomon | 085c086 | 2017-08-31 15:44:51 -0400 | [diff] [blame] | 1918 | SkPath path; |
| 1919 | path.toggleInverseFillType(); |
| 1920 | TestCase fillEmptyInverted(r, path, fill); |
| 1921 | TestCase fillABInverted(r, invLineAB, fill); |
| 1922 | fillABInverted.compare(r, fillEmptyInverted, TestCase::kAllSame_ComparisonExpecation); |
| 1923 | REPORTER_ASSERT(r, !fillABInverted.baseShape().asLine(nullptr, nullptr)); |
| 1924 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1925 | TestCase strokeAB(r, lineAB, stroke); |
| 1926 | TestCase strokeBA(r, lineBA, stroke); |
| 1927 | TestCase strokeAC(r, lineAC, stroke); |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 1928 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1929 | TestCase hairlineAB(r, lineAB, hairline); |
| 1930 | TestCase hairlineBA(r, lineBA, hairline); |
| 1931 | TestCase hairlineAC(r, lineAC, hairline); |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 1932 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1933 | TestCase dashAB(r, lineAB, dash); |
| 1934 | TestCase dashBA(r, lineBA, dash); |
| 1935 | TestCase dashAC(r, lineAC, dash); |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 1936 | |
| 1937 | strokeAB.compare(r, fillAB, TestCase::kAllDifferent_ComparisonExpecation); |
| 1938 | |
| 1939 | strokeAB.compare(r, strokeBA, TestCase::kAllSame_ComparisonExpecation); |
| 1940 | strokeAB.compare(r, strokeAC, TestCase::kAllDifferent_ComparisonExpecation); |
| 1941 | |
| 1942 | hairlineAB.compare(r, hairlineBA, TestCase::kAllSame_ComparisonExpecation); |
| 1943 | hairlineAB.compare(r, hairlineAC, TestCase::kAllDifferent_ComparisonExpecation); |
| 1944 | |
| 1945 | dashAB.compare(r, dashBA, TestCase::kAllDifferent_ComparisonExpecation); |
| 1946 | dashAB.compare(r, dashAC, TestCase::kAllDifferent_ComparisonExpecation); |
| 1947 | |
| 1948 | strokeAB.compare(r, hairlineAB, TestCase::kSameUpToStroke_ComparisonExpecation); |
| 1949 | |
| 1950 | // One of dashAB or dashBA should have the same line as strokeAB. It depends upon how |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1951 | // GrStyledShape canonicalizes line endpoints (when it can, i.e. when not dashed). |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 1952 | bool canonicalizeAsAB; |
| 1953 | SkPoint canonicalPts[2] {kA, kB}; |
| 1954 | // Init these to suppress warnings. |
| 1955 | bool inverted = true; |
| 1956 | SkPoint pts[2] {{0, 0}, {0, 0}}; |
| 1957 | REPORTER_ASSERT(r, strokeAB.baseShape().asLine(pts, &inverted) && !inverted); |
| 1958 | if (pts[0] == kA && pts[1] == kB) { |
| 1959 | canonicalizeAsAB = true; |
| 1960 | } else if (pts[1] == kA && pts[0] == kB) { |
| 1961 | canonicalizeAsAB = false; |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 1962 | using std::swap; |
| 1963 | swap(canonicalPts[0], canonicalPts[1]); |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 1964 | } else { |
| 1965 | ERRORF(r, "Should return pts (a,b) or (b, a)"); |
| 1966 | return; |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [diff] [blame] | 1967 | } |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 1968 | |
| 1969 | strokeAB.compare(r, canonicalizeAsAB ? dashAB : dashBA, |
| 1970 | TestCase::kSameUpToPE_ComparisonExpecation); |
| 1971 | REPORTER_ASSERT(r, strokeAB.baseShape().asLine(pts, &inverted) && !inverted && |
| 1972 | pts[0] == canonicalPts[0] && pts[1] == canonicalPts[1]); |
| 1973 | REPORTER_ASSERT(r, hairlineAB.baseShape().asLine(pts, &inverted) && !inverted && |
| 1974 | pts[0] == canonicalPts[0] && pts[1] == canonicalPts[1]); |
| 1975 | REPORTER_ASSERT(r, dashAB.baseShape().asLine(pts, &inverted) && !inverted && |
| 1976 | pts[0] == kA && pts[1] == kB); |
| 1977 | REPORTER_ASSERT(r, dashBA.baseShape().asLine(pts, &inverted) && !inverted && |
| 1978 | pts[0] == kB && pts[1] == kA); |
| 1979 | |
| 1980 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 1981 | TestCase strokeInvAB(r, invLineAB, stroke); |
| 1982 | TestCase hairlineInvAB(r, invLineAB, hairline); |
| 1983 | TestCase dashInvAB(r, invLineAB, dash); |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 1984 | strokeInvAB.compare(r, strokeAB, TestCase::kAllDifferent_ComparisonExpecation); |
| 1985 | hairlineInvAB.compare(r, hairlineAB, TestCase::kAllDifferent_ComparisonExpecation); |
| 1986 | // Dashing ignores inverse. |
| 1987 | dashInvAB.compare(r, dashAB, TestCase::kAllSame_ComparisonExpecation); |
| 1988 | |
| 1989 | REPORTER_ASSERT(r, strokeInvAB.baseShape().asLine(pts, &inverted) && inverted && |
| 1990 | pts[0] == canonicalPts[0] && pts[1] == canonicalPts[1]); |
| 1991 | REPORTER_ASSERT(r, hairlineInvAB.baseShape().asLine(pts, &inverted) && inverted && |
| 1992 | pts[0] == canonicalPts[0] && pts[1] == canonicalPts[1]); |
| 1993 | // Dashing ignores inverse. |
| 1994 | REPORTER_ASSERT(r, dashInvAB.baseShape().asLine(pts, &inverted) && !inverted && |
| 1995 | pts[0] == kA && pts[1] == kB); |
| 1996 | |
| 1997 | } |
| 1998 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 1999 | DEF_TEST(GrStyledShape_stroked_lines, r) { |
Brian Salomon | 72f78c3 | 2017-12-21 11:56:42 -0500 | [diff] [blame] | 2000 | static constexpr SkScalar kIntervals1[] = {1.f, 0.f}; |
| 2001 | auto dash1 = SkDashPathEffect::Make(kIntervals1, SK_ARRAY_COUNT(kIntervals1), 0.f); |
| 2002 | REPORTER_ASSERT(r, dash1); |
| 2003 | static constexpr SkScalar kIntervals2[] = {10.f, 0.f, 5.f, 0.f}; |
| 2004 | auto dash2 = SkDashPathEffect::Make(kIntervals2, SK_ARRAY_COUNT(kIntervals2), 10.f); |
| 2005 | REPORTER_ASSERT(r, dash2); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2006 | |
Brian Salomon | 72f78c3 | 2017-12-21 11:56:42 -0500 | [diff] [blame] | 2007 | sk_sp<SkPathEffect> pathEffects[] = {nullptr, std::move(dash1), std::move(dash2)}; |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2008 | |
Brian Salomon | 72f78c3 | 2017-12-21 11:56:42 -0500 | [diff] [blame] | 2009 | for (const auto& pe : pathEffects) { |
| 2010 | // Paints to try |
| 2011 | SkPaint buttCap; |
| 2012 | buttCap.setStyle(SkPaint::kStroke_Style); |
| 2013 | buttCap.setStrokeWidth(4); |
| 2014 | buttCap.setStrokeCap(SkPaint::kButt_Cap); |
| 2015 | buttCap.setPathEffect(pe); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2016 | |
Brian Salomon | 72f78c3 | 2017-12-21 11:56:42 -0500 | [diff] [blame] | 2017 | SkPaint squareCap = buttCap; |
| 2018 | squareCap.setStrokeCap(SkPaint::kSquare_Cap); |
| 2019 | squareCap.setPathEffect(pe); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2020 | |
Brian Salomon | 72f78c3 | 2017-12-21 11:56:42 -0500 | [diff] [blame] | 2021 | SkPaint roundCap = buttCap; |
| 2022 | roundCap.setStrokeCap(SkPaint::kRound_Cap); |
| 2023 | roundCap.setPathEffect(pe); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2024 | |
Brian Salomon | 72f78c3 | 2017-12-21 11:56:42 -0500 | [diff] [blame] | 2025 | // vertical |
| 2026 | SkPath linePath; |
| 2027 | linePath.moveTo(4, 4); |
| 2028 | linePath.lineTo(4, 5); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2029 | |
Brian Salomon | 72f78c3 | 2017-12-21 11:56:42 -0500 | [diff] [blame] | 2030 | SkPaint fill; |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2031 | |
Brian Salomon | 72f78c3 | 2017-12-21 11:56:42 -0500 | [diff] [blame] | 2032 | make_TestCase(r, linePath, buttCap)->compare( |
| 2033 | r, TestCase(r, SkRect::MakeLTRB(2, 4, 6, 5), fill), |
| 2034 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2035 | |
Brian Salomon | 72f78c3 | 2017-12-21 11:56:42 -0500 | [diff] [blame] | 2036 | make_TestCase(r, linePath, squareCap)->compare( |
| 2037 | r, TestCase(r, SkRect::MakeLTRB(2, 2, 6, 7), fill), |
| 2038 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2039 | |
Brian Salomon | 72f78c3 | 2017-12-21 11:56:42 -0500 | [diff] [blame] | 2040 | make_TestCase(r, linePath, roundCap)->compare(r, |
| 2041 | TestCase(r, SkRRect::MakeRectXY(SkRect::MakeLTRB(2, 2, 6, 7), 2, 2), fill), |
| 2042 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2043 | |
Brian Salomon | 72f78c3 | 2017-12-21 11:56:42 -0500 | [diff] [blame] | 2044 | // horizontal |
| 2045 | linePath.reset(); |
| 2046 | linePath.moveTo(4, 4); |
| 2047 | linePath.lineTo(5, 4); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2048 | |
Brian Salomon | 72f78c3 | 2017-12-21 11:56:42 -0500 | [diff] [blame] | 2049 | make_TestCase(r, linePath, buttCap)->compare( |
| 2050 | r, TestCase(r, SkRect::MakeLTRB(4, 2, 5, 6), fill), |
| 2051 | TestCase::kAllSame_ComparisonExpecation); |
| 2052 | make_TestCase(r, linePath, squareCap)->compare( |
| 2053 | r, TestCase(r, SkRect::MakeLTRB(2, 2, 7, 6), fill), |
| 2054 | TestCase::kAllSame_ComparisonExpecation); |
| 2055 | make_TestCase(r, linePath, roundCap)->compare( |
| 2056 | r, TestCase(r, SkRRect::MakeRectXY(SkRect::MakeLTRB(2, 2, 7, 6), 2, 2), fill), |
| 2057 | TestCase::kAllSame_ComparisonExpecation); |
| 2058 | |
| 2059 | // point |
| 2060 | linePath.reset(); |
| 2061 | linePath.moveTo(4, 4); |
| 2062 | linePath.lineTo(4, 4); |
| 2063 | |
| 2064 | make_TestCase(r, linePath, buttCap)->compare( |
| 2065 | r, TestCase(r, SkRect::MakeEmpty(), fill), |
| 2066 | TestCase::kAllSame_ComparisonExpecation); |
| 2067 | make_TestCase(r, linePath, squareCap)->compare( |
| 2068 | r, TestCase(r, SkRect::MakeLTRB(2, 2, 6, 6), fill), |
| 2069 | TestCase::kAllSame_ComparisonExpecation); |
| 2070 | make_TestCase(r, linePath, roundCap)->compare( |
| 2071 | r, TestCase(r, SkRRect::MakeRectXY(SkRect::MakeLTRB(2, 2, 6, 6), 2, 2), fill), |
| 2072 | TestCase::kAllSame_ComparisonExpecation); |
| 2073 | } |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2074 | } |
| 2075 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2076 | DEF_TEST(GrStyledShape_short_path_keys, r) { |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 2077 | SkPaint paints[4]; |
| 2078 | paints[1].setStyle(SkPaint::kStroke_Style); |
| 2079 | paints[1].setStrokeWidth(5.f); |
| 2080 | paints[2].setStyle(SkPaint::kStroke_Style); |
| 2081 | paints[2].setStrokeWidth(0.f); |
| 2082 | paints[3].setStyle(SkPaint::kStrokeAndFill_Style); |
| 2083 | paints[3].setStrokeWidth(5.f); |
| 2084 | |
bsalomon | aa84064 | 2016-09-23 12:09:16 -0700 | [diff] [blame] | 2085 | auto compare = [r, &paints] (const SkPath& pathA, const SkPath& pathB, |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 2086 | TestCase::ComparisonExpecation expectation) { |
bsalomon | aa84064 | 2016-09-23 12:09:16 -0700 | [diff] [blame] | 2087 | SkPath volatileA = pathA; |
| 2088 | SkPath volatileB = pathB; |
| 2089 | volatileA.setIsVolatile(true); |
| 2090 | volatileB.setIsVolatile(true); |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 2091 | for (const SkPaint& paint : paints) { |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2092 | REPORTER_ASSERT(r, !GrStyledShape(volatileA, paint).hasUnstyledKey()); |
| 2093 | REPORTER_ASSERT(r, !GrStyledShape(volatileB, paint).hasUnstyledKey()); |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 2094 | for (PathGeo::Invert invert : {PathGeo::Invert::kNo, PathGeo::Invert::kYes}) { |
bsalomon | aa84064 | 2016-09-23 12:09:16 -0700 | [diff] [blame] | 2095 | TestCase caseA(PathGeo(pathA, invert), paint, r); |
| 2096 | TestCase caseB(PathGeo(pathB, invert), paint, r); |
| 2097 | caseA.compare(r, caseB, expectation); |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 2098 | } |
| 2099 | } |
| 2100 | }; |
| 2101 | |
| 2102 | SkPath pathA; |
| 2103 | SkPath pathB; |
| 2104 | |
| 2105 | // Two identical paths |
| 2106 | pathA.lineTo(10.f, 10.f); |
| 2107 | pathA.conicTo(20.f, 20.f, 20.f, 30.f, 0.7f); |
| 2108 | |
| 2109 | pathB.lineTo(10.f, 10.f); |
| 2110 | pathB.conicTo(20.f, 20.f, 20.f, 30.f, 0.7f); |
bsalomon | aa84064 | 2016-09-23 12:09:16 -0700 | [diff] [blame] | 2111 | compare(pathA, pathB, TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 2112 | |
| 2113 | // Give path b a different point |
| 2114 | pathB.reset(); |
| 2115 | pathB.lineTo(10.f, 10.f); |
| 2116 | pathB.conicTo(21.f, 20.f, 20.f, 30.f, 0.7f); |
bsalomon | aa84064 | 2016-09-23 12:09:16 -0700 | [diff] [blame] | 2117 | compare(pathA, pathB, TestCase::kAllDifferent_ComparisonExpecation); |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 2118 | |
| 2119 | // Give path b a different conic weight |
| 2120 | pathB.reset(); |
| 2121 | pathB.lineTo(10.f, 10.f); |
| 2122 | pathB.conicTo(20.f, 20.f, 20.f, 30.f, 0.6f); |
bsalomon | aa84064 | 2016-09-23 12:09:16 -0700 | [diff] [blame] | 2123 | compare(pathA, pathB, TestCase::kAllDifferent_ComparisonExpecation); |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 2124 | |
| 2125 | // Give path b an extra lineTo verb |
| 2126 | pathB.reset(); |
| 2127 | pathB.lineTo(10.f, 10.f); |
| 2128 | pathB.conicTo(20.f, 20.f, 20.f, 30.f, 0.6f); |
| 2129 | pathB.lineTo(50.f, 50.f); |
bsalomon | aa84064 | 2016-09-23 12:09:16 -0700 | [diff] [blame] | 2130 | compare(pathA, pathB, TestCase::kAllDifferent_ComparisonExpecation); |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 2131 | |
| 2132 | // Give path b a close |
| 2133 | pathB.reset(); |
| 2134 | pathB.lineTo(10.f, 10.f); |
| 2135 | pathB.conicTo(20.f, 20.f, 20.f, 30.f, 0.7f); |
| 2136 | pathB.close(); |
bsalomon | aa84064 | 2016-09-23 12:09:16 -0700 | [diff] [blame] | 2137 | compare(pathA, pathB, TestCase::kAllDifferent_ComparisonExpecation); |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2140 | DEF_TEST(GrStyledShape, reporter) { |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2141 | SkTArray<std::unique_ptr<Geo>> geos; |
| 2142 | SkTArray<std::unique_ptr<RRectPathGeo>> rrectPathGeos; |
| 2143 | |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 2144 | for (auto r : { SkRect::MakeWH(10, 20), |
| 2145 | SkRect::MakeWH(-10, -20), |
| 2146 | SkRect::MakeWH(-10, 20), |
| 2147 | SkRect::MakeWH(10, -20)}) { |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2148 | geos.emplace_back(new RectGeo(r)); |
| 2149 | SkPath rectPath; |
| 2150 | rectPath.addRect(r); |
| 2151 | geos.emplace_back(new RRectPathGeo(rectPath, r, RRectPathGeo::RRectForStroke::kYes, |
| 2152 | PathGeo::Invert::kNo)); |
| 2153 | geos.emplace_back(new RRectPathGeo(rectPath, r, RRectPathGeo::RRectForStroke::kYes, |
| 2154 | PathGeo::Invert::kYes)); |
| 2155 | rrectPathGeos.emplace_back(new RRectPathGeo(rectPath, r, RRectPathGeo::RRectForStroke::kYes, |
| 2156 | PathGeo::Invert::kNo)); |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 2157 | } |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 2158 | for (auto rr : { SkRRect::MakeRect(SkRect::MakeWH(10, 10)), |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 2159 | SkRRect::MakeRectXY(SkRect::MakeWH(10, 10), 3, 4), |
| 2160 | SkRRect::MakeOval(SkRect::MakeWH(20, 20))}) { |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2161 | geos.emplace_back(new RRectGeo(rr)); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 2162 | test_rrect(reporter, rr); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2163 | SkPath rectPath; |
| 2164 | rectPath.addRRect(rr); |
| 2165 | geos.emplace_back(new RRectPathGeo(rectPath, rr, RRectPathGeo::RRectForStroke::kYes, |
| 2166 | PathGeo::Invert::kNo)); |
| 2167 | geos.emplace_back(new RRectPathGeo(rectPath, rr, RRectPathGeo::RRectForStroke::kYes, |
| 2168 | PathGeo::Invert::kYes)); |
| 2169 | rrectPathGeos.emplace_back(new RRectPathGeo(rectPath, rr, |
| 2170 | RRectPathGeo::RRectForStroke::kYes, |
| 2171 | PathGeo::Invert::kNo)); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 2174 | // Arcs |
| 2175 | geos.emplace_back(new ArcGeo(SkRect::MakeWH(200, 100), 12.f, 110.f, false)); |
| 2176 | geos.emplace_back(new ArcGeo(SkRect::MakeWH(200, 100), 12.f, 110.f, true)); |
| 2177 | |
Mike Klein | 4334428 | 2017-08-16 11:56:22 -0400 | [diff] [blame] | 2178 | { |
| 2179 | SkPath openRectPath; |
| 2180 | openRectPath.moveTo(0, 0); |
| 2181 | openRectPath.lineTo(10, 0); |
| 2182 | openRectPath.lineTo(10, 10); |
| 2183 | openRectPath.lineTo(0, 10); |
| 2184 | geos.emplace_back(new RRectPathGeo( |
| 2185 | openRectPath, SkRect::MakeWH(10, 10), |
| 2186 | RRectPathGeo::RRectForStroke::kNo, PathGeo::Invert::kNo)); |
| 2187 | geos.emplace_back(new RRectPathGeo( |
| 2188 | openRectPath, SkRect::MakeWH(10, 10), |
| 2189 | RRectPathGeo::RRectForStroke::kNo, PathGeo::Invert::kYes)); |
| 2190 | rrectPathGeos.emplace_back(new RRectPathGeo( |
| 2191 | openRectPath, SkRect::MakeWH(10, 10), |
| 2192 | RRectPathGeo::RRectForStroke::kNo, PathGeo::Invert::kNo)); |
| 2193 | } |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 2194 | |
Mike Klein | 4334428 | 2017-08-16 11:56:22 -0400 | [diff] [blame] | 2195 | { |
| 2196 | SkPath quadPath; |
| 2197 | quadPath.quadTo(10, 10, 5, 8); |
| 2198 | geos.emplace_back(new PathGeo(quadPath, PathGeo::Invert::kNo)); |
| 2199 | geos.emplace_back(new PathGeo(quadPath, PathGeo::Invert::kYes)); |
| 2200 | } |
bsalomon | 398e3f4 | 2016-06-13 10:22:48 -0700 | [diff] [blame] | 2201 | |
Mike Klein | 4334428 | 2017-08-16 11:56:22 -0400 | [diff] [blame] | 2202 | { |
| 2203 | SkPath linePath; |
| 2204 | linePath.lineTo(10, 10); |
| 2205 | geos.emplace_back(new PathGeo(linePath, PathGeo::Invert::kNo)); |
| 2206 | geos.emplace_back(new PathGeo(linePath, PathGeo::Invert::kYes)); |
| 2207 | } |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 2208 | |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2209 | // Horizontal and vertical paths become rrects when stroked. |
Mike Klein | 4334428 | 2017-08-16 11:56:22 -0400 | [diff] [blame] | 2210 | { |
| 2211 | SkPath vLinePath; |
| 2212 | vLinePath.lineTo(0, 10); |
| 2213 | geos.emplace_back(new PathGeo(vLinePath, PathGeo::Invert::kNo)); |
| 2214 | geos.emplace_back(new PathGeo(vLinePath, PathGeo::Invert::kYes)); |
| 2215 | } |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2216 | |
Mike Klein | 4334428 | 2017-08-16 11:56:22 -0400 | [diff] [blame] | 2217 | { |
| 2218 | SkPath hLinePath; |
| 2219 | hLinePath.lineTo(10, 0); |
| 2220 | geos.emplace_back(new PathGeo(hLinePath, PathGeo::Invert::kNo)); |
| 2221 | geos.emplace_back(new PathGeo(hLinePath, PathGeo::Invert::kYes)); |
| 2222 | } |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2223 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2224 | for (int i = 0; i < geos.count(); ++i) { |
| 2225 | test_basic(reporter, *geos[i]); |
| 2226 | test_scale(reporter, *geos[i]); |
| 2227 | test_dash_fill(reporter, *geos[i]); |
| 2228 | test_null_dash(reporter, *geos[i]); |
| 2229 | // Test modifying various stroke params. |
| 2230 | test_stroke_param<SkScalar>( |
| 2231 | reporter, *geos[i], |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 2232 | [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);}, |
| 2233 | SkIntToScalar(2), SkIntToScalar(4)); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2234 | test_stroke_join(reporter, *geos[i]); |
| 2235 | test_stroke_cap(reporter, *geos[i]); |
| 2236 | test_miter_limit(reporter, *geos[i]); |
| 2237 | test_path_effect_makes_rrect(reporter, *geos[i]); |
| 2238 | test_unknown_path_effect(reporter, *geos[i]); |
| 2239 | test_path_effect_makes_empty_shape(reporter, *geos[i]); |
| 2240 | test_path_effect_fails(reporter, *geos[i]); |
| 2241 | test_make_hairline_path_effect(reporter, *geos[i]); |
| 2242 | test_volatile_path(reporter, *geos[i]); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 2243 | } |
bsalomon | fd32df7 | 2016-06-14 14:37:21 -0700 | [diff] [blame] | 2244 | |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2245 | for (int i = 0; i < rrectPathGeos.count(); ++i) { |
| 2246 | const RRectPathGeo& rrgeo = *rrectPathGeos[i]; |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 2247 | SkPaint fillPaint; |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2248 | TestCase fillPathCase(reporter, rrgeo.path(), fillPaint); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 2249 | SkRRect rrect; |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2250 | REPORTER_ASSERT(reporter, rrgeo.isNonPath(fillPaint) == |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 2251 | fillPathCase.baseShape().asRRect(&rrect, nullptr, nullptr, |
| 2252 | nullptr)); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2253 | if (rrgeo.isNonPath(fillPaint)) { |
| 2254 | TestCase fillPathCase2(reporter, rrgeo.path(), fillPaint); |
| 2255 | REPORTER_ASSERT(reporter, rrect == rrgeo.rrect()); |
| 2256 | TestCase fillRRectCase(reporter, rrect, fillPaint); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 2257 | fillPathCase2.compare(reporter, fillRRectCase, |
| 2258 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 2259 | } |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 2260 | SkPaint strokePaint; |
| 2261 | strokePaint.setStrokeWidth(3.f); |
| 2262 | strokePaint.setStyle(SkPaint::kStroke_Style); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2263 | TestCase strokePathCase(reporter, rrgeo.path(), strokePaint); |
| 2264 | if (rrgeo.isNonPath(strokePaint)) { |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 2265 | REPORTER_ASSERT(reporter, strokePathCase.baseShape().asRRect(&rrect, nullptr, nullptr, |
| 2266 | nullptr)); |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2267 | REPORTER_ASSERT(reporter, rrect == rrgeo.rrect()); |
| 2268 | TestCase strokeRRectCase(reporter, rrect, strokePaint); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 2269 | strokePathCase.compare(reporter, strokeRRectCase, |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 2270 | TestCase::kAllSame_ComparisonExpecation); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 2271 | } |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 2272 | } |
bsalomon | 409ed73 | 2016-04-27 12:36:02 -0700 | [diff] [blame] | 2273 | |
bsalomon | 4eeccc9 | 2016-04-27 13:30:25 -0700 | [diff] [blame] | 2274 | // Test a volatile empty path. |
bsalomon | a395f7c | 2016-08-24 17:47:40 -0700 | [diff] [blame] | 2275 | test_volatile_path(reporter, PathGeo(SkPath(), PathGeo::Invert::kNo)); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2278 | DEF_TEST(GrStyledShape_arcs, reporter) { |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 2279 | SkStrokeRec roundStroke(SkStrokeRec::kFill_InitStyle); |
| 2280 | roundStroke.setStrokeStyle(2.f); |
| 2281 | roundStroke.setStrokeParams(SkPaint::kRound_Cap, SkPaint::kRound_Join, 1.f); |
| 2282 | |
| 2283 | SkStrokeRec squareStroke(roundStroke); |
| 2284 | squareStroke.setStrokeParams(SkPaint::kSquare_Cap, SkPaint::kRound_Join, 1.f); |
| 2285 | |
| 2286 | SkStrokeRec roundStrokeAndFill(roundStroke); |
| 2287 | roundStrokeAndFill.setStrokeStyle(2.f, true); |
| 2288 | |
| 2289 | static constexpr SkScalar kIntervals[] = {1, 2}; |
| 2290 | auto dash = SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), 1.5f); |
| 2291 | |
| 2292 | SkTArray<GrStyle> styles; |
| 2293 | styles.push_back(GrStyle::SimpleFill()); |
| 2294 | styles.push_back(GrStyle::SimpleHairline()); |
| 2295 | styles.push_back(GrStyle(roundStroke, nullptr)); |
| 2296 | styles.push_back(GrStyle(squareStroke, nullptr)); |
| 2297 | styles.push_back(GrStyle(roundStrokeAndFill, nullptr)); |
| 2298 | styles.push_back(GrStyle(roundStroke, dash)); |
| 2299 | |
| 2300 | for (const auto& style : styles) { |
| 2301 | // An empty rect never draws anything according to SkCanvas::drawArc() docs. |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2302 | TestCase emptyArc(GrStyledShape::MakeArc(SkRect::MakeEmpty(), 0, 90.f, false, style), |
| 2303 | reporter); |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 2304 | TestCase emptyPath(reporter, SkPath(), style); |
| 2305 | emptyArc.compare(reporter, emptyPath, TestCase::kAllSame_ComparisonExpecation); |
| 2306 | |
| 2307 | static constexpr SkRect kOval1{0, 0, 50, 50}; |
| 2308 | static constexpr SkRect kOval2{50, 0, 100, 50}; |
| 2309 | // Test that swapping starting and ending angle doesn't change the shape unless the arc |
| 2310 | // has a path effect. Also test that different ovals produce different shapes. |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2311 | TestCase arc1CW(GrStyledShape::MakeArc(kOval1, 0, 90.f, false, style), reporter); |
| 2312 | TestCase arc1CCW(GrStyledShape::MakeArc(kOval1, 90.f, -90.f, false, style), reporter); |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 2313 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2314 | TestCase arc1CWWithCenter(GrStyledShape::MakeArc(kOval1, 0, 90.f, true, style), reporter); |
| 2315 | TestCase arc1CCWWithCenter(GrStyledShape::MakeArc(kOval1, 90.f, -90.f, true, style), |
| 2316 | reporter); |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 2317 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2318 | TestCase arc2CW(GrStyledShape::MakeArc(kOval2, 0, 90.f, false, style), reporter); |
| 2319 | TestCase arc2CWWithCenter(GrStyledShape::MakeArc(kOval2, 0, 90.f, true, style), reporter); |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 2320 | |
| 2321 | auto reversedExepectations = style.hasPathEffect() |
| 2322 | ? TestCase::kAllDifferent_ComparisonExpecation |
| 2323 | : TestCase::kAllSame_ComparisonExpecation; |
| 2324 | arc1CW.compare(reporter, arc1CCW, reversedExepectations); |
| 2325 | arc1CWWithCenter.compare(reporter, arc1CCWWithCenter, reversedExepectations); |
| 2326 | arc1CW.compare(reporter, arc2CW, TestCase::kAllDifferent_ComparisonExpecation); |
| 2327 | arc1CW.compare(reporter, arc1CWWithCenter, TestCase::kAllDifferent_ComparisonExpecation); |
| 2328 | arc1CWWithCenter.compare(reporter, arc2CWWithCenter, |
| 2329 | TestCase::kAllDifferent_ComparisonExpecation); |
| 2330 | |
| 2331 | // Test that two arcs that start at the same angle but specified differently are equivalent. |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2332 | TestCase arc3A(GrStyledShape::MakeArc(kOval1, 224.f, 73.f, false, style), reporter); |
| 2333 | TestCase arc3B(GrStyledShape::MakeArc(kOval1, 224.f - 360.f, 73.f, false, style), reporter); |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 2334 | arc3A.compare(reporter, arc3B, TestCase::kAllDifferent_ComparisonExpecation); |
| 2335 | |
| 2336 | // Test that an arc that traverses the entire oval (and then some) is equivalent to the |
| 2337 | // oval itself unless there is a path effect. |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2338 | TestCase ovalArc(GrStyledShape::MakeArc(kOval1, 150.f, -790.f, false, style), reporter); |
| 2339 | TestCase oval(GrStyledShape(SkRRect::MakeOval(kOval1)), reporter); |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 2340 | auto ovalExpectations = style.hasPathEffect() ? TestCase::kAllDifferent_ComparisonExpecation |
| 2341 | : TestCase::kAllSame_ComparisonExpecation; |
| 2342 | if (style.strokeRec().getWidth() >= 0 && style.strokeRec().getCap() != SkPaint::kButt_Cap) { |
| 2343 | ovalExpectations = TestCase::kAllDifferent_ComparisonExpecation; |
| 2344 | } |
| 2345 | ovalArc.compare(reporter, oval, ovalExpectations); |
| 2346 | |
| 2347 | // If the the arc starts/ends at the center then it is then equivalent to the oval only for |
| 2348 | // simple fills. |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 2349 | TestCase ovalArcWithCenter(GrStyledShape::MakeArc(kOval1, 304.f, 1225.f, true, style), |
| 2350 | reporter); |
Brian Salomon | e494940 | 2018-04-26 15:22:04 -0400 | [diff] [blame] | 2351 | ovalExpectations = style.isSimpleFill() ? TestCase::kAllSame_ComparisonExpecation |
| 2352 | : TestCase::kAllDifferent_ComparisonExpecation; |
| 2353 | ovalArcWithCenter.compare(reporter, oval, ovalExpectations); |
| 2354 | } |
| 2355 | } |