Home | History | Annotate | Download | only in bench
      1 /*
      2  * Copyright 2015 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 #include "Benchmark.h"
      8 #include "SkBitmap.h"
      9 #include "SkCanvas.h"
     10 #include "SkMatrix.h"
     11 #include "SkPaint.h"
     12 #include "SkString.h"
     13 
     14 /**
     15  * This bench measures the rendering time of SkCanvas::drawBitmap with different anti-aliasing /
     16  * matrix combinations.
     17  */
     18 
     19 class DrawBitmapAABench : public Benchmark {
     20 public:
     21     DrawBitmapAABench(bool doAA, const SkMatrix& matrix, const char name[])
     22         : fMatrix(matrix)
     23         , fName("draw_bitmap_") {
     24 
     25         fPaint.setAntiAlias(doAA);
     26         // Most clients use filtering, so let's focus on this for now.
     27         fPaint.setFilterQuality(kLow_SkFilterQuality);
     28         fName.appendf("%s_%s", doAA ? "aa" : "noaa", name);
     29     }
     30 
     31 protected:
     32     const char* onGetName() override {
     33         return fName.c_str();
     34     }
     35 
     36     void onDelayedSetup() override {
     37         fBitmap.allocN32Pixels(200, 200);
     38         fBitmap.eraseARGB(255, 0, 255, 0);
     39     }
     40 
     41     void onDraw(int loops, SkCanvas* canvas) override {
     42         canvas->concat(fMatrix);
     43         for (int i = 0; i < loops; i++) {
     44             canvas->drawBitmap(fBitmap, 0, 0, &fPaint);
     45         }
     46     }
     47 
     48 private:
     49     SkPaint  fPaint;
     50     SkMatrix fMatrix;
     51     SkString fName;
     52     SkBitmap fBitmap;
     53 
     54     typedef Benchmark INHERITED;
     55 };
     56 
     57 DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeScale(1), "ident"); )
     58 
     59 DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeScale(1.17f), "scale"); )
     60 
     61 DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeTrans(17.5f, 17.5f), "translate"); )
     62 
     63 DEF_BENCH(
     64     SkMatrix m;
     65     m.reset();
     66     m.preRotate(15);
     67     return new DrawBitmapAABench(false, m, "rotate");
     68 )
     69 
     70 DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeScale(1), "ident"); )
     71 
     72 DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeScale(1.17f), "scale"); )
     73 
     74 DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeTrans(17.5f, 17.5f), "translate"); )
     75 
     76 DEF_BENCH(
     77     SkMatrix m;
     78     m.reset();
     79     m.preRotate(15);
     80     return new DrawBitmapAABench(true, m, "rotate");
     81 )
     82