diff options
author | mtklein <mtklein@chromium.org> | 2015-11-05 09:46:23 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-05 09:46:23 -0800 |
commit | cd4954152490c7492284a7914571531ba8c75b4a (patch) | |
tree | 674d240d842221a51e05a1f48b8ed5ea65d919a7 /include/core/SkMallocPixelRef.h | |
parent | 8515377d8f67b7d4d3edfd669fbc727a007ddab3 (diff) |
For non-opaque SkBitmapDevices, replace malloc-then-zero with calloc.
There seem about a zillion possible ways to slice this.
This adds and uses SkMallocPixelRef::ZeroedPRFactory.
I'm not married to it.
This appears to clear up a hot spot in the benchmark referenced in this bug:
BUG=516426
I'm not confident enough on Windows to declare that definitively yet.
It probably helps all other non-opaque layers too. Possibly significantly.
So I don't forget, I profiled this:
out/Release/performance_browser_tests.exe --gtest_filter=TabCapturePerformanceTest.Performance/2 --single-process
No diffs:
https://gold.skia.org/search2?issue=1430593007&unt=true&query=source_type%3Dgm&master=false
TBR=reed@google.com
Review URL: https://codereview.chromium.org/1430593007
Diffstat (limited to 'include/core/SkMallocPixelRef.h')
-rw-r--r-- | include/core/SkMallocPixelRef.h | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h index 1baceae166..ab337b9241 100644 --- a/include/core/SkMallocPixelRef.h +++ b/include/core/SkMallocPixelRef.h @@ -43,6 +43,12 @@ public: size_t rowBytes, SkColorTable*); /** + * Identical to NewAllocate, except all pixel bytes are zeroed. + */ + static SkMallocPixelRef* NewZeroed(const SkImageInfo& info, + size_t rowBytes, SkColorTable*); + + /** * Return a new SkMallocPixelRef with the provided pixel storage, * rowBytes, and optional colortable. On destruction, ReleaseProc * will be called. @@ -81,9 +87,12 @@ public: class PRFactory : public SkPixelRefFactory { public: - virtual SkPixelRef* create(const SkImageInfo&, - size_t rowBytes, - SkColorTable*) override; + SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable*) override; + }; + + class ZeroedPRFactory : public SkPixelRefFactory { + public: + SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable*) override; }; protected: @@ -97,6 +106,12 @@ protected: size_t getAllocatedSizeInBytes() const override; private: + // Uses alloc to implement NewAllocate or NewZeroed. + static SkMallocPixelRef* NewUsing(void*(*alloc)(size_t), + const SkImageInfo&, + size_t rowBytes, + SkColorTable*); + void* fStorage; SkColorTable* fCTable; size_t fRB; |