diff --git a/gm/lerpmode.cpp b/gm/lerpmode.cpp deleted file mode 100644 index ea30b6b5a4..0000000000 --- a/gm/lerpmode.cpp +++ /dev/null @@ -1,42 +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 "gm.h" -#include "SkCanvas.h" -#include "SkLerpXfermode.h" - -static void show_circlelayers(SkCanvas* canvas, SkXfermode* mode) { - SkPaint paint; - paint.setAntiAlias(true); - SkRect r, bounds = { 10, 10, 110, 110 }; - - r = bounds; - r.fRight = bounds.centerX(); - canvas->drawRect(r, paint); - - canvas->saveLayer(&bounds, nullptr); - - paint.setColor(0x80FF0000); - r = bounds; - r.inset(20, 0); - canvas->drawOval(r, paint); - - paint.setColor(0x800000FF); - r = bounds; - r.inset(0, 20); - paint.setXfermode(mode); - canvas->drawOval(r, paint); - - canvas->restore(); -} - -DEF_SIMPLE_GM(lerpmode, canvas, 240, 120) { - show_circlelayers(canvas, nullptr); - canvas->translate(150, 0); - SkAutoTUnref mode(SkLerpXfermode::Create(0.5f)); - show_circlelayers(canvas, mode.get()); -} diff --git a/gyp/effects.gypi b/gyp/effects.gypi index 1c9e6fd8c6..0ab3cf5fc1 100644 --- a/gyp/effects.gypi +++ b/gyp/effects.gypi @@ -45,7 +45,6 @@ '<(skia_src_path)/effects/SkGpuBlurUtils.cpp', '<(skia_src_path)/effects/SkLayerDrawLooper.cpp', '<(skia_src_path)/effects/SkLayerRasterizer.cpp', - '<(skia_src_path)/effects/SkLerpXfermode.cpp', '<(skia_src_path)/effects/SkLightingImageFilter.cpp', '<(skia_src_path)/effects/SkLumaColorFilter.cpp', '<(skia_src_path)/effects/SkMagnifierImageFilter.cpp', @@ -104,7 +103,6 @@ '<(skia_include_path)/effects/SkImageSource.h', '<(skia_include_path)/effects/SkLayerDrawLooper.h', '<(skia_include_path)/effects/SkLayerRasterizer.h', - '<(skia_include_path)/effects/SkLerpXfermode.h', '<(skia_include_path)/effects/SkLightingImageFilter.h', '<(skia_include_path)/effects/SkLumaColorFilter.h', '<(skia_include_path)/effects/SkMagnifierImageFilter.h', diff --git a/include/core/SkScalar.h b/include/core/SkScalar.h index 4efa8417af..84b53c8575 100644 --- a/include/core/SkScalar.h +++ b/include/core/SkScalar.h @@ -218,7 +218,7 @@ static inline SkScalar SkScalarSignAsScalar(SkScalar x) { #define SK_ScalarNearlyZero (SK_Scalar1 / (1 << 12)) static inline bool SkScalarNearlyZero(SkScalar x, - SkScalar tolerance = SK_ScalarNearlyZero) { + SkScalar tolerance = SK_ScalarNearlyZero) { SkASSERT(tolerance >= 0); return SkScalarAbs(x) <= tolerance; } diff --git a/include/effects/SkLerpXfermode.h b/include/effects/SkLerpXfermode.h deleted file mode 100644 index 27daf78982..0000000000 --- a/include/effects/SkLerpXfermode.h +++ /dev/null @@ -1,47 +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. - */ - -#ifndef SkLerpXfermode_DEFINED -#define SkLerpXfermode_DEFINED - -#include "SkXfermode.h" - -class SK_API SkLerpXfermode : public SkXfermode { -public: - /** - * result = scale * src + (1 - scale) * dst - * - * When scale == 1, this is the same as kSrc_Mode - * When scale == 0, this is the same as kDst_Mode - */ - static SkXfermode* Create(SkScalar scale); - - // overrides from SkXfermode - virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count, - const SkAlpha aa[]) const override; - virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count, - const SkAlpha aa[]) const override; - virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count, - const SkAlpha aa[]) const override; - - SK_TO_STRING_OVERRIDE() - SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLerpXfermode) - -protected: - void flatten(SkWriteBuffer&) const override; - -private: - SkLerpXfermode(unsigned scale256); - - unsigned fScale256; // 0..256 - - SkValue asValue() const override; - - typedef SkXfermode INHERITED; -}; - -#endif diff --git a/samplecode/SamplePathEffects.cpp b/samplecode/SamplePathEffects.cpp index e194793f36..a162cf33ad 100644 --- a/samplecode/SamplePathEffects.cpp +++ b/samplecode/SamplePathEffects.cpp @@ -19,7 +19,6 @@ #include "SkPathMeasure.h" #include "SkRandom.h" #include "SkColorPriv.h" -#include "SkPixelXorXfermode.h" #define CORNER_RADIUS 12 diff --git a/src/core/SkValue.h b/src/core/SkValue.h index 5a6453f908..5200842228 100644 --- a/src/core/SkValue.h +++ b/src/core/SkValue.h @@ -29,7 +29,6 @@ public: ArithmeticXfermode, DefaultXfermode, - LerpXfermode, PixelXorXfermode, ProcCoeffXfermode, diff --git a/src/effects/SkArithmeticMode.cpp b/src/effects/SkArithmeticMode.cpp index 9eb7dd2198..33783a52f8 100644 --- a/src/effects/SkArithmeticMode.cpp +++ b/src/effects/SkArithmeticMode.cpp @@ -21,8 +21,16 @@ static const bool gUseUnpremul = false; class SkArithmeticMode_scalar : public SkXfermode { public: - static SkArithmeticMode_scalar* Create(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4, - bool enforcePMColor) { + static SkXfermode* Create(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4, + bool enforcePMColor) { + if (SkScalarNearlyZero(k1) && SkScalarNearlyEqual(k2, SK_Scalar1) && + SkScalarNearlyZero(k3) && SkScalarNearlyZero(k4)) { + return SkXfermode::Create(SkXfermode::kSrc_Mode); + } else if (SkScalarNearlyZero(k1) && SkScalarNearlyZero(k2) && + SkScalarNearlyEqual(k3, SK_Scalar1) && SkScalarNearlyZero(k4)) { + return SkXfermode::Create(SkXfermode::kDst_Mode); + } + return new SkArithmeticMode_scalar(k1, k2, k3, k4, enforcePMColor); } diff --git a/src/effects/SkLerpXfermode.cpp b/src/effects/SkLerpXfermode.cpp deleted file mode 100644 index a069e8b367..0000000000 --- a/src/effects/SkLerpXfermode.cpp +++ /dev/null @@ -1,118 +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 "SkLerpXfermode.h" -#include "SkColorPriv.h" -#include "SkReadBuffer.h" -#include "SkWriteBuffer.h" -#include "SkString.h" -#include "SkValue.h" -#include "SkValueKeys.h" - -SkXfermode* SkLerpXfermode::Create(SkScalar scale) { - int scale256 = SkScalarRoundToInt(scale * 256); - if (scale256 >= 256) { - return SkXfermode::Create(SkXfermode::kSrc_Mode); - } else if (scale256 <= 0) { - return SkXfermode::Create(SkXfermode::kDst_Mode); - } - return new SkLerpXfermode(scale256); -} - -SkLerpXfermode::SkLerpXfermode(unsigned scale256) : fScale256(scale256) {} - -void SkLerpXfermode::flatten(SkWriteBuffer& buffer) const { - buffer.writeUInt(fScale256); -} - -SkFlattenable* SkLerpXfermode::CreateProc(SkReadBuffer& buffer) { - return new SkLerpXfermode(buffer.readUInt()); -} - -void SkLerpXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count, - const SkAlpha aa[]) const { - const int scale = fScale256; - - if (aa) { - for (int i = 0; i < count; ++i) { - unsigned a = aa[i]; - if (a) { - SkPMColor dstC = dst[i]; - SkPMColor resC = SkFastFourByteInterp256(src[i], dstC, scale); - if (a < 255) { - resC = SkFastFourByteInterp256(resC, dstC, a + (a >> 7)); - } - dst[i] = resC; - } - } - } else { - for (int i = 0; i < count; ++i) { - dst[i] = SkFastFourByteInterp256(src[i], dst[i], scale); - } - } -} - -void SkLerpXfermode::xfer16(uint16_t dst[], const SkPMColor src[], int count, - const SkAlpha aa[]) const { - const int scale = fScale256; - - if (aa) { - for (int i = 0; i < count; ++i) { - unsigned a = aa[i]; - if (a) { - SkPMColor dstC = SkPixel16ToPixel32(dst[i]); - SkPMColor resC = SkFastFourByteInterp256(src[i], dstC, scale); - if (a < 255) { - resC = SkFastFourByteInterp256(resC, dstC, a + (a >> 7)); - } - dst[i] = SkPixel32ToPixel16(resC); - } - } - } else { - for (int i = 0; i < count; ++i) { - SkPMColor dstC = SkPixel16ToPixel32(dst[i]); - SkPMColor resC = SkFastFourByteInterp256(src[i], dstC, scale); - dst[i] = SkPixel32ToPixel16(resC); - } - } -} - -void SkLerpXfermode::xferA8(SkAlpha dst[], const SkPMColor src[], int count, - const SkAlpha aa[]) const { - const int scale = fScale256; - - if (aa) { - for (int i = 0; i < count; ++i) { - unsigned a = aa[i]; - if (a) { - unsigned dstA = dst[i]; - unsigned resA = SkAlphaBlend(SkGetPackedA32(src[i]), dstA, scale); - if (a < 255) { - resA = SkAlphaBlend(resA, dstA, a + (a >> 7)); - } - dst[i] = resA; - } - } - } else { - for (int i = 0; i < count; ++i) { - dst[i] = SkAlphaBlend(SkGetPackedA32(src[i]), dst[i], scale); - } - } -} - -#ifndef SK_IGNORE_TO_STRING -void SkLerpXfermode::toString(SkString* str) const { - str->printf("SkLerpXfermode: scale: %g", fScale256 / 256.0); -} -#endif - -SkValue SkLerpXfermode::asValue() const { - auto value = SkValue::Object(SkValue::LerpXfermode); - value.set(SkValueKeys::LerpXfermode::kScale, - SkValue::FromF32(fScale256 / 256.0f)); - return value; -} diff --git a/src/effects/SkToFromValue.cpp b/src/effects/SkToFromValue.cpp index b981d1715e..cbb265b33f 100644 --- a/src/effects/SkToFromValue.cpp +++ b/src/effects/SkToFromValue.cpp @@ -6,7 +6,6 @@ */ #include "SkArithmeticMode.h" -#include "SkLerpXfermode.h" #include "SkMatrix.h" #include "SkPixelXorXfermode.h" #include "SkToFromValue.h" @@ -89,14 +88,6 @@ static bool from_value_ArithmeticXfermode(const SkValue& val, return true; } -static bool from_value_LerpXfermode(const SkValue& val, - SkAutoTUnref* dst) { - float scale; - REQUIRE(getT(val, SkValueKeys::LerpXfermode::kScale, &scale)); - dst->reset(SkLerpXfermode::Create(scale)); - return true; -} - static bool from_value_PixelXorXfermode(const SkValue& val, SkAutoTUnref* dst) { uint32_t opColor; @@ -118,7 +109,6 @@ template<> bool SkFromValue< SkAutoTUnref >( switch (val.type()) { case SkValue::DefaultXfermode: return from_value_DefaultXfermode(val, dst); case SkValue::ArithmeticXfermode: return from_value_ArithmeticXfermode(val, dst); - case SkValue::LerpXfermode: return from_value_LerpXfermode(val, dst); case SkValue::PixelXorXfermode: return from_value_PixelXorXfermode(val, dst); case SkValue::ProcCoeffXfermode: return from_value_ProcCoeffXfermode(val, dst); default: REQUIRE(false); diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp index 9471f01c88..de5052760a 100644 --- a/src/ports/SkGlobalInitialization_default.cpp +++ b/src/ports/SkGlobalInitialization_default.cpp @@ -28,7 +28,6 @@ #include "SkImageSource.h" #include "SkLayerDrawLooper.h" #include "SkLayerRasterizer.h" -#include "SkLerpXfermode.h" #include "SkLightingImageFilter.h" #include "SkLightingShader.h" #include "SkLumaColorFilter.h" @@ -82,7 +81,6 @@ void SkFlattenable::PrivateInitializer::InitEffects() { SkLightingShader::InitializeFlattenables(); // Xfermode - SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLerpXfermode) SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPixelXorXfermode) // PathEffect