blob: 59136bbf8361e9f0579244834db78a9034596179 [file] [log] [blame]
commit-bot@chromium.org6adce672014-02-03 14:48:17 +00001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "bench/GMBench.h"
commit-bot@chromium.org6adce672014-02-03 14:48:17 +00009
tfarinaf168b862014-06-19 12:32:29 -070010GMBench::GMBench(skiagm::GM* gm) : fGM(gm) {
mtkleine714e752014-07-31 12:13:48 -070011 fName.printf("GM_%s", gm->getName());
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000012}
13
tfarinaf168b862014-06-19 12:32:29 -070014GMBench::~GMBench() { delete fGM; }
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000015
tfarinaf168b862014-06-19 12:32:29 -070016const char* GMBench::onGetName() {
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000017 return fName.c_str();
18}
19
tfarinaf168b862014-06-19 12:32:29 -070020bool GMBench::isSuitableFor(Backend backend) {
mtklein1c402922015-01-23 11:07:07 -080021 return kNonRendering_Backend != backend;
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000022}
23
mtkleina1ebeb22015-10-01 09:43:39 -070024void GMBench::onDraw(int loops, SkCanvas* canvas) {
bsalomond584d462016-05-16 09:09:18 -070025 fGM->setMode(skiagm::GM::kBench_Mode);
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000026 // Do we care about timing the draw of the background (once)?
27 // Does the GM ever rely on drawBackground to lazily compute something?
28 fGM->drawBackground(canvas);
29 for (int i = 0; i < loops; ++i) {
Brian Osman7035a8e2017-12-15 14:25:11 -050030 SkAutoCanvasRestore acr(canvas, true);
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000031 fGM->drawContent(canvas);
32 }
33}
34
tfarinaf168b862014-06-19 12:32:29 -070035SkIPoint GMBench::onGetSize() {
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000036 SkISize size = fGM->getISize();
37 return SkIPoint::Make(size.fWidth, size.fHeight);
38}