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 "Benchmark.h" 9 10 #if SK_SUPPORT_GPU 11 12 #include "GrPathUtils.h" 13 #include "SkGeometry.h" 14 15 class CubicKLMBench : public Benchmark { 16 public: 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 switch (SkClassifyCubic(fPoints)) { 26 case SkCubicType::kSerpentine: 27 fName.append("serp"); 28 break; 29 case SkCubicType::kLoop: 30 fName.append("loop"); 31 break; 32 default: 33 SK_ABORT("Unexpected cubic type"); 34 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 55 private: 56 SkPoint fPoints[4]; 57 SkString fName; 58 59 typedef Benchmark INHERITED; 60 }; 61 62 DEF_BENCH( return new CubicKLMBench(285.625f, 499.687f, 411.625f, 808.188f, 63 1064.62f, 135.688f, 1042.63f, 585.187f); ) 64 DEF_BENCH( return new CubicKLMBench(635.625f, 614.687f, 171.625f, 236.188f, 65 1064.62f, 135.688f, 516.625f, 570.187f); ) 66 67 #endif 68