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