OLD | NEW |
(Empty) | |
| 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 "Benchmark.h" |
| 9 #include "SkTileImageFilter.h" |
| 10 #include "SkCanvas.h" |
| 11 #include "SkPaint.h" |
| 12 #include "SkString.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 |
| 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; |
| 40 SkAutoTUnref<SkImageFilter> tile(SkTileImageFilter::Create( |
| 41 SkRect::MakeWH(50, 50), |
| 42 SkRect::MakeWH(WIDTH, HEIGHT), |
| 43 nullptr)); |
| 44 paint.setImageFilter(tile); |
| 45 |
| 46 for (int i = 0; i < loops; i++) { |
| 47 if (fTileSize > 0) { |
| 48 for (int y = 0; y < HEIGHT; y += fTileSize) { |
| 49 for (int x = 0; x < WIDTH; x += fTileSize) { |
| 50 canvas->save(); |
| 51 SkIRect clipIRect = SkIRect::MakeXYWH(x, y, fTileSize, f
TileSize); |
| 52 canvas->clipRect(SkRect::Make(clipIRect)); |
| 53 canvas->drawRect(SkRect::MakeWH(WIDTH, HEIGHT), paint); |
| 54 canvas->restore(); |
| 55 } |
| 56 } |
| 57 } else { |
| 58 canvas->drawRect(SkRect::MakeWH(WIDTH, HEIGHT), paint); |
| 59 } |
| 60 } |
| 61 } |
| 62 |
| 63 private: |
| 64 SkString fName; |
| 65 // Note: this is the tile size used for tiled rendering, not for the size |
| 66 // of the SkTileImageFilter source rect. |
| 67 int fTileSize; |
| 68 typedef Benchmark INHERITED; |
| 69 }; |
| 70 |
| 71 DEF_BENCH(return new TileImageFilterBench(0);) |
| 72 DEF_BENCH(return new TileImageFilterBench(32);) |
| 73 DEF_BENCH(return new TileImageFilterBench(64);) |
OLD | NEW |