Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 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 | |
| 8 #include "gm.h" | |
| 9 #include "SkCanvas.h" | |
| 10 #include "SkPath.h" | |
| 11 | |
| 12 namespace skiagm { | |
| 13 | |
|
robertphillips
2013/11/08 16:19:44
Could you add a comment here describing what the G
yunchao
2013/11/08 16:54:43
Agree.
| |
| 14 class NonClosedPathsGM: public GM { | |
| 15 public: | |
| 16 NonClosedPathsGM() {} | |
| 17 | |
| 18 enum ClosureType { | |
|
robertphillips
2013/11/08 16:19:44
TotalNonClose -> TotallyNonClosed
| |
| 19 TotalNonClose, // The last point doesn't coincide with the first one in the contour. | |
| 20 // The path looks not closed at all. | |
| 21 | |
| 22 FakeCloseCorner, // The last point coincides with the first one at a co rner. | |
|
robertphillips
2013/11/08 16:19:44
Please remove the "like".
| |
| 23 // The path looks like closed, but final rendering has 2 ends with cap. | |
| 24 | |
| 25 FakeCloseMiddle, // The last point coincides with the first one in the middle of a line. | |
| 26 // The path looks closed, and the final rendering look s closed too. | |
| 27 | |
| 28 kClosureTypeCount | |
| 29 }; | |
| 30 | |
| 31 protected: | |
| 32 virtual SkString onShortName() SK_OVERRIDE { | |
| 33 return SkString("nonclosedpaths"); | |
| 34 } | |
| 35 | |
| 36 virtual SkISize onISize() SK_OVERRIDE { | |
| 37 return SkISize::Make(1220, 1920); | |
| 38 } | |
| 39 | |
| 40 // Use rect-like geometry for non-closed path, for right angles make it | |
| 41 // easier to show the visual difference of lineCap and lineJoin. | |
|
robertphillips
2013/11/08 16:19:44
Please change makePath to MakePath.
| |
| 42 static void makePath(SkPath* path, ClosureType type) { | |
| 43 if (FakeCloseMiddle == type) { | |
| 44 path.moveTo(30, 50); | |
| 45 path.lineTo(30, 30); | |
| 46 } else { | |
| 47 path.moveTo(30, 30); | |
| 48 } | |
| 49 path.lineTo(70, 30); | |
| 50 path.lineTo(70, 70); | |
| 51 path.lineTo(30, 70); | |
| 52 path.lineTo(30, 50); | |
| 53 if (FakeCloseCorner == type) { | |
| 54 path.lineTo(30, 30); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 // Set the location for the current test on the canvas | |
|
robertphillips
2013/11/08 16:19:44
Please change to SetLocation.
| |
| 59 static void setLocation(SkCanvas* canvas, int counter, int lineNum) { | |
| 60 SkScalar x = SK_Scalar1 * 100 * (counter % lineNum) + 10 + SK_Scalar1 / 4; | |
| 61 SkScalar y = SK_Scalar1 * 100 * (counter / lineNum) + 10 + 3 * SK_Scalar 1 / 4; | |
| 62 canvas->translate(x, y); | |
| 63 } | |
| 64 | |
| 65 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | |
| 66 static const int kStrokeWidth[] = {0, 10, 40, 50}; | |
| 67 size_t numWidths = SK_ARRAY_COUNT(kStrokeWidth); | |
| 68 | |
| 69 static const SkPaint::Style kStyle[] = { | |
| 70 SkPaint::kStroke_Style, SkPaint::kStrokeAndFill_Style | |
| 71 }; | |
| 72 | |
| 73 static const SkPaint::Cap kCap[] = { | |
| 74 SkPaint::kButt_Cap, SkPaint::kRound_Cap, SkPaint::kSquare_Cap | |
| 75 }; | |
| 76 | |
| 77 static const SkPaint::Join kJoin[] = { | |
| 78 SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join | |
| 79 }; | |
| 80 | |
| 81 static const ClosureType kType[] = { | |
| 82 TotalNonClose, FakeCloseCorner, FakeCloseMiddle | |
| 83 }; | |
| 84 | |
| 85 int counter = 0; | |
| 86 SkPaint paint; | |
| 87 paint.setAntiAlias(true); | |
| 88 | |
| 89 // For stroke style painter and fill-and-stroke style painter | |
| 90 for (size_t type = 0; type < kClosureTypeCount; ++type) { | |
| 91 for (size_t style = 0; style < SK_ARRAY_COUNT(kStyle); ++style) { | |
| 92 for (size_t cap = 0; cap < SK_ARRAY_COUNT(kCap); ++cap) { | |
| 93 for (size_t join = 0; join < SK_ARRAY_COUNT(kJoin); ++join) { | |
| 94 for (size_t width = 0; width < numWidths; ++width) { | |
| 95 canvas->save(); | |
| 96 setLocation(canvas, counter, SkPaint::kJoinCount * n umWidths); | |
| 97 | |
| 98 SkPath path; | |
|
robertphillips
2013/11/08 16:19:44
Don't need this-> any more.
yunchao
2013/11/08 16:54:43
I don't know what I was thinking, I have made it a
| |
| 99 this->makePath(&path, kType[type]); | |
| 100 | |
| 101 paint.setStyle(kStyle[style]); | |
| 102 paint.setStrokeCap(kCap[cap]); | |
| 103 paint.setStrokeJoin(kJoin[join]); | |
| 104 paint.setStrokeWidth(SkIntToScalar(strokeWidth[width ])); | |
| 105 | |
| 106 canvas->drawPath(path, paint); | |
| 107 canvas->restore(); | |
|
robertphillips
2013/11/08 16:19:44
Pre-increment here please.
| |
| 108 counter++; | |
| 109 } | |
| 110 } | |
| 111 } | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 // For fill style painter | |
| 116 for (size_t type = 0; type < kClosureTypeCount; ++type) { | |
| 117 canvas->save(); | |
| 118 setLocation(canvas, counter, SkPaint::kJoinCount * numWidths); | |
| 119 | |
| 120 SkPath path; | |
|
robertphillips
2013/11/08 16:19:44
Don't need this-> here anymore
| |
| 121 this->makePath(&path, kType[type]); | |
| 122 | |
|
robertphillips
2013/11/08 16:19:44
Don't think this needs to be inside the loop.
| |
| 123 paint.setStyle(SkPaint::kFill_Style); | |
| 124 | |
| 125 canvas->drawPath(path, paint); | |
| 126 canvas->restore(); | |
|
robertphillips
2013/11/08 16:19:44
Pre-increment here too.
| |
| 127 counter++; | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 private: | |
| 132 typedef GM INHERITED; | |
| 133 }; | |
| 134 | |
| 135 ////////////////////////////////////////////////////////////////////////////// | |
| 136 | |
| 137 DEF_GM(return new NonClosedPathsGM;) | |
| 138 | |
| 139 } | |
| OLD | NEW |