Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(511)

Unified Diff: gm/nonclosepaths.cpp

Issue 64173009: add GM case nonclosedpaths (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/nonclosepaths.cpp
diff --git a/gm/nonclosepaths.cpp b/gm/nonclosepaths.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1173a7de6c1451baf6fc43224b1ed788d661e4c9
--- /dev/null
+++ b/gm/nonclosepaths.cpp
@@ -0,0 +1,140 @@
+/*
+ * 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 14:18:50 // This GM tests ...
+class NonClosePathsGM: public GM {
+public:
+ NonClosePathsGM() {}
+
robertphillips 2013/11/08 14:18:50 Maybe make this ClosureType rather than NonCloseTy
+ enum NonCloseType {
+ TotalNonClose, // The last point doesn't coincide with the first one in the contour.
+ // The path looks not closed at all.
+
robertphillips 2013/11/08 14:18:50 coincide -> coincides
+ FakeCloseCorner, // The last point coincide with the first one at a corner.
+ // The path looks like closed, but final rendering has 2 ends with cap.
+
robertphillips 2013/11/08 14:18:50 coincide -> coincides
+ FakeCloseMiddle, // The last point coincide with the first one in the middle of a line.
robertphillips 2013/11/08 14:18:50 // The path looks closed, and the final rendering
+ // The path looks like closed, and the final rendering looks closed too.
+
+ kNonCloseTypeCount
+ };
+
+protected:
robertphillips 2013/11/08 14:18:50 SK_OVERRIDE
+ virtual SkString onShortName() {
robertphillips 2013/11/08 14:18:50 nonclosedpaths (i.e., add 'd')
+ return SkString("nonclosepaths");
+ }
+
robertphillips 2013/11/08 14:18:50 SK_OVERRIDE
+ virtual SkISize onISize() {
robertphillips 2013/11/08 14:18:50 Does it need to be this big?
yunchao 2013/11/08 15:56:21 Yeah, there are 12 * 18 + 3 cases, very one is 100
+ return SkISize::Make(1220, 1920);
+ }
+
robertphillips 2013/11/08 14:18:50 non-close path -> non-closed paths for right angle
+ // Use rect-like geometry for non-close path, for right angle is easier to
+ // show the visual difference of lineCap and lineJoin.
robertphillips 2013/11/08 14:18:50 We only use const references in Skia. If the objec
yunchao 2013/11/08 15:56:21 Because some cases are stroke-style, and the bigge
+ void makePath(SkPath& path, NonCloseType 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 14:18:50 SetLocation for static member methods
+ 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);
+ }
+
robertphillips 2013/11/08 14:18:50 SK_OVERRIDE
+ virtual void onDraw(SkCanvas* canvas) {
robertphillips 2013/11/08 14:18:50 Maybe kStrokeWidths or gStrokeWidths?
+ static const int strokeWidth[] = {0, 10, 40, 50};
robertphillips 2013/11/08 14:18:50 Maybe numWidths?
+ size_t size = SK_ARRAY_COUNT(strokeWidth);
+
robertphillips 2013/11/08 14:18:50 Same here w.r.t. naming. Maybe prefix with a 'k' o
+ static const SkPaint::Style testStyle[] = {
+ SkPaint::kStroke_Style, SkPaint::kStrokeAndFill_Style
+ };
+
+ static const SkPaint::Cap testCap[] = {
+ SkPaint::kButt_Cap, SkPaint::kRound_Cap, SkPaint::kSquare_Cap
+ };
+
+ static const SkPaint::Join testJoin[] = {
+ SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join
+ };
+
+ static const NonCloseType testType[] = {
+ TotalNonClose, FakeCloseCorner, FakeCloseMiddle
+ };
+
+ int counter = 0;
+ SkPaint paint;
+ paint.setAntiAlias(true);
+
+ // For stroke style painter and fill-and-stroke style painter
robertphillips 2013/11/08 14:18:50 pre-increments for these please (e.g., ++type)
+ for (size_t type = 0; type < kNonCloseTypeCount; type++) {
+ for (size_t style = 0; style < SK_ARRAY_COUNT(testStyle); style++) {
+ for (size_t cap = 0; cap < SK_ARRAY_COUNT(testCap); cap++) {
+ for (size_t join = 0; join < SK_ARRAY_COUNT(testJoin); join++) {
+ for (size_t width = 0; width < size; width++) {
+ canvas->save();
+ setLocation(canvas, counter, SkPaint::kJoinCount * size);
+
+ SkPath path;
robertphillips 2013/11/08 14:18:50 this->makePath
+ makePath(path, testType[type]);
+
+ paint.setStyle(testStyle[style]);
+ paint.setStrokeCap(testCap[cap]);
+ paint.setStrokeJoin(testJoin[join]);
robertphillips 2013/11/08 14:18:50 SkIntToScalar instead of SkScalar
+ paint.setStrokeWidth(SkScalar(strokeWidth[width]));
+
+ canvas->drawPath(path, paint);
+ canvas->restore();
+ counter++;
+ }
+ }
+ }
+ }
+ }
+
+ // For fill style painter
+ for (size_t type = 0; type < kNonCloseTypeCount; type++) {
+ canvas->save();
+ setLocation(canvas, counter, SkPaint::kJoinCount * size);
+
+ SkPath path;
robertphillips 2013/11/08 14:18:50 this->makePath
+ makePath(path, testType[type]);
+
+ paint.setStyle(SkPaint::kFill_Style);
+
+ canvas->drawPath(path, paint);
+ canvas->restore();
+ counter++;
+ }
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
robertphillips 2013/11/08 14:18:50 Please use DEF_GM macro instead here
+static GM* MyFactory(void*) { return new NonClosePathsGM; }
+static GMRegistry reg(MyFactory);
+
+}
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698