blob: 1f41e817db4e9d2389ed88690aa738091152a8d7 [file] [log] [blame]
reed96638d12015-01-26 12:28:54 -08001/*
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
12class MipMapBench: public Benchmark {
13 SkBitmap fBitmap;
reed3396fb52016-01-15 07:41:07 -080014 SkString fName;
reed0b64b982016-01-15 18:47:38 -080015 const int fW, fH;
reed6644d932016-06-10 11:41:47 -070016 SkSourceGammaTreatment fTreatment;
reed96638d12015-01-26 12:28:54 -080017
18public:
reed6644d932016-06-10 11:41:47 -070019 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));
reed3396fb52016-01-15 07:41:07 -080023 }
reed96638d12015-01-26 12:28:54 -080024
25protected:
mtklein36352bf2015-03-25 18:17:31 -070026 bool isSuitableFor(Backend backend) override {
reed96638d12015-01-26 12:28:54 -080027 return kNonRendering_Backend == backend;
28 }
29
reed3396fb52016-01-15 07:41:07 -080030 const char* onGetName() override { return fName.c_str(); }
reed96638d12015-01-26 12:28:54 -080031
joshualitt8a6697a2015-09-30 12:11:07 -070032 void onDelayedSetup() override {
reed6644d932016-06-10 11:41:47 -070033 SkImageInfo info = SkImageInfo::MakeS32(fW, fH, kPremul_SkAlphaType);
34 fBitmap.allocPixels(info);
reed96638d12015-01-26 12:28:54 -080035 fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized memory
36 }
37
mtkleina1ebeb22015-10-01 09:43:39 -070038 void onDraw(int loops, SkCanvas*) override {
reed3396fb52016-01-15 07:41:07 -080039 for (int i = 0; i < loops * 4; i++) {
reed6644d932016-06-10 11:41:47 -070040 SkMipMap::Build(fBitmap, fTreatment, nullptr)->unref();
reed96638d12015-01-26 12:28:54 -080041 }
42 }
43
44private:
45 typedef Benchmark INHERITED;
46};
47
reed0b64b982016-01-15 18:47:38 -080048// 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//
reed6644d932016-06-10 11:41:47 -070051DEF_BENCH( return new MipMapBench(511, 511, SkSourceGammaTreatment::kIgnore); )
52DEF_BENCH( return new MipMapBench(512, 511, SkSourceGammaTreatment::kIgnore); )
53DEF_BENCH( return new MipMapBench(511, 512, SkSourceGammaTreatment::kIgnore); )
54DEF_BENCH( return new MipMapBench(512, 512, SkSourceGammaTreatment::kIgnore); )
55DEF_BENCH( return new MipMapBench(512, 512, SkSourceGammaTreatment::kRespect); )