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 bool fHalfFoat; 17 18 public: MipMapBench(int w,int h,bool halfFloat=false)19 MipMapBench(int w, int h, bool halfFloat = false) 20 : fW(w), fH(h), fHalfFoat(halfFloat) 21 { 22 fName.printf("mipmap_build_%dx%d", w, h); 23 if (halfFloat) { 24 fName.append("_f16"); 25 } 26 } 27 28 protected: isSuitableFor(Backend backend)29 bool isSuitableFor(Backend backend) override { 30 return kNonRendering_Backend == backend; 31 } 32 onGetName()33 const char* onGetName() override { return fName.c_str(); } 34 onDelayedSetup()35 void onDelayedSetup() override { 36 SkColorType ct = fHalfFoat ? kRGBA_F16_SkColorType : kN32_SkColorType; 37 SkImageInfo info = SkImageInfo::Make(fW, fH, ct, kPremul_SkAlphaType, 38 SkColorSpace::MakeSRGB()); 39 fBitmap.allocPixels(info); 40 fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized memory 41 } 42 onDraw(int loops,SkCanvas *)43 void onDraw(int loops, SkCanvas*) override { 44 for (int i = 0; i < loops * 4; i++) { 45 SkMipMap::Build(fBitmap, nullptr)->unref(); 46 } 47 } 48 49 private: 50 typedef Benchmark INHERITED; 51 }; 52 53 // Build variants that exercise the width and heights being even or odd at each level, as the 54 // impl specializes on each of these. 55 // 56 DEF_BENCH( return new MipMapBench(511, 511); ) 57 DEF_BENCH( return new MipMapBench(512, 511); ) 58 DEF_BENCH( return new MipMapBench(511, 512); ) 59 DEF_BENCH( return new MipMapBench(512, 512); ) 60 61 DEF_BENCH( return new MipMapBench(512, 512, true); ) 62 DEF_BENCH( return new MipMapBench(511, 511, true); ) 63 64 DEF_BENCH( return new MipMapBench(2048, 2048); ) 65 DEF_BENCH( return new MipMapBench(2047, 2047); ) 66 DEF_BENCH( return new MipMapBench(2048, 2047); ) 67 DEF_BENCH( return new MipMapBench(2047, 2048); ) 68