Flutter Engine
The Flutter Engine
MipmapBench.cpp
Go to the documentation of this file.
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 "bench/Benchmark.h"
11#include "src/core/SkMipmap.h"
12
13class MipmapBench: public Benchmark {
14 SkBitmap fBitmap;
15 SkString fName;
16 const int fW, fH;
17 bool fHalfFoat;
18
19public:
20 MipmapBench(int w, int h, bool halfFloat = false)
21 : fW(w), fH(h), fHalfFoat(halfFloat)
22 {
23 fName.printf("mipmap_build_%dx%d", w, h);
24 if (halfFloat) {
25 fName.append("_f16");
26 }
27 }
28
29protected:
30 bool isSuitableFor(Backend backend) override {
32 }
33
34 const char* onGetName() override { return fName.c_str(); }
35
36 void onDelayedSetup() override {
37 SkColorType ct = fHalfFoat ? kRGBA_F16_SkColorType : kN32_SkColorType;
40 fBitmap.allocPixels(info);
41 fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized memory
42 }
43
44 void onDraw(int loops, SkCanvas*) override {
45 for (int i = 0; i < loops * 4; i++) {
46 SkMipmap::Build(fBitmap, nullptr)->unref();
47 }
48 }
49
50private:
51 using INHERITED = Benchmark;
52};
53
54// Build variants that exercise the width and heights being even or odd at each level, as the
55// impl specializes on each of these.
56//
57DEF_BENCH( return new MipmapBench(511, 511); )
58DEF_BENCH( return new MipmapBench(512, 511); )
59DEF_BENCH( return new MipmapBench(511, 512); )
60DEF_BENCH( return new MipmapBench(512, 512); )
61
62DEF_BENCH( return new MipmapBench(512, 512, true); )
63DEF_BENCH( return new MipmapBench(511, 511, true); )
64
65DEF_BENCH( return new MipmapBench(2048, 2048); )
66DEF_BENCH( return new MipmapBench(2047, 2047); )
67DEF_BENCH( return new MipmapBench(2048, 2047); )
68DEF_BENCH( return new MipmapBench(2047, 2048); )
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * backend
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
const char * fName
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
SkColorType
Definition: SkColorType.h:19
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition: SkColorType.h:38
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
MipmapBench(int w, int h, bool halfFloat=false)
Definition: MipmapBench.cpp:20
const char * onGetName() override
Definition: MipmapBench.cpp:34
void onDelayedSetup() override
Definition: MipmapBench.cpp:36
void onDraw(int loops, SkCanvas *) override
Definition: MipmapBench.cpp:44
bool isSuitableFor(Backend backend) override
Definition: MipmapBench.cpp:30
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
void unref() const
Definition: SkCachedData.h:31
static sk_sp< SkColorSpace > MakeSRGB()
static SkMipmap * Build(const SkPixmap &src, SkDiscardableFactoryProc, bool computeContents=true)
Definition: SkMipmap.cpp:45
SkScalar w
SkScalar h
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)