aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/PictureOverheadBench.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2016-08-06 12:51:51 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-06 12:51:51 -0700
commit9c5052f16b249d2b7674ea86bd24ed0038ccc61f (patch)
treedb2e05f246b2e7d65c91275943e1ada80a4856f1 /bench/PictureOverheadBench.cpp
parentc6f411e72b1fea6608f540f64a57bcacbe3378cd (diff)
SkLite*
SkLiteRecorder, a new SkCanvas, fills out SkLiteDL, a new SkDrawable. This SkDrawable is a display list similar to SkRecord and SkBigPicture / SkRecordedDrawable, but with a few new design points inspired by Android and slimming paint: 1) SkLiteDL is structured as one big contiguous array rather than the two layer structure of SkRecord. This trades away flexibility and large-op-count performance for better data locality for small to medium size pictures. 2) We keep a global freelist of SkLiteDLs, both reusing the SkLiteDL struct itself and its contiguous byte array. This keeps the expected number of mallocs per display list allocation <1 (really, ~0) for cyclical use cases. These two together mean recording is faster. Measuring against the code we use at head, SkLiteRecorder trends about ~3x faster across various size pictures, matching speed at 0 draws and beating the special-case 1-draw pictures we have today. (I.e. we won't need those special case implementations anymore, because they're slower than this new generic code.) This new strategy records 10 drawRects() in about the same time the old strategy took for 2. This strategy stays the winner until at least 500 drawRect()s on my laptop, where I stopped checking. A simpler alternative to freelisting is also possible (but not implemented here), where we allow the client to manually reset() an SkLiteDL for reuse when its refcnt is 1. That's essentially what we're doing with the freelist, except tracking what's available for reuse globally instead of making the client do it. This code is not fully capable yet, but most of the key design points are there. The internal structure of SkLiteDL is the area I expect to be most volatile (anything involving Op), but its interface and the whole of SkLiteRecorder ought to be just about done. You can run nanobench --match picture_overhead as a demo. Everything it exercises is fully fleshed out, so what it tests is an apples-to-apples comparison as far as recording costs go. I have not yet compared playback performance. It should be simple to wrap this into an SkPicture subclass if we want. I won't start proposing we replace anything old with anything new quite yet until I have more ducks in a row, but this does look pretty promising (similar to the SkRecord over old SkPicture change a couple years ago) and I'd like to land, experiment, iterate, especially with an eye toward Android. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2213333002 Review-Url: https://codereview.chromium.org/2213333002
Diffstat (limited to 'bench/PictureOverheadBench.cpp')
-rw-r--r--bench/PictureOverheadBench.cpp45
1 files changed, 36 insertions, 9 deletions
diff --git a/bench/PictureOverheadBench.cpp b/bench/PictureOverheadBench.cpp
index fc72f8623a..3bd9fb0bd9 100644
--- a/bench/PictureOverheadBench.cpp
+++ b/bench/PictureOverheadBench.cpp
@@ -10,26 +10,53 @@
#include "Benchmark.h"
#include "SkCanvas.h"
+#include "SkLiteDL.h"
+#include "SkLiteRecorder.h"
#include "SkPictureRecorder.h"
-template <bool kDraw>
+template <int kDraws, bool kLite>
struct PictureOverheadBench : public Benchmark {
- const char* onGetName() override {
- return kDraw ? "picture_overhead_draw" : "picture_overhead_nodraw";
+ PictureOverheadBench() {
+ fName.appendf("picture_overhead_%d%s\n", kDraws, kLite ? "_lite" : "");
}
+ const char* onGetName() override { return fName.c_str(); }
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
void onDraw(int loops, SkCanvas*) override {
+ SkLiteRecorder lite;
SkPictureRecorder rec;
for (int i = 0; i < loops; i++) {
- rec.beginRecording(SkRect::MakeWH(2000,3000));
- if (kDraw) {
- rec.getRecordingCanvas()->drawRect(SkRect::MakeXYWH(10, 10, 1000, 1000), SkPaint());
+ SkRect bounds{0,0, 2000,3000};
+
+ sk_sp<SkLiteDL> liteDL;
+ SkCanvas* canvas;
+ if (kLite) {
+ liteDL = SkLiteDL::New(bounds);
+ lite.reset(liteDL.get());
+ canvas = &lite;
+ } else {
+ rec.beginRecording(bounds);
+ canvas = rec.getRecordingCanvas();
+ }
+
+ for (int i = 0; i < kDraws; i++) {
+ canvas->drawRect({10,10, 1000, 1000}, SkPaint{});
+ }
+
+ if (!kLite) {
+ (void)rec.finishRecordingAsPicture();
}
- (void)rec.finishRecordingAsPicture();
}
}
+
+ SkString fName;
};
-DEF_BENCH(return (new PictureOverheadBench<false>);)
-DEF_BENCH(return (new PictureOverheadBench< true>);)
+DEF_BENCH(return (new PictureOverheadBench<0, false>);)
+DEF_BENCH(return (new PictureOverheadBench<1, false>);)
+DEF_BENCH(return (new PictureOverheadBench<2, false>);)
+DEF_BENCH(return (new PictureOverheadBench<10,false>);)
+DEF_BENCH(return (new PictureOverheadBench<0, true>);)
+DEF_BENCH(return (new PictureOverheadBench<1, true>);)
+DEF_BENCH(return (new PictureOverheadBench<2, true>);)
+DEF_BENCH(return (new PictureOverheadBench<10, true>);)