skia2/tools/VisualBench/VisualSKPBench.cpp
cdalton e6d2024c68 Flush GrContext between benchmark draw loops
This change updates a small subset of benchmarks to flush the GrContext
between draw loops (specifically SKP benchmarks, SampleApp, and the
warmup in visualbench). This helps improve timing accuracy by not
allowing the gpu to batch across draw boundaries in the affected
benchmarks.

BUG=skia:

Review URL: https://codereview.chromium.org/1427533002
2015-10-26 13:45:29 -07:00

44 lines
966 B
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
*/
#include "VisualSKPBench.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#endif
VisualSKPBench::VisualSKPBench(const char* name, const SkPicture* pic)
: fPic(SkRef(pic))
, fName(name) {
fUniqueName.printf("%s", name);
}
const char* VisualSKPBench::onGetName() {
return fName.c_str();
}
const char* VisualSKPBench::onGetUniqueName() {
return fUniqueName.c_str();
}
bool VisualSKPBench::isSuitableFor(Backend backend) {
return backend != kNonRendering_Backend;
}
void VisualSKPBench::onDraw(int loops, SkCanvas* canvas) {
for (int i = 0; i < loops; i++) {
canvas->drawPicture(fPic);
#if SK_SUPPORT_GPU
// Ensure the GrContext doesn't batch across draw loops.
if (GrContext* context = canvas->getGrContext()) {
context->flush();
}
#endif
}
}