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; |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 16 | SkSourceGammaTreatment fTreatment; |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 17 | |
| 18 | public: |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 19 | MipMapBench(int w, int h, SkSourceGammaTreatment treatment) |
| 20 | : fW(w), fH(h), fTreatment(treatment) |
| 21 | { |
| 22 | fName.printf("mipmap_build_%dx%d_%d_gamma", w, h, static_cast<int>(treatment)); |
reed | 3396fb5 | 2016-01-15 07:41:07 -0800 | [diff] [blame] | 23 | } |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 24 | |
| 25 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 26 | bool isSuitableFor(Backend backend) override { |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 27 | return kNonRendering_Backend == backend; |
| 28 | } |
| 29 | |
reed | 3396fb5 | 2016-01-15 07:41:07 -0800 | [diff] [blame] | 30 | const char* onGetName() override { return fName.c_str(); } |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 31 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 32 | void onDelayedSetup() override { |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 33 | SkImageInfo info = SkImageInfo::MakeS32(fW, fH, kPremul_SkAlphaType); |
| 34 | fBitmap.allocPixels(info); |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 35 | fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized memory |
| 36 | } |
| 37 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 38 | void onDraw(int loops, SkCanvas*) override { |
reed | 3396fb5 | 2016-01-15 07:41:07 -0800 | [diff] [blame] | 39 | for (int i = 0; i < loops * 4; i++) { |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 40 | SkMipMap::Build(fBitmap, fTreatment, nullptr)->unref(); |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
| 44 | private: |
| 45 | typedef Benchmark INHERITED; |
| 46 | }; |
| 47 | |
reed | 0b64b98 | 2016-01-15 18:47:38 -0800 | [diff] [blame] | 48 | // Build variants that exercise the width and heights being even or odd at each level, as the |
| 49 | // impl specializes on each of these. |
| 50 | // |
reed | 6644d93 | 2016-06-10 11:41:47 -0700 | [diff] [blame] | 51 | DEF_BENCH( return new MipMapBench(511, 511, SkSourceGammaTreatment::kIgnore); ) |
| 52 | DEF_BENCH( return new MipMapBench(512, 511, SkSourceGammaTreatment::kIgnore); ) |
| 53 | DEF_BENCH( return new MipMapBench(511, 512, SkSourceGammaTreatment::kIgnore); ) |
| 54 | DEF_BENCH( return new MipMapBench(512, 512, SkSourceGammaTreatment::kIgnore); ) |
| 55 | DEF_BENCH( return new MipMapBench(512, 512, SkSourceGammaTreatment::kRespect); ) |