Remove ability for Release code to call getRefCnt() or getWeakRefCnt().

These getRefCnt() methods are not thread safe, so Skia code should not
be calling them.  unique() is fine.

SkDEBUG code (SkASSERTs) can still call getRefCnt() / getWeakRefCnt().

This adds tools/RefCntIs.{h,cpp}, which lets tests make their assertions in
both debug and release modes.

BUG=skia:2726

Committed: https://skia.googlesource.com/skia/+/4ae94ffce5ecf1b71cb5e295b68bf4ec9e697443

R=senorblanco@chromium.org, mtklein@google.com, reed@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/378643003
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
index ea88253..a571184 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -51,6 +51,7 @@
     class SK_API Cache : public SkRefCnt {
     public:
         // By default, we cache only image filters with 2 or more children.
+        // Values less than 2 mean always cache; values greater than 2 are not supported.
         static Cache* Create(int minChildren = 2);
         virtual ~Cache() {}
         virtual bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset) = 0;
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 8402a55..64603b4 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -361,7 +361,10 @@
 
 class CacheImpl : public SkImageFilter::Cache {
 public:
-    explicit CacheImpl(int minChildren) : fMinChildren(minChildren) {}
+    explicit CacheImpl(int minChildren) : fMinChildren(minChildren) {
+        SkASSERT(fMinChildren <= 2);
+    }
+
     virtual ~CacheImpl();
     bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
     void set(const SkImageFilter* key, const SkBitmap& result, const SkIPoint& offset) SK_OVERRIDE;
@@ -404,7 +407,10 @@
 }
 
 void CacheImpl::set(const SkImageFilter* key, const SkBitmap& result, const SkIPoint& offset) {
-    if (key->getRefCnt() >= fMinChildren) {
+    if (fMinChildren < 2 || !key->unique()) {
+        // We take !key->unique() as a signal that there are probably at least 2 refs on the key,
+        // meaning this filter probably has at least two children and is worth caching when
+        // fMinChildren is 2.  If fMinChildren is less than two, we'll just always cache.
         fData.add(new Value(key, result, offset));
     }
 }
diff --git a/tools/tsan.supp b/tools/tsan.supp
index 8c95e7a..f687014 100644
--- a/tools/tsan.supp
+++ b/tools/tsan.supp
@@ -25,6 +25,3 @@
 race:RefFCI
 race:SkString
 race:SkPDF
-
-# This calls SkRefCnt::getRefCnt(), which is not thread safe.  skia:2726
-race:SkImageFilter::filterImage