mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 "SKPBench.h" |
mtklein | c7f7f46 | 2014-10-21 12:29:25 -0700 | [diff] [blame] | 9 | #include "SkCommandLineFlags.h" |
| 10 | |
mtklein | 6838d85 | 2014-10-29 14:15:10 -0700 | [diff] [blame] | 11 | DEFINE_int32(benchTile, 256, "Tile dimension used for SKP playback."); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 12 | |
| 13 | SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale) |
| 14 | : fPic(SkRef(pic)) |
| 15 | , fClip(clip) |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 16 | , fScale(scale) |
| 17 | , fName(name) { |
| 18 | fUniqueName.printf("%s_%.2g", name, scale); // Scale makes this unqiue for skiaperf.com traces. |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | const char* SKPBench::onGetName() { |
| 22 | return fName.c_str(); |
| 23 | } |
| 24 | |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 25 | const char* SKPBench::onGetUniqueName() { |
| 26 | return fUniqueName.c_str(); |
| 27 | } |
| 28 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 29 | bool SKPBench::isSuitableFor(Backend backend) { |
| 30 | return backend != kNonRendering_Backend; |
| 31 | } |
| 32 | |
| 33 | SkIPoint SKPBench::onGetSize() { |
| 34 | return SkIPoint::Make(fClip.width(), fClip.height()); |
| 35 | } |
| 36 | |
| 37 | void SKPBench::onDraw(const int loops, SkCanvas* canvas) { |
mtklein | c7f7f46 | 2014-10-21 12:29:25 -0700 | [diff] [blame] | 38 | SkIRect bounds; |
| 39 | SkAssertResult(canvas->getClipDeviceBounds(&bounds)); |
| 40 | |
| 41 | SkAutoCanvasRestore overall(canvas, true/*save now*/); |
| 42 | canvas->scale(fScale, fScale); |
| 43 | |
| 44 | for (int i = 0; i < loops; i++) { |
| 45 | for (int y = bounds.fTop; y < bounds.fBottom; y += FLAGS_benchTile) { |
| 46 | for (int x = bounds.fLeft; x < bounds.fRight; x += FLAGS_benchTile) { |
| 47 | SkAutoCanvasRestore perTile(canvas, true/*save now*/); |
| 48 | canvas->clipRect(SkRect::Make( |
| 49 | SkIRect::MakeXYWH(x, y, FLAGS_benchTile, FLAGS_benchTile))); |
| 50 | fPic->playback(canvas); |
| 51 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 52 | } |
mtklein | c7f7f46 | 2014-10-21 12:29:25 -0700 | [diff] [blame] | 53 | canvas->flush(); |
| 54 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 55 | } |