Home | History | Annotate | Download | only in bench
      1 /*
      2  * Copyright 2013 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 "SkCanvas.h"
     10 #include "SkRandom.h"
     11 #include "SkShader.h"
     12 #include "SkString.h"
     13 #include "SkBicubicImageFilter.h"
     14 
     15 // This bench exercises SkBicubicImageFilter, upsampling a 40x40 input to
     16 // 100x100, 400x100, 100x400, and 400x400.
     17 
     18 class BicubicBench : public SkBenchmark {
     19     SkSize         fScale;
     20     SkString       fName;
     21 
     22 public:
     23     BicubicBench(void* param, float x, float y)
     24         :  INHERITED(param), fScale(SkSize::Make(SkFloatToScalar(x), SkFloatToScalar(y))) {
     25         fName.printf("bicubic_%gx%g",
     26             SkScalarToFloat(fScale.fWidth), SkScalarToFloat(fScale.fHeight));
     27     }
     28 
     29 protected:
     30     virtual const char* onGetName() {
     31         return fName.c_str();
     32     }
     33 
     34     virtual void onDraw(SkCanvas* canvas) {
     35         SkPaint paint;
     36         this->setupPaint(&paint);
     37 
     38         paint.setAntiAlias(true);
     39 
     40         SkRandom rand;
     41         SkRect r = SkRect::MakeWH(40, 40);
     42         SkAutoTUnref<SkImageFilter> bicubic(SkBicubicImageFilter::CreateMitchell(fScale));
     43         paint.setImageFilter(bicubic);
     44         canvas->save();
     45         canvas->clipRect(r);
     46         canvas->drawOval(r, paint);
     47         canvas->restore();
     48     }
     49 
     50 private:
     51     typedef SkBenchmark INHERITED;
     52 };
     53 
     54 static SkBenchmark* Fact00(void* p) { return new BicubicBench(p, 10.0f, 10.0f); }
     55 static SkBenchmark* Fact01(void* p) { return new BicubicBench(p, 2.5f, 10.0f); }
     56 static SkBenchmark* Fact02(void* p) { return new BicubicBench(p, 10.0f, 2.5f); }
     57 static SkBenchmark* Fact03(void* p) { return new BicubicBench(p, 2.5f, 2.5f); }
     58 
     59 static BenchRegistry gReg00(Fact00);
     60 static BenchRegistry gReg01(Fact01);
     61 static BenchRegistry gReg02(Fact02);
     62 static BenchRegistry gReg03(Fact03);
     63