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

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: 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 | src/effects/SkDashPathEffect.cpp » ('j') | src/effects/SkDashPathEffect.cpp » ('J')
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(640, 300); }
416
417 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
418 static const int kStrokeWidth = 8;
419
420 SkPaint paint;
421 paint.setStyle(SkPaint::kStroke_Style);
422
423 paint.setAntiAlias(fDoAA);
424 paint.setStrokeWidth(SkIntToScalar(kStrokeWidth));
425
426 for (int x = 0; x < 640; x += 10) {
427 drawline(canvas, 1, 1, paint, SkIntToScalar(x), -SkIntToScalar(10 * 1000), 0,
428 SkIntToScalar(x), SkIntToScalar(10 * 1000));
429 }
430
431 for (int y = 0; y < 300; y += 10) {
432 drawline(canvas, 1, 1, paint, -SkIntToScalar(10 * 1000), SkIntToScal ar(y), 0,
433 SkIntToScalar(10 * 1000), SkIntToScal ar(y));
434 }
435 }
436
437 private:
438 bool fDoAA;
439 };
440
441 //////////////////////////////////////////////////////////////////////////////
442
443 DEF_GM(return SkNEW(DashingGM);)
444 DEF_GM(return SkNEW(Dashing2GM);)
445 DEF_GM(return SkNEW(Dashing3GM);)
446 DEF_GM(return SkNEW(Dashing4GM);)
447 DEF_GM(return SkNEW_ARGS(Dashing5GM, (true));)
448 DEF_GM(return SkNEW_ARGS(Dashing5GM, (false));)
449
OLDNEW
« no previous file with comments | « no previous file | src/effects/SkDashPathEffect.cpp » ('j') | src/effects/SkDashPathEffect.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698