Flutter Engine
The Flutter Engine
FilteringBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 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"
14#include "tools/DecodeUtils.h"
15#include "tools/Resources.h"
16
17class FilteringBench : public Benchmark {
18public:
19 FilteringBench(SkFilterMode fm, SkMipmapMode mm) : fSampling(fm, mm) {
20 fName.printf("samplingoptions_filter_%d_mipmap_%d", (int)fm, (int)mm);
21 }
22
23protected:
24 const char* onGetName() override {
25 return fName.c_str();
26 }
27
28 void onDelayedSetup() override {
29 auto img = ToolUtils::GetResourceAsImage("images/ship.png");
30 // need to force raster since lazy doesn't support filteroptions yet
31 img = img->makeRasterImage();
32
33 fRect = SkRect::MakeIWH(img->width(), img->height());
34 fShader = img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, fSampling);
35 }
36
37 void onDraw(int loops, SkCanvas* canvas) override {
38 // scale so we will trigger lerping between levels if we mipmapping
39 canvas->scale(0.75f, 0.75f);
40
42 paint.setShader(fShader);
43 for (int i = 0; i < loops; ++i) {
44 for (int j = 0; j < 10; ++j) {
45 canvas->drawRect(fRect, paint);
46 }
47 }
48 }
49
50private:
51 SkString fName;
52 SkRect fRect;
53 sk_sp<SkShader> fShader;
54 SkSamplingOptions fSampling;
55
56 using INHERITED = Benchmark;
57};
58
62
#define DEF_BENCH(code)
Definition: Benchmark.h:20
SkFilterMode
SkMipmapMode
FilteringBench(SkFilterMode fm, SkMipmapMode mm)
void onDelayedSetup() override
const char * onGetName() override
void onDraw(int loops, SkCanvas *canvas) override
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
const char * c_str() const
Definition: SkString.h:133
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623