Home | History | Annotate | Download | only in bench
      1 /*
      2  * Copyright 2011 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 "SkBenchmark.h"
      9 #include "SkAAClip.h"
     10 #include "SkPath.h"
     11 #include "SkRegion.h"
     12 #include "SkString.h"
     13 
     14 class AAClipBuilderBench : public SkBenchmark {
     15     SkString fName;
     16     SkPath   fPath;
     17     SkRect   fRect;
     18     SkRegion fRegion;
     19     bool     fDoPath;
     20     bool     fDoAA;
     21 
     22     enum {
     23         N = SkBENCHLOOP(200),
     24     };
     25 
     26 public:
     27     AAClipBuilderBench(void* param, bool doPath, bool doAA) : INHERITED(param) {
     28         fDoPath = doPath;
     29         fDoAA = doAA;
     30 
     31         fName.printf("aaclip_build_%s_%s", doPath ? "path" : "rect",
     32                      doAA ? "AA" : "BW");
     33 
     34         fRegion.setRect(0, 0, 640, 480);
     35         fRect.set(fRegion.getBounds());
     36         fRect.inset(SK_Scalar1/4, SK_Scalar1/4);
     37         fPath.addRoundRect(fRect, SkIntToScalar(20), SkIntToScalar(20));
     38     }
     39 
     40 protected:
     41     virtual const char* onGetName() { return fName.c_str(); }
     42     virtual void onDraw(SkCanvas* canvas) {
     43         SkPaint paint;
     44         this->setupPaint(&paint);
     45 
     46         for (int i = 0; i < N; ++i) {
     47             SkAAClip clip;
     48             if (fDoPath) {
     49                 clip.setPath(fPath, &fRegion, fDoAA);
     50             } else {
     51                 clip.setRect(fRect, fDoAA);
     52             }
     53         }
     54     }
     55 private:
     56     typedef SkBenchmark INHERITED;
     57 };
     58 
     59 class AAClipRegionBench : public SkBenchmark {
     60 public:
     61     AAClipRegionBench(void* param) : INHERITED(param) {
     62         SkPath path;
     63         // test conversion of a complex clip to a aaclip
     64         path.addCircle(0, 0, SkIntToScalar(200));
     65         path.addCircle(0, 0, SkIntToScalar(180));
     66         // evenodd means we've constructed basically a stroked circle
     67         path.setFillType(SkPath::kEvenOdd_FillType);
     68 
     69         SkIRect bounds;
     70         path.getBounds().roundOut(&bounds);
     71         fRegion.setPath(path, SkRegion(bounds));
     72     }
     73 
     74 protected:
     75     virtual const char* onGetName() { return "aaclip_setregion"; }
     76     virtual void onDraw(SkCanvas* canvas) {
     77         for (int i = 0; i < N; ++i) {
     78             SkAAClip clip;
     79             clip.setRegion(fRegion);
     80         }
     81     }
     82 
     83 private:
     84     enum {
     85         N = SkBENCHLOOP(400),
     86     };
     87     SkRegion fRegion;
     88     typedef SkBenchmark INHERITED;
     89 };
     90 
     91 ///////////////////////////////////////////////////////////////////////////////
     92 
     93 static SkBenchmark* Fact0(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, false, false)); }
     94 static SkBenchmark* Fact1(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, false, true)); }
     95 static SkBenchmark* Fact2(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, true, false)); }
     96 static SkBenchmark* Fact3(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, true, true)); }
     97 
     98 static BenchRegistry gReg0(Fact0);
     99 static BenchRegistry gReg1(Fact1);
    100 static BenchRegistry gReg2(Fact2);
    101 static BenchRegistry gReg3(Fact3);
    102 
    103 static SkBenchmark* Fact01(void* p) { return SkNEW_ARGS(AAClipRegionBench, (p)); }
    104 static BenchRegistry gReg01(Fact01);
    105