Port uses of SkLazyPtr to SkOncePtr.

This gives SkOncePtr a non-trivial destructor that uses std::default_delete
by default.  This is overrideable, as seen in SkColorTable.

SK_DECLARE_STATIC_ONCE_PTR still just leaves its pointers hanging at EOP.

BUG=skia:

No public API changes.
TBR=reed@google.com

Committed: https://skia.googlesource.com/skia/+/a1254acdb344174e761f5061c820559dab64a74c

Review URL: https://codereview.chromium.org/1322933005
diff --git a/src/core/SkBigPicture.cpp b/src/core/SkBigPicture.cpp
index 02011ee..61f3a0e 100644
--- a/src/core/SkBigPicture.cpp
+++ b/src/core/SkBigPicture.cpp
@@ -58,8 +58,7 @@
 }
 
 const SkBigPicture::Analysis& SkBigPicture::analysis() const {
-    auto create = [&]() { return new Analysis(*fRecord); };
-    return *fAnalysis.get(create);
+    return *fAnalysis.get([&]{ return new Analysis(*fRecord); });
 }
 
 SkRect SkBigPicture::cullRect()            const { return fCullRect; }
diff --git a/src/core/SkBigPicture.h b/src/core/SkBigPicture.h
index dfd6b80..2e42213 100644
--- a/src/core/SkBigPicture.h
+++ b/src/core/SkBigPicture.h
@@ -8,7 +8,7 @@
 #ifndef SkBigPicture_DEFINED
 #define SkBigPicture_DEFINED
 
-#include "SkLazyPtr.h"
+#include "SkOncePtr.h"
 #include "SkPicture.h"
 #include "SkTemplates.h"
 
@@ -79,7 +79,7 @@
 
     const SkRect                          fCullRect;
     const size_t                          fApproxBytesUsedBySubPictures;
-    SkLazyPtr<const Analysis>             fAnalysis;
+    SkOncePtr<const Analysis>             fAnalysis;
     SkAutoTUnref<const SkRecord>          fRecord;
     SkAutoTDelete<const SnapshotArray>    fDrawablePicts;
     SkAutoTUnref<const SkBBoxHierarchy>   fBBH;
diff --git a/src/core/SkColorTable.cpp b/src/core/SkColorTable.cpp
index ca9a865..f52ac90 100644
--- a/src/core/SkColorTable.cpp
+++ b/src/core/SkColorTable.cpp
@@ -47,26 +47,14 @@
 
 #include "SkColorPriv.h"
 
-namespace {
-struct Build16BitCache {
-    const SkPMColor* fColors;
-    int fCount;
-
-    uint16_t* operator()() const {
+const uint16_t* SkColorTable::read16BitCache() const {
+    return f16BitCache.get([&]{
         uint16_t* cache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t));
         for (int i = 0; i < fCount; i++) {
             cache[i] = SkPixel32ToPixel16_ToU16(fColors[i]);
         }
         return cache;
-    }
-};
-}//namespace
-
-void SkColorTable::Free16BitCache(uint16_t* cache) { sk_free(cache); }
-
-const uint16_t* SkColorTable::read16BitCache() const {
-    const Build16BitCache create = { fColors, fCount };
-    return f16BitCache.get(create);
+    });
 }
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkData.cpp b/src/core/SkData.cpp
index 9e65d2a..017c397 100644
--- a/src/core/SkData.cpp
+++ b/src/core/SkData.cpp
@@ -6,8 +6,8 @@
  */
 
 #include "SkData.h"
-#include "SkLazyPtr.h"
 #include "SkOSFile.h"
+#include "SkOncePtr.h"
 #include "SkReadBuffer.h"
 #include "SkStream.h"
 #include "SkWriteBuffer.h"
@@ -80,14 +80,9 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-// As a template argument these must have external linkage.
-SkData* sk_new_empty_data() { return new SkData(nullptr, 0, nullptr, nullptr); }
-namespace { void sk_unref_data(SkData* ptr) { return SkSafeUnref(ptr); } }
-
-SK_DECLARE_STATIC_LAZY_PTR(SkData, empty, sk_new_empty_data, sk_unref_data);
-
+SK_DECLARE_STATIC_ONCE_PTR(SkData, gEmpty);
 SkData* SkData::NewEmpty() {
-    return SkRef(empty.get());
+    return SkRef(gEmpty.get([]{return new SkData(nullptr, 0, nullptr, nullptr); }));
 }
 
 // assumes fPtr was allocated via sk_malloc
diff --git a/src/core/SkFontMgr.cpp b/src/core/SkFontMgr.cpp
index 7c06690..3190825 100644
--- a/src/core/SkFontMgr.cpp
+++ b/src/core/SkFontMgr.cpp
@@ -7,7 +7,7 @@
 
 #include "SkFontDescriptor.h"
 #include "SkFontMgr.h"
-#include "SkLazyPtr.h"
+#include "SkOncePtr.h"
 #include "SkStream.h"
 #include "SkTypes.h"
 
@@ -158,14 +158,10 @@
     return this->onLegacyCreateTypeface(familyName, styleBits);
 }
 
-// As a template argument this must have external linkage.
-SkFontMgr* sk_fontmgr_create_default() {
-    SkFontMgr* fm = SkFontMgr::Factory();
-    return fm ? fm : new SkEmptyFontMgr;
-}
-
-SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, sk_fontmgr_create_default);
-
+SK_DECLARE_STATIC_ONCE_PTR(SkFontMgr, singleton);
 SkFontMgr* SkFontMgr::RefDefault() {
-    return SkRef(singleton.get());
+    return SkRef(singleton.get([]{
+        SkFontMgr* fm = SkFontMgr::Factory();
+        return fm ? fm : new SkEmptyFontMgr;
+    }));
 }
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 309707c..9bee4e5 100644
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -8,7 +8,7 @@
 #include "SkGlyphCache.h"
 #include "SkGlyphCache_Globals.h"
 #include "SkGraphics.h"
-#include "SkLazyPtr.h"
+#include "SkOncePtr.h"
 #include "SkPath.h"
 #include "SkTemplates.h"
 #include "SkTraceMemoryDump.h"
@@ -18,8 +18,6 @@
 
 namespace {
 
-SkGlyphCache_Globals* create_globals() { return new SkGlyphCache_Globals; }
-
 const char gGlyphCacheDumpName[] = "skia/sk_glyph_cache";
 
 // Used to pass context to the sk_trace_dump_visitor.
@@ -30,11 +28,10 @@
 
 }  // namespace
 
-SK_DECLARE_STATIC_LAZY_PTR(SkGlyphCache_Globals, globals, create_globals);
-
 // Returns the shared globals
+SK_DECLARE_STATIC_ONCE_PTR(SkGlyphCache_Globals, globals);
 static SkGlyphCache_Globals& get_globals() {
-    return *globals.get();
+    return *globals.get([]{ return new SkGlyphCache_Globals; });
 }
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 3256294..ffb1f83 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -11,9 +11,9 @@
 #include "SkBitmapDevice.h"
 #include "SkChecksum.h"
 #include "SkDevice.h"
-#include "SkLazyPtr.h"
 #include "SkMatrixImageFilter.h"
 #include "SkMutex.h"
+#include "SkOncePtr.h"
 #include "SkReadBuffer.h"
 #include "SkRect.h"
 #include "SkTDynamicHash.h"
@@ -560,24 +560,19 @@
     mutable SkMutex                    fMutex;
 };
 
-SkImageFilter::Cache* CreateCache() {
-    return SkImageFilter::Cache::Create(kDefaultCacheSize);
-}
-
 } // namespace
 
 SkImageFilter::Cache* SkImageFilter::Cache::Create(size_t maxBytes) {
     return new CacheImpl(maxBytes);
 }
 
-SK_DECLARE_STATIC_LAZY_PTR(SkImageFilter::Cache, cache, CreateCache);
-
+SK_DECLARE_STATIC_ONCE_PTR(SkImageFilter::Cache, cache);
 SkImageFilter::Cache* SkImageFilter::Cache::Get() {
-    return cache.get();
+    return cache.get([]{ return SkImageFilter::Cache::Create(kDefaultCacheSize); });
 }
 
 void SkImageFilter::PurgeCache() {
-    cache.get()->purge();
+    Cache::Get()->purge();
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkMessageBus.h b/src/core/SkMessageBus.h
index 6f032a1..a2802f0 100644
--- a/src/core/SkMessageBus.h
+++ b/src/core/SkMessageBus.h
@@ -8,8 +8,8 @@
 #ifndef SkMessageBus_DEFINED
 #define SkMessageBus_DEFINED
 
-#include "SkLazyPtr.h"
 #include "SkMutex.h"
+#include "SkOncePtr.h"
 #include "SkTArray.h"
 #include "SkTDArray.h"
 #include "SkTypes.h"
@@ -40,20 +40,17 @@
     SkMessageBus();
     static SkMessageBus* Get();
 
-    // Allow SkLazyPtr to call SkMessageBus::SkMessageBus().
-    template <typename T> friend T* Private::sk_new();
-
     SkTDArray<Inbox*> fInboxes;
     SkMutex           fInboxesMutex;
 };
 
 // This must go in a single .cpp file, not some .h, or we risk creating more than one global
 // SkMessageBus per type when using shared libraries.  NOTE: at most one per file will compile.
-#define DECLARE_SKMESSAGEBUS_MESSAGE(Message)               \
-    SK_DECLARE_STATIC_LAZY_PTR(SkMessageBus<Message>, bus); \
-    template <>                                             \
-    SkMessageBus<Message>* SkMessageBus<Message>::Get() {   \
-        return bus.get();                                   \
+#define DECLARE_SKMESSAGEBUS_MESSAGE(Message)                      \
+    SK_DECLARE_STATIC_ONCE_PTR(SkMessageBus<Message>, bus);        \
+    template <>                                                    \
+    SkMessageBus<Message>* SkMessageBus<Message>::Get() {          \
+        return bus.get([]{ return new SkMessageBus<Message>(); }); \
     }
 
 //   ----------------------- Implementation of SkMessageBus::Inbox -----------------------
diff --git a/src/core/SkMiniRecorder.cpp b/src/core/SkMiniRecorder.cpp
index 5161c64..0a4859f 100644
--- a/src/core/SkMiniRecorder.cpp
+++ b/src/core/SkMiniRecorder.cpp
@@ -7,8 +7,8 @@
 
 #include "SkCanvas.h"
 #include "SkTLazy.h"
-#include "SkLazyPtr.h"
 #include "SkMiniRecorder.h"
+#include "SkOncePtr.h"
 #include "SkPicture.h"
 #include "SkPictureCommon.h"
 #include "SkRecordDraw.h"
@@ -27,7 +27,7 @@
     int    numSlowPaths()         const override { return 0; }
     bool   willPlayBackBitmaps()  const override { return false; }
 };
-SK_DECLARE_STATIC_LAZY_PTR(SkEmptyPicture, gEmptyPicture);
+SK_DECLARE_STATIC_ONCE_PTR(SkEmptyPicture, gEmptyPicture);
 
 template <typename T>
 class SkMiniPicture final : public SkPicture {
@@ -108,7 +108,7 @@
         return new SkMiniPicture<Type>(cull, reinterpret_cast<Type*>(fBuffer.get()))
 
     switch (fState) {
-        case State::kEmpty: return SkRef(gEmptyPicture.get());
+        case State::kEmpty: return SkRef(gEmptyPicture.get([]{ return new SkEmptyPicture; }));
         CASE(DrawBitmapRectFixedSize);
         CASE(DrawPath);
         CASE(DrawRect);
diff --git a/src/core/SkPathRef.cpp b/src/core/SkPathRef.cpp
index be7c66c..1197113 100644
--- a/src/core/SkPathRef.cpp
+++ b/src/core/SkPathRef.cpp
@@ -6,7 +6,7 @@
  */
 
 #include "SkBuffer.h"
-#include "SkLazyPtr.h"
+#include "SkOncePtr.h"
 #include "SkPath.h"
 #include "SkPathRef.h"
 
@@ -44,17 +44,13 @@
     SkDEBUGCODE(fEditorsAttached = 0x7777777;)
 }
 
-// As a template argument, this must have external linkage.
-SkPathRef* sk_create_empty_pathref() {
-    SkPathRef* empty = new SkPathRef;
-    empty->computeBounds();   // Avoids races later to be the first to do this.
-    return empty;
-}
-
-SK_DECLARE_STATIC_LAZY_PTR(SkPathRef, empty, sk_create_empty_pathref);
-
+SK_DECLARE_STATIC_ONCE_PTR(SkPathRef, empty);
 SkPathRef* SkPathRef::CreateEmpty() {
-    return SkRef(empty.get());
+    return SkRef(empty.get([]{
+        SkPathRef* pr = new SkPathRef;
+        pr->computeBounds();   // Avoids races later to be the first to do this.
+        return pr;
+    }));
 }
 
 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst,
@@ -443,7 +439,7 @@
 }
 
 void SkPathRef::addGenIDChangeListener(GenIDChangeListener* listener) {
-    if (nullptr == listener || this == empty.get()) {
+    if (nullptr == listener || this == (SkPathRef*)empty) {
         delete listener;
         return;
     }
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 3ed2565..e6a9b4d 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -9,9 +9,9 @@
 #include "SkEndian.h"
 #include "SkFontDescriptor.h"
 #include "SkFontMgr.h"
-#include "SkLazyPtr.h"
 #include "SkMutex.h"
 #include "SkOTTable_OS_2.h"
+#include "SkOncePtr.h"
 #include "SkStream.h"
 #include "SkTypeface.h"
 
@@ -73,33 +73,22 @@
     }
 };
 
-namespace {
-
 SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex);
-
-// As a template arguments, these must have external linkage.
-SkTypeface* sk_create_default_typeface(int style) {
-    // It is not safe to call FontConfigTypeface::LegacyCreateTypeface concurrently.
-    // To be safe, we serialize here with a mutex so only one call to
-    // CreateTypeface is happening at any given time.
-    // TODO(bungeman, mtklein): This is sad.  Make our fontconfig code safe?
-    SkAutoMutexAcquire lock(&gCreateDefaultMutex);
-
-    SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
-    SkTypeface* t = fm->legacyCreateTypeface(nullptr, style);
-    return t ? t : SkEmptyTypeface::Create();
-}
-
-void sk_unref_typeface(SkTypeface* ptr) { SkSafeUnref(ptr); }
-
-}  // namespace
-
-SK_DECLARE_STATIC_LAZY_PTR_ARRAY(SkTypeface, defaults, 4,
-                                 sk_create_default_typeface, sk_unref_typeface);
+SK_DECLARE_STATIC_ONCE_PTR(SkTypeface, defaults[4]);
 
 SkTypeface* SkTypeface::GetDefaultTypeface(Style style) {
     SkASSERT((int)style < 4);
-    return defaults[style];
+    return defaults[style].get([=]{
+        // It is not safe to call FontConfigTypeface::LegacyCreateTypeface concurrently.
+        // To be safe, we serialize here with a mutex so only one call to
+        // CreateTypeface is happening at any given time.
+        // TODO(bungeman, mtklein): This is sad.  Make our fontconfig code safe?
+        SkAutoMutexAcquire lock(&gCreateDefaultMutex);
+
+        SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
+        SkTypeface* t = fm->legacyCreateTypeface(nullptr, style);
+        return t ? t : SkEmptyTypeface::Create();
+    });
 }
 
 SkTypeface* SkTypeface::RefDefault(Style style) {
@@ -325,22 +314,14 @@
 #include "SkDescriptor.h"
 #include "SkPaint.h"
 
-struct SkTypeface::BoundsComputer {
-    const SkTypeface& fTypeface;
-
-    BoundsComputer(const SkTypeface& tf) : fTypeface(tf) {}
-
-    SkRect* operator()() const {
+SkRect SkTypeface::getBounds() const {
+    return *fLazyBounds.get([&] {
         SkRect* rect = new SkRect;
-        if (!fTypeface.onComputeBounds(rect)) {
+        if (!this->onComputeBounds(rect)) {
             rect->setEmpty();
         }
         return rect;
-    }
-};
-
-SkRect SkTypeface::getBounds() const {
-    return *fLazyBounds.get(BoundsComputer(*this));
+    });
 }
 
 bool SkTypeface::onComputeBounds(SkRect* bounds) const {
diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp
index 18ab9b6..8548fe8 100644
--- a/src/core/SkXfermode.cpp
+++ b/src/core/SkXfermode.cpp
@@ -9,8 +9,8 @@
 #include "SkXfermode.h"
 #include "SkXfermode_proccoeff.h"
 #include "SkColorPriv.h"
-#include "SkLazyPtr.h"
 #include "SkMathPriv.h"
+#include "SkOncePtr.h"
 #include "SkOpts.h"
 #include "SkReadBuffer.h"
 #include "SkString.h"
@@ -996,20 +996,7 @@
 #endif
 
 
-// Technically, can't be static and passed as a template parameter.  So we use anonymous namespace.
-namespace {
-SkXfermode* create_mode(int iMode) {
-    SkXfermode::Mode mode = (SkXfermode::Mode)iMode;
-
-    ProcCoeff rec = gProcCoeffs[mode];
-    if (auto xfermode = SkOpts::create_xfermode(rec, mode)) {
-        return xfermode;
-    }
-    return new SkProcCoeffXfermode(rec, mode);
-}
-}  // namespace
-
-SK_DECLARE_STATIC_LAZY_PTR_ARRAY(SkXfermode, cached, SkXfermode::kLastMode + 1, create_mode);
+SK_DECLARE_STATIC_ONCE_PTR(SkXfermode, cached[SkXfermode::kLastMode + 1]);
 
 SkXfermode* SkXfermode::Create(Mode mode) {
     SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount);
@@ -1025,7 +1012,13 @@
         return nullptr;
     }
 
-    return SkSafeRef(cached[mode]);
+    return SkSafeRef(cached[mode].get([=]{
+        ProcCoeff rec = gProcCoeffs[mode];
+        if (auto xfermode = SkOpts::create_xfermode(rec, mode)) {
+            return xfermode;
+        }
+        return (SkXfermode*) new SkProcCoeffXfermode(rec, mode);
+    }));
 }
 
 SkXfermodeProc SkXfermode::GetProc(Mode mode) {
diff --git a/src/fonts/SkRemotableFontMgr.cpp b/src/fonts/SkRemotableFontMgr.cpp
index 5299fad..41e3bc3 100644
--- a/src/fonts/SkRemotableFontMgr.cpp
+++ b/src/fonts/SkRemotableFontMgr.cpp
@@ -5,10 +5,9 @@
  * found in the LICENSE file.
  */
 
+#include "SkOncePtr.h"
 #include "SkRemotableFontMgr.h"
 
-#include "SkLazyPtr.h"
-
 SkRemotableFontIdentitySet::SkRemotableFontIdentitySet(int count, SkFontIdentity** data)
       : fCount(count), fData(count)
 {
@@ -16,12 +15,7 @@
     *data = fData;
 }
 
-// As a template argument, this must have external linkage.
-SkRemotableFontIdentitySet* sk_remotable_font_identity_set_new() {
-    return new SkRemotableFontIdentitySet;
-}
-
-SK_DECLARE_STATIC_LAZY_PTR(SkRemotableFontIdentitySet, empty, sk_remotable_font_identity_set_new);
+SK_DECLARE_STATIC_ONCE_PTR(SkRemotableFontIdentitySet, empty);
 SkRemotableFontIdentitySet* SkRemotableFontIdentitySet::NewEmpty() {
-    return SkRef(empty.get());
+    return SkRef(empty.get([]{ return new SkRemotableFontIdentitySet; }));
 }
diff --git a/src/lazy/SkDiscardableMemoryPool.cpp b/src/lazy/SkDiscardableMemoryPool.cpp
index 17b8c23..78c48f50 100644
--- a/src/lazy/SkDiscardableMemoryPool.cpp
+++ b/src/lazy/SkDiscardableMemoryPool.cpp
@@ -8,8 +8,8 @@
 #include "SkDiscardableMemory.h"
 #include "SkDiscardableMemoryPool.h"
 #include "SkImageGenerator.h"
-#include "SkLazyPtr.h"
 #include "SkMutex.h"
+#include "SkOncePtr.h"
 #include "SkTInternalLList.h"
 
 // Note:
@@ -246,23 +246,18 @@
     this->dumpDownTo(0);
 }
 
-////////////////////////////////////////////////////////////////////////////////
-SK_DECLARE_STATIC_MUTEX(gMutex);
-SkDiscardableMemoryPool* create_global_pool() {
-    return SkDiscardableMemoryPool::Create(SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE,
-                                           &gMutex);
-}
-
 }  // namespace
 
 SkDiscardableMemoryPool* SkDiscardableMemoryPool::Create(size_t size, SkBaseMutex* mutex) {
     return new DiscardableMemoryPool(size, mutex);
 }
 
-SK_DECLARE_STATIC_LAZY_PTR(SkDiscardableMemoryPool, global, create_global_pool);
+SK_DECLARE_STATIC_MUTEX(gMutex);
+SK_DECLARE_STATIC_ONCE_PTR(SkDiscardableMemoryPool, global);
 
 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool() {
-    return global.get();
+    return global.get([] {
+        return SkDiscardableMemoryPool::Create(SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE,
+                                               &gMutex);
+    });
 }
-
-////////////////////////////////////////////////////////////////////////////////
diff --git a/src/opts/opts_check_x86.cpp b/src/opts/opts_check_x86.cpp
index d3450c1..3c817e1 100644
--- a/src/opts/opts_check_x86.cpp
+++ b/src/opts/opts_check_x86.cpp
@@ -13,7 +13,7 @@
 #include "SkBlitRow.h"
 #include "SkBlitRow_opts_SSE2.h"
 #include "SkBlitRow_opts_SSE4.h"
-#include "SkLazyPtr.h"
+#include "SkOncePtr.h"
 #include "SkRTConf.h"
 
 #if defined(_MSC_VER) && defined(_WIN64)
@@ -71,8 +71,7 @@
 /* Fetch the SIMD level directly from the CPU, at run-time.
  * Only checks the levels needed by the optimizations in this file.
  */
-namespace {  // get_SIMD_level() technically must have external linkage, so no static.
-int* get_SIMD_level() {
+static int* get_SIMD_level() {
     int cpu_info[4] = { 0, 0, 0, 0 };
     getcpuid(1, cpu_info);
 
@@ -91,9 +90,8 @@
     }
     return level;
 }
-} // namespace
 
-SK_DECLARE_STATIC_LAZY_PTR(int, gSIMDLevel, get_SIMD_level);
+SK_DECLARE_STATIC_ONCE_PTR(int, gSIMDLevel);
 
 /* Verify that the requested SIMD level is supported in the build.
  * If not, check if the platform supports it.
@@ -114,7 +112,7 @@
          */
         return false;
 #else
-        return minLevel <= *gSIMDLevel.get();
+        return minLevel <= *gSIMDLevel.get(get_SIMD_level);
 #endif
     }
 }
diff --git a/src/pdf/SkPDFGraphicState.cpp b/src/pdf/SkPDFGraphicState.cpp
index 162ddc8..0ad1853 100644
--- a/src/pdf/SkPDFGraphicState.cpp
+++ b/src/pdf/SkPDFGraphicState.cpp
@@ -6,7 +6,7 @@
  */
 
 #include "SkData.h"
-#include "SkLazyPtr.h"
+#include "SkOncePtr.h"
 #include "SkPDFCanon.h"
 #include "SkPDFFormXObject.h"
 #include "SkPDFGraphicState.h"
@@ -126,8 +126,7 @@
     return pdfGraphicState;
 }
 
-namespace {
-SkPDFObject* create_invert_function() {
+static SkPDFObject* create_invert_function() {
     // Acrobat crashes if we use a type 0 function, kpdf crashes if we use
     // a type 2 function, so we use a type 4 function.
     SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray);
@@ -147,13 +146,7 @@
     return invertFunction;
 }
 
-template <typename T> void unref(T* ptr) { ptr->unref(); }
-}  // namespace
-
-SK_DECLARE_STATIC_LAZY_PTR(SkPDFObject,
-                           invertFunction,
-                           create_invert_function,
-                           unref<SkPDFObject>);
+SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, invertFunction);
 
 // static
 SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask,
@@ -169,7 +162,7 @@
     }
     sMaskDict->insertObjRef("G", SkRef(sMask));
     if (invert) {
-        sMaskDict->insertObjRef("TR", SkRef(invertFunction.get()));
+        sMaskDict->insertObjRef("TR", SkRef(invertFunction.get(create_invert_function)));
     }
 
     SkPDFDict* result = new SkPDFDict("ExtGState");
@@ -177,21 +170,16 @@
     return result;
 }
 
-namespace {
-SkPDFDict* create_no_smask_graphic_state() {
+static SkPDFDict* create_no_smask_graphic_state() {
     SkPDFDict* noSMaskGS = new SkPDFDict("ExtGState");
     noSMaskGS->insertName("SMask", "None");
     return noSMaskGS;
 }
-} // namespace
-SK_DECLARE_STATIC_LAZY_PTR(SkPDFDict,
-                           noSMaskGraphicState,
-                           create_no_smask_graphic_state,
-                           unref<SkPDFDict>);
+SK_DECLARE_STATIC_ONCE_PTR(SkPDFDict, noSMaskGraphicState);
 
 // static
 SkPDFDict* SkPDFGraphicState::GetNoSMaskGraphicState() {
-    return SkRef(noSMaskGraphicState.get());
+    return SkRef(noSMaskGraphicState.get(create_no_smask_graphic_state));
 }
 
 void SkPDFGraphicState::emitObject(
diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp
index 645091d..fe6e47c 100644
--- a/src/pdf/SkPDFShader.cpp
+++ b/src/pdf/SkPDFShader.cpp
@@ -10,6 +10,7 @@
 #include "SkPDFShader.h"
 
 #include "SkData.h"
+#include "SkOncePtr.h"
 #include "SkPDFCanon.h"
 #include "SkPDFDevice.h"
 #include "SkPDFFormXObject.h"
@@ -677,8 +678,7 @@
     return true;
 }
 
-namespace {
-SkPDFObject* create_range_object() {
+static SkPDFObject* create_range_object() {
     SkPDFArray* range = new SkPDFArray;
     range->reserve(6);
     range->appendInt(0);
@@ -689,12 +689,7 @@
     range->appendInt(1);
     return range;
 }
-
-template <typename T> void unref(T* ptr) { ptr->unref();}
-}  // namespace
-
-SK_DECLARE_STATIC_LAZY_PTR(SkPDFObject, rangeObject,
-                           create_range_object, unref<SkPDFObject>);
+SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, rangeObject);
 
 static SkPDFStream* make_ps_function(const SkString& psCode,
                                      SkPDFArray* domain) {
@@ -703,7 +698,7 @@
     SkPDFStream* result = new SkPDFStream(funcData.get());
     result->insertInt("FunctionType", 4);
     result->insertObject("Domain", SkRef(domain));
-    result->insertObject("Range", SkRef(rangeObject.get()));
+    result->insertObject("Range", SkRef(rangeObject.get(create_range_object)));
     return result;
 }
 
diff --git a/src/utils/SkEventTracer.cpp b/src/utils/SkEventTracer.cpp
index 1c916ed..32a0207 100644
--- a/src/utils/SkEventTracer.cpp
+++ b/src/utils/SkEventTracer.cpp
@@ -7,7 +7,7 @@
 
 #include "SkAtomics.h"
 #include "SkEventTracer.h"
-#include "SkLazyPtr.h"
+#include "SkOncePtr.h"
 
 #include <stdlib.h>
 
@@ -41,7 +41,7 @@
 
 // We prefer gUserTracer if it's been set, otherwise we fall back on gDefaultTracer.
 static SkEventTracer* gUserTracer = nullptr;
-SK_DECLARE_STATIC_LAZY_PTR(SkDefaultEventTracer, gDefaultTracer);
+SK_DECLARE_STATIC_ONCE_PTR(SkDefaultEventTracer, gDefaultTracer);
 
 void SkEventTracer::SetInstance(SkEventTracer* tracer) {
     SkASSERT(nullptr == sk_atomic_load(&gUserTracer, sk_memory_order_acquire));
@@ -54,5 +54,5 @@
     if (SkEventTracer* tracer = sk_atomic_load(&gUserTracer, sk_memory_order_acquire)) {
         return tracer;
     }
-    return gDefaultTracer.get();
+    return gDefaultTracer.get([]{ return new SkDefaultEventTracer; });
 }