Home | History | Annotate | Download | only in bench
      1 /*
      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 
     10 #include "ccpr/GrCCFillGeometry.h"
     11 #include "SkGeometry.h"
     12 
     13 static int kNumBaseLoops = 50000;
     14 
     15 class GrCCGeometryBench : public Benchmark {
     16 public:
     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);
     23         fPoints[4].set(x0, y0); // Flat closing edge.
     24 
     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);
     54                 fGeometry.lineTo(fPoints+3);
     55             }
     56             fGeometry.endContour();
     57             fGeometry.reset();
     58         }
     59     }
     60 
     61 private:
     62     SkPoint fPoints[5];
     63     SkString fName;
     64     GrCCFillGeometry fGeometry{4*100*kNumBaseLoops, 2*100*kNumBaseLoops};
     65 
     66     typedef Benchmark INHERITED;
     67 };
     68 
     69 // Loops.
     70 DEF_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 
     74 DEF_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 
     78 DEF_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.
     83 DEF_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 
     87 DEF_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 
     91 DEF_BENCH( return new GrCCGeometryBench(560.049988f, 364.049988f, 217.750000f, 314.049988f,
     92                                         21.750000f, 364.950012f, 83.049988f, 624.950012f,
     93                                         "0_roots"); )
     94