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" |
| 9 | |
| 10 | SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale) |
| 11 | : fPic(SkRef(pic)) |
| 12 | , fClip(clip) |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame^] | 13 | , fScale(scale) |
| 14 | , fName(name) { |
| 15 | 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] | 16 | } |
| 17 | |
| 18 | const char* SKPBench::onGetName() { |
| 19 | return fName.c_str(); |
| 20 | } |
| 21 | |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame^] | 22 | const char* SKPBench::onGetUniqueName() { |
| 23 | return fUniqueName.c_str(); |
| 24 | } |
| 25 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 26 | bool SKPBench::isSuitableFor(Backend backend) { |
| 27 | return backend != kNonRendering_Backend; |
| 28 | } |
| 29 | |
| 30 | SkIPoint SKPBench::onGetSize() { |
| 31 | return SkIPoint::Make(fClip.width(), fClip.height()); |
| 32 | } |
| 33 | |
| 34 | void SKPBench::onDraw(const int loops, SkCanvas* canvas) { |
| 35 | canvas->save(); |
| 36 | canvas->scale(fScale, fScale); |
| 37 | for (int i = 0; i < loops; i++) { |
robertphillips | c5ba71d | 2014-09-04 08:42:50 -0700 | [diff] [blame] | 38 | fPic->playback(canvas); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 39 | canvas->flush(); |
| 40 | } |
| 41 | canvas->restore(); |
| 42 | } |