diff options
author | mtklein <mtklein@chromium.org> | 2015-05-20 10:32:22 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-20 10:32:22 -0700 |
commit | 2e172ecd3b0ed570f6bf27594c524ea63a606066 (patch) | |
tree | 63a69e238c081dbcaeee083233d858f30b68ab0b /src/core/SkMiniRecorder.cpp | |
parent | d41ea1d1cf0358e8b147c30c2dd168b631cc9b47 (diff) |
Make SkEmptyPicture a singleton.
In my confusion yesterday I accidentally left this as a non-singleton.
The issue in Blink was not related to this being a singleton,
and it should be safe to make it one.
This means recording an empty picture properly costs zero mallocs.
BUG=skia:
Review URL: https://codereview.chromium.org/1147053002
Diffstat (limited to 'src/core/SkMiniRecorder.cpp')
-rw-r--r-- | src/core/SkMiniRecorder.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/core/SkMiniRecorder.cpp b/src/core/SkMiniRecorder.cpp index 6707e863ac..ff17edb257 100644 --- a/src/core/SkMiniRecorder.cpp +++ b/src/core/SkMiniRecorder.cpp @@ -6,6 +6,7 @@ */ #include "SkCanvas.h" +#include "SkLazyPtr.h" #include "SkMiniRecorder.h" #include "SkPicture.h" #include "SkPictureCommon.h" @@ -14,9 +15,6 @@ using namespace SkRecords; -// SkEmptyPicture could logically be a singleton, but that plays badly with Blink's -// Debug-only adopted() / requireAdoption() tracking in sk_ref_cnt_ext_debug.h. -// TODO(mtklein): modify sk_ref_cnt_ext_debug.h to play better with non-new'd objects. class SkEmptyPicture final : public SkPicture { public: void playback(SkCanvas*, AbortCallback*) const override { } @@ -28,6 +26,7 @@ public: int numSlowPaths() const override { return 0; } bool willPlayBackBitmaps() const override { return false; } }; +SK_DECLARE_STATIC_LAZY_PTR(SkEmptyPicture, gEmptyPicture); template <typename T> class SkMiniPicture final : public SkPicture { @@ -94,7 +93,7 @@ SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) { return SkNEW_ARGS(SkMiniPicture<Type>, (cull, reinterpret_cast<Type*>(fBuffer.get()))) switch (fState) { - case State::kEmpty: return SkNEW(SkEmptyPicture); + case State::kEmpty: return SkRef(gEmptyPicture.get()); CASE(DrawPath); CASE(DrawRect); CASE(DrawTextBlob); |