9c5052f16b
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
65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
/*
|
|
* Copyright 2016 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "Test.h"
|
|
#include "SkLiteDL.h"
|
|
#include "SkLiteRecorder.h"
|
|
|
|
#if 0 // This test doesn't make sense when run in a threaded environment. It tests global state.
|
|
DEF_TEST(SkLiteDL_freelisting, r) {
|
|
// TODO: byte and count limit tests
|
|
sk_sp<SkLiteDL> sp1 = SkLiteDL::New({1,1,10,10}),
|
|
sp2 = SkLiteDL::New({2,2,20,20});
|
|
|
|
SkLiteDL* p1 = sp1.get();
|
|
SkLiteDL* p2 = sp2.get();
|
|
REPORTER_ASSERT(r, p1 != p2);
|
|
REPORTER_ASSERT(r, p1->getBounds().left() == 1);
|
|
REPORTER_ASSERT(r, p2->getBounds().left() == 2);
|
|
|
|
sp2.reset();
|
|
|
|
sk_sp<SkLiteDL> sp3 = SkLiteDL::New({3,3,30,30});
|
|
SkLiteDL* p3 = sp3.get();
|
|
REPORTER_ASSERT(r, p1 != p3);
|
|
REPORTER_ASSERT(r, p2 == p3);
|
|
REPORTER_ASSERT(r, p1->getBounds().left() == 1);
|
|
REPORTER_ASSERT(r, p3->getBounds().left() == 3);
|
|
|
|
sp3.reset();
|
|
sp1.reset();
|
|
|
|
sk_sp<SkLiteDL> sp4 = SkLiteDL::New({4,4,40,40});
|
|
SkLiteDL* p4 = sp4.get();
|
|
REPORTER_ASSERT(r, p4 == p1); // Checks that we operate in stack order. Nice, not essential.
|
|
REPORTER_ASSERT(r, p4->getBounds().left() == 4);
|
|
}
|
|
#endif
|
|
|
|
DEF_TEST(SkLiteDL_basics, r) {
|
|
sk_sp<SkLiteDL> p { SkLiteDL::New({2,2,3,3}) };
|
|
|
|
p->save();
|
|
p->clipRect(SkRect{2,3,4,5}, SkRegion::kIntersect_Op, true);
|
|
p->drawRect(SkRect{0,0,9,9}, SkPaint{});
|
|
p->restore();
|
|
}
|
|
|
|
DEF_TEST(SkLiteRecorder, r) {
|
|
sk_sp<SkLiteDL> p { SkLiteDL::New({2,2,3,3}) };
|
|
|
|
SkLiteRecorder rec;
|
|
SkCanvas* c = &rec;
|
|
|
|
rec.reset(p.get());
|
|
|
|
c->save();
|
|
c->clipRect(SkRect{2,3,4,5}, SkRegion::kIntersect_Op, true);
|
|
c->drawRect(SkRect{0,0,9,9}, SkPaint{});
|
|
c->restore();
|
|
}
|