senorblanco | 3c14681 | 2016-01-05 13:27:43 -0800 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "bench/Benchmark.h" |
| 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkPaint.h" |
| 11 | #include "include/core/SkString.h" |
Michael Ludwig | 2300318 | 2019-08-05 11:25:23 -0400 | [diff] [blame] | 12 | #include "include/effects/SkImageFilters.h" |
senorblanco | 3c14681 | 2016-01-05 13:27:43 -0800 | [diff] [blame] | 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 | |
| 23 | class TileImageFilterBench : public Benchmark { |
| 24 | public: |
| 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 | |
| 33 | protected: |
| 34 | const char* onGetName() override { |
| 35 | return fName.c_str(); |
| 36 | } |
| 37 | |
| 38 | void onDraw(int loops, SkCanvas* canvas) override { |
| 39 | SkPaint paint; |
Michael Ludwig | 2300318 | 2019-08-05 11:25:23 -0400 | [diff] [blame] | 40 | paint.setImageFilter(SkImageFilters::Tile( |
| 41 | SkRect::MakeWH(50, 50), SkRect::MakeWH(WIDTH, HEIGHT), nullptr)); |
senorblanco | 3c14681 | 2016-01-05 13:27:43 -0800 | [diff] [blame] | 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)); |
| 50 | canvas->drawRect(SkRect::MakeWH(WIDTH, HEIGHT), paint); |
| 51 | canvas->restore(); |
| 52 | } |
| 53 | } |
| 54 | } else { |
| 55 | canvas->drawRect(SkRect::MakeWH(WIDTH, HEIGHT), paint); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | private: |
| 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; |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 65 | using INHERITED = Benchmark; |
senorblanco | 3c14681 | 2016-01-05 13:27:43 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | DEF_BENCH(return new TileImageFilterBench(0);) |
| 69 | DEF_BENCH(return new TileImageFilterBench(32);) |
| 70 | DEF_BENCH(return new TileImageFilterBench(64);) |