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