blob: 1e15c321f70e6afa8afebbafd516a0484aa99d43 [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
Ben Wagner406ff502019-08-12 16:39:24 -040010GMBench::GMBench(std::unique_ptr<skiagm::GM> gm) : fGM(std::move(gm)) {
11 fName.printf("GM_%s", fGM->getName());
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000012}
13
tfarinaf168b862014-06-19 12:32:29 -070014const char* GMBench::onGetName() {
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000015 return fName.c_str();
16}
17
tfarinaf168b862014-06-19 12:32:29 -070018bool GMBench::isSuitableFor(Backend backend) {
mtklein1c402922015-01-23 11:07:07 -080019 return kNonRendering_Backend != backend;
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000020}
21
mtkleina1ebeb22015-10-01 09:43:39 -070022void GMBench::onDraw(int loops, SkCanvas* canvas) {
bsalomond584d462016-05-16 09:09:18 -070023 fGM->setMode(skiagm::GM::kBench_Mode);
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000024 // Do we care about timing the draw of the background (once)?
25 // Does the GM ever rely on drawBackground to lazily compute something?
26 fGM->drawBackground(canvas);
27 for (int i = 0; i < loops; ++i) {
Brian Osman7035a8e2017-12-15 14:25:11 -050028 SkAutoCanvasRestore acr(canvas, true);
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000029 fGM->drawContent(canvas);
30 }
31}
32
tfarinaf168b862014-06-19 12:32:29 -070033SkIPoint GMBench::onGetSize() {
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000034 SkISize size = fGM->getISize();
35 return SkIPoint::Make(size.fWidth, size.fHeight);
36}