remove non-static uses of SkOncePtr

Still slowly working through all the SK_DECLARE_STATIC_FOO macros.

SkOncePtr is complicating things by having SkOncePtr delete its pointer
and SkBaseOncePtr not.  Simplify things by removing SkOncePtr, leaving
only the leaky SkBaseOncePtr.

We replace SkOncePtr<T> instead with SkOnce and T.  In most cases this
did not need to be a pointer, and in some cases here we're even saving
a few bytes by replacing SkOncePtr<T> with SkOnce and a T.

The dependency map of SK_DECLARE_STATIC_FOO is:
  SkBaseMutex -> SkBaseSemaphore -> SkBaseOncePtr

They're intertwined enough that I think I've got to do all three in one
next CL.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1939503002

Review-Url: https://codereview.chromium.org/1939503002
diff --git a/include/core/SkColorTable.h b/include/core/SkColorTable.h
index ccea7ed..39553ba 100644
--- a/include/core/SkColorTable.h
+++ b/include/core/SkColorTable.h
@@ -10,7 +10,7 @@
 #ifndef SkColorTable_DEFINED
 #define SkColorTable_DEFINED
 
-#include "../private/SkOncePtr.h"
+#include "../private/SkOnce.h"
 #include "SkColor.h"
 #include "SkFlattenable.h"
 #include "SkImageInfo.h"
@@ -62,7 +62,8 @@
     SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc);
 
     SkPMColor*            fColors;
-    SkOncePtr<uint16_t[]> f16BitCache;
+    mutable uint16_t*     f16BitCache = nullptr;
+    mutable SkOnce        f16BitCacheOnce;
     int                   fCount;
 
     void init(const SkPMColor* colors, int count);
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index 0fbf6a3..f22d2bd 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -8,7 +8,7 @@
 #ifndef SkTypeface_DEFINED
 #define SkTypeface_DEFINED
 
-#include "../private/SkOncePtr.h"
+#include "../private/SkOnce.h"
 #include "../private/SkWeakRefCnt.h"
 #include "SkFontStyle.h"
 #include "SkRect.h"
@@ -398,9 +398,10 @@
     static SkTypeface* CreateDefault(int style);  // SkLazyPtr requires an int, not a Style.
     static void        DeleteDefault(SkTypeface*);
 
-    SkOncePtr<SkRect>   fLazyBounds;
     SkFontID            fUniqueID;
     SkFontStyle         fStyle;
+    mutable SkRect      fBounds;
+    mutable SkOnce      fBoundsOnce;
     bool                fIsFixedPitch;
 
     friend class SkPaint;
diff --git a/include/gpu/GrProcessor.h b/include/gpu/GrProcessor.h
index 27fce2e..d374a7f 100644
--- a/include/gpu/GrProcessor.h
+++ b/include/gpu/GrProcessor.h
@@ -15,6 +15,7 @@
 #include "GrBufferAccess.h"
 #include "SkMath.h"
 #include "SkString.h"
+#include "../private/SkAtomics.h"
 
 class GrContext;
 class GrCoordTransform;
diff --git a/include/private/SkOncePtr.h b/include/private/SkOncePtr.h
index b60d968..921c6a6 100644
--- a/include/private/SkOncePtr.h
+++ b/include/private/SkOncePtr.h
@@ -11,51 +11,9 @@
 #include "../private/SkAtomics.h"
 #include <memory>
 
-template <typename T> class SkBaseOncePtr;
-
 // Use this to create a global static pointer that's intialized exactly once when you call get().
 #define SK_DECLARE_STATIC_ONCE_PTR(type, name) namespace {} static SkBaseOncePtr<type> name;
 
-// Use this for a local or member pointer that's initialized exactly once when you call get().
-template <typename T, typename Delete = std::default_delete<T>>
-class SkOncePtr : SkNoncopyable {
-public:
-    SkOncePtr() { sk_bzero(this, sizeof(*this)); }
-    ~SkOncePtr() {
-        if (T* ptr = (T*)*this) {
-            Delete()(ptr);
-        }
-    }
-
-    template <typename F>
-    T* get(const F& f) const {
-        return fOnce.get(f);
-    }
-
-    operator T*() const {
-        return (T*)fOnce;
-    }
-
-private:
-    SkBaseOncePtr<T> fOnce;
-};
-
-// If you ask for SkOncePtr<T[]>, we'll clean up with delete[] by default.
-template <typename T>
-class SkOncePtr<T[]> : public SkOncePtr<T, std::default_delete<T[]>> {};
-
-/* TODO(mtklein): in next CL
-typedef SkBaseOncePtr<void> SkOnceFlag;
-#define SK_DECLARE_STATIC_ONCE(name) namespace {} static SkOnceFlag name
-
-template <typename F>
-inline void SkOnce(SkOnceFlag* once, const F& f) {
-    once->get([&]{ f(); return (void*)2; });
-}
-*/
-
-// Implementation details below here!  No peeking!
-
 template <typename T>
 class SkBaseOncePtr {
 public:
diff --git a/src/core/SkBigPicture.cpp b/src/core/SkBigPicture.cpp
index 70f68db..da3d3a8 100644
--- a/src/core/SkBigPicture.cpp
+++ b/src/core/SkBigPicture.cpp
@@ -58,7 +58,8 @@
 }
 
 const SkBigPicture::Analysis& SkBigPicture::analysis() const {
-    return *fAnalysis.get([&]{ return new Analysis(*fRecord); });
+    fAnalysisOnce([this] { fAnalysis.init(*fRecord); });
+    return fAnalysis;
 }
 
 SkRect SkBigPicture::cullRect()            const { return fCullRect; }
@@ -80,8 +81,8 @@
     return fDrawablePicts ? fDrawablePicts->begin() : nullptr;
 }
 
-SkBigPicture::Analysis::Analysis(const SkRecord& record) {
-    TRACE_EVENT0("disabled-by-default-skia", "SkBigPicture::Analysis::Analysis()");
+void SkBigPicture::Analysis::init(const SkRecord& record) {
+    TRACE_EVENT0("disabled-by-default-skia", "SkBigPicture::Analysis::init()");
     SkTextHunter   text;
     SkBitmapHunter bitmap;
     SkPathCounter  path;
diff --git a/src/core/SkBigPicture.h b/src/core/SkBigPicture.h
index 0834709..f9997f7 100644
--- a/src/core/SkBigPicture.h
+++ b/src/core/SkBigPicture.h
@@ -8,7 +8,7 @@
 #ifndef SkBigPicture_DEFINED
 #define SkBigPicture_DEFINED
 
-#include "SkOncePtr.h"
+#include "SkOnce.h"
 #include "SkPicture.h"
 #include "SkRect.h"
 #include "SkTemplates.h"
@@ -65,7 +65,7 @@
 
 private:
     struct Analysis {
-        explicit Analysis(const SkRecord&);
+        void init(const SkRecord&);
 
         bool suitableForGpuRasterization(const char** reason) const;
 
@@ -81,7 +81,8 @@
 
     const SkRect                          fCullRect;
     const size_t                          fApproxBytesUsedBySubPictures;
-    SkOncePtr<const Analysis>             fAnalysis;
+    mutable SkOnce                        fAnalysisOnce;
+    mutable 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 d7253e1..296b31c 100644
--- a/src/core/SkColorTable.cpp
+++ b/src/core/SkColorTable.cpp
@@ -41,19 +41,19 @@
 
 SkColorTable::~SkColorTable() {
     sk_free(fColors);
-    // f16BitCache frees itself
+    sk_free(f16BitCache);
 }
 
 #include "SkColorPriv.h"
 
 const uint16_t* SkColorTable::read16BitCache() const {
-    return f16BitCache.get([&]{
-        auto cache = new uint16_t[fCount];
+    f16BitCacheOnce([this] {
+        f16BitCache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t));
         for (int i = 0; i < fCount; i++) {
-            cache[i] = SkPixel32ToPixel16_ToU16(fColors[i]);
+            f16BitCache[i] = SkPixel32ToPixel16_ToU16(fColors[i]);
         }
-        return cache;
     });
+    return f16BitCache;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index d768efc..3830c46 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -318,13 +318,12 @@
 #include "SkPaint.h"
 
 SkRect SkTypeface::getBounds() const {
-    return *fLazyBounds.get([&] {
-        SkRect* rect = new SkRect;
-        if (!this->onComputeBounds(rect)) {
-            rect->setEmpty();
+    fBoundsOnce([this] {
+        if (!this->onComputeBounds(&fBounds)) {
+            fBounds.setEmpty();
         }
-        return rect;
     });
+    return fBounds;
 }
 
 bool SkTypeface::onComputeBounds(SkRect* bounds) const {
diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp
index d6f6980..8f6e308 100644
--- a/src/image/SkSurface.cpp
+++ b/src/image/SkSurface.cpp
@@ -5,6 +5,7 @@
  * found in the LICENSE file.
  */
 
+#include "SkAtomics.h"
 #include "SkSurface_Base.h"
 #include "SkImagePriv.h"
 #include "SkCanvas.h"
diff --git a/tests/OncePtrTest.cpp b/tests/OncePtrTest.cpp
index d01cee0..0aacdf5 100644
--- a/tests/OncePtrTest.cpp
+++ b/tests/OncePtrTest.cpp
@@ -9,9 +9,9 @@
 #include "SkOncePtr.h"
 #include "SkTaskGroup.h"
 
-DEF_TEST(OncePtr, r) {
-    SkOncePtr<int> once;
+SK_DECLARE_STATIC_ONCE_PTR(int, once);
 
+DEF_TEST(OncePtr, r) {
     static SkAtomic<int> calls(0);
     auto create = [&] {
         calls.fetch_add(1);
@@ -24,20 +24,3 @@
     });
     REPORTER_ASSERT(r, calls.load() == 1);
 }
-
-/* TODO(mtklein): next CL
-
-SK_DECLARE_STATIC_ONCE(once_noptr);
-DEF_TEST(OnceNoPtr, r) {
-    static SkAtomic<int> calls(0);
-
-    SkAtomic<int> force_a_race(sk_num_cores());
-    SkTaskGroup().batch(sk_num_cores()*4, [&](size_t) {
-        force_a_race.fetch_add(-1);
-        while (force_a_race.load() > 0);
-
-        SkOnce(&once_noptr, [&] { calls.fetch_add(1); });
-    });
-    REPORTER_ASSERT(r, calls.load() == 1);
-}
-*/