SkXfermode no longer needs to e a flattenable

SkArithmeticMode is unreachable, so delete it

Bug: skia:
Change-Id: Ibe4c48fcf756280569c4b302da8d96bd4e21b717
Reviewed-on: https://skia-review.googlesource.com/19394
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/gn/effects.gni b/gn/effects.gni
index 61b1b39..b2166d2 100644
--- a/gn/effects.gni
+++ b/gn/effects.gni
@@ -20,7 +20,6 @@
   "$_src/effects/SkAlphaThresholdFilter.cpp",
   "$_src/effects/SkArcToPathEffect.cpp",
   "$_src/effects/SkArithmeticImageFilter.cpp",
-  "$_src/effects/SkArithmeticMode.cpp",
   "$_src/effects/SkBlurMask.cpp",
   "$_src/effects/SkBlurMask.h",
   "$_src/effects/SkBlurMaskFilter.cpp",
diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h
index 49c491e..c36d181 100644
--- a/include/core/SkFlattenable.h
+++ b/include/core/SkFlattenable.h
@@ -80,7 +80,7 @@
         kSkRasterizer_Type,
         kSkShaderBase_Type,
         kSkUnused_Type,     // used to be SkUnitMapper
-        kSkXfermode_Type,
+        kSkUnused_Xfermode_Type,
         kSkNormalSource_Type,
     };
 
diff --git a/src/core/SkGlobalInitialization_core.cpp b/src/core/SkGlobalInitialization_core.cpp
index 9fa128f..bc3e254 100644
--- a/src/core/SkGlobalInitialization_core.cpp
+++ b/src/core/SkGlobalInitialization_core.cpp
@@ -44,7 +44,6 @@
     SkColorFilter::InitializeFlattenables();
     SkPathEffect::InitializeFlattenables();
     SkShaderBase::InitializeFlattenables();
-    SkXfermode::InitializeFlattenables();
 
     // Drawable
     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRecordedDrawable)
diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h
index 48cb225..6a2c525 100644
--- a/src/core/SkReadBuffer.h
+++ b/src/core/SkReadBuffer.h
@@ -23,7 +23,6 @@
 #include "SkShaderBase.h"
 #include "SkTHash.h"
 #include "SkWriteBuffer.h"
-#include "SkXfermodePriv.h"
 
 class SkBitmap;
 class SkImage;
@@ -152,7 +151,6 @@
     sk_sp<SkPathEffect> readPathEffect() { return this->readFlattenable<SkPathEffect>(); }
     sk_sp<SkRasterizer> readRasterizer() { return this->readFlattenable<SkRasterizer>(); }
     sk_sp<SkShader> readShader() { return this->readFlattenable<SkShaderBase>(); }
-    sk_sp<SkXfermode> readXfermode() { return this->readFlattenable<SkXfermode>(); }
 
     // binary data and arrays
     virtual bool readByteArray(void* value, size_t size);
diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp
index e6c10e7..a0b5935 100644
--- a/src/core/SkXfermode.cpp
+++ b/src/core/SkXfermode.cpp
@@ -679,18 +679,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
 
-sk_sp<SkFlattenable> SkProcCoeffXfermode::CreateProc(SkReadBuffer& buffer) {
-    uint32_t mode32 = buffer.read32();
-    if (!buffer.validate(mode32 < SK_ARRAY_COUNT(gProcs))) {
-        return nullptr;
-    }
-    return SkXfermode::Make((SkBlendMode)mode32);
-}
-
-void SkProcCoeffXfermode::flatten(SkWriteBuffer& buffer) const {
-    buffer.write32((int)fMode);
-}
-
 bool SkProcCoeffXfermode::asMode(SkBlendMode* mode) const {
     if (mode) {
         *mode = fMode;
@@ -758,16 +746,6 @@
     static_assert(SK_ARRAY_COUNT(gModeStrings) == (size_t)SkBlendMode::kLastMode + 1, "mode_count");
 }
 
-#ifndef SK_IGNORE_TO_STRING
-void SkProcCoeffXfermode::toString(SkString* str) const {
-    str->append("SkProcCoeffXfermode: ");
-
-    str->append("mode: ");
-    str->append(SkBlendMode_Name(fMode));
-}
-#endif
-
-
 sk_sp<SkXfermode> SkXfermode::Make(SkBlendMode mode) {
     if ((unsigned)mode > (unsigned)SkBlendMode::kLastMode) {
         // report error
@@ -805,10 +783,6 @@
     return proc;
 }
 
-SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode)
-    SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode)
-SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 bool SkXfermode::IsOpaque(SkBlendMode mode, SrcColorOpacity opacityType) {
diff --git a/src/core/SkXfermodePriv.h b/src/core/SkXfermodePriv.h
index baed483..bca627e 100644
--- a/src/core/SkXfermodePriv.h
+++ b/src/core/SkXfermodePriv.h
@@ -10,7 +10,7 @@
 
 #include "SkBlendMode.h"
 #include "SkColor.h"
-#include "SkFlattenable.h"
+#include "SkRefCnt.h"
 
 class GrFragmentProcessor;
 class GrTexture;
@@ -18,23 +18,7 @@
 class SkRasterPipeline;
 class SkString;
 
-struct SkArithmeticParams;
-
-struct SkPM4f;
-typedef SkPM4f (*SkXfermodeProc4f)(const SkPM4f& src, const SkPM4f& dst);
-
-/** \class SkXfermode
- *
- *  SkXfermode is the base class for objects that are called to implement custom
- *  "transfer-modes" in the drawing pipeline. The static function Create(Modes)
- *  can be called to return an instance of any of the predefined subclasses as
- *  specified in the Modes enum. When an SkXfermode is assigned to an SkPaint,
- *  then objects drawn with that paint have the xfermode applied.
- *
- *  All subclasses are required to be reentrant-safe : it must be legal to share
- *  the same instance between several threads.
- */
-class SK_API SkXfermode : public SkFlattenable {
+class SkXfermode : public SkRefCnt {
 public:
     virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
                         const SkAlpha aa[]) const = 0;
@@ -103,16 +87,11 @@
     virtual const GrXPFactory* asXPFactory() const;
 #endif
 
-    SK_TO_STRING_PUREVIRT()
-    SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
-    SK_DEFINE_FLATTENABLE_TYPE(SkXfermode)
-
 protected:
     SkXfermode() {}
+    virtual ~SkXfermode() {}
 
 private:
-
-    typedef SkFlattenable INHERITED;
 };
 
 #endif
diff --git a/src/core/SkXfermode_proccoeff.h b/src/core/SkXfermode_proccoeff.h
index 5bcd3a0..960b8c3 100644
--- a/src/core/SkXfermode_proccoeff.h
+++ b/src/core/SkXfermode_proccoeff.h
@@ -30,12 +30,7 @@
     const GrXPFactory* asXPFactory() const override;
 #endif
 
-    SK_TO_STRING_OVERRIDE()
-    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkProcCoeffXfermode)
-
 protected:
-    void flatten(SkWriteBuffer& buffer) const override;
-
     SkBlendMode getMode() const { return fMode; }
 
     SkXfermodeProc getProc() const { return fProc; }
diff --git a/src/effects/SkArithmeticImageFilter.cpp b/src/effects/SkArithmeticImageFilter.cpp
index d9c2b60..eebaa95 100644
--- a/src/effects/SkArithmeticImageFilter.cpp
+++ b/src/effects/SkArithmeticImageFilter.cpp
@@ -6,7 +6,6 @@
  */
 
 #include "SkArithmeticImageFilter.h"
-#include "SkArithmeticModePriv.h"
 #include "SkCanvas.h"
 #include "SkNx.h"
 #include "SkReadBuffer.h"
diff --git a/src/effects/SkArithmeticMode.cpp b/src/effects/SkArithmeticMode.cpp
deleted file mode 100644
index 0fbce6c53..0000000
--- a/src/effects/SkArithmeticMode.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkArithmeticModePriv.h"
-#include "SkReadBuffer.h"
-
-// This class only exists to unflatten instances that were serialized into old pictures as part of
-// SkXfermodeImageFilter before the advent of SkBlendMode. Those image filters will now be
-// transformed to SkArithmeticImageFilter which does not use this class in its implementation.
-class SkArithmeticMode_scalar : public SkXfermode {
-public:
-    SkArithmeticMode_scalar(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4,
-                            bool enforcePMColor) {
-        fK[0] = k1;
-        fK[1] = k2;
-        fK[2] = k3;
-        fK[3] = k4;
-        fEnforcePMColor = enforcePMColor;
-    }
-
-    void xfer32(SkPMColor[], const SkPMColor[], int count, const SkAlpha[]) const override {
-        SkFAIL("This should never be called.");
-    }
-
-    SK_TO_STRING_OVERRIDE()
-    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkArithmeticMode_scalar)
-
-private:
-    void flatten(SkWriteBuffer& buffer) const override { SkFAIL("This shouild never be called."); }
-
-    SkScalar fK[4];
-    bool fEnforcePMColor;
-
-    friend class SkArithmeticMode;
-
-    typedef SkXfermode INHERITED;
-};
-
-sk_sp<SkFlattenable> SkArithmeticMode_scalar::CreateProc(SkReadBuffer& buffer) {
-    const SkScalar k1 = buffer.readScalar();
-    const SkScalar k2 = buffer.readScalar();
-    const SkScalar k3 = buffer.readScalar();
-    const SkScalar k4 = buffer.readScalar();
-    const bool enforcePMColor = buffer.readBool();
-    return SkArithmeticMode::Make(k1, k2, k3, k4, enforcePMColor);
-}
-
-#ifndef SK_IGNORE_TO_STRING
-void SkArithmeticMode_scalar::toString(SkString* str) const {
-    SkFAIL("This should never be called.");
-}
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-
-sk_sp<SkXfermode> SkArithmeticMode::Make(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4,
-                                         bool enforcePMColor) {
-    if (SkScalarNearlyZero(k1) && SkScalarNearlyEqual(k2, SK_Scalar1) &&
-        SkScalarNearlyZero(k3) && SkScalarNearlyZero(k4)) {
-        return SkXfermode::Make(SkBlendMode::kSrc);
-    } else if (SkScalarNearlyZero(k1) && SkScalarNearlyZero(k2) &&
-               SkScalarNearlyEqual(k3, SK_Scalar1) && SkScalarNearlyZero(k4)) {
-        return SkXfermode::Make(SkBlendMode::kDst);
-    }
-    return sk_make_sp<SkArithmeticMode_scalar>(k1, k2, k3, k4, enforcePMColor);
-}
-
-SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode)
-    SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar)
-SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
diff --git a/src/effects/SkArithmeticModePriv.h b/src/effects/SkArithmeticModePriv.h
deleted file mode 100644
index 831410e..0000000
--- a/src/effects/SkArithmeticModePriv.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkArithmeticModePriv_DEFINED
-#define SkArithmeticModePriv_DEFINED
-
-#include "SkScalar.h"
-#include "SkXfermodePriv.h"
-
-class SkXfermode;
-
-// This only exists to unflatten instances that were serialized into old pictures as part of
-// SkXfermodeImageFilter before the advent of SkBlendMode.
-class SK_API SkArithmeticMode {
-public:
-    /**
-     *  result = clamp[k1 * src * dst + k2 * src + k3 * dst + k4]
-     *
-     *  k1=k2=k3=0, k4=1.0 results in returning opaque white
-     *  k1=k3=k4=0, k2=1.0 results in returning the src
-     *  k1=k2=k4=0, k3=1.0 results in returning the dst
-     */
-    static sk_sp<SkXfermode> Make(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4,
-                                  bool enforcePMColor = true);
-    SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP();
-
-private:
-    SkArithmeticMode(); // can't be instantiated
-};
-
-#endif
diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp
index feeea66..4fb6293 100644
--- a/src/effects/SkLayerDrawLooper.cpp
+++ b/src/effects/SkLayerDrawLooper.cpp
@@ -16,6 +16,7 @@
 #include "SkString.h"
 #include "SkStringUtils.h"
 #include "SkUnPreMultiply.h"
+#include "SkXfermodePriv.h"
 
 SkLayerDrawLooper::LayerInfo::LayerInfo() {
     fPaintBits = 0;                     // ignore our paint fields
diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp
index ca49f93..0be8c22 100644
--- a/src/effects/SkXfermodeImageFilter.cpp
+++ b/src/effects/SkXfermodeImageFilter.cpp
@@ -7,7 +7,6 @@
 
 #include "SkXfermodeImageFilter.h"
 #include "SkArithmeticImageFilter.h"
-#include "SkArithmeticModePriv.h"
 #include "SkCanvas.h"
 #include "SkColorPriv.h"
 #include "SkReadBuffer.h"
diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp
index de9b61a..fd13e2c 100644
--- a/src/ports/SkGlobalInitialization_default.cpp
+++ b/src/ports/SkGlobalInitialization_default.cpp
@@ -8,7 +8,6 @@
 #include "Sk1DPathEffect.h"
 #include "Sk2DPathEffect.h"
 #include "SkAlphaThresholdFilter.h"
-#include "../../src/effects/SkArithmeticModePriv.h"
 #include "SkArcToPathEffect.h"
 #include "SkBitmapSourceDeserializer.h"
 #include "SkBlurImageFilter.h"
@@ -81,7 +80,6 @@
     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkColorMatrixFilterRowMajor255)
     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLumaColorFilter)
     SkAlphaThresholdFilter::InitializeFlattenables();
-    SkArithmeticMode::InitializeFlattenables();
     SkTableColorFilter::InitializeFlattenables();
     SkOverdrawColorFilter::InitializeFlattenables();
     SkHighContrastFilter::InitializeFlattenables();