• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "Benchmark.h"
9 #include "SkBitmap.h"
10 #include "SkMipMap.h"
11 
12 class MipMapBench: public Benchmark {
13     SkBitmap fBitmap;
14     SkString fName;
15     const int fW, fH;
16 
17 public:
MipMapBench(int w,int h)18     MipMapBench(int w, int h) : fW(w), fH(h) {
19         fName.printf("mipmap_build_%dx%d", w, h);
20     }
21 
22 protected:
isSuitableFor(Backend backend)23     bool isSuitableFor(Backend backend) override {
24         return kNonRendering_Backend == backend;
25     }
26 
onGetName()27     const char* onGetName() override { return fName.c_str(); }
28 
onDelayedSetup()29     void onDelayedSetup() override {
30         fBitmap.allocN32Pixels(fW, fH, true);
31         fBitmap.eraseColor(SK_ColorWHITE);  // so we don't read uninitialized memory
32     }
33 
onDraw(int loops,SkCanvas *)34     void onDraw(int loops, SkCanvas*) override {
35         for (int i = 0; i < loops * 4; i++) {
36             SkMipMap::Build(fBitmap, nullptr)->unref();
37         }
38     }
39 
40 private:
41     typedef Benchmark INHERITED;
42 };
43 
44 // Build variants that exercise the width and heights being even or odd at each level, as the
45 // impl specializes on each of these.
46 //
47 DEF_BENCH( return new MipMapBench(511, 511); )
48 DEF_BENCH( return new MipMapBench(512, 511); )
49 DEF_BENCH( return new MipMapBench(511, 512); )
50 DEF_BENCH( return new MipMapBench(512, 512); )
51