blob: 191e1804aa886248c2c72b6912771e7dbc9d26a2 [file] [log] [blame]
csmartdaltoncc261272017-03-23 13:38:45 -06001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "Benchmark.h"
9
10#if SK_SUPPORT_GPU
11
12#include "GrPathUtils.h"
13#include "SkGeometry.h"
14
15class CubicKLMBench : public Benchmark {
16public:
17 CubicKLMBench(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1,
18 SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3) {
19 fPoints[0].set(x0, y0);
20 fPoints[1].set(x1, y1);
21 fPoints[2].set(x2, y2);
22 fPoints[3].set(x3, y3);
23
24 fName = "cubic_klm_";
Chris Daltonfebbffa2017-06-08 13:12:02 -060025 switch (SkClassifyCubic(fPoints)) {
Chris Dalton43436542017-04-13 14:26:00 -060026 case SkCubicType::kSerpentine:
csmartdaltoncc261272017-03-23 13:38:45 -060027 fName.append("serp");
28 break;
Chris Dalton43436542017-04-13 14:26:00 -060029 case SkCubicType::kLoop:
csmartdaltoncc261272017-03-23 13:38:45 -060030 fName.append("loop");
31 break;
32 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040033 SK_ABORT("Unexpected cubic type");
csmartdaltoncc261272017-03-23 13:38:45 -060034 break;
35 }
36 }
37
38 bool isSuitableFor(Backend backend) override {
39 return backend == kNonRendering_Backend;
40 }
41
42 const char* onGetName() override {
43 return fName.c_str();
44 }
45
46 void onDraw(int loops, SkCanvas*) override {
47 SkPoint dst[10];
48 SkMatrix klm;
49 int loopIdx;
50 for (int i = 0; i < loops * 50000; ++i) {
51 GrPathUtils::chopCubicAtLoopIntersection(fPoints, dst, &klm, &loopIdx);
52 }
53 }
54
55private:
56 SkPoint fPoints[4];
57 SkString fName;
58
59 typedef Benchmark INHERITED;
60};
61
62DEF_BENCH( return new CubicKLMBench(285.625f, 499.687f, 411.625f, 808.188f,
63 1064.62f, 135.688f, 1042.63f, 585.187f); )
64DEF_BENCH( return new CubicKLMBench(635.625f, 614.687f, 171.625f, 236.188f,
65 1064.62f, 135.688f, 516.625f, 570.187f); )
66
67#endif