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

Unified Diff: gm/dashing.cpp

Issue 274673004: Add Dashing gpu effect for simple dashed lines (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move DrawDashLine into namespace Created 6 years, 7 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 | « expectations/gm/ignored-tests.txt ('k') | gyp/gpu.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/dashing.cpp
diff --git a/gm/dashing.cpp b/gm/dashing.cpp
index 2f5be081597d55a940405b9c1fc5d323f1e68760..23de24d26b7fce6be551de705a0b86204b869dc6 100644
--- a/gm/dashing.cpp
+++ b/gm/dashing.cpp
@@ -11,7 +11,8 @@
#include "SkDashPathEffect.h"
static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint,
- SkScalar finalX = SkIntToScalar(600)) {
+ SkScalar finalX = SkIntToScalar(600), SkScalar finalY = SkIntToScalar(0),
+ SkScalar phase = SkIntToScalar(0)) {
SkPaint p(paint);
const SkScalar intervals[] = {
@@ -19,8 +20,8 @@ static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint,
SkIntToScalar(off),
};
- p.setPathEffect(SkDashPathEffect::Create(intervals, 2, 0))->unref();
- canvas->drawLine(0, 0, finalX, 0, p);
+ p.setPathEffect(SkDashPathEffect::Create(intervals, 2, phase))->unref();
+ canvas->drawLine(0, 0, finalX, finalY, p);
}
// earlier bug stopped us from drawing very long single-segment dashes, because
@@ -233,6 +234,7 @@ protected:
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p);
}
+
}
virtual void onDraw(SkCanvas* canvas) {
@@ -313,10 +315,96 @@ protected:
//////////////////////////////////////////////////////////////////////////////
+class Dashing4GM : public skiagm::GM {
+public:
+ Dashing4GM() {}
+
+protected:
+ virtual uint32_t onGetFlags() const SK_OVERRIDE {
+ return kSkipTiled_Flag;
+ }
+
+ SkString onShortName() {
+ return SkString("dashing4");
+ }
+
+ SkISize onISize() { return skiagm::make_isize(640, 950); }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ static const struct {
+ int fOnInterval;
+ int fOffInterval;
+ } gData[] = {
+ { 1, 1 },
+ { 4, 2 },
+ { 0, 4 }, // test for zero length on interval
+ };
+
+ SkPaint paint;
+ paint.setStyle(SkPaint::kStroke_Style);
+
+ canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
+ canvas->translate(0, SK_ScalarHalf);
+
+ for (int width = 0; width <= 2; ++width) {
+ for (size_t data = 0; data < SK_ARRAY_COUNT(gData); ++data) {
+ for (int aa = 0; aa <= 1; ++aa) {
+ for (int cap = 0; cap <= 1; ++cap) {
+ int w = width * width * width;
+ paint.setAntiAlias(SkToBool(aa));
+ paint.setStrokeWidth(SkIntToScalar(w));
+
+ SkToBool(cap) ? paint.setStrokeCap(SkPaint::kSquare_Cap)
+ : paint.setStrokeCap(SkPaint::kRound_Cap);
+
+ int scale = w ? w : 1;
+
+ drawline(canvas, gData[data].fOnInterval * scale,
+ gData[data].fOffInterval * scale,
+ paint);
+ canvas->translate(0, SkIntToScalar(20));
+ }
+ }
+ }
+ }
+
+ for (int aa = 0; aa <= 1; ++aa) {
+ paint.setAntiAlias(SkToBool(aa));
+ paint.setStrokeWidth(8.f);
+ paint.setStrokeCap(SkPaint::kSquare_Cap);
+
+ // Single dash element that is cut off at start and end
+ drawline(canvas, 32.f, 16.f, paint, 20.f, 0, 5.f);
+ canvas->translate(0, SkIntToScalar(20));
+
+ // Two dash elements where each one is cut off at beginning and end respectively
+ drawline(canvas, 32.f, 16.f, paint, 56.f, 0, 5.f);
+ canvas->translate(0, SkIntToScalar(20));
+
+ // Many dash elements where first and last are cut off at beginning and end respectively
+ drawline(canvas, 32.f, 16.f, paint, 584.f, 0, 5.f);
+ canvas->translate(0, SkIntToScalar(20));
+
+ // Diagonal dash line where src pnts are not axis aligned (as apposed to being diagonal from
+ // a canvas rotation)
+ drawline(canvas, 32.f, 16.f, paint, 600.f, 30.f);
+ canvas->translate(0, SkIntToScalar(20));
+
+ // Case where only the off interval exists on the line. Thus nothing should be drawn
+ drawline(canvas, 32.f, 16.f, paint, 8.f, 0.f, 40.f);
+ canvas->translate(0, SkIntToScalar(20));
+ }
+ }
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
static skiagm::GM* F0(void*) { return new DashingGM; }
static skiagm::GM* F1(void*) { return new Dashing2GM; }
static skiagm::GM* F2(void*) { return new Dashing3GM; }
+static skiagm::GM* F3(void*) { return new Dashing4GM; }
static skiagm::GMRegistry gR0(F0);
static skiagm::GMRegistry gR1(F1);
static skiagm::GMRegistry gR2(F2);
+static skiagm::GMRegistry gR3(F3);
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | gyp/gpu.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698