From 2e172ecd3b0ed570f6bf27594c524ea63a606066 Mon Sep 17 00:00:00 2001 From: mtklein Date: Wed, 20 May 2015 10:32:22 -0700 Subject: [PATCH] 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 --- src/core/SkMiniRecorder.cpp | 7 +++---- 1 file 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 class SkMiniPicture final : public SkPicture { @@ -94,7 +93,7 @@ SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) { return SkNEW_ARGS(SkMiniPicture, (cull, reinterpret_cast(fBuffer.get()))) switch (fState) { - case State::kEmpty: return SkNEW(SkEmptyPicture); + case State::kEmpty: return SkRef(gEmptyPicture.get()); CASE(DrawPath); CASE(DrawRect); CASE(DrawTextBlob);