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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "bench/Benchmark.h" |
| 9 | #include "include/core/SkBitmap.h" |
| 10 | #include "src/core/SkMipMap.h" |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 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 | e9c99b8 | 2017-03-06 16:16:15 -0500 | [diff] [blame] | 16 | bool fHalfFoat; |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 17 | |
| 18 | public: |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 19 | MipMapBench(int w, int h, bool halfFloat = false) |
| 20 | : fW(w), fH(h), fHalfFoat(halfFloat) |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 21 | { |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 22 | fName.printf("mipmap_build_%dx%d", w, h); |
Brian Osman | e9c99b8 | 2017-03-06 16:16:15 -0500 | [diff] [blame] | 23 | if (halfFloat) { |
| 24 | fName.append("_f16"); |
| 25 | } |
reed | 3396fb5 | 2016-01-15 07:41:07 -0800 | [diff] [blame] | 26 | } |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 27 | |
| 28 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 29 | bool isSuitableFor(Backend backend) override { |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 30 | return kNonRendering_Backend == backend; |
| 31 | } |
| 32 | |
reed | 3396fb5 | 2016-01-15 07:41:07 -0800 | [diff] [blame] | 33 | const char* onGetName() override { return fName.c_str(); } |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 34 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 35 | void onDelayedSetup() override { |
Brian Osman | 6b62296 | 2018-08-27 19:16:02 +0000 | [diff] [blame] | 36 | SkColorType ct = fHalfFoat ? kRGBA_F16_SkColorType : kN32_SkColorType; |
| 37 | SkImageInfo info = SkImageInfo::Make(fW, fH, ct, kPremul_SkAlphaType, |
| 38 | SkColorSpace::MakeSRGB()); |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 39 | fBitmap.allocPixels(info); |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 40 | fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized memory |
| 41 | } |
| 42 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 43 | void onDraw(int loops, SkCanvas*) override { |
reed | 3396fb5 | 2016-01-15 07:41:07 -0800 | [diff] [blame] | 44 | for (int i = 0; i < loops * 4; i++) { |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 45 | SkMipMap::Build(fBitmap, nullptr)->unref(); |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
| 49 | private: |
| 50 | typedef Benchmark INHERITED; |
| 51 | }; |
| 52 | |
reed | 0b64b98 | 2016-01-15 18:47:38 -0800 | [diff] [blame] | 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 | // |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 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); ) |