blob: 84a9e1ef9c6769750047e192fd4870b3facee63c [file] [log] [blame]
Chris Daltonb3a69592018-04-18 14:10:22 -06001/*
2 * Copyright 2018 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
Chris Daltone1639692018-08-20 14:00:30 -060010#include "ccpr/GrCCFillGeometry.h"
Chris Daltonb3a69592018-04-18 14:10:22 -060011#include "SkGeometry.h"
12
13static int kNumBaseLoops = 50000;
14
15class GrCCGeometryBench : public Benchmark {
16public:
17 GrCCGeometryBench(float x0, float y0, float x1, float y1,
18 float x2, float y2, float x3, float y3, const char* extraName) {
19 fPoints[0].set(x0, y0);
20 fPoints[1].set(x1, y1);
21 fPoints[2].set(x2, y2);
22 fPoints[3].set(x3, y3);
Chris Dalton6f5e77a2018-04-23 21:14:42 -060023 fPoints[4].set(x0, y0); // Flat closing edge.
Chris Daltonb3a69592018-04-18 14:10:22 -060024
25 fName = "ccprgeometry";
26 switch (SkClassifyCubic(fPoints)) {
27 case SkCubicType::kSerpentine:
28 fName.append("_serp");
29 break;
30 case SkCubicType::kLoop:
31 fName.append("_loop");
32 break;
33 default:
34 SK_ABORT("Unexpected cubic type");
35 break;
36 }
37
38 fName.appendf("_%s", extraName);
39 }
40
41 bool isSuitableFor(Backend backend) override {
42 return backend == kNonRendering_Backend;
43 }
44
45 const char* onGetName() override {
46 return fName.c_str();
47 }
48
49 void onDraw(int loops, SkCanvas*) override {
50 for (int j = 0; j < loops; ++j) {
51 fGeometry.beginContour(fPoints[0]);
52 for (int i = 0; i < kNumBaseLoops; ++i) {
53 fGeometry.cubicTo(fPoints);
Chris Dalton6f5e77a2018-04-23 21:14:42 -060054 fGeometry.lineTo(fPoints+3);
Chris Daltonb3a69592018-04-18 14:10:22 -060055 }
56 fGeometry.endContour();
57 fGeometry.reset();
58 }
59 }
60
61private:
Chris Dalton6f5e77a2018-04-23 21:14:42 -060062 SkPoint fPoints[5];
Chris Daltonb3a69592018-04-18 14:10:22 -060063 SkString fName;
Chris Daltone1639692018-08-20 14:00:30 -060064 GrCCFillGeometry fGeometry{4*100*kNumBaseLoops, 2*100*kNumBaseLoops};
Chris Daltonb3a69592018-04-18 14:10:22 -060065
66 typedef Benchmark INHERITED;
67};
68
69// Loops.
70DEF_BENCH( return new GrCCGeometryBench(529.049988f, 637.050049f, 335.750000f, -135.950012f,
71 912.750000f, 560.949951f, 59.049988f, 295.950012f,
72 "2_roots"); )
73
74DEF_BENCH( return new GrCCGeometryBench(182.050003f, 300.049988f, 490.750000f, 111.049988f,
75 482.750000f, 500.950012f, 451.049988f, 553.950012f,
76 "1_root"); )
77
78DEF_BENCH( return new GrCCGeometryBench(498.049988f, 476.049988f, 330.750000f, 330.049988f,
79 222.750000f, 389.950012f, 169.049988f, 542.950012f,
80 "0_roots"); )
81
82// Serpentines.
83DEF_BENCH( return new GrCCGeometryBench(529.049988f, 714.049988f, 315.750000f, 196.049988f,
84 484.750000f, 110.950012f, 349.049988f, 630.950012f,
85 "2_roots"); )
86
87DEF_BENCH( return new GrCCGeometryBench(513.049988f, 245.049988f, 73.750000f, 137.049988f,
88 508.750000f, 657.950012f, 99.049988f, 601.950012f,
89 "1_root"); )
90
91DEF_BENCH( return new GrCCGeometryBench(560.049988f, 364.049988f, 217.750000f, 314.049988f,
92 21.750000f, 364.950012f, 83.049988f, 624.950012f,
93 "0_roots"); )