Flutter Engine
The Flutter Engine
TileImageFilterBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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"
13
14#define WIDTH 512
15#define HEIGHT 512
16
17// This bench exercises SkTileImageFilter drawn from a 50x50 source to
18// a 512x512 destination. It is drawn using a single rect, or "tiled"
19// rendering (using 32x32, 64x64 tiles). Tiled rendering is currently an order
20// of magnitude slower, since SkTileImageFilter does not clip the
21// source or destination rects.
22
24public:
25 TileImageFilterBench(int tileSize) : fTileSize(tileSize) {
26 if (tileSize > 0) {
27 fName.printf("tile_image_filter_tiled_%d", tileSize);
28 } else {
29 fName.printf("tile_image_filter");
30 }
31 }
32
33protected:
34 const char* onGetName() override {
35 return fName.c_str();
36 }
37
38 void onDraw(int loops, SkCanvas* canvas) override {
40 paint.setImageFilter(SkImageFilters::Tile(
41 SkRect::MakeWH(50, 50), SkRect::MakeWH(WIDTH, HEIGHT), nullptr));
42
43 for (int i = 0; i < loops; i++) {
44 if (fTileSize > 0) {
45 for (int y = 0; y < HEIGHT; y += fTileSize) {
46 for (int x = 0; x < WIDTH; x += fTileSize) {
47 canvas->save();
48 SkIRect clipIRect = SkIRect::MakeXYWH(x, y, fTileSize, fTileSize);
49 canvas->clipRect(SkRect::Make(clipIRect));
51 canvas->restore();
52 }
53 }
54 } else {
56 }
57 }
58 }
59
60private:
61 SkString fName;
62 // Note: this is the tile size used for tiled rendering, not for the size
63 // of the SkTileImageFilter source rect.
64 int fTileSize;
65 using INHERITED = Benchmark;
66};
67
68DEF_BENCH(return new TileImageFilterBench(0);)
69DEF_BENCH(return new TileImageFilterBench(32);)
70DEF_BENCH(return new TileImageFilterBench(64);)
#define DEF_BENCH(code)
Definition: Benchmark.h:20
#define WIDTH
#define HEIGHT
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
int save()
Definition: SkCanvas.cpp:447
static sk_sp< SkImageFilter > Tile(const SkRect &src, const SkRect &dst, sk_sp< SkImageFilter > input)
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
const char * c_str() const
Definition: SkString.h:133
void onDraw(int loops, SkCanvas *canvas) override
const char * onGetName() override
TileImageFilterBench(int tileSize)
const Paint & paint
Definition: color_source.cc:38
double y
double x
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609