Index: bench/SKPBench.cpp |
diff --git a/bench/SKPBench.cpp b/bench/SKPBench.cpp |
index 910af6b802337a700557f1ceedc24ab5a1375458..c5480904053dbfd98cce060e1860f3bc366f3e61 100644 |
--- a/bench/SKPBench.cpp |
+++ b/bench/SKPBench.cpp |
@@ -155,3 +155,41 @@ void SKPBench::drawPicture() { |
fSurfaces[j]->getCanvas()->flush(); |
} |
} |
+ |
+#if SK_SUPPORT_GPU |
+static void draw_pic_for_stats(SkCanvas* canvas, GrContext* context, const SkPicture* picture, |
+ 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); |
+ } |
+} |
+#endif |
+ |
+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 |
+} |