commit-bot@chromium.org | 6adce67 | 2014-02-03 14:48:17 +0000 | [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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "bench/GMBench.h" |
commit-bot@chromium.org | 6adce67 | 2014-02-03 14:48:17 +0000 | [diff] [blame] | 9 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 10 | #include "include/gpu/GrRecordingContext.h" |
| 11 | #include "src/gpu/GrRecordingContextPriv.h" |
| 12 | |
Ben Wagner | 406ff50 | 2019-08-12 16:39:24 -0400 | [diff] [blame] | 13 | GMBench::GMBench(std::unique_ptr<skiagm::GM> gm) : fGM(std::move(gm)) { |
Robert Phillips | 83b749a | 2020-06-25 11:41:19 -0400 | [diff] [blame] | 14 | fGM->setMode(skiagm::GM::kBench_Mode); |
| 15 | |
Ben Wagner | 406ff50 | 2019-08-12 16:39:24 -0400 | [diff] [blame] | 16 | fName.printf("GM_%s", fGM->getName()); |
commit-bot@chromium.org | 6adce67 | 2014-02-03 14:48:17 +0000 | [diff] [blame] | 17 | } |
| 18 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 19 | const char* GMBench::onGetName() { |
commit-bot@chromium.org | 6adce67 | 2014-02-03 14:48:17 +0000 | [diff] [blame] | 20 | return fName.c_str(); |
| 21 | } |
| 22 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 23 | bool GMBench::isSuitableFor(Backend backend) { |
mtklein | 1c40292 | 2015-01-23 11:07:07 -0800 | [diff] [blame] | 24 | return kNonRendering_Backend != backend; |
commit-bot@chromium.org | 6adce67 | 2014-02-03 14:48:17 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Robert Phillips | 83b749a | 2020-06-25 11:41:19 -0400 | [diff] [blame] | 27 | void GMBench::onPerCanvasPreDraw(SkCanvas* canvas) { |
Adlai Holler | e3ad527 | 2020-07-07 10:27:55 -0400 | [diff] [blame] | 28 | auto direct = GrAsDirectContext(canvas->recordingContext()); |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 29 | |
| 30 | if (fGM->gpuSetup(direct, canvas) != skiagm::DrawResult::kOk) { |
Robert Phillips | e922953 | 2020-06-26 10:10:49 -0400 | [diff] [blame] | 31 | fGpuSetupFailed = true; |
| 32 | } |
| 33 | |
Robert Phillips | 83b749a | 2020-06-25 11:41:19 -0400 | [diff] [blame] | 34 | fGM->onceBeforeDraw(); |
| 35 | } |
| 36 | |
Robert Phillips | e922953 | 2020-06-26 10:10:49 -0400 | [diff] [blame] | 37 | void GMBench::onPerCanvasPostDraw(SkCanvas*) { |
| 38 | fGM->gpuTeardown(); |
| 39 | |
| 40 | // The same GM will be reused with multiple GrContexts. Let the next GrContext start |
| 41 | // afresh. |
| 42 | fGpuSetupFailed = false; |
| 43 | } |
Robert Phillips | 83b749a | 2020-06-25 11:41:19 -0400 | [diff] [blame] | 44 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 45 | void GMBench::onDraw(int loops, SkCanvas* canvas) { |
Robert Phillips | e922953 | 2020-06-26 10:10:49 -0400 | [diff] [blame] | 46 | if (fGpuSetupFailed) { |
| 47 | return; |
| 48 | } |
| 49 | |
commit-bot@chromium.org | 6adce67 | 2014-02-03 14:48:17 +0000 | [diff] [blame] | 50 | fGM->drawBackground(canvas); |
| 51 | for (int i = 0; i < loops; ++i) { |
| 52 | fGM->drawContent(canvas); |
| 53 | } |
| 54 | } |
| 55 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 56 | SkIPoint GMBench::onGetSize() { |
commit-bot@chromium.org | 6adce67 | 2014-02-03 14:48:17 +0000 | [diff] [blame] | 57 | SkISize size = fGM->getISize(); |
| 58 | return SkIPoint::Make(size.fWidth, size.fHeight); |
| 59 | } |