| OLD | NEW |
| 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)) { | 14 SkScalar finalX = SkIntToScalar(600)) { |
| 15 SkPaint p(paint); | 15 SkPaint p(paint); |
| 16 | 16 |
| 17 const SkScalar intervals[] = { | 17 const SkScalar intervals[] = { |
| 18 SkIntToScalar(on), | 18 SkIntToScalar(on), |
| 19 SkIntToScalar(off), | 19 SkIntToScalar(off), |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 p.setPathEffect(new SkDashPathEffect(intervals, 2, 0))->unref(); | 22 p.setPathEffect(SkDashPathEffect::Create(intervals, 2, 0))->unref(); |
| 23 canvas->drawLine(0, 0, finalX, 0, p); | 23 canvas->drawLine(0, 0, finalX, 0, p); |
| 24 } | 24 } |
| 25 | 25 |
| 26 // earlier bug stopped us from drawing very long single-segment dashes, because | 26 // earlier bug stopped us from drawing very long single-segment dashes, because |
| 27 // SkPathMeasure was skipping very small delta-T values (nearlyzero). This is | 27 // SkPathMeasure was skipping very small delta-T values (nearlyzero). This is |
| 28 // now fixes, so this giant dash should appear. | 28 // now fixes, so this giant dash should appear. |
| 29 static void show_giant_dash(SkCanvas* canvas) { | 29 static void show_giant_dash(SkCanvas* canvas) { |
| 30 SkPaint paint; | 30 SkPaint paint; |
| 31 | 31 |
| 32 drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000)); | 32 drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000)); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 SkScalar dy = bounds.height() * 4 / 3; | 148 SkScalar dy = bounds.height() * 4 / 3; |
| 149 | 149 |
| 150 const int* intervals = &gIntervals[1]; | 150 const int* intervals = &gIntervals[1]; |
| 151 for (int y = 0; y < gIntervals[0]; ++y) { | 151 for (int y = 0; y < gIntervals[0]; ++y) { |
| 152 SkScalar vals[SK_ARRAY_COUNT(gIntervals)]; // more than enough | 152 SkScalar vals[SK_ARRAY_COUNT(gIntervals)]; // more than enough |
| 153 int count = *intervals++; | 153 int count = *intervals++; |
| 154 for (int i = 0; i < count; ++i) { | 154 for (int i = 0; i < count; ++i) { |
| 155 vals[i] = SkIntToScalar(*intervals++); | 155 vals[i] = SkIntToScalar(*intervals++); |
| 156 } | 156 } |
| 157 SkScalar phase = vals[0] / 2; | 157 SkScalar phase = vals[0] / 2; |
| 158 paint.setPathEffect(new SkDashPathEffect(vals, count, phase))->unref
(); | 158 paint.setPathEffect(SkDashPathEffect::Create(vals, count, phase))->u
nref(); |
| 159 | 159 |
| 160 for (size_t x = 0; x < SK_ARRAY_COUNT(gProc); ++x) { | 160 for (size_t x = 0; x < SK_ARRAY_COUNT(gProc); ++x) { |
| 161 SkPath path; | 161 SkPath path; |
| 162 SkRect r = bounds; | 162 SkRect r = bounds; |
| 163 r.offset(x * dx, y * dy); | 163 r.offset(x * dx, y * dy); |
| 164 gProc[x](&path, r); | 164 gProc[x](&path, r); |
| 165 | 165 |
| 166 canvas->drawPath(path, paint); | 166 canvas->drawPath(path, paint); |
| 167 } | 167 } |
| 168 } | 168 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 195 p.setColor(SK_ColorBLACK); | 195 p.setColor(SK_ColorBLACK); |
| 196 p.setStyle(SkPaint::kStroke_Style); | 196 p.setStyle(SkPaint::kStroke_Style); |
| 197 p.setStrokeWidth(SkIntToScalar(strokeWidth)); | 197 p.setStrokeWidth(SkIntToScalar(strokeWidth)); |
| 198 | 198 |
| 199 if (circles) { | 199 if (circles) { |
| 200 p.setStrokeCap(SkPaint::kRound_Cap); | 200 p.setStrokeCap(SkPaint::kRound_Cap); |
| 201 } | 201 } |
| 202 | 202 |
| 203 SkScalar intervals[2] = { dashLength, dashLength }; | 203 SkScalar intervals[2] = { dashLength, dashLength }; |
| 204 | 204 |
| 205 p.setPathEffect(new SkDashPathEffect(intervals, 2, phase, false))->unref
(); | 205 p.setPathEffect(SkDashPathEffect::Create(intervals, 2, phase, false))->u
nref(); |
| 206 | 206 |
| 207 SkPoint pts[2]; | 207 SkPoint pts[2]; |
| 208 | 208 |
| 209 for (int y = 0; y < 100; y += 10*strokeWidth) { | 209 for (int y = 0; y < 100; y += 10*strokeWidth) { |
| 210 pts[0].set(0, SkIntToScalar(y)); | 210 pts[0].set(0, SkIntToScalar(y)); |
| 211 pts[1].set(lineLength, SkIntToScalar(y)); | 211 pts[1].set(lineLength, SkIntToScalar(y)); |
| 212 | 212 |
| 213 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p); | 213 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p); |
| 214 } | 214 } |
| 215 | 215 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 301 |
| 302 ////////////////////////////////////////////////////////////////////////////// | 302 ////////////////////////////////////////////////////////////////////////////// |
| 303 | 303 |
| 304 static skiagm::GM* F0(void*) { return new DashingGM; } | 304 static skiagm::GM* F0(void*) { return new DashingGM; } |
| 305 static skiagm::GM* F1(void*) { return new Dashing2GM; } | 305 static skiagm::GM* F1(void*) { return new Dashing2GM; } |
| 306 static skiagm::GM* F2(void*) { return new Dashing3GM; } | 306 static skiagm::GM* F2(void*) { return new Dashing3GM; } |
| 307 | 307 |
| 308 static skiagm::GMRegistry gR0(F0); | 308 static skiagm::GMRegistry gR0(F0); |
| 309 static skiagm::GMRegistry gR1(F1); | 309 static skiagm::GMRegistry gR1(F1); |
| 310 static skiagm::GMRegistry gR2(F2); | 310 static skiagm::GMRegistry gR2(F2); |
| OLD | NEW |