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

Side by Side Diff: gm/dashing.cpp

Issue 699623003: Crop the fast path dashed lines to the cull rect (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address coordinate xform issue 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 unified diff | Download patch
« no previous file with comments | « no previous file | include/core/SkMatrix.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
11 #include "SkDashPathEffect.h" 11 #include "SkDashPathEffect.h"
12 12
13 static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint, 13 static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint,
14 SkScalar finalX = SkIntToScalar(600), SkScalar finalY = SkI ntToScalar(0), 14 SkScalar finalX = SkIntToScalar(600), SkScalar finalY = SkI ntToScalar(0),
15 SkScalar phase = SkIntToScalar(0)) { 15 SkScalar phase = SkIntToScalar(0),
16 SkScalar startX = SkIntToScalar(0), SkScalar startY = SkInt ToScalar(0)) {
16 SkPaint p(paint); 17 SkPaint p(paint);
17 18
18 const SkScalar intervals[] = { 19 const SkScalar intervals[] = {
19 SkIntToScalar(on), 20 SkIntToScalar(on),
20 SkIntToScalar(off), 21 SkIntToScalar(off),
21 }; 22 };
22 23
23 p.setPathEffect(SkDashPathEffect::Create(intervals, 2, phase))->unref(); 24 p.setPathEffect(SkDashPathEffect::Create(intervals, 2, phase))->unref();
24 canvas->drawLine(0, 0, finalX, finalY, p); 25 canvas->drawLine(startX, startY, finalX, finalY, p);
25 } 26 }
26 27
27 // earlier bug stopped us from drawing very long single-segment dashes, because 28 // earlier bug stopped us from drawing very long single-segment dashes, because
28 // SkPathMeasure was skipping very small delta-T values (nearlyzero). This is 29 // SkPathMeasure was skipping very small delta-T values (nearlyzero). This is
29 // now fixes, so this giant dash should appear. 30 // now fixes, so this giant dash should appear.
30 static void show_giant_dash(SkCanvas* canvas) { 31 static void show_giant_dash(SkCanvas* canvas) {
31 SkPaint paint; 32 SkPaint paint;
32 33
33 drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000)); 34 drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000));
34 } 35 }
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 390
390 // Case where only the off interval exists on the line. Thus nothing should be drawn 391 // Case where only the off interval exists on the line. Thus nothing should be drawn
391 drawline(canvas, 32, 16, paint, 8.f, 0.f, 40.f); 392 drawline(canvas, 32, 16, paint, 8.f, 0.f, 40.f);
392 canvas->translate(0, SkIntToScalar(20)); 393 canvas->translate(0, SkIntToScalar(20));
393 } 394 }
394 } 395 }
395 }; 396 };
396 397
397 ////////////////////////////////////////////////////////////////////////////// 398 //////////////////////////////////////////////////////////////////////////////
398 399
399 static skiagm::GM* F0(void*) { return new DashingGM; } 400 class Dashing5GM : public skiagm::GM {
400 static skiagm::GM* F1(void*) { return new Dashing2GM; } 401 public:
401 static skiagm::GM* F2(void*) { return new Dashing3GM; } 402 Dashing5GM(bool doAA) : fDoAA(doAA) {}
402 static skiagm::GM* F3(void*) { return new Dashing4GM; }
403 403
404 static skiagm::GMRegistry gR0(F0); 404 protected:
405 static skiagm::GMRegistry gR1(F1); 405 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kAsBench_Flag | kSk ipTiled_Flag; }
406 static skiagm::GMRegistry gR2(F2); 406
407 static skiagm::GMRegistry gR3(F3); 407 virtual SkString onShortName() SK_OVERRIDE {
408 if (fDoAA) {
409 return SkString("dashing5_aa");
410 } else {
411 return SkString("dashing5_bw");
412 }
413 }
414
415 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(400, 200); }
416
417 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
418 static const int kOn = 4;
419 static const int kOff = 4;
420 static const int kIntervalLength = kOn + kOff;
421
422 static const SkColor gColors[kIntervalLength] = {
423 SK_ColorRED,
424 SK_ColorGREEN,
425 SK_ColorBLUE,
426 SK_ColorCYAN,
427 SK_ColorMAGENTA,
428 SK_ColorYELLOW,
429 SK_ColorGRAY,
430 SK_ColorDKGRAY
431 };
432
433 SkPaint paint;
434 paint.setStyle(SkPaint::kStroke_Style);
435
436 paint.setAntiAlias(fDoAA);
437
438 SkMatrix rot;
439 rot.setRotate(90);
440 SkASSERT(rot.rectStaysRect());
441
442 canvas->concat(rot);
443
444 int sign; // used to toggle the direction of the lines
445 int phase = 0;
446
447 for (int x = 0; x < 200; x += 10) {
448 paint.setStrokeWidth(SkIntToScalar(phase+1));
449 paint.setColor(gColors[phase]);
450 sign = (x % 20) ? 1 : -1;
451 drawline(canvas, kOn, kOff, paint,
452 SkIntToScalar(x), -sign * SkIntToScalar(10003),
453 SkIntToScalar(phase),
454 SkIntToScalar(x), sign * SkIntToScalar(10003));
455 phase = (phase + 1) % kIntervalLength;
456 }
457
458 for (int y = -400; y < 0; y += 10) {
459 paint.setStrokeWidth(SkIntToScalar(phase+1));
460 paint.setColor(gColors[phase]);
461 sign = (y % 20) ? 1 : -1;
462 drawline(canvas, kOn, kOff, paint,
463 -sign * SkIntToScalar(10003), SkIntToScalar(y),
464 SkIntToScalar(phase),
465 sign * SkIntToScalar(10003), SkIntToScalar(y));
466 phase = (phase + 1) % kIntervalLength;
467 }
468 }
469
470 private:
471 bool fDoAA;
472 };
473
474 //////////////////////////////////////////////////////////////////////////////
475
476 DEF_GM(return SkNEW(DashingGM);)
477 DEF_GM(return SkNEW(Dashing2GM);)
478 DEF_GM(return SkNEW(Dashing3GM);)
479 DEF_GM(return SkNEW(Dashing4GM);)
480 DEF_GM(return SkNEW_ARGS(Dashing5GM, (true));)
481 DEF_GM(return SkNEW_ARGS(Dashing5GM, (false));)
482
OLDNEW
« no previous file with comments | « no previous file | include/core/SkMatrix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698