reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 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; |
reed | 3396fb5 | 2016-01-15 07:41:07 -0800 | [diff] [blame] | 14 | SkString fName; |
reed | 0b64b98 | 2016-01-15 18:47:38 -0800 | [diff] [blame] | 15 | const int fW, fH; |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 16 | SkDestinationSurfaceColorMode fColorMode; |
Brian Osman | e9c99b8 | 2017-03-06 16:16:15 -0500 | [diff] [blame] | 17 | bool fHalfFoat; |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 18 | |
| 19 | public: |
Brian Osman | e9c99b8 | 2017-03-06 16:16:15 -0500 | [diff] [blame] | 20 | MipMapBench(int w, int h, SkDestinationSurfaceColorMode colorMode, bool halfFloat = false) |
| 21 | : fW(w), fH(h), fColorMode(colorMode), fHalfFoat(halfFloat) |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 22 | { |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 23 | fName.printf("mipmap_build_%dx%d_%d_gamma", w, h, static_cast<int>(colorMode)); |
Brian Osman | e9c99b8 | 2017-03-06 16:16:15 -0500 | [diff] [blame] | 24 | if (halfFloat) { |
| 25 | fName.append("_f16"); |
| 26 | } |
reed | 3396fb5 | 2016-01-15 07:41:07 -0800 | [diff] [blame] | 27 | } |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 28 | |
| 29 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 30 | bool isSuitableFor(Backend backend) override { |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 31 | return kNonRendering_Backend == backend; |
| 32 | } |
| 33 | |
reed | 3396fb5 | 2016-01-15 07:41:07 -0800 | [diff] [blame] | 34 | const char* onGetName() override { return fName.c_str(); } |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 35 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 36 | void onDelayedSetup() override { |
Brian Osman | e9c99b8 | 2017-03-06 16:16:15 -0500 | [diff] [blame] | 37 | SkImageInfo info = fHalfFoat ? SkImageInfo::Make(fW, fH, kRGBA_F16_SkColorType, |
| 38 | kPremul_SkAlphaType, |
| 39 | SkColorSpace::MakeSRGBLinear()) |
| 40 | : SkImageInfo::MakeS32(fW, fH, kPremul_SkAlphaType); |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 41 | fBitmap.allocPixels(info); |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 42 | fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized memory |
| 43 | } |
| 44 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 45 | void onDraw(int loops, SkCanvas*) override { |
reed | 3396fb5 | 2016-01-15 07:41:07 -0800 | [diff] [blame] | 46 | for (int i = 0; i < loops * 4; i++) { |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 47 | SkMipMap::Build(fBitmap, fColorMode, nullptr)->unref(); |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | typedef Benchmark INHERITED; |
| 53 | }; |
| 54 | |
reed | 0b64b98 | 2016-01-15 18:47:38 -0800 | [diff] [blame] | 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 | // |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 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); ) |
Brian Osman | f12248a | 2017-03-06 13:58:54 -0500 | [diff] [blame] | 64 | DEF_BENCH( return new MipMapBench(511, 511, |
| 65 | SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); ) |
Brian Osman | e9c99b8 | 2017-03-06 16:16:15 -0500 | [diff] [blame] | 66 | DEF_BENCH( return new MipMapBench(512, 512, SkDestinationSurfaceColorMode::kLegacy, true); ) |
| 67 | DEF_BENCH( return new MipMapBench(511, 511, SkDestinationSurfaceColorMode::kLegacy, true); ) |
Matt Sarett | 08541e8 | 2017-03-08 16:30:18 -0500 | [diff] [blame] | 68 | DEF_BENCH( return new MipMapBench(2048, 2048, SkDestinationSurfaceColorMode::kLegacy); ) |
| 69 | DEF_BENCH( return new MipMapBench(2048, 2048, |
| 70 | SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); ) |
Matt Sarett | b667fe2 | 2017-03-22 09:20:02 -0400 | [diff] [blame] | 71 | DEF_BENCH( return new MipMapBench(2047, 2047, SkDestinationSurfaceColorMode::kLegacy); ) |
| 72 | DEF_BENCH( return new MipMapBench(2047, 2047, |
| 73 | SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); ) |
Matt Sarett | 8a8e5fe | 2017-04-11 11:53:24 -0400 | [diff] [blame] | 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); ) |