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

Unified Diff: gm/inversepaths.cpp

Issue 2057213002: Extend inverse_paths GM to test dashing (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/inversepaths.cpp
diff --git a/gm/inversepaths.cpp b/gm/inversepaths.cpp
index 92ea051d123c9e0ecb3889f9fc85964354412675..6eb054e22aa6581142454ee537fad7fdc5f6c6b8 100644
--- a/gm/inversepaths.cpp
+++ b/gm/inversepaths.cpp
@@ -8,6 +8,7 @@
#include "gm.h"
#include "SkCanvas.h"
#include "SkPath.h"
+#include "SkDashPathEffect.h"
static SkPath generate_square(SkScalar cx, SkScalar cy, SkScalar w) {
SkRect rect = SkRect::MakeXYWH(cx - w / 2, cy - w / 2, w, w);
@@ -37,11 +38,26 @@ static SkPath generate_line(SkScalar cx, SkScalar cy, SkScalar l) {
}
namespace {
-SkPaint::Style styles[] = {
- SkPaint::kStroke_Style,
- SkPaint::kStrokeAndFill_Style,
- SkPaint::kFill_Style
+struct Style {
+ Style(SkPaint::Style paintStyle, sk_sp<SkPathEffect> pe = sk_sp<SkPathEffect>())
+ : fPaintStyle(paintStyle)
+ , fPathEffect(std::move(pe)) {}
+ SkPaint::Style fPaintStyle;
+ sk_sp<SkPathEffect> fPathEffect;
};
+
+sk_sp<SkPathEffect> make_dash() {
+ static constexpr SkScalar kIntervals[] = { 4.f, 3.f };
+ return SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), 0);
+}
+
+Style styles[] {
+ {SkPaint::kStroke_Style},
+ {SkPaint::kStrokeAndFill_Style},
+ {SkPaint::kFill_Style},
+ {SkPaint::kStroke_Style, make_dash()},
+};
+
SkScalar pathSizes[] = {
40,
10,
@@ -63,62 +79,62 @@ const SkScalar slideBoundary = 5;
} // namespace
-DEF_SIMPLE_GM(inverse_paths, canvas, 800, 900) {
- SkScalar cx = slideWidth / 2 + slideBoundary;
- SkScalar cy = slideHeight / 2 + slideBoundary;
- SkScalar dx = slideWidth + 2 * slideBoundary;
- SkScalar dy = slideHeight + 2 * slideBoundary;
-
- SkRect clipRect = SkRect::MakeLTRB(slideBoundary, slideBoundary,
- slideBoundary + slideWidth,
- slideBoundary + slideHeight);
- SkPaint clipPaint;
- clipPaint.setStyle(SkPaint::kStroke_Style);
- clipPaint.setStrokeWidth(SkIntToScalar(2));
-
- SkPaint outlinePaint;
- outlinePaint.setColor(0x40000000);
- outlinePaint.setStyle(SkPaint::kStroke_Style);
- outlinePaint.setStrokeWidth(SkIntToScalar(0));
-
- for (size_t styleIndex = 0; styleIndex < SK_ARRAY_COUNT(styles);
- styleIndex++) {
- for (size_t sizeIndex = 0; sizeIndex < SK_ARRAY_COUNT(pathSizes);
- sizeIndex++) {
- SkScalar size = pathSizes[sizeIndex];
-
- canvas->save();
-
- for (size_t widthIndex = 0;
- widthIndex < SK_ARRAY_COUNT(strokeWidths);
- widthIndex++) {
- SkPaint paint;
- paint.setColor(0xff007000);
- paint.setStrokeWidth(strokeWidths[widthIndex]);
- paint.setStyle(styles[styleIndex]);
-
- for (size_t pathIndex = 0;
- pathIndex < SK_ARRAY_COUNT(paths);
- pathIndex++) {
- canvas->drawRect(clipRect, clipPaint);
-
- canvas->save();
- canvas->clipRect(clipRect);
-
- SkPath path = paths[pathIndex](cx, cy, size);
- path.setFillType(SkPath::kInverseWinding_FillType);
- canvas->drawPath(path, paint);
-
- path.setFillType(SkPath::kWinding_FillType);
- canvas->drawPath(path, outlinePaint);
-
- canvas->restore();
- canvas->translate(dx, 0);
- }
+DEF_SIMPLE_GM(inverse_paths, canvas, 800, 1200) {
+ SkScalar cx = slideWidth / 2 + slideBoundary;
+ SkScalar cy = slideHeight / 2 + slideBoundary;
+ SkScalar dx = slideWidth + 2 * slideBoundary;
+ SkScalar dy = slideHeight + 2 * slideBoundary;
+
+ SkRect clipRect = SkRect::MakeLTRB(slideBoundary, slideBoundary,
+ slideBoundary + slideWidth,
+ slideBoundary + slideHeight);
+ SkPaint clipPaint;
+ clipPaint.setStyle(SkPaint::kStroke_Style);
+ clipPaint.setStrokeWidth(SkIntToScalar(2));
+
+ SkPaint outlinePaint;
+ outlinePaint.setColor(0x40000000);
+ outlinePaint.setStyle(SkPaint::kStroke_Style);
+ outlinePaint.setStrokeWidth(SkIntToScalar(0));
+
+ for (size_t styleIndex = 0; styleIndex < SK_ARRAY_COUNT(styles);
+ styleIndex++) {
+ for (size_t sizeIndex = 0; sizeIndex < SK_ARRAY_COUNT(pathSizes);
+ sizeIndex++) {
+ SkScalar size = pathSizes[sizeIndex];
+
+ canvas->save();
+
+ for (size_t widthIndex = 0;
+ widthIndex < SK_ARRAY_COUNT(strokeWidths);
+ widthIndex++) {
+ SkPaint paint;
+ paint.setColor(0xff007000);
+ paint.setStrokeWidth(strokeWidths[widthIndex]);
+ paint.setStyle(styles[styleIndex].fPaintStyle);
+ paint.setPathEffect(styles[styleIndex].fPathEffect);
+
+ for (size_t pathIndex = 0;
+ pathIndex < SK_ARRAY_COUNT(paths);
+ pathIndex++) {
+ canvas->drawRect(clipRect, clipPaint);
+
+ canvas->save();
+ canvas->clipRect(clipRect);
+
+ SkPath path = paths[pathIndex](cx, cy, size);
+ path.setFillType(SkPath::kInverseWinding_FillType);
+ canvas->drawPath(path, paint);
+
+ path.setFillType(SkPath::kWinding_FillType);
+ canvas->drawPath(path, outlinePaint);
+
+ canvas->restore();
+ canvas->translate(dx, 0);
}
-
- canvas->restore();
- canvas->translate(0, dy);
}
+ canvas->restore();
+ canvas->translate(0, dy);
}
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698