| 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 |
|
| 8 |
#include "bench/GMBench.h" |
| 9 |
|
| 10 |
#include "include/gpu/ganesh/GrRecordingContext.h" |
| 11 |
#include "src/gpu/ganesh/GrRecordingContextPriv.h" |
| 12 |
|
| 13 |
GMBench::GMBench(std::unique_ptr<skiagm::GM> gm) : fGM(std::move(gm)) { |
| 14 |
fGM->setMode(skiagm::GM::kBench_Mode); |
| 15 |
|
| 16 |
fName.printf("GM_%s", fGM->getName().c_str()); |
| 17 |
} |
| 18 |
|
| 19 |
const char* GMBench::onGetName() { |
| 20 |
return fName.c_str(); |
| 21 |
} |
| 22 |
|
| 23 |
bool GMBench::isSuitableFor(Backend backend) { |
| 24 |
return Backend::kNonRendering != backend; |
| 25 |
} |
| 26 |
|
| 27 |
void GMBench::onPerCanvasPreDraw(SkCanvas* canvas) { |
| 28 |
SkString msg; |
| 29 |
if (fGM->gpuSetup(canvas, &msg) != skiagm::DrawResult::kOk) { |
| 30 |
fGpuSetupFailed = true; |
| 31 |
} |
| 32 |
|
| 33 |
fGM->onceBeforeDraw(); |
| 34 |
} |
| 35 |
|
| 36 |
void GMBench::onPerCanvasPostDraw(SkCanvas*) { |
| 37 |
fGM->gpuTeardown(); |
| 38 |
|
| 39 |
// The same GM will be reused with multiple GrContexts. Let the next GrContext start |
| 40 |
// afresh. |
| 41 |
fGpuSetupFailed = false; |
| 42 |
} |
| 43 |
|
| 44 |
void GMBench::onDraw(int loops, SkCanvas* canvas) { |
| 45 |
if (fGpuSetupFailed) { |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
fGM->drawBackground(canvas); |
| 50 |
for (int i = 0; i < loops; ++i) { |
| 51 |
fGM->drawContent(canvas); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
SkISize GMBench::onGetSize() { |
| 56 |
return fGM->getISize(); |
| 57 |
} |