diff options
author | bsalomon <bsalomon@google.com> | 2016-05-10 09:14:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-10 09:14:17 -0700 |
commit | 6663acff010ce752e4bf778da81fa97448c9db31 (patch) | |
tree | ba48f7716f7ef948d9faac90599b8a555c0f51d3 /src/gpu/GrTestUtils.cpp | |
parent | 44d427e048b2e290e086dc2c9f9227818388ef17 (diff) |
Replace GrStrokeInfo with GrStyle.
A side effect is that arbitrary path effects can no be pushed deeper into the Ganesh flow for paths. They may be applied by path renderers.
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1957363002
Committed: https://skia.googlesource.com/skia/+/33595bdf4b64a745f6340338d307e806e96c587f
Review-Url: https://codereview.chromium.org/1957363002
Diffstat (limited to 'src/gpu/GrTestUtils.cpp')
-rw-r--r-- | src/gpu/GrTestUtils.cpp | 65 |
1 files changed, 46 insertions, 19 deletions
diff --git a/src/gpu/GrTestUtils.cpp b/src/gpu/GrTestUtils.cpp index 86a84ceb0a..e962978fc3 100644 --- a/src/gpu/GrTestUtils.cpp +++ b/src/gpu/GrTestUtils.cpp @@ -5,10 +5,10 @@ * found in the LICENSE file. */ -#include "GrStrokeInfo.h" #include "GrTestUtils.h" +#include "GrStyle.h" +#include "SkDashPathPriv.h" #include "SkMatrix.h" -#include "SkPathEffect.h" #include "SkPath.h" #include "SkRRect.h" @@ -237,26 +237,53 @@ SkStrokeRec TestStrokeRec(SkRandom* random) { return rec; } -GrStrokeInfo TestStrokeInfo(SkRandom* random) { - SkStrokeRec::InitStyle style = +void TestStyle(SkRandom* random, GrStyle* style) { + SkStrokeRec::InitStyle initStyle = SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_InitStyle + 1)); - GrStrokeInfo strokeInfo(style); - randomize_stroke_rec(&strokeInfo, random); - SkPathEffect::DashInfo dashInfo; - dashInfo.fCount = random->nextRangeU(1, 50) * 2; - dashInfo.fIntervals = new SkScalar[dashInfo.fCount]; - SkScalar sum = 0; - for (int i = 0; i < dashInfo.fCount; i++) { - dashInfo.fIntervals[i] = random->nextRangeScalar(SkDoubleToScalar(0.01), - SkDoubleToScalar(10.0)); - sum += dashInfo.fIntervals[i]; + SkStrokeRec stroke(initStyle); + randomize_stroke_rec(&stroke, random); + sk_sp<SkPathEffect> pe; + if (random->nextBool()) { + int cnt = random->nextRangeU(1, 50) * 2; + SkAutoTDeleteArray<SkScalar> intervals(new SkScalar[cnt]); + SkScalar sum = 0; + for (int i = 0; i < cnt; i++) { + intervals[i] = random->nextRangeScalar(SkDoubleToScalar(0.01), + SkDoubleToScalar(10.0)); + sum += intervals[i]; + } + SkScalar phase = random->nextRangeScalar(0, sum); + pe = TestDashPathEffect::Make(intervals.get(), cnt, phase); } - dashInfo.fPhase = random->nextRangeScalar(0, sum); - strokeInfo.setDashInfo(dashInfo); - delete[] dashInfo.fIntervals; - return strokeInfo; + *style = GrStyle(stroke, pe.get()); +} + +TestDashPathEffect::TestDashPathEffect(const SkScalar* intervals, int count, SkScalar phase) { + fCount = count; + fIntervals.reset(count); + memcpy(fIntervals.get(), intervals, count * sizeof(SkScalar)); + SkDashPath::CalcDashParameters(phase, intervals, count, &fInitialDashLength, + &fInitialDashIndex, &fIntervalLength, &fPhase); +} + + bool TestDashPathEffect::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec, + const SkRect* cullRect) const { + return SkDashPath::InternalFilter(dst, src, rec, cullRect, fIntervals.get(), fCount, + fInitialDashLength, fInitialDashIndex, fIntervalLength); } -}; +SkPathEffect::DashType TestDashPathEffect::asADash(DashInfo* info) const { + if (info) { + if (info->fCount >= fCount && info->fIntervals) { + memcpy(info->fIntervals, fIntervals.get(), fCount * sizeof(SkScalar)); + } + info->fCount = fCount; + info->fPhase = fPhase; + } + return kDash_DashType; +} + + +} // namespace GrTest #endif |