aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/dashing.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2014-11-04 13:33:50 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-04 13:33:50 -0800
commit9f2251c73ed6f417dd1057d487bf523e04488440 (patch)
tree8d2195fb4413dbd74b7cd7f6cd7c8a2c6c832f68 /gm/dashing.cpp
parent0e66aaa503fd30b9860c0306ae20e8d7758b0fe6 (diff)
Crop the fast path dashed lines to the cull rect
Without: maxrss loops min median mean max stddev samples config bench 56M 1 13.3ms 13.6ms 13.6ms 14.2ms 2% Ooooo..... 8888 GM_dashing5_bw 56M 13 390us 417us 416us 459us 5% ooooO..o.o gpu GM_dashing5_bw 56M 1 13.4ms 13.9ms 14.1ms 15ms 3% Oooo..ooOo 8888 GM_dashing5_aa 56M 13 402us 421us 416us 425us 2% Ooo.ooOOOO gpu GM_dashing5_aa With: 40M 1 1.53ms 1.54ms 1.54ms 1.55ms 0% oo.O...o.. 8888 GM_dashing5_bw 40M 12 407us 412us 415us 445us 3% ...Oo..... gpu GM_dashing5_bw 40M 1 1.7ms 1.7ms 1.7ms 1.72ms 0% o.O....... 8888 GM_dashing5_aa 43M 13 405us 409us 409us 415us 1% ooo.Ooo..o gpu GM_dashing5_aa The GM images (including the new one) are the same with and without this CL. BUG=428296 Review URL: https://codereview.chromium.org/699623003
Diffstat (limited to 'gm/dashing.cpp')
-rw-r--r--gm/dashing.cpp95
1 files changed, 85 insertions, 10 deletions
diff --git a/gm/dashing.cpp b/gm/dashing.cpp
index 55addc8a66..d6c1c97df9 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
@@ -396,12 +397,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);