This allows devices (gpu, pdf) which are themselves always dynamically allocated
(since they are reference counted) to provide storage to clipstack, allowing it
to avoid calls to malloc.
Previously this was attempted by embedding the storage directly in clipstack,
but that increased the size of clipstack in all instances, even those where
it might be on the stack. This can be problematic for small-stack environments
like servers.
See previous (reverted) CL: https://skia-review.googlesource.com/c/9522/
BUG=skia:
Change-Id: Ifc7f5ef411303f33513195b1502ea9f281e995c5
Reviewed-on: https://skia-review.googlesource.com/9508
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Mike Reed <reed@google.com>
, fSaveCount(0) {
}
+SkClipStack::SkClipStack(void* storage, size_t size)
+ : fDeque(sizeof(Element), storage, size, kDefaultElementAllocCnt)
+ , fSaveCount(0) {
+}
+
SkClipStack::SkClipStack(const SkClipStack& b)
: fDeque(sizeof(Element), kDefaultElementAllocCnt) {
*this = b;
};
SkClipStack();
+ SkClipStack(void* storage, size_t size);
SkClipStack(const SkClipStack& b);
~SkClipStack();
public:
SkClipStackDevice(const SkImageInfo& info, const SkSurfaceProps& props)
: SkBaseDevice(info, props)
+ , fClipStack(fStorage, sizeof(fStorage))
{}
const SkClipStack& cs() const { return fClipStack; }
ClipType onGetClipType() const override;
private:
+ enum {
+ kPreallocCount = 16 // empirically determined, adjust as needed to reduce mallocs
+ };
+ intptr_t fStorage[kPreallocCount * sizeof(SkClipStack::Element) / sizeof(intptr_t)];
SkClipStack fClipStack;
typedef SkBaseDevice INHERITED;