2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkCommandLineFlags.h"
11 DEFINE_int32(benchTile, 256, "Tile dimension used for SKP playback.");
13 SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale)
18 fUniqueName.printf("%s_%.2g", name, scale); // Scale makes this unqiue for skiaperf.com traces.
21 const char* SKPBench::onGetName() {
25 const char* SKPBench::onGetUniqueName() {
26 return fUniqueName.c_str();
29 bool SKPBench::isSuitableFor(Backend backend) {
30 return backend != kNonRendering_Backend;
33 SkIPoint SKPBench::onGetSize() {
34 return SkIPoint::Make(fClip.width(), fClip.height());
37 void SKPBench::onDraw(const int loops, SkCanvas* canvas) {
39 SkAssertResult(canvas->getClipDeviceBounds(&bounds));
41 SkAutoCanvasRestore overall(canvas, true/*save now*/);
42 canvas->scale(fScale, fScale);
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);