remove sk_atomic_fetch_add

Change-Id: Ia400db2b73a8061668e62f8e961538a060b216a1
Reviewed-on: https://skia-review.googlesource.com/c/174282
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/include/private/SkAtomics.h b/include/private/SkAtomics.h
index 5f8380f..0a34429 100644
--- a/include/private/SkAtomics.h
+++ b/include/private/SkAtomics.h
@@ -11,25 +11,17 @@
 #include "SkTypes.h"
 #include <atomic>
 
-// ~~~~~~~~ Legacy APIs ~~~~~~~~~
-//
-// Please use types from <atomic> for any new code.
-// That's all this file ends up doing under the hood.
-
-template <typename T>
-T sk_atomic_fetch_add(T* ptr, T val, std::memory_order mo = std::memory_order_seq_cst) {
-    // All values of mo are valid.
-    std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
-    return std::atomic_fetch_add_explicit(ap, val, mo);
-}
-
 // ~~~~~~~~ Very Legacy APIs ~~~~~~~~~
 //
 // Here are shims for our very old atomics API, to be weaned off of.  They use
 // sequentially-consistent memory order to match historical behavior, but most
 // of the callers could perform better with explicit, weaker memory ordering.
 
-inline int32_t sk_atomic_inc(int32_t* ptr) { return sk_atomic_fetch_add(ptr, +1); }
-inline int32_t sk_atomic_dec(int32_t* ptr) { return sk_atomic_fetch_add(ptr, -1); }
+inline int32_t sk_atomic_inc(int32_t* ptr) {
+    return reinterpret_cast<std::atomic<int32_t>*>(ptr)->fetch_add(+1);
+}
+inline int32_t sk_atomic_dec(int32_t* ptr) {
+    return reinterpret_cast<std::atomic<int32_t>*>(ptr)->fetch_add(-1);
+}
 
 #endif//SkAtomics_DEFINED
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index b50ac34..f646f14 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -5,32 +5,26 @@
  * found in the LICENSE file.
  */
 
-#include "SkAtomics.h"
 #include "SkBitmapCache.h"
 #include "SkMutex.h"
+#include "SkNextID.h"
 #include "SkPixelRef.h"
 #include "SkTraceEvent.h"
-
-//#define SK_TRACE_PIXELREF_LIFETIME
-
-#include "SkNextID.h"
+#include <atomic>
 
 uint32_t SkNextID::ImageID() {
-    static uint32_t gID = 0;
+    // We never set the low bit.... see SkPixelRef::genIDIsUnique().
+    static std::atomic<uint32_t> nextID{2};
+
     uint32_t id;
-    // Loop in case our global wraps around, as we never want to return a 0.
     do {
-        id = sk_atomic_fetch_add(&gID, 2u) + 2;  // Never set the low bit.
-    } while (0 == id);
+        id = nextID.fetch_add(2);
+    } while (id == 0);
     return id;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
-#ifdef SK_TRACE_PIXELREF_LIFETIME
-    static int32_t gInstCounter;
-#endif
-
 SkPixelRef::SkPixelRef(int width, int height, void* pixels, size_t rowBytes)
     : fWidth(width)
     , fHeight(height)
@@ -38,18 +32,11 @@
     , fRowBytes(rowBytes)
     , fAddedToCache(false)
 {
-#ifdef SK_TRACE_PIXELREF_LIFETIME
-    SkDebugf(" pixelref %d\n", sk_atomic_inc(&gInstCounter));
-#endif
-
     this->needsNewGenID();
     fMutability = kMutable;
 }
 
 SkPixelRef::~SkPixelRef() {
-#ifdef SK_TRACE_PIXELREF_LIFETIME
-    SkDebugf("~pixelref %d\n", sk_atomic_dec(&gInstCounter) - 1);
-#endif
     this->callGenIDChangeListeners();
 }