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

Unified Diff: gm/dashing.cpp

Issue 706013005: Cherry pick two CLs back to M39 to fix a bug (Closed) Base URL: https://skia.googlesource.com/skia.git@m39
Patch Set: Created 6 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 | « expectations/gm/ignored-tests.txt ('k') | include/core/SkMatrix.h » ('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 55addc8a66f3cba4086924ff90289e90c29ad938..7e32bfaf90a7adfeea6c26662a2116e602e84147 100644
--- a/gm/dashing.cpp
+++ b/gm/dashing.cpp
@@ -12,7 +12,8 @@
static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint,
SkScalar finalX = SkIntToScalar(600), SkScalar finalY = SkIntToScalar(0),
- SkScalar phase = SkIntToScalar(0)) {
+ SkScalar phase = SkIntToScalar(0),
+ SkScalar startX = SkIntToScalar(0), SkScalar startY = SkIntToScalar(0)) {
SkPaint p(paint);
const SkScalar intervals[] = {
@@ -21,7 +22,7 @@ static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint,
};
p.setPathEffect(SkDashPathEffect::Create(intervals, 2, phase))->unref();
- canvas->drawLine(0, 0, finalX, finalY, p);
+ canvas->drawLine(startX, startY, finalX, finalY, p);
}
// earlier bug stopped us from drawing very long single-segment dashes, because
@@ -33,6 +34,16 @@ static void show_giant_dash(SkCanvas* canvas) {
drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000));
}
+static void show_zero_len_dash(SkCanvas* canvas) {
+ SkPaint paint;
+
+ drawline(canvas, 2, 2, paint, SkIntToScalar(0));
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStrokeWidth(SkIntToScalar(2));
+ canvas->translate(0, SkIntToScalar(20));
+ drawline(canvas, 4, 4, paint, SkIntToScalar(0));
+}
+
class DashingGM : public skiagm::GM {
public:
DashingGM() {}
@@ -80,6 +91,8 @@ protected:
}
show_giant_dash(canvas);
+ canvas->translate(0, SkIntToScalar(20));
+ show_zero_len_dash(canvas);
}
};
@@ -396,12 +409,86 @@ protected:
//////////////////////////////////////////////////////////////////////////////
-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; }
+class Dashing5GM : public skiagm::GM {
+public:
+ Dashing5GM(bool doAA) : fDoAA(doAA) {}
+
+protected:
+ virtual uint32_t onGetFlags() const SK_OVERRIDE { return kAsBench_Flag | kSkipTiled_Flag; }
+
+ virtual SkString onShortName() SK_OVERRIDE {
+ if (fDoAA) {
+ return SkString("dashing5_aa");
+ } else {
+ return SkString("dashing5_bw");
+ }
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(400, 200); }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ static const int kOn = 4;
+ static const int kOff = 4;
+ static const int kIntervalLength = kOn + kOff;
+
+ static const SkColor gColors[kIntervalLength] = {
+ SK_ColorRED,
+ SK_ColorGREEN,
+ SK_ColorBLUE,
+ SK_ColorCYAN,
+ SK_ColorMAGENTA,
+ SK_ColorYELLOW,
+ SK_ColorGRAY,
+ SK_ColorDKGRAY
+ };
+
+ SkPaint paint;
+ paint.setStyle(SkPaint::kStroke_Style);
+
+ paint.setAntiAlias(fDoAA);
+
+ SkMatrix rot;
+ rot.setRotate(90);
+ SkASSERT(rot.rectStaysRect());
+
+ canvas->concat(rot);
+
+ int sign; // used to toggle the direction of the lines
+ int phase = 0;
+
+ for (int x = 0; x < 200; x += 10) {
+ paint.setStrokeWidth(SkIntToScalar(phase+1));
+ paint.setColor(gColors[phase]);
+ sign = (x % 20) ? 1 : -1;
+ drawline(canvas, kOn, kOff, paint,
+ SkIntToScalar(x), -sign * SkIntToScalar(10003),
+ SkIntToScalar(phase),
+ SkIntToScalar(x), sign * SkIntToScalar(10003));
+ phase = (phase + 1) % kIntervalLength;
+ }
+
+ for (int y = -400; y < 0; y += 10) {
+ paint.setStrokeWidth(SkIntToScalar(phase+1));
+ paint.setColor(gColors[phase]);
+ sign = (y % 20) ? 1 : -1;
+ drawline(canvas, kOn, kOff, paint,
+ -sign * SkIntToScalar(10003), SkIntToScalar(y),
+ SkIntToScalar(phase),
+ sign * SkIntToScalar(10003), SkIntToScalar(y));
+ phase = (phase + 1) % kIntervalLength;
+ }
+ }
+
+private:
+ bool fDoAA;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_GM(return SkNEW(DashingGM);)
+DEF_GM(return SkNEW(Dashing2GM);)
+DEF_GM(return SkNEW(Dashing3GM);)
+DEF_GM(return SkNEW(Dashing4GM);)
+DEF_GM(return SkNEW_ARGS(Dashing5GM, (true));)
+DEF_GM(return SkNEW_ARGS(Dashing5GM, (false));)
-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') | include/core/SkMatrix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698