1 /* 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 "bench/Benchmark.h" 9 10 #include "src/core/SkGeometry.h" 11 #include "src/gpu/geometry/GrPathUtils.h" 12 13 class CubicKLMBench : public Benchmark { 14 public: CubicKLMBench(SkScalar x0,SkScalar y0,SkScalar x1,SkScalar y1,SkScalar x2,SkScalar y2,SkScalar x3,SkScalar y3)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_"; 23 switch (SkClassifyCubic(fPoints)) { 24 case SkCubicType::kSerpentine: 25 fName.append("serp"); 26 break; 27 case SkCubicType::kLoop: 28 fName.append("loop"); 29 break; 30 default: 31 SK_ABORT("Unexpected cubic type"); 32 break; 33 } 34 } 35 isSuitableFor(Backend backend)36 bool isSuitableFor(Backend backend) override { 37 return backend == kNonRendering_Backend; 38 } 39 onGetName()40 const char* onGetName() override { 41 return fName.c_str(); 42 } 43 onDraw(int loops,SkCanvas *)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 53 private: 54 SkPoint fPoints[4]; 55 SkString fName; 56 57 typedef Benchmark INHERITED; 58 }; 59 60 DEF_BENCH( return new CubicKLMBench(285.625f, 499.687f, 411.625f, 808.188f, 61 1064.62f, 135.688f, 1042.63f, 585.187f); ) 62 DEF_BENCH( return new CubicKLMBench(635.625f, 614.687f, 171.625f, 236.188f, 63 1064.62f, 135.688f, 516.625f, 570.187f); ) 64