diff options
author | csmartdalton <csmartdalton@google.com> | 2017-03-23 13:38:45 -0600 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-23 21:05:45 +0000 |
commit | cc26127920069cbd83e92cca3c69bb56cb165bcc (patch) | |
tree | 4454582e03d9b0701fbd4a23042a27cfeaea868b /bench/CubicKLMBench.cpp | |
parent | f160ad4d76e9e7ec21c48f92ba05c16ffec566b4 (diff) |
Find cubic KLM functionals directly
- Updates GrPathUtils to computes the KLM functionals directly instead
of deriving them from their explicit values at the control points.
- Updates the utility to return these functionals as a matrix
rather than an array of scalar values.
- Adds a benchmark for chopCubicAtLoopIntersection.
BUG=skia:
Change-Id: I97a9b5cf610d33e15c9af96b9d9a8eb4a94b1ca7
Reviewed-on: https://skia-review.googlesource.com/9951
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'bench/CubicKLMBench.cpp')
-rw-r--r-- | bench/CubicKLMBench.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/bench/CubicKLMBench.cpp b/bench/CubicKLMBench.cpp new file mode 100644 index 0000000000..3c8f740bc7 --- /dev/null +++ b/bench/CubicKLMBench.cpp @@ -0,0 +1,68 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "Benchmark.h" + +#if SK_SUPPORT_GPU + +#include "GrPathUtils.h" +#include "SkGeometry.h" + +class CubicKLMBench : public Benchmark { +public: + CubicKLMBench(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, + SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3) { + fPoints[0].set(x0, y0); + fPoints[1].set(x1, y1); + fPoints[2].set(x2, y2); + fPoints[3].set(x3, y3); + + fName = "cubic_klm_"; + SkScalar d[3]; + switch (SkClassifyCubic(fPoints, d)) { + case kSerpentine_SkCubicType: + fName.append("serp"); + break; + case kLoop_SkCubicType: + fName.append("loop"); + break; + default: + SkFAIL("Unexpected cubic type"); + break; + } + } + + bool isSuitableFor(Backend backend) override { + return backend == kNonRendering_Backend; + } + + const char* onGetName() override { + return fName.c_str(); + } + + void onDraw(int loops, SkCanvas*) override { + SkPoint dst[10]; + SkMatrix klm; + int loopIdx; + for (int i = 0; i < loops * 50000; ++i) { + GrPathUtils::chopCubicAtLoopIntersection(fPoints, dst, &klm, &loopIdx); + } + } + +private: + SkPoint fPoints[4]; + SkString fName; + + typedef Benchmark INHERITED; +}; + +DEF_BENCH( return new CubicKLMBench(285.625f, 499.687f, 411.625f, 808.188f, + 1064.62f, 135.688f, 1042.63f, 585.187f); ) +DEF_BENCH( return new CubicKLMBench(635.625f, 614.687f, 171.625f, 236.188f, + 1064.62f, 135.688f, 516.625f, 570.187f); ) + +#endif |