2014-02-03 14:48:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/GMBench.h"
|
2014-02-03 14:48:17 +00:00
|
|
|
|
2020-07-01 18:45:24 +00:00
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
|
|
|
|
2019-08-12 20:39:24 +00:00
|
|
|
GMBench::GMBench(std::unique_ptr<skiagm::GM> gm) : fGM(std::move(gm)) {
|
2020-06-25 15:41:19 +00:00
|
|
|
fGM->setMode(skiagm::GM::kBench_Mode);
|
|
|
|
|
2019-08-12 20:39:24 +00:00
|
|
|
fName.printf("GM_%s", fGM->getName());
|
2014-02-03 14:48:17 +00:00
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
const char* GMBench::onGetName() {
|
2014-02-03 14:48:17 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
bool GMBench::isSuitableFor(Backend backend) {
|
2015-01-23 19:07:07 +00:00
|
|
|
return kNonRendering_Backend != backend;
|
2014-02-03 14:48:17 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 15:41:19 +00:00
|
|
|
void GMBench::onPerCanvasPreDraw(SkCanvas* canvas) {
|
2020-07-07 14:27:55 +00:00
|
|
|
auto direct = GrAsDirectContext(canvas->recordingContext());
|
2020-07-01 18:45:24 +00:00
|
|
|
|
|
|
|
if (fGM->gpuSetup(direct, canvas) != skiagm::DrawResult::kOk) {
|
2020-06-26 14:10:49 +00:00
|
|
|
fGpuSetupFailed = true;
|
|
|
|
}
|
|
|
|
|
2020-06-25 15:41:19 +00:00
|
|
|
fGM->onceBeforeDraw();
|
|
|
|
}
|
|
|
|
|
2020-06-26 14:10:49 +00:00
|
|
|
void GMBench::onPerCanvasPostDraw(SkCanvas*) {
|
|
|
|
fGM->gpuTeardown();
|
|
|
|
|
|
|
|
// The same GM will be reused with multiple GrContexts. Let the next GrContext start
|
|
|
|
// afresh.
|
|
|
|
fGpuSetupFailed = false;
|
|
|
|
}
|
2020-06-25 15:41:19 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void GMBench::onDraw(int loops, SkCanvas* canvas) {
|
2020-06-26 14:10:49 +00:00
|
|
|
if (fGpuSetupFailed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-03 14:48:17 +00:00
|
|
|
fGM->drawBackground(canvas);
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
fGM->drawContent(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
SkIPoint GMBench::onGetSize() {
|
2014-02-03 14:48:17 +00:00
|
|
|
SkISize size = fGM->getISize();
|
|
|
|
return SkIPoint::Make(size.fWidth, size.fHeight);
|
|
|
|
}
|