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; |
| 14 | |
| 15 | public: |
| 16 | MipMapBench() {} |
| 17 | |
| 18 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 19 | bool isSuitableFor(Backend backend) override { |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 20 | return kNonRendering_Backend == backend; |
| 21 | } |
| 22 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 23 | const char* onGetName() override { return "mipmap_build"; } |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 24 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 25 | void onDelayedSetup() override { |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 26 | fBitmap.allocN32Pixels(1000, 1000, true); |
| 27 | fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized memory |
| 28 | } |
| 29 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 30 | void onDraw(int loops, SkCanvas*) override { |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 31 | for (int i = 0; i < loops; i++) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 32 | SkMipMap::Build(fBitmap, nullptr)->unref(); |
reed | 96638d1 | 2015-01-26 12:28:54 -0800 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | |
| 36 | private: |
| 37 | typedef Benchmark INHERITED; |
| 38 | }; |
| 39 | |
| 40 | DEF_BENCH( return new MipMapBench; ) |