blob: 3c8f740bc73e19bd7ae021f65f621357475f2097 [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_";
25 SkScalar d[3];
26 switch (SkClassifyCubic(fPoints, d)) {
27 case kSerpentine_SkCubicType:
28 fName.append("serp");
29 break;
30 case kLoop_SkCubicType:
31 fName.append("loop");
32 break;
33 default:
34 SkFAIL("Unexpected cubic type");
35 break;
36 }
37 }
38
39 bool isSuitableFor(Backend backend) override {
40 return backend == kNonRendering_Backend;
41 }
42
43 const char* onGetName() override {
44 return fName.c_str();
45 }
46
47 void onDraw(int loops, SkCanvas*) override {
48 SkPoint dst[10];
49 SkMatrix klm;
50 int loopIdx;
51 for (int i = 0; i < loops * 50000; ++i) {
52 GrPathUtils::chopCubicAtLoopIntersection(fPoints, dst, &klm, &loopIdx);
53 }
54 }
55
56private:
57 SkPoint fPoints[4];
58 SkString fName;
59
60 typedef Benchmark INHERITED;
61};
62
63DEF_BENCH( return new CubicKLMBench(285.625f, 499.687f, 411.625f, 808.188f,
64 1064.62f, 135.688f, 1042.63f, 585.187f); )
65DEF_BENCH( return new CubicKLMBench(635.625f, 614.687f, 171.625f, 236.188f,
66 1064.62f, 135.688f, 516.625f, 570.187f); )
67
68#endif