From 8d3f4433d888e88ee09d53749936a45c22a14194 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Sat, 10 Jun 2017 11:08:53 -0400 Subject: [PATCH] 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 Commit-Queue: Mike Reed --- gn/effects.gni | 1 - include/core/SkFlattenable.h | 2 +- src/core/SkGlobalInitialization_core.cpp | 1 - src/core/SkReadBuffer.h | 2 - src/core/SkXfermode.cpp | 26 ------- src/core/SkXfermodePriv.h | 27 +------ src/core/SkXfermode_proccoeff.h | 5 -- src/effects/SkArithmeticImageFilter.cpp | 1 - src/effects/SkArithmeticMode.cpp | 74 -------------------- src/effects/SkArithmeticModePriv.h | 35 --------- src/effects/SkLayerDrawLooper.cpp | 1 + src/effects/SkXfermodeImageFilter.cpp | 1 - src/ports/SkGlobalInitialization_default.cpp | 2 - 13 files changed, 5 insertions(+), 173 deletions(-) delete mode 100644 src/effects/SkArithmeticMode.cpp delete mode 100644 src/effects/SkArithmeticModePriv.h diff --git a/gn/effects.gni b/gn/effects.gni index 61b1b39424..b2166d2189 100644 --- a/gn/effects.gni +++ b/gn/effects.gni @@ -20,7 +20,6 @@ skia_effects_sources = [ "$_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 49c491eb20..c36d181c1a 100644 --- a/include/core/SkFlattenable.h +++ b/include/core/SkFlattenable.h @@ -80,7 +80,7 @@ public: 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 9fa128f987..bc3e254bd0 100644 --- a/src/core/SkGlobalInitialization_core.cpp +++ b/src/core/SkGlobalInitialization_core.cpp @@ -44,7 +44,6 @@ void SkFlattenable::PrivateInitializer::InitCore() { 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 48cb22511f..6a2c5252c7 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 @@ public: sk_sp readPathEffect() { return this->readFlattenable(); } sk_sp readRasterizer() { return this->readFlattenable(); } sk_sp readShader() { return this->readFlattenable(); } - sk_sp readXfermode() { return this->readFlattenable(); } // 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 e6c10e7c4b..a0b593517a 100644 --- a/src/core/SkXfermode.cpp +++ b/src/core/SkXfermode.cpp @@ -679,18 +679,6 @@ const GrXPFactory* SkXfermode::asXPFactory() const { /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -sk_sp 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 @@ const char* SkBlendMode_Name(SkBlendMode mode) { 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::Make(SkBlendMode mode) { if ((unsigned)mode > (unsigned)SkBlendMode::kLastMode) { // report error @@ -805,10 +783,6 @@ SkXfermodeProc SkXfermode::GetProc(SkBlendMode mode) { 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 baed483dad..bca627efe8 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 GrXPFactory; 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 @@ public: 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 5bcd3a05c2..960b8c313a 100644 --- a/src/core/SkXfermode_proccoeff.h +++ b/src/core/SkXfermode_proccoeff.h @@ -30,12 +30,7 @@ public: 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 d9c2b60b1a..eebaa9570b 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 0fbce6c530..0000000000 --- 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 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 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(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 831410ed6c..0000000000 --- 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 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 feeea66a35..4fb629376e 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 ca49f93351..0be8c22fd1 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 de9b61ae9c..fd13e2c9bb 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 @@ void SkFlattenable::PrivateInitializer::InitEffects() { SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkColorMatrixFilterRowMajor255) SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLumaColorFilter) SkAlphaThresholdFilter::InitializeFlattenables(); - SkArithmeticMode::InitializeFlattenables(); SkTableColorFilter::InitializeFlattenables(); SkOverdrawColorFilter::InitializeFlattenables(); SkHighContrastFilter::InitializeFlattenables();