blob: 9b6fc27cfb5092568f300e7c736f842018723cfb [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;
Brian Osman7b8400d2016-11-08 17:08:54 -050016 SkDestinationSurfaceColorMode fColorMode;
Brian Osmane9c99b82017-03-06 16:16:15 -050017 bool fHalfFoat;
reed96638d12015-01-26 12:28:54 -080018
19public:
Brian Osmane9c99b82017-03-06 16:16:15 -050020 MipMapBench(int w, int h, SkDestinationSurfaceColorMode colorMode, bool halfFloat = false)
21 : fW(w), fH(h), fColorMode(colorMode), fHalfFoat(halfFloat)
reed6644d932016-06-10 11:41:47 -070022 {
Brian Osman7b8400d2016-11-08 17:08:54 -050023 fName.printf("mipmap_build_%dx%d_%d_gamma", w, h, static_cast<int>(colorMode));
Brian Osmane9c99b82017-03-06 16:16:15 -050024 if (halfFloat) {
25 fName.append("_f16");
26 }
reed3396fb52016-01-15 07:41:07 -080027 }
reed96638d12015-01-26 12:28:54 -080028
29protected:
mtklein36352bf2015-03-25 18:17:31 -070030 bool isSuitableFor(Backend backend) override {
reed96638d12015-01-26 12:28:54 -080031 return kNonRendering_Backend == backend;
32 }
33
reed3396fb52016-01-15 07:41:07 -080034 const char* onGetName() override { return fName.c_str(); }
reed96638d12015-01-26 12:28:54 -080035
joshualitt8a6697a2015-09-30 12:11:07 -070036 void onDelayedSetup() override {
Brian Osmane9c99b82017-03-06 16:16:15 -050037 SkImageInfo info = fHalfFoat ? SkImageInfo::Make(fW, fH, kRGBA_F16_SkColorType,
38 kPremul_SkAlphaType,
39 SkColorSpace::MakeSRGBLinear())
40 : SkImageInfo::MakeS32(fW, fH, kPremul_SkAlphaType);
reed6644d932016-06-10 11:41:47 -070041 fBitmap.allocPixels(info);
reed96638d12015-01-26 12:28:54 -080042 fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized memory
43 }
44
mtkleina1ebeb22015-10-01 09:43:39 -070045 void onDraw(int loops, SkCanvas*) override {
reed3396fb52016-01-15 07:41:07 -080046 for (int i = 0; i < loops * 4; i++) {
Brian Osman7b8400d2016-11-08 17:08:54 -050047 SkMipMap::Build(fBitmap, fColorMode, nullptr)->unref();
reed96638d12015-01-26 12:28:54 -080048 }
49 }
50
51private:
52 typedef Benchmark INHERITED;
53};
54
reed0b64b982016-01-15 18:47:38 -080055// 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 Osman7b8400d2016-11-08 17:08:54 -050058DEF_BENCH( return new MipMapBench(511, 511, SkDestinationSurfaceColorMode::kLegacy); )
59DEF_BENCH( return new MipMapBench(512, 511, SkDestinationSurfaceColorMode::kLegacy); )
60DEF_BENCH( return new MipMapBench(511, 512, SkDestinationSurfaceColorMode::kLegacy); )
61DEF_BENCH( return new MipMapBench(512, 512, SkDestinationSurfaceColorMode::kLegacy); )
62DEF_BENCH( return new MipMapBench(512, 512,
63 SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); )
Brian Osmanf12248a2017-03-06 13:58:54 -050064DEF_BENCH( return new MipMapBench(511, 511,
65 SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); )
Brian Osmane9c99b82017-03-06 16:16:15 -050066DEF_BENCH( return new MipMapBench(512, 512, SkDestinationSurfaceColorMode::kLegacy, true); )
67DEF_BENCH( return new MipMapBench(511, 511, SkDestinationSurfaceColorMode::kLegacy, true); )
Matt Sarett08541e82017-03-08 16:30:18 -050068DEF_BENCH( return new MipMapBench(2048, 2048, SkDestinationSurfaceColorMode::kLegacy); )
69DEF_BENCH( return new MipMapBench(2048, 2048,
70 SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); )
Matt Sarettb667fe22017-03-22 09:20:02 -040071DEF_BENCH( return new MipMapBench(2047, 2047, SkDestinationSurfaceColorMode::kLegacy); )
72DEF_BENCH( return new MipMapBench(2047, 2047,
73 SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); )
Matt Sarett8a8e5fe2017-04-11 11:53:24 -040074DEF_BENCH( return new MipMapBench(2048, 2047, SkDestinationSurfaceColorMode::kLegacy); )
75DEF_BENCH( return new MipMapBench(2048, 2047,
76 SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); )
77DEF_BENCH( return new MipMapBench(2047, 2048, SkDestinationSurfaceColorMode::kLegacy); )
78DEF_BENCH( return new MipMapBench(2047, 2048,
79 SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); )