| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkPath.h" | 9 #include "SkPath.h" |
| 10 #include "Test.h" | 10 #include "Test.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 ERRORF(reporter, "%s style[%d] cap[%d] join[%d] antialias[%d]" | 48 ERRORF(reporter, "%s style[%d] cap[%d] join[%d] antialias[%d]" |
| 49 " filltype[%d] ptcount[%d]", str, paint.getStyle(), | 49 " filltype[%d] ptcount[%d]", str, paint.getStyle(), |
| 50 paint.getStrokeCap(), paint.getStrokeJoin(), | 50 paint.getStrokeCap(), paint.getStrokeJoin(), |
| 51 paint.isAntiAlias(), path.getFillType(), path.countPoints()); | 51 paint.isAntiAlias(), path.getFillType(), path.countPoints()); |
| 52 // uncomment this if you want to step in to see the failure | 52 // uncomment this if you want to step in to see the failure |
| 53 // canvas.drawPath(path, p); | 53 // canvas.drawPath(path, p); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 static void iter_paint(skiatest::Reporter* reporter, const SkPath& path, bool sh
ouldDraw) { | 57 enum DrawCaps { |
| 58 kDontDrawCaps, |
| 59 kDrawCaps |
| 60 }; |
| 61 |
| 62 static void iter_paint(skiatest::Reporter* reporter, const SkPath& path, bool sh
ouldDraw, |
| 63 DrawCaps drawCaps) { |
| 58 static const SkPaint::Cap gCaps[] = { | 64 static const SkPaint::Cap gCaps[] = { |
| 59 SkPaint::kButt_Cap, | 65 SkPaint::kButt_Cap, |
| 60 SkPaint::kRound_Cap, | 66 SkPaint::kRound_Cap, |
| 61 SkPaint::kSquare_Cap | 67 SkPaint::kSquare_Cap |
| 62 }; | 68 }; |
| 63 static const SkPaint::Join gJoins[] = { | 69 static const SkPaint::Join gJoins[] = { |
| 64 SkPaint::kMiter_Join, | 70 SkPaint::kMiter_Join, |
| 65 SkPaint::kRound_Join, | 71 SkPaint::kRound_Join, |
| 66 SkPaint::kBevel_Join | 72 SkPaint::kBevel_Join |
| 67 }; | 73 }; |
| 68 static const SkPaint::Style gStyles[] = { | 74 static const SkPaint::Style gStyles[] = { |
| 69 SkPaint::kFill_Style, | 75 SkPaint::kFill_Style, |
| 70 SkPaint::kStroke_Style, | 76 SkPaint::kStroke_Style, |
| 71 SkPaint::kStrokeAndFill_Style | 77 SkPaint::kStrokeAndFill_Style |
| 72 }; | 78 }; |
| 73 for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) { | 79 for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) { |
| 74 for (size_t join = 0; join < SK_ARRAY_COUNT(gJoins); ++join) { | 80 for (size_t join = 0; join < SK_ARRAY_COUNT(gJoins); ++join) { |
| 75 for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) { | 81 for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) { |
| 82 if (drawCaps && SkPaint::kButt_Cap != gCaps[cap] |
| 83 && SkPaint::kFill_Style != gStyles[style]) { |
| 84 continue; |
| 85 } |
| 86 |
| 76 SkPaint paint; | 87 SkPaint paint; |
| 77 paint.setStrokeWidth(SkIntToScalar(10)); | 88 paint.setStrokeWidth(SkIntToScalar(10)); |
| 78 | 89 |
| 79 paint.setStrokeCap(gCaps[cap]); | 90 paint.setStrokeCap(gCaps[cap]); |
| 80 paint.setStrokeJoin(gJoins[join]); | 91 paint.setStrokeJoin(gJoins[join]); |
| 81 paint.setStyle(gStyles[style]); | 92 paint.setStyle(gStyles[style]); |
| 82 | 93 |
| 83 paint.setAntiAlias(false); | 94 paint.setAntiAlias(false); |
| 84 drawAndTest(reporter, path, paint, shouldDraw); | 95 drawAndTest(reporter, path, paint, shouldDraw); |
| 85 paint.setAntiAlias(true); | 96 paint.setAntiAlias(true); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 105 * - if the path is drawn non-inverse, it should draw nowhere | 116 * - if the path is drawn non-inverse, it should draw nowhere |
| 106 * | 117 * |
| 107 * Things to iterate on: | 118 * Things to iterate on: |
| 108 * - path (empty, degenerate line/quad/cubic w/ and w/o close | 119 * - path (empty, degenerate line/quad/cubic w/ and w/o close |
| 109 * - paint style | 120 * - paint style |
| 110 * - path filltype | 121 * - path filltype |
| 111 * - path stroke variants (e.g. caps, joins, width) | 122 * - path stroke variants (e.g. caps, joins, width) |
| 112 */ | 123 */ |
| 113 static void test_emptydrawing(skiatest::Reporter* reporter) { | 124 static void test_emptydrawing(skiatest::Reporter* reporter) { |
| 114 static void (*gMakeProc[])(SkPath*) = { | 125 static void (*gMakeProc[])(SkPath*) = { |
| 115 make_empty, make_M, make_MM, make_MZM, make_L, make_Q, make_C | 126 make_empty, make_M, make_MM, make_MZM |
| 116 }; | 127 }; |
| 117 static SkPath::FillType gFills[] = { | 128 static SkPath::FillType gFills[] = { |
| 118 SkPath::kWinding_FillType, | 129 SkPath::kWinding_FillType, |
| 119 SkPath::kEvenOdd_FillType, | 130 SkPath::kEvenOdd_FillType, |
| 120 SkPath::kInverseWinding_FillType, | 131 SkPath::kInverseWinding_FillType, |
| 121 SkPath::kInverseEvenOdd_FillType | 132 SkPath::kInverseEvenOdd_FillType |
| 122 }; | 133 }; |
| 123 for (int doClose = 0; doClose < 2; ++doClose) { | 134 for (int doClose = 0; doClose < 2; ++doClose) { |
| 124 for (size_t i = 0; i < SK_ARRAY_COUNT(gMakeProc); ++i) { | 135 for (size_t i = 0; i < SK_ARRAY_COUNT(gMakeProc); ++i) { |
| 125 SkPath path; | 136 SkPath path; |
| 126 gMakeProc[i](&path); | 137 gMakeProc[i](&path); |
| 127 if (doClose) { | 138 if (doClose) { |
| 128 path.close(); | 139 path.close(); |
| 129 } | 140 } |
| 130 for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { | 141 for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { |
| 131 path.setFillType(gFills[fill]); | 142 path.setFillType(gFills[fill]); |
| 132 bool shouldDraw = path.isInverseFillType(); | 143 bool shouldDraw = path.isInverseFillType(); |
| 133 iter_paint(reporter, path, shouldDraw); | 144 iter_paint(reporter, path, shouldDraw, kDontDrawCaps); |
| 134 } | 145 } |
| 135 } | 146 } |
| 136 } | 147 } |
| 148 static void (*gMakeCapProc[])(SkPath*) = { |
| 149 make_L, make_Q, make_C |
| 150 }; |
| 151 for (int doClose = 0; doClose < 2; ++doClose) { |
| 152 for (size_t i = 0; i < SK_ARRAY_COUNT(gMakeCapProc); ++i) { |
| 153 SkPath path; |
| 154 gMakeCapProc[i](&path); |
| 155 if (doClose) { |
| 156 path.close(); |
| 157 } |
| 158 for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { |
| 159 path.setFillType(gFills[fill]); |
| 160 bool shouldDraw = path.isInverseFillType(); |
| 161 iter_paint(reporter, path, shouldDraw, kDrawCaps); |
| 162 } |
| 163 } |
| 164 } |
| 137 } | 165 } |
| 138 | 166 |
| 139 DEF_TEST(EmptyPath, reporter) { | 167 DEF_TEST(EmptyPath, reporter) { |
| 140 test_emptydrawing(reporter); | 168 test_emptydrawing(reporter); |
| 141 } | 169 } |
| OLD | NEW |