blob: 8e13a2de00e44fd5e56550caede19f303f615ec8 [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
csmartdaltoncc261272017-03-23 13:38:45 -060010#include "GrPathUtils.h"
11#include "SkGeometry.h"
12
13class CubicKLMBench : public Benchmark {
14public:
15 CubicKLMBench(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1,
16 SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3) {
17 fPoints[0].set(x0, y0);
18 fPoints[1].set(x1, y1);
19 fPoints[2].set(x2, y2);
20 fPoints[3].set(x3, y3);
21
22 fName = "cubic_klm_";
Chris Daltonfebbffa2017-06-08 13:12:02 -060023 switch (SkClassifyCubic(fPoints)) {
Chris Dalton43436542017-04-13 14:26:00 -060024 case SkCubicType::kSerpentine:
csmartdaltoncc261272017-03-23 13:38:45 -060025 fName.append("serp");
26 break;
Chris Dalton43436542017-04-13 14:26:00 -060027 case SkCubicType::kLoop:
csmartdaltoncc261272017-03-23 13:38:45 -060028 fName.append("loop");
29 break;
30 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040031 SK_ABORT("Unexpected cubic type");
csmartdaltoncc261272017-03-23 13:38:45 -060032 break;
33 }
34 }
35
36 bool isSuitableFor(Backend backend) override {
37 return backend == kNonRendering_Backend;
38 }
39
40 const char* onGetName() override {
41 return fName.c_str();
42 }
43
44 void onDraw(int loops, SkCanvas*) override {
45 SkPoint dst[10];
46 SkMatrix klm;
47 int loopIdx;
48 for (int i = 0; i < loops * 50000; ++i) {
49 GrPathUtils::chopCubicAtLoopIntersection(fPoints, dst, &klm, &loopIdx);
50 }
51 }
52
53private:
54 SkPoint fPoints[4];
55 SkString fName;
56
57 typedef Benchmark INHERITED;
58};
59
60DEF_BENCH( return new CubicKLMBench(285.625f, 499.687f, 411.625f, 808.188f,
61 1064.62f, 135.688f, 1042.63f, 585.187f); )
62DEF_BENCH( return new CubicKLMBench(635.625f, 614.687f, 171.625f, 236.188f,
63 1064.62f, 135.688f, 516.625f, 570.187f); )