Index: gm/nonclosedpaths.cpp |
diff --git a/gm/nonclosedpaths.cpp b/gm/nonclosedpaths.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6bab76b24841f4f8bc27d46aac3f0669f52dea27 |
--- /dev/null |
+++ b/gm/nonclosedpaths.cpp |
@@ -0,0 +1,139 @@ |
+/* |
+ * Copyright 2013 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "gm.h" |
+#include "SkCanvas.h" |
+#include "SkPath.h" |
+ |
+namespace skiagm { |
+ |
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.
|
+class NonClosedPathsGM: public GM { |
+public: |
+ NonClosedPathsGM() {} |
+ |
+ enum ClosureType { |
robertphillips
2013/11/08 16:19:44
TotalNonClose -> TotallyNonClosed
|
+ TotalNonClose, // The last point doesn't coincide with the first one in the contour. |
+ // The path looks not closed at all. |
+ |
+ FakeCloseCorner, // The last point coincides with the first one at a corner. |
robertphillips
2013/11/08 16:19:44
Please remove the "like".
|
+ // The path looks like closed, but final rendering has 2 ends with cap. |
+ |
+ FakeCloseMiddle, // The last point coincides with the first one in the middle of a line. |
+ // The path looks closed, and the final rendering looks closed too. |
+ |
+ kClosureTypeCount |
+ }; |
+ |
+protected: |
+ virtual SkString onShortName() SK_OVERRIDE { |
+ return SkString("nonclosedpaths"); |
+ } |
+ |
+ virtual SkISize onISize() SK_OVERRIDE { |
+ return SkISize::Make(1220, 1920); |
+ } |
+ |
+ // Use rect-like geometry for non-closed path, for right angles make it |
+ // easier to show the visual difference of lineCap and lineJoin. |
robertphillips
2013/11/08 16:19:44
Please change makePath to MakePath.
|
+ static void makePath(SkPath* path, ClosureType type) { |
+ if (FakeCloseMiddle == type) { |
+ path.moveTo(30, 50); |
+ path.lineTo(30, 30); |
+ } else { |
+ path.moveTo(30, 30); |
+ } |
+ path.lineTo(70, 30); |
+ path.lineTo(70, 70); |
+ path.lineTo(30, 70); |
+ path.lineTo(30, 50); |
+ if (FakeCloseCorner == type) { |
+ path.lineTo(30, 30); |
+ } |
+ } |
+ |
+ // Set the location for the current test on the canvas |
robertphillips
2013/11/08 16:19:44
Please change to SetLocation.
|
+ static void setLocation(SkCanvas* canvas, int counter, int lineNum) { |
+ SkScalar x = SK_Scalar1 * 100 * (counter % lineNum) + 10 + SK_Scalar1 / 4; |
+ SkScalar y = SK_Scalar1 * 100 * (counter / lineNum) + 10 + 3 * SK_Scalar1 / 4; |
+ canvas->translate(x, y); |
+ } |
+ |
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
+ static const int kStrokeWidth[] = {0, 10, 40, 50}; |
+ size_t numWidths = SK_ARRAY_COUNT(kStrokeWidth); |
+ |
+ static const SkPaint::Style kStyle[] = { |
+ SkPaint::kStroke_Style, SkPaint::kStrokeAndFill_Style |
+ }; |
+ |
+ static const SkPaint::Cap kCap[] = { |
+ SkPaint::kButt_Cap, SkPaint::kRound_Cap, SkPaint::kSquare_Cap |
+ }; |
+ |
+ static const SkPaint::Join kJoin[] = { |
+ SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join |
+ }; |
+ |
+ static const ClosureType kType[] = { |
+ TotalNonClose, FakeCloseCorner, FakeCloseMiddle |
+ }; |
+ |
+ int counter = 0; |
+ SkPaint paint; |
+ paint.setAntiAlias(true); |
+ |
+ // For stroke style painter and fill-and-stroke style painter |
+ for (size_t type = 0; type < kClosureTypeCount; ++type) { |
+ for (size_t style = 0; style < SK_ARRAY_COUNT(kStyle); ++style) { |
+ for (size_t cap = 0; cap < SK_ARRAY_COUNT(kCap); ++cap) { |
+ for (size_t join = 0; join < SK_ARRAY_COUNT(kJoin); ++join) { |
+ for (size_t width = 0; width < numWidths; ++width) { |
+ canvas->save(); |
+ setLocation(canvas, counter, SkPaint::kJoinCount * numWidths); |
+ |
+ 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
|
+ this->makePath(&path, kType[type]); |
+ |
+ paint.setStyle(kStyle[style]); |
+ paint.setStrokeCap(kCap[cap]); |
+ paint.setStrokeJoin(kJoin[join]); |
+ paint.setStrokeWidth(SkIntToScalar(strokeWidth[width])); |
+ |
+ canvas->drawPath(path, paint); |
+ canvas->restore(); |
robertphillips
2013/11/08 16:19:44
Pre-increment here please.
|
+ counter++; |
+ } |
+ } |
+ } |
+ } |
+ } |
+ |
+ // For fill style painter |
+ for (size_t type = 0; type < kClosureTypeCount; ++type) { |
+ canvas->save(); |
+ setLocation(canvas, counter, SkPaint::kJoinCount * numWidths); |
+ |
+ SkPath path; |
robertphillips
2013/11/08 16:19:44
Don't need this-> here anymore
|
+ this->makePath(&path, kType[type]); |
+ |
robertphillips
2013/11/08 16:19:44
Don't think this needs to be inside the loop.
|
+ paint.setStyle(SkPaint::kFill_Style); |
+ |
+ canvas->drawPath(path, paint); |
+ canvas->restore(); |
robertphillips
2013/11/08 16:19:44
Pre-increment here too.
|
+ counter++; |
+ } |
+ } |
+ |
+private: |
+ typedef GM INHERITED; |
+}; |
+ |
+////////////////////////////////////////////////////////////////////////////// |
+ |
+DEF_GM(return new NonClosedPathsGM;) |
+ |
+} |