2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
14 // This GM tests a grab-bag of non-closed paths. All these paths look like
15 // closed rects, but they don't call path.close(). Depending on the stroke
16 // settings these slightly different paths give widely different results.
17 class NonClosedPathsGM: public GM {
22 TotallyNonClosed, // The last point doesn't coincide with the first one in the contour.
23 // The path looks not closed at all.
25 FakeCloseCorner, // The last point coincides with the first one at a corner.
26 // The path looks closed, but final rendering has 2 ends with cap.
28 FakeCloseMiddle, // The last point coincides with the first one in the middle of a line.
29 // The path looks closed, and the final rendering looks closed too.
36 SkString onShortName() override {
37 return SkString("nonclosedpaths");
40 // 12 * 18 + 3 cases, every case is 100 * 100 pixels.
41 SkISize onISize() override {
42 return SkISize::Make(1220, 1920);
45 // Use rect-like geometry for non-closed path, for right angles make it
46 // easier to show the visual difference of lineCap and lineJoin.
47 static void MakePath(SkPath* path, ClosureType type) {
48 if (FakeCloseMiddle == type) {
58 if (FakeCloseCorner == type) {
63 // Set the location for the current test on the canvas
64 static void SetLocation(SkCanvas* canvas, int counter, int lineNum) {
65 SkScalar x = SK_Scalar1 * 100 * (counter % lineNum) + 10 + SK_Scalar1 / 4;
66 SkScalar y = SK_Scalar1 * 100 * (counter / lineNum) + 10 + 3 * SK_Scalar1 / 4;
67 canvas->translate(x, y);
70 void onDraw(SkCanvas* canvas) override {
72 // 0(may use hairline rendering), 10(common case for stroke-style)
73 // 40 and 50(>= geometry width/height, make the contour filled in fact)
74 static const int kStrokeWidth[] = {0, 10, 40, 50};
75 int numWidths = SK_ARRAY_COUNT(kStrokeWidth);
77 static const SkPaint::Style kStyle[] = {
78 SkPaint::kStroke_Style, SkPaint::kStrokeAndFill_Style
81 static const SkPaint::Cap kCap[] = {
82 SkPaint::kButt_Cap, SkPaint::kRound_Cap, SkPaint::kSquare_Cap
85 static const SkPaint::Join kJoin[] = {
86 SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join
89 static const ClosureType kType[] = {
90 TotallyNonClosed, FakeCloseCorner, FakeCloseMiddle
95 paint.setAntiAlias(true);
97 // For stroke style painter and fill-and-stroke style painter
98 for (size_t type = 0; type < kClosureTypeCount; ++type) {
99 for (size_t style = 0; style < SK_ARRAY_COUNT(kStyle); ++style) {
100 for (size_t cap = 0; cap < SK_ARRAY_COUNT(kCap); ++cap) {
101 for (size_t join = 0; join < SK_ARRAY_COUNT(kJoin); ++join) {
102 for (int width = 0; width < numWidths; ++width) {
104 SetLocation(canvas, counter, SkPaint::kJoinCount * numWidths);
107 MakePath(&path, kType[type]);
109 paint.setStyle(kStyle[style]);
110 paint.setStrokeCap(kCap[cap]);
111 paint.setStrokeJoin(kJoin[join]);
112 paint.setStrokeWidth(SkIntToScalar(kStrokeWidth[width]));
114 canvas->drawPath(path, paint);
123 // For fill style painter
124 paint.setStyle(SkPaint::kFill_Style);
125 for (size_t type = 0; type < kClosureTypeCount; ++type) {
127 SetLocation(canvas, counter, SkPaint::kJoinCount * numWidths);
130 MakePath(&path, kType[type]);
132 canvas->drawPath(path, paint);
139 typedef GM INHERITED;
142 //////////////////////////////////////////////////////////////////////////////
144 DEF_GM(return new NonClosedPathsGM;)