diff options
author | cdalton <cdalton@nvidia.com> | 2015-10-26 13:45:29 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-26 13:45:29 -0700 |
commit | e6d2024c689199b09df0d7048fc5252179d52aff (patch) | |
tree | fd967ae58aa7566d6d8418fe6c1ebf7e84de1ffe | |
parent | c70483f5ab83aaa29c0697398aeca3432f3591b6 (diff) |
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
-rw-r--r-- | bench/SKPBench.cpp | 10 | ||||
-rw-r--r-- | samplecode/SampleApp.cpp | 6 | ||||
-rw-r--r-- | tools/VisualBench/VisualBenchmarkStream.cpp | 10 | ||||
-rw-r--r-- | tools/VisualBench/VisualSKPBench.cpp | 10 |
4 files changed, 36 insertions, 0 deletions
diff --git a/bench/SKPBench.cpp b/bench/SKPBench.cpp index 44261335da..910af6b802 100644 --- a/bench/SKPBench.cpp +++ b/bench/SKPBench.cpp @@ -10,6 +10,10 @@ #include "SkMultiPictureDraw.h" #include "SkSurface.h" +#if SK_SUPPORT_GPU +#include "GrContext.h" +#endif + // These CPU tile sizes are not good per se, but they are similar to what Chrome uses. DEFINE_int32(CPUbenchTileW, 256, "Tile width used for CPU SKP playback."); DEFINE_int32(CPUbenchTileH, 256, "Tile height used for CPU SKP playback."); @@ -115,6 +119,12 @@ void SKPBench::onDraw(int loops, SkCanvas* canvas) { this->drawPicture(); } } +#if SK_SUPPORT_GPU + // Ensure the GrContext doesn't batch across draw loops. + if (GrContext* context = canvas->getGrContext()) { + context->flush(); + } +#endif } void SKPBench::drawMPDPicture() { diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 9be7567ea0..07a7a87b7f 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -2257,6 +2257,12 @@ void SampleView::onDraw(SkCanvas* canvas) { for (int i = 0; i < fRepeatCount; i++) { SkAutoCanvasRestore acr(canvas, true); this->onDrawContent(canvas); +#if SK_SUPPORT_GPU + // Ensure the GrContext doesn't batch across draw loops. + if (GrContext* context = canvas->getGrContext()) { + context->flush(); + } +#endif } } diff --git a/tools/VisualBench/VisualBenchmarkStream.cpp b/tools/VisualBench/VisualBenchmarkStream.cpp index 66e7cb0aab..2efb3c886e 100644 --- a/tools/VisualBench/VisualBenchmarkStream.cpp +++ b/tools/VisualBench/VisualBenchmarkStream.cpp @@ -17,6 +17,10 @@ #include "VisualFlags.h" #include "VisualSKPBench.h" +#if SK_SUPPORT_GPU +#include "GrContext.h" +#endif + DEFINE_bool(cpu, false, "Run in CPU mode?"); DEFINE_string2(match, m, nullptr, "[~][^]substring[$] [...] of bench name to run.\n" @@ -52,6 +56,12 @@ private: for (int i = 0; i < loops; i++) { canvas->drawPath(fPath, paint); canvas->drawRect(rect, perlinPaint); +#if SK_SUPPORT_GPU + // Ensure the GrContext doesn't batch across draw loops. + if (GrContext* context = canvas->getGrContext()) { + context->flush(); + } +#endif } } SkPath fPath; diff --git a/tools/VisualBench/VisualSKPBench.cpp b/tools/VisualBench/VisualSKPBench.cpp index 649d324a66..628265e53e 100644 --- a/tools/VisualBench/VisualSKPBench.cpp +++ b/tools/VisualBench/VisualSKPBench.cpp @@ -8,6 +8,10 @@ #include "VisualSKPBench.h" +#if SK_SUPPORT_GPU +#include "GrContext.h" +#endif + VisualSKPBench::VisualSKPBench(const char* name, const SkPicture* pic) : fPic(SkRef(pic)) , fName(name) { @@ -29,5 +33,11 @@ bool VisualSKPBench::isSuitableFor(Backend 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 } } |