Chromium Code Reviews| Index: bench/SKPBench.cpp |
| diff --git a/bench/SKPBench.cpp b/bench/SKPBench.cpp |
| index 910af6b802337a700557f1ceedc24ab5a1375458..bca179c2c083644d157cafbe3e086692cc89a635 100644 |
| --- a/bench/SKPBench.cpp |
| +++ b/bench/SKPBench.cpp |
| @@ -155,3 +155,39 @@ void SKPBench::drawPicture() { |
| fSurfaces[j]->getCanvas()->flush(); |
| } |
| } |
| + |
| +static void draw_pic_for_stats(SkCanvas* canvas, GrContext* context, const SkPicture* picture, |
|
bsalomon
2015/12/02 15:58:10
might need to protect this by a SK_SUPPORT_GPU
|
| + SkTArray<SkString>* keys, SkTArray<double>* values, |
| + const char* tag) { |
| + context->resetGpuStats(); |
| + canvas->drawPicture(picture); |
| + canvas->flush(); |
| + |
| + int offset = keys->count(); |
| + context->dumpGpuStatsKeyValuePairs(keys, values); |
| + |
| + // append tag, but only to new tags |
| + for (int i = offset; i < keys->count(); i++, offset++) { |
| + (*keys)[i].appendf("_%s", tag); |
| + } |
| +} |
| + |
| +void SKPBench::getGpuStats(SkCanvas* canvas, SkTArray<SkString>* keys, SkTArray<double>* values) { |
| +#if SK_SUPPORT_GPU |
| + // we do a special single draw and then dump the key / value pairs |
| + GrContext* context = canvas->getGrContext(); |
| + if (!context) { |
| + return; |
| + } |
| + |
| + // TODO refactor this out if we want to test other subclasses of skpbench |
| + context->flush(); |
| + context->freeGpuResources(); |
| + context->resetContext(); |
| + draw_pic_for_stats(canvas, context, fPic, keys, values, "first_frame"); |
| + |
| + // draw second frame |
| + draw_pic_for_stats(canvas, context, fPic, keys, values, "second_frame"); |
| + |
| +#endif |
| +} |