skia2/bench/CubicKLMBench.cpp
Chris Dalton febbffad1c Improve cubic KLM accuracy
Moves cubic root finding logic out of GrPathUtils and
PathOpsCubicIntersectionTest, and unifies it in SkGeometry.

"Normalizes" the homogeneous parameter values of the roots, rather
than the cubic inflection function. Does this normalization by
twiddling the exponents instead of division (which causes a loss of
precision).

Abandons the built-in derivatives in GrCubicEffect. These don't have
high enough precision on many mobile gpus. Instead we pass the KLM
matrix to the vertex shader via uniform, where we can use it to set up
new linear functionals from which the fragment shader can calculate
the gradient of the implicit function.

Bug: skia:4410
Change-Id: Ibd64e999520adc8cdef7803a492d3699995aef5a
Reviewed-on: https://skia-review.googlesource.com/19017
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
2017-06-09 17:13:54 +00:00

68 lines
1.8 KiB
C++

/*
* 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_";
switch (SkClassifyCubic(fPoints)) {
case SkCubicType::kSerpentine:
fName.append("serp");
break;
case SkCubicType::kLoop:
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