blob: 5844d8a588ab4597ab76661f684ace36865cc9c2 [file] [log] [blame]
mtklein92007582014-08-01 07:46:52 -07001/*
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"
mtkleinc7f7f462014-10-21 12:29:25 -07009#include "SkCommandLineFlags.h"
10
mtklein6838d852014-10-29 14:15:10 -070011DEFINE_int32(benchTile, 256, "Tile dimension used for SKP playback.");
mtklein92007582014-08-01 07:46:52 -070012
13SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale)
14 : fPic(SkRef(pic))
15 , fClip(clip)
mtklein96289052014-09-10 12:05:59 -070016 , fScale(scale)
17 , fName(name) {
18 fUniqueName.printf("%s_%.2g", name, scale); // Scale makes this unqiue for skiaperf.com traces.
mtklein92007582014-08-01 07:46:52 -070019}
20
21const char* SKPBench::onGetName() {
22 return fName.c_str();
23}
24
mtklein96289052014-09-10 12:05:59 -070025const char* SKPBench::onGetUniqueName() {
26 return fUniqueName.c_str();
27}
28
mtklein92007582014-08-01 07:46:52 -070029bool SKPBench::isSuitableFor(Backend backend) {
30 return backend != kNonRendering_Backend;
31}
32
33SkIPoint SKPBench::onGetSize() {
34 return SkIPoint::Make(fClip.width(), fClip.height());
35}
36
37void SKPBench::onDraw(const int loops, SkCanvas* canvas) {
mtkleinc7f7f462014-10-21 12:29:25 -070038 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 }
mtklein92007582014-08-01 07:46:52 -070052 }
mtkleinc7f7f462014-10-21 12:29:25 -070053 canvas->flush();
54 }
mtklein92007582014-08-01 07:46:52 -070055}