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

Unified Diff: gm/arcto.cpp

Issue 1675053002: test parsepath (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: unused variable Created 4 years, 10 months 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/tools.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/arcto.cpp
diff --git a/gm/arcto.cpp b/gm/arcto.cpp
index aac9bde1b324cf8c254ab19aed44d5a73ede5cf0..432b889fb8dcfe0a55be4dd59db6a0d87c720a56 100644
--- a/gm/arcto.cpp
+++ b/gm/arcto.cpp
@@ -102,3 +102,86 @@ DEF_SIMPLE_GM(arcto, canvas, 500, 600) {
path.arcTo(80, 80, 0, SkPath::kLarge_ArcSize, SkPath::kCW_Direction, 200, 100);
canvas->drawPath(path, paint);
}
+
+#include "random_parse_path.h"
+#include "SkRandom.h"
+
+/* The test below generates a reference image using SVG. To compare the result for correctness,
+ enable the define below and then view the generated SVG in a browser.
+ */
+#define GENERATE_SVG_REFERENCE 0
+
+#if GENERATE_SVG_REFERENCE
+#include "SkOSFile.h"
+#endif
+
+enum {
+ kParsePathTestDimension = 500
+};
+
+DEF_SIMPLE_GM(parsedpaths, canvas, kParsePathTestDimension, kParsePathTestDimension) {
+#if GENERATE_SVG_REFERENCE
+ FILE* file = sk_fopen("svgout.htm", kWrite_SkFILE_Flag);
+ SkString str;
+ str.printf("<svg width=\"%d\" height=\"%d\">\n", kParsePathTestDimension,
+ kParsePathTestDimension);
+ sk_fwrite(str.c_str(), str.size(), file);
+#endif
+ SkRandom rand;
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ for (int xStart = 0; xStart < kParsePathTestDimension; xStart += 100) {
+ canvas->save();
+ for (int yStart = 0; yStart < kParsePathTestDimension; yStart += 100) {
+#if GENERATE_SVG_REFERENCE
+ str.printf("<g transform='translate(%d,%d) scale(%d,%d)'>\n", xStart, yStart,
+ 1, 1);
+ sk_fwrite(str.c_str(), str.size(), file);
+ str.printf("<clipPath id='clip_%d_%d'>\n", xStart, yStart);
+ sk_fwrite(str.c_str(), str.size(), file);
+ str.printf("<rect width='100' height='100' x='0' y='0'></rect>\n");
+ sk_fwrite(str.c_str(), str.size(), file);
+ str.printf("</clipPath>\n");
+ sk_fwrite(str.c_str(), str.size(), file);
+#endif
+ int count = 3;
+ do {
+ SkPath path;
+ SkString spec;
+ spec.printf("M %d,%d\n", rand.nextRangeU(30, 70), rand.nextRangeU(30, 70));
+ uint32_t count = rand.nextRangeU(0, 10);
+ for (uint32_t i = 0; i < count; ++i) {
+ spec.append(MakeRandomParsePathPiece(&rand));
+ }
+ SkAssertResult(SkParsePath::FromSVGString(spec.c_str(), &path));
+ paint.setColor(rand.nextU());
+ canvas->save();
+ canvas->clipRect(SkRect::MakeIWH(100, 100));
+ canvas->drawPath(path, paint);
+ canvas->restore();
+#if GENERATE_SVG_REFERENCE
+ str.printf("<path d='\n");
+ sk_fwrite(str.c_str(), str.size(), file);
+ sk_fwrite(spec.c_str(), spec.size(), file);
+ str.printf("\n' fill='#%06x' fill-opacity='%g'", paint.getColor() & 0xFFFFFF,
+ paint.getAlpha() / 255.f);
+ sk_fwrite(str.c_str(), str.size(), file);
+ str.printf(" clip-path='url(#clip_%d_%d)'/>\n", xStart, yStart);
+ sk_fwrite(str.c_str(), str.size(), file);
+#endif
+ } while (--count > 0);
+#if GENERATE_SVG_REFERENCE
+ str.printf("</g>\n");
+ sk_fwrite(str.c_str(), str.size(), file);
+#endif
+ canvas->translate(0, 100);
+ }
+ canvas->restore();
+ canvas->translate(100, 0);
+ }
+#if GENERATE_SVG_REFERENCE
+ const char trailer[] = "</svg>\n";
+ sk_fwrite(trailer, sizeof(trailer) - 1, file);
+ sk_fclose(file);
+#endif
+}
« no previous file with comments | « no previous file | gyp/tools.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698