+++ /dev/null
-/*
- * Copyright 2016 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 "Resources.h"
-
-#include "SkAvoidXfermode.h"
-#include "SkStream.h"
-
-class AvoidXfermodeGM : public skiagm::GM {
-public:
- AvoidXfermodeGM() { }
-
-protected:
- SkString onShortName() override {
- return SkString("avoidxfermode");
- }
-
- SkISize onISize() override { return SkISize::Make(128, 128); }
-
- void onOnceBeforeDraw() override {
- if (!GetResourceAsBitmap("color_wheel.png", &fBM)) {
- fBM.allocN32Pixels(1, 1);
- fBM.eraseARGB(255, 255, 0 , 0); // red == bad
- }
- }
-
- void onDraw(SkCanvas* canvas) override {
- canvas->drawBitmap(fBM, 0, 0);
-
- SkRect r = SkRect::MakeIWH(64, 64);
-
- // UL corner: replace white with black with a tight tolerance
- SkPaint p1;
- p1.setColor(SK_ColorBLACK);
- p1.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 5, SkAvoidXfermode::kTargetColor_Mode));
-
- canvas->drawRect(r, p1);
-
- r.offsetTo(64, 0.0f);
-
- // UR corner: draw black everywhere except white with a tight tolerance
- SkPaint p2;
- p2.setColor(SK_ColorBLACK);
- p2.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 250,
- SkAvoidXfermode::kAvoidColor_Mode));
-
- canvas->drawRect(r, p2);
-
- r.offsetTo(0.0f, 64);
-
- // LL corner: replace red with transparent blue with a loose tolerance
- SkPaint p3;
- p3.setColor(0x7F0000FF);
- p3.setXfermode(SkAvoidXfermode::Make(SK_ColorRED, 250, SkAvoidXfermode::kTargetColor_Mode));
-
- canvas->drawRect(r, p3);
-
- r.offsetTo(64, 64);
-
- // LR corner: draw black everywhere except red with a loose tolerance
- SkPaint p4;
- p4.setColor(SK_ColorBLACK);
- p4.setXfermode(SkAvoidXfermode::Make(SK_ColorRED, 5, SkAvoidXfermode::kAvoidColor_Mode));
-
- canvas->drawRect(r, p4);
- }
-
-private:
- SkBitmap fBM;
-
- typedef GM INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-DEF_GM(return new AvoidXfermodeGM;)
+++ /dev/null
-/*
- * Copyright 2016 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 "SkAvoidXfermode.h"
-
-class AvoidXfermode2GM : public skiagm::GM {
-public:
- AvoidXfermode2GM() { }
-
-protected:
- SkString onShortName() override {
- return SkString("avoidxfermode2");
- }
-
- SkISize onISize() override { return SkISize::Make(128, 128); }
-
- void onDraw(SkCanvas* canvas) override {
- canvas->drawARGB(255, 0, 0, 0);
-
- SkRect r = SkRect::MakeXYWH(32, 32, 64, 64);
-
- SkPaint p0;
- p0.setColor(SK_ColorGREEN);
- p0.setAntiAlias(false);
-
- canvas->drawRect(r, p0);
-
- r = SkRect::MakeIWH(64, 64);
-
- // UL corner: replace the green with a tight tolerance
- SkPaint p1;
- p1.setColor(SK_ColorRED);
- p1.setXfermode(SkAvoidXfermode::Make(SK_ColorGREEN, 55,
- SkAvoidXfermode::kTargetColor_Mode));
-
- canvas->drawRect(r, p1);
-
- r.offsetTo(64, 0.0f);
-
- // UR corner: avoid the green with a tight tolerance
- SkPaint p2;
- p2.setColor(SK_ColorRED);
- p2.setXfermode(SkAvoidXfermode::Make(SK_ColorGREEN, 200,
- SkAvoidXfermode::kAvoidColor_Mode));
-
- canvas->drawRect(r, p2);
-
- r.offsetTo(0.0f, 64);
-
- // LL corner: replace the green with a loose tolerance
- SkPaint p3;
- p3.setColor(SK_ColorRED);
- p3.setXfermode(SkAvoidXfermode::Make(SK_ColorGREEN, 200,
- SkAvoidXfermode::kTargetColor_Mode));
-
- canvas->drawRect(r, p3);
-
- r.offsetTo(64, 64);
-
- // LR corner: avoid the green with a loose tolerance
- SkPaint p4;
- p4.setColor(SK_ColorRED);
- p4.setXfermode(SkAvoidXfermode::Make(SK_ColorGREEN, 55, SkAvoidXfermode::kAvoidColor_Mode));
-
- canvas->drawRect(r, p4);
- }
-
-private:
- typedef GM INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-DEF_GM(return new AvoidXfermode2GM;)
+++ /dev/null
-/*
-* Copyright 2016 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 "SkAvoidXfermode.h"
-
-// This GM exercises how the avoid xfer mode interacts with partial coverage
-class AvoidXfermode3GM : public skiagm::GM {
-public:
- AvoidXfermode3GM() { }
-
-protected:
- SkString onShortName() override {
- return SkString("avoidxfermode3");
- }
-
- SkISize onISize() override { return SkISize::Make(128, 128); }
-
- void onDraw(SkCanvas* canvas) override {
- canvas->drawARGB(255, 0, 0, 0);
-
- SkRect r = SkRect::MakeXYWH(16.5f, 16.5f, 96.0f, 96.0f);
-
- SkPaint p0;
- p0.setColor(SK_ColorWHITE);
- p0.setAntiAlias(true);
-
- canvas->drawRect(r, p0);
-
- r = SkRect::MakeXYWH(3.5f, 3.5f, 59.0f, 59.0f);
-
- // UL corner: replace white with green with a tight tolerance
- SkPaint p1;
- p1.setColor(SK_ColorGREEN);
- p1.setAntiAlias(true);
- p1.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 5, SkAvoidXfermode::kTargetColor_Mode));
-
- canvas->drawRect(r, p1);
-
- r.offsetTo(65.5f, 3.5f);
-
- // UR corner: draw red everywhere except white with a tight tolerance
- SkPaint p2;
- p2.setColor(SK_ColorRED);
- p2.setAntiAlias(true);
- p2.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 250,
- SkAvoidXfermode::kAvoidColor_Mode));
-
- canvas->drawRect(r, p2);
-
- r.offsetTo(3.5f, 65.5f);
-
- // LL corner: replace white with blue with a loose tolerance
- SkPaint p3;
- p3.setColor(SK_ColorBLUE);
- p3.setAntiAlias(true);
- p3.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 250,
- SkAvoidXfermode::kTargetColor_Mode));
-
- canvas->drawRect(r, p3);
-
- r.offsetTo(65.5f, 65.5f);
-
- // LR corner: draw yellow everywhere except white with a loose tolerance
- SkPaint p4;
- p4.setColor(SK_ColorYELLOW);
- p4.setAntiAlias(true);
- p4.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 5, SkAvoidXfermode::kAvoidColor_Mode));
-
- canvas->drawRect(r, p4);
- }
-
-private:
- typedef GM INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-DEF_GM(return new AvoidXfermode3GM;)
+++ /dev/null
-/*
- * Copyright 2016 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 "Resources.h"
-
-#include "SkPixelXorXfermode.h"
-#include "SkStream.h"
-
-class PixelXorXfermodeGM : public skiagm::GM {
-public:
- PixelXorXfermodeGM() { }
-
-protected:
- SkString onShortName() override {
- return SkString("pixelxorxfermode");
- }
-
- SkISize onISize() override { return SkISize::Make(512, 512); }
-
- void onOnceBeforeDraw() override {
- if (!GetResourceAsBitmap("mandrill_512.png", &fBM)) {
- fBM.allocN32Pixels(1, 1);
- fBM.eraseARGB(255, 255, 0 , 0); // red == bad
- }
- }
-
- void onDraw(SkCanvas* canvas) override {
- canvas->drawBitmap(fBM, 0, 0);
-
- SkRect r = SkRect::MakeIWH(256, 256);
-
- // Negate the red channel of the dst (via the ancillary color) but leave
- // the green & blue channels alone
- SkPaint p1;
- p1.setColor(SK_ColorBLACK); // noop
- p1.setXfermode(SkPixelXorXfermode::Make(0x7FFF0000));
-
- canvas->drawRect(r, p1);
-
- r.offsetTo(256.0f, 0.0f);
-
- // Negate the dst color via the src color
- SkPaint p2;
- p2.setColor(SK_ColorWHITE);
- p2.setXfermode(SkPixelXorXfermode::Make(SK_ColorBLACK)); // noop
-
- canvas->drawRect(r, p2);
-
- r.offsetTo(0.0f, 256.0f);
-
- // Just return the original color
- SkPaint p3;
- p3.setColor(SK_ColorBLACK); // noop
- p3.setXfermode(SkPixelXorXfermode::Make(SK_ColorBLACK)); // noop
-
- canvas->drawRect(r, p3);
-
- r.offsetTo(256.0f, 256.0f);
-
- // Negate the red & green channels (via the ancillary color) but leave
- // the blue channel alone
- SkPaint p4;
- p4.setColor(SK_ColorBLACK); // noop
- p4.setXfermode(SkPixelXorXfermode::Make(SK_ColorYELLOW));
-
- canvas->drawRect(r, p4);
- }
-
-private:
- SkBitmap fBM;
-
- typedef GM INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-DEF_GM(return new PixelXorXfermodeGM;)
#include "SkPM4f.h"
#include "SkArithmeticMode.h"
-#include "SkPixelXorXfermode.h"
-#include "SkAvoidXfermode.h"
#define kCustomShift 16
#define kCustomMask (~0xFFFF)
enum CustomModes {
kArithmetic_CustomMode = 1 << kCustomShift,
- kPixelXor_CustomMode = 2 << kCustomShift,
- kAvoid_CustomMode = 3 << kCustomShift,
};
static sk_sp<SkXfermode> make_custom(int customMode) {
const SkScalar k4 = -0.25;
return SkArithmeticMode::Make(k1, k2, k3, k4);
}
- case kPixelXor_CustomMode:
- return SkPixelXorXfermode::Make(0xFF88CC44);
- case kAvoid_CustomMode:
- return SkAvoidXfermode::Make(0xFFFF0000, 0x44, SkAvoidXfermode::kAvoidColor_Mode);
default:
break;
}
{ SkXfermode::kLuminosity_Mode, "Luminosity", kBasic_SrcType },
{ SkXfermode::Mode(0xFFFF), "Arithmetic", kBasic_SrcType + kArithmetic_CustomMode },
- { SkXfermode::Mode(0xFFFF), "PixelXor", kBasic_SrcType + kPixelXor_CustomMode },
- { SkXfermode::Mode(0xFFFF), "Avoid", kBasic_SrcType + kAvoid_CustomMode },
};
static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst,
'<(skia_src_path)/effects/SkArithmeticMode.cpp',
'<(skia_src_path)/effects/SkArithmeticMode_gpu.cpp',
'<(skia_src_path)/effects/SkArithmeticMode_gpu.h',
- '<(skia_src_path)/effects/SkAvoidXfermode.cpp',
'<(skia_src_path)/effects/SkBlurDrawLooper.cpp',
'<(skia_src_path)/effects/SkBlurMask.cpp',
'<(skia_src_path)/effects/SkBlurMask.h',
'<(skia_src_path)/effects/SkPaintImageFilter.cpp',
'<(skia_src_path)/effects/SkPerlinNoiseShader.cpp',
'<(skia_src_path)/effects/SkPictureImageFilter.cpp',
- '<(skia_src_path)/effects/SkPixelXorXfermode.cpp',
'<(skia_src_path)/effects/SkTableColorFilter.cpp',
'<(skia_src_path)/effects/SkTableMaskFilter.cpp',
'<(skia_src_path)/effects/SkTestImageFilters.cpp',
'<(skia_include_path)/effects/SkTableMaskFilter.h',
'<(skia_include_path)/effects/SkTileImageFilter.h',
'<(skia_include_path)/effects/SkXfermodeImageFilter.h',
-
- '<(skia_include_path)/client/android/SkAvoidXfermode.h',
- '<(skia_include_path)/client/android/SkPixelXorXfermode.h',
],
}
+++ /dev/null
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkAvoidXfermode_DEFINED
-#define SkAvoidXfermode_DEFINED
-
-#include "SkColor.h"
-#include "SkTypes.h"
-#include "SkXfermode.h"
-
-/** \class AvoidXfermode
-
- This xfermode will draw the src everywhere except on top of the specified
- color.
-*/
-class SkAvoidXfermode : public SkXfermode {
-public:
- enum Mode {
- kAvoidColor_Mode, //!< draw everywhere except on the opColor
- kTargetColor_Mode //!< draw only on top of the opColor
- };
-
- /** This xfermode draws, or doesn't draw, based on the destination's
- distance from an op-color.
-
- There are two modes, and each mode interprets a tolerance value.
-
- Avoid: In this mode, drawing is allowed only on destination pixels that
- are different from the op-color.
- Tolerance near 0: avoid any colors even remotely similar to the op-color
- Tolerance near 255: avoid only colors nearly identical to the op-color
-
- Target: In this mode, drawing only occurs on destination pixels that
- are similar to the op-color
- Tolerance near 0: draw only on colors that are nearly identical to the op-color
- Tolerance near 255: draw on any colors even remotely similar to the op-color
- */
- static sk_sp<SkXfermode> Make(SkColor opColor, U8CPU tolerance, Mode mode) {
- return sk_sp<SkXfermode>(new SkAvoidXfermode(opColor, tolerance, mode));
- }
-#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
- static SkAvoidXfermode* Create(SkColor opColor, U8CPU tolerance, Mode mode) {
- return (SkAvoidXfermode*)(Make(opColor, tolerance, mode).release());
- }
-#endif
-
- // overrides from SkXfermode
- void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
- const SkAlpha aa[]) const override;
- void xfer16(uint16_t dst[], const SkPMColor src[], int count,
- const SkAlpha aa[]) const override;
- void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
- const SkAlpha aa[]) const override;
-
-#if SK_SUPPORT_GPU
- const GrFragmentProcessor* getFragmentProcessorForImageFilter(
- const GrFragmentProcessor* dst) const override;
- GrXPFactory* asXPFactory() const override;
-#endif
-
- SK_TO_STRING_OVERRIDE()
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(AvoidXfermode)
-
-protected:
- SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
- void flatten(SkWriteBuffer&) const override;
-
-private:
- SkColor fOpColor;
- uint32_t fDistMul; // x.14 cached from fTolerance
- uint8_t fTolerance;
- Mode fMode;
-
- typedef SkXfermode INHERITED;
-};
-
-#endif
+++ /dev/null
-/*
- * Copyright 2007 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkPixelXorXfermode_DEFINED
-#define SkPixelXorXfermode_DEFINED
-
-#include "SkXfermode.h"
-
-/** SkPixelXorXfermode implements a simple pixel xor (op ^ src ^ dst).
- This transformation does not follow premultiplied conventions, therefore
- this proc *always* returns an opaque color (alpha == 255). Thus it is
- not really usefull for operating on blended colors.
-*/
-class SK_API SkPixelXorXfermode : public SkXfermode {
-public:
- static sk_sp<SkXfermode> Make(SkColor opColor) {
- return sk_sp<SkXfermode>(new SkPixelXorXfermode(opColor));
- }
-#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
- static SkXfermode* Create(SkColor opColor) {
- return Make(opColor).release();
- }
-#endif
-
-#if SK_SUPPORT_GPU
- const GrFragmentProcessor* getFragmentProcessorForImageFilter(
- const GrFragmentProcessor* dst) const override;
- GrXPFactory* asXPFactory() const override;
-#endif
-
- SK_TO_STRING_OVERRIDE()
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPixelXorXfermode)
-
-protected:
- void flatten(SkWriteBuffer&) const override;
- SkPMColor xferColor(SkPMColor src, SkPMColor dst) const override;
-
-private:
- explicit SkPixelXorXfermode(SkColor opColor) {
- fOpColor = SkPreMultiplyColor(opColor | 0xFF000000);
- }
-
- SkPMColor fOpColor;
-
- typedef SkXfermode INHERITED;
-};
-
-#endif
+++ /dev/null
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkAvoidXfermode.h"
-#include "SkColorPriv.h"
-#include "SkReadBuffer.h"
-#include "SkWriteBuffer.h"
-#include "SkString.h"
-
-SkAvoidXfermode::SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode) {
- if (tolerance > 255) {
- tolerance = 255;
- }
- fTolerance = SkToU8(tolerance);
- fOpColor = opColor;
- fDistMul = (256 << 14) / (tolerance + 1);
- fMode = mode;
-}
-
-sk_sp<SkFlattenable> SkAvoidXfermode::CreateProc(SkReadBuffer& buffer) {
- const SkColor color = buffer.readColor();
- const unsigned tolerance = buffer.readUInt();
- const unsigned mode = buffer.readUInt();
- return Make(color, tolerance, (Mode)mode);
-}
-
-void SkAvoidXfermode::flatten(SkWriteBuffer& buffer) const {
- buffer.writeColor(fOpColor);
- buffer.writeUInt(fTolerance);
- buffer.writeUInt(fMode);
-}
-
-// returns 0..31
-static unsigned color_dist16(uint16_t c, unsigned r, unsigned g, unsigned b) {
- SkASSERT(r <= SK_R16_MASK);
- SkASSERT(g <= SK_G16_MASK);
- SkASSERT(b <= SK_B16_MASK);
-
- unsigned dr = SkAbs32(SkGetPackedR16(c) - r);
- unsigned dg = SkAbs32(SkGetPackedG16(c) - g) >> (SK_G16_BITS - SK_R16_BITS);
- unsigned db = SkAbs32(SkGetPackedB16(c) - b);
-
- return SkMax32(dr, SkMax32(dg, db));
-}
-
-// returns 0..255
-static unsigned color_dist32(SkPMColor c, U8CPU r, U8CPU g, U8CPU b) {
- SkASSERT(r <= 0xFF);
- SkASSERT(g <= 0xFF);
- SkASSERT(b <= 0xFF);
-
- unsigned dr = SkAbs32(SkGetPackedR32(c) - r);
- unsigned dg = SkAbs32(SkGetPackedG32(c) - g);
- unsigned db = SkAbs32(SkGetPackedB32(c) - b);
-
- return SkMax32(dr, SkMax32(dg, db));
-}
-
-static int scale_dist_14(int dist, uint32_t mul, uint32_t sub) {
- int tmp = dist * mul - sub;
- int result = (tmp + (1 << 13)) >> 14;
-
- return result;
-}
-
-static inline unsigned Accurate255To256(unsigned x) {
- return x + (x >> 7);
-}
-
-void SkAvoidXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count,
- const SkAlpha aa[]) const {
- unsigned opR = SkColorGetR(fOpColor);
- unsigned opG = SkColorGetG(fOpColor);
- unsigned opB = SkColorGetB(fOpColor);
- uint32_t mul = fDistMul;
- uint32_t sub = (fDistMul - (1 << 14)) << 8;
-
- int MAX, mask;
-
- if (kTargetColor_Mode == fMode) {
- mask = -1;
- MAX = 255;
- } else {
- mask = 0;
- MAX = 0;
- }
-
- for (int i = 0; i < count; i++) {
- int d = color_dist32(dst[i], opR, opG, opB);
- // now reverse d if we need to
- d = MAX + (d ^ mask) - mask;
- SkASSERT((unsigned)d <= 255);
- d = Accurate255To256(d);
-
- d = scale_dist_14(d, mul, sub);
- SkASSERT(d <= 256);
-
- if (d > 0) {
- if (aa) {
- d = SkAlphaMul(d, Accurate255To256(*aa++));
- if (0 == d) {
- continue;
- }
- }
- dst[i] = SkFourByteInterp256(src[i], dst[i], d);
- }
- }
-}
-
-static inline U16CPU SkBlend3216(SkPMColor src, U16CPU dst, unsigned scale) {
- SkASSERT(scale <= 32);
- scale <<= 3;
-
- return SkPackRGB16(SkAlphaBlend(SkPacked32ToR16(src), SkGetPackedR16(dst), scale),
- SkAlphaBlend(SkPacked32ToG16(src), SkGetPackedG16(dst), scale),
- SkAlphaBlend(SkPacked32ToB16(src), SkGetPackedB16(dst), scale));
-}
-
-void SkAvoidXfermode::xfer16(uint16_t dst[], const SkPMColor src[], int count,
- const SkAlpha aa[]) const {
- unsigned opR = SkColorGetR(fOpColor) >> (8 - SK_R16_BITS);
- unsigned opG = SkColorGetG(fOpColor) >> (8 - SK_G16_BITS);
- unsigned opB = SkColorGetB(fOpColor) >> (8 - SK_R16_BITS);
- uint32_t mul = fDistMul;
- uint32_t sub = (fDistMul - (1 << 14)) << SK_R16_BITS;
-
- int MAX, mask;
-
- if (kTargetColor_Mode == fMode) {
- mask = -1;
- MAX = 31;
- } else {
- mask = 0;
- MAX = 0;
- }
-
- for (int i = 0; i < count; i++) {
- int d = color_dist16(dst[i], opR, opG, opB);
- // now reverse d if we need to
- d = MAX + (d ^ mask) - mask;
- SkASSERT((unsigned)d <= 31);
- // convert from 0..31 to 0..32
- d += d >> 4;
- d = scale_dist_14(d, mul, sub);
- SkASSERT(d <= 32);
-
- if (d > 0) {
- if (aa) {
- d = SkAlphaMul(d, Accurate255To256(*aa++));
- if (0 == d) {
- continue;
- }
- }
- dst[i] = SkBlend3216(src[i], dst[i], d);
- }
- }
-}
-
-void SkAvoidXfermode::xferA8(SkAlpha dst[], const SkPMColor src[], int count,
- const SkAlpha aa[]) const {
-}
-
-
-#if SK_SUPPORT_GPU
-
-#include "GrFragmentProcessor.h"
-#include "GrInvariantOutput.h"
-#include "GrXferProcessor.h"
-#include "glsl/GrGLSLFragmentProcessor.h"
-#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLUniformHandler.h"
-#include "glsl/GrGLSLXferProcessor.h"
-
-///////////////////////////////////////////////////////////////////////////////
-// Fragment Processor
-///////////////////////////////////////////////////////////////////////////////
-
-class GLAvoidFP;
-
-class AvoidFP : public GrFragmentProcessor {
-public:
- static const GrFragmentProcessor* Create(SkColor opColor, uint8_t tolerance,
- SkAvoidXfermode::Mode mode,
- const GrFragmentProcessor* dst) {
- return new AvoidFP(opColor, tolerance, mode, dst);
- }
-
- ~AvoidFP() override { }
-
- const char* name() const override { return "Avoid"; }
-
- SkString dumpInfo() const override {
- SkString str;
- str.appendf("Color: 0x%08x Tol: %d Mode: %s",
- fOpColor, fTolerance,
- fMode == SkAvoidXfermode::kAvoidColor_Mode ? "Avoid" : "Target");
- return str;
- }
-
- SkColor opColor() const { return fOpColor; }
- uint8_t tol() const { return fTolerance; }
- SkAvoidXfermode::Mode mode() const { return fMode; }
-
-private:
- GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
-
- void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override;
-
- bool onIsEqual(const GrFragmentProcessor& fpBase) const override {
- const AvoidFP& fp = fpBase.cast<AvoidFP>();
-
- return fOpColor == fp.fOpColor &&
- fTolerance == fp.fTolerance &&
- fMode == fp.fMode;
- }
-
- void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
- inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
- }
-
- AvoidFP(SkColor opColor, uint8_t tolerance,
- SkAvoidXfermode::Mode mode, const GrFragmentProcessor* dst)
- : fOpColor(opColor), fTolerance(tolerance), fMode(mode) {
- this->initClassID<AvoidFP>();
-
- SkASSERT(dst);
- SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst);
- SkASSERT(0 == dstIndex);
- }
-
- SkColor fOpColor;
- uint8_t fTolerance;
- SkAvoidXfermode::Mode fMode;
-
- GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
- typedef GrFragmentProcessor INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-// Add common code for calculating avoid's distance value
-static void add_avoid_code(GrGLSLFragmentBuilder* fragBuilder,
- const char* dstColor,
- const char* srcCoverage,
- const char* kColorAndTolUni,
- const char* kCoverageName,
- SkAvoidXfermode::Mode mode) {
-
- fragBuilder->codeAppendf("vec3 temp = %s.rgb - %s.rgb;", dstColor, kColorAndTolUni);
- fragBuilder->codeAppendf("float dist = max(max(abs(temp.r), abs(temp.g)), abs(temp.b));");
-
- if (SkAvoidXfermode::kTargetColor_Mode == mode) {
- fragBuilder->codeAppendf("dist = 1.0 - dist;");
- }
-
- // the 'a' portion of the uniform is the scaled and inverted tolerance
- fragBuilder->codeAppendf("dist = dist * %s.a - (%s.a - 1.0);",
- kColorAndTolUni, kColorAndTolUni);
-
- fragBuilder->codeAppendf("vec4 %s = vec4(dist);", kCoverageName);
- if (srcCoverage) {
- fragBuilder->codeAppendf("%s *= %s;", kCoverageName, srcCoverage);
- }
-}
-
-class GLAvoidFP : public GrGLSLFragmentProcessor {
-public:
- void emitCode(EmitArgs& args) override {
- const AvoidFP& avoid = args.fFp.cast<AvoidFP>();
-
- GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString dstColor("dstColor");
- this->emitChild(0, nullptr, &dstColor, args);
-
- fColorAndTolUni = args.fUniformHandler->addUniform(
- kFragment_GrShaderFlag,
- kVec4f_GrSLType, kDefault_GrSLPrecision,
- "colorAndTol");
- const char* kColorAndTolUni = args.fUniformHandler->getUniformCStr(fColorAndTolUni);
-
- const char* kCoverageName = "newCoverage";
-
- // add_avoid_code emits the code needed to compute the new coverage
- add_avoid_code(fragBuilder,
- dstColor.c_str(), nullptr,
- kColorAndTolUni, kCoverageName, avoid.mode());
-
- // The raster implementation's quantization and behavior yield a very noticeable
- // effect near zero (0.0039 = 1/256).
- fragBuilder->codeAppendf("if (%s.r < 0.0039) { %s = %s; } else {",
- kCoverageName, args.fOutputColor, dstColor.c_str());
- fragBuilder->codeAppendf("%s = %s * %s + (vec4(1.0)-%s) * %s;",
- args.fOutputColor,
- kCoverageName, args.fInputColor ? args.fInputColor : "vec4(1.0)",
- kCoverageName, dstColor.c_str());
- fragBuilder->codeAppend("}");
- }
-
- static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, GrProcessorKeyBuilder* b) {
- const AvoidFP& avoid = proc.cast<AvoidFP>();
- uint32_t key = avoid.mode() == SkAvoidXfermode::kTargetColor_Mode ? 1 : 0;
- b->add32(key);
- }
-
-protected:
- void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {
- const AvoidFP& avoid = proc.cast<AvoidFP>();
- pdman.set4f(fColorAndTolUni,
- SkColorGetR(avoid.opColor())/255.0f,
- SkColorGetG(avoid.opColor())/255.0f,
- SkColorGetB(avoid.opColor())/255.0f,
- 256.0f/(avoid.tol()+1.0f));
- }
-
-private:
- GrGLSLProgramDataManager::UniformHandle fColorAndTolUni;
-
- typedef GrGLSLFragmentProcessor INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-GrGLSLFragmentProcessor* AvoidFP::onCreateGLSLInstance() const {
- return new GLAvoidFP;
-}
-
-void AvoidFP::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const {
- GLAvoidFP::GenKey(*this, caps, b);
-}
-
-const GrFragmentProcessor* AvoidFP::TestCreate(GrProcessorTestData* d) {
- SkColor opColor = d->fRandom->nextU();
- uint8_t tolerance = d->fRandom->nextBits(8);
- SkAvoidXfermode::Mode mode = d->fRandom->nextBool() ? SkAvoidXfermode::kAvoidColor_Mode
- : SkAvoidXfermode::kTargetColor_Mode;
-
- SkAutoTUnref<const GrFragmentProcessor> dst(GrProcessorUnitTest::CreateChildFP(d));
- return new AvoidFP(opColor, tolerance, mode, dst);
-}
-
-GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AvoidFP);
-
-///////////////////////////////////////////////////////////////////////////////
-// Xfer Processor
-///////////////////////////////////////////////////////////////////////////////
-
-class AvoidXP : public GrXferProcessor {
-public:
- AvoidXP(const DstTexture* dstTexture, bool hasMixedSamples,
- SkColor opColor, uint8_t tolerance, SkAvoidXfermode::Mode mode)
- : INHERITED(dstTexture, true, hasMixedSamples)
- , fOpColor(opColor)
- , fTolerance(tolerance)
- , fMode(mode) {
- this->initClassID<AvoidXP>();
- }
-
- const char* name() const override { return "Avoid"; }
-
- GrGLSLXferProcessor* createGLSLInstance() const override;
-
- SkColor opColor() const { return fOpColor; }
- uint8_t tol() const { return fTolerance; }
- SkAvoidXfermode::Mode mode() const { return fMode; }
-
-private:
- GrXferProcessor::OptFlags onGetOptimizations(const GrPipelineOptimizations& optimizations,
- bool doesStencilWrite,
- GrColor* overrideColor,
- const GrCaps& caps) const override {
- return GrXferProcessor::kNone_OptFlags;
- }
-
- void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override;
-
- bool onIsEqual(const GrXferProcessor& xpBase) const override {
- const AvoidXP& xp = xpBase.cast<AvoidXP>();
-
- return fOpColor == xp.fOpColor &&
- fTolerance == xp.fTolerance &&
- fMode == xp.fMode;
- }
-
- SkColor fOpColor;
- uint8_t fTolerance;
- SkAvoidXfermode::Mode fMode;
-
- typedef GrXferProcessor INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-class GLAvoidXP : public GrGLSLXferProcessor {
-public:
- static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProcessorKeyBuilder* b) {
- const AvoidXP& avoid = processor.cast<AvoidXP>();
- uint32_t key = SkAvoidXfermode::kTargetColor_Mode == avoid.mode() ? 1 : 0;
- b->add32(key);
- }
-
-private:
- void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder* fragBuilder,
- GrGLSLUniformHandler* uniformHandler,
- const char* srcColor,
- const char* srcCoverage,
- const char* dstColor,
- const char* outColor,
- const char* outColorSecondary,
- const GrXferProcessor& proc) override {
- const AvoidXP& avoid = proc.cast<AvoidXP>();
-
- fColorAndTolUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
- kVec4f_GrSLType, kDefault_GrSLPrecision,
- "colorAndTol");
- const char* kColorandTolUni = uniformHandler->getUniformCStr(fColorAndTolUni);
-
- const char* kCoverageName = "newCoverage";
-
- // add_avoid_code emits the code needed to compute the new coverage
- add_avoid_code(fragBuilder,
- dstColor, srcCoverage,
- kColorandTolUni, kCoverageName, avoid.mode());
-
- // The raster implementation's quantization and behavior yield a very noticeable
- // effect near zero (0.0039 = 1/256).
- fragBuilder->codeAppendf("if (%s.r < 0.0039) { %s = %s; } else {",
- kCoverageName, outColor, dstColor);
- fragBuilder->codeAppendf("%s = %s;", outColor, srcColor ? srcColor : "vec4(1.0)");
- INHERITED::DefaultCoverageModulation(fragBuilder, kCoverageName, dstColor, outColor,
- outColorSecondary, proc);
- fragBuilder->codeAppend("}");
- }
-
- void onSetData(const GrGLSLProgramDataManager& pdman,
- const GrXferProcessor& processor) override {
- const AvoidXP& avoid = processor.cast<AvoidXP>();
- pdman.set4f(fColorAndTolUni,
- SkColorGetR(avoid.opColor())/255.0f,
- SkColorGetG(avoid.opColor())/255.0f,
- SkColorGetB(avoid.opColor())/255.0f,
- 256.0f/(avoid.tol()+1.0f));
- };
-
- GrGLSLProgramDataManager::UniformHandle fColorAndTolUni;
-
- typedef GrGLSLXferProcessor INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-void AvoidXP::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const {
- GLAvoidXP::GenKey(*this, caps, b);
-}
-
-GrGLSLXferProcessor* AvoidXP::createGLSLInstance() const { return new GLAvoidXP; }
-
-///////////////////////////////////////////////////////////////////////////////
-class GrAvoidXPFactory : public GrXPFactory {
-public:
- static GrXPFactory* Create(SkColor opColor, uint8_t tolerance,
- SkAvoidXfermode::Mode mode) {
- return new GrAvoidXPFactory(opColor, tolerance, mode);
- }
-
- void getInvariantBlendedColor(const GrProcOptInfo& colorPOI,
- GrXPFactory::InvariantBlendedColor* blendedColor) const override {
- blendedColor->fWillBlendWithDst = true;
- blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags;
- }
-
-private:
- GrAvoidXPFactory(SkColor opColor, uint8_t tolerance, SkAvoidXfermode::Mode mode)
- : fOpColor(opColor)
- , fTolerance(tolerance)
- , fMode(mode) {
- this->initClassID<GrAvoidXPFactory>();
- }
-
- GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
- const GrPipelineOptimizations& optimizations,
- bool hasMixedSamples,
- const DstTexture* dstTexture) const override {
- return new AvoidXP(dstTexture, hasMixedSamples, fOpColor, fTolerance, fMode);
- }
-
- bool onWillReadDstColor(const GrCaps& caps,
- const GrPipelineOptimizations& optimizations,
- bool hasMixedSamples) const override {
- return true;
- }
-
- bool onIsEqual(const GrXPFactory& xpfBase) const override {
- const GrAvoidXPFactory& xpf = xpfBase.cast<GrAvoidXPFactory>();
- return fOpColor == xpf.fOpColor &&
- fTolerance == xpf.fTolerance &&
- fMode == xpf.fMode;
- }
-
- GR_DECLARE_XP_FACTORY_TEST;
-
- SkColor fOpColor;
- uint8_t fTolerance;
- SkAvoidXfermode::Mode fMode;
-
- typedef GrXPFactory INHERITED;
-};
-
-GR_DEFINE_XP_FACTORY_TEST(GrAvoidXPFactory);
-
-const GrXPFactory* GrAvoidXPFactory::TestCreate(GrProcessorTestData* d) {
- SkColor opColor = d->fRandom->nextU();
- uint8_t tolerance = d->fRandom->nextBits(8);
- SkAvoidXfermode::Mode mode = d->fRandom->nextBool() ? SkAvoidXfermode::kAvoidColor_Mode
- : SkAvoidXfermode::kTargetColor_Mode;
- return GrAvoidXPFactory::Create(opColor, tolerance, mode);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-const GrFragmentProcessor* SkAvoidXfermode::getFragmentProcessorForImageFilter(
- const GrFragmentProcessor* dst) const {
- return AvoidFP::Create(fOpColor, fTolerance, fMode, dst);
-}
-
-GrXPFactory* SkAvoidXfermode::asXPFactory() const {
- return GrAvoidXPFactory::Create(fOpColor, fTolerance, fMode);
-}
-#endif
-
-#ifndef SK_IGNORE_TO_STRING
-void SkAvoidXfermode::toString(SkString* str) const {
- str->append("AvoidXfermode: opColor: ");
- str->appendHex(fOpColor);
- str->appendf("tolerance: %d ", fTolerance);
-
- static const char* gModeStrings[] = { "Avoid", "Target" };
-
- str->appendf("mode: %s", gModeStrings[fMode]);
-}
-#endif
+++ /dev/null
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkPixelXorXfermode.h"
-#include "SkColorPriv.h"
-#include "SkReadBuffer.h"
-#include "SkWriteBuffer.h"
-#include "SkString.h"
-
-// we always return an opaque color, 'cause I don't know what to do with
-// the alpha-component and still return a valid premultiplied color.
-SkPMColor SkPixelXorXfermode::xferColor(SkPMColor src, SkPMColor dst) const {
- SkPMColor res = src ^ dst ^ fOpColor;
-
- res |= (SK_A32_MASK << SK_A32_SHIFT); // force it to be opaque
- return res;
-}
-
-void SkPixelXorXfermode::flatten(SkWriteBuffer& wb) const {
- wb.writeColor(SkColorSetRGB(SkGetPackedR32(fOpColor),
- SkGetPackedG32(fOpColor),
- SkGetPackedB32(fOpColor)));
-}
-
-sk_sp<SkFlattenable> SkPixelXorXfermode::CreateProc(SkReadBuffer& buffer) {
- return Make(buffer.readColor());
-}
-
-#ifndef SK_IGNORE_TO_STRING
-void SkPixelXorXfermode::toString(SkString* str) const {
- str->append("SkPixelXorXfermode: ");
- str->appendHex(fOpColor);
-}
-#endif
-
-#if SK_SUPPORT_GPU
-#include "GrFragmentProcessor.h"
-#include "GrInvariantOutput.h"
-#include "GrXferProcessor.h"
-
-#include "glsl/GrGLSLFragmentProcessor.h"
-#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramDataManager.h"
-#include "glsl/GrGLSLUniformHandler.h"
-#include "glsl/GrGLSLXferProcessor.h"
-
-///////////////////////////////////////////////////////////////////////////////
-// Fragment Processor
-///////////////////////////////////////////////////////////////////////////////
-
-static void add_pixelxor_code(GrGLSLFragmentBuilder* fragBuilder,
- const char* srcColor,
- const char* dstColor,
- const char* outputColor,
- const char* opColor) {
- static const GrGLSLShaderVar gXorArgs[] = {
- GrGLSLShaderVar("f1", kFloat_GrSLType),
- GrGLSLShaderVar("f2", kFloat_GrSLType),
- GrGLSLShaderVar("f3", kFloat_GrSLType),
- GrGLSLShaderVar("fPowerOf2Divisor", kFloat_GrSLType),
- };
- SkString xorFuncName;
-
- // The xor function checks if the three passed in floats (f1, f2, f3) would
- // have a bit in the log2(fPowerOf2Divisor)-th position if they were
- // represented by an int. It then performs an xor of the 3 bits (using
- // the property that serial xors can be treated as a sum of 0s & 1s mod 2).
- fragBuilder->emitFunction(kFloat_GrSLType,
- "xor",
- SK_ARRAY_COUNT(gXorArgs),
- gXorArgs,
- "float bit1 = floor(f1 / fPowerOf2Divisor);"
- "float bit2 = floor(f2 / fPowerOf2Divisor);"
- "float bit3 = floor(f3 / fPowerOf2Divisor);"
- "return mod(bit1 + bit2 + bit3, 2.0);",
- &xorFuncName);
-
- fragBuilder->codeAppend("float red = 0.0, green = 0.0, blue = 0.0;");
-
- if (srcColor) {
- fragBuilder->codeAppendf("vec3 src = 255.99 * %s.rgb;", srcColor);
- } else {
- fragBuilder->codeAppendf("vec3 src = vec3(255.99);");
- }
- fragBuilder->codeAppendf("vec3 dst = 255.99 * %s.rgb;", dstColor);
- fragBuilder->codeAppendf("vec3 op = 255.99 * %s;", opColor);
-
- fragBuilder->codeAppend("float modValue = 128.0;");
-
- fragBuilder->codeAppend("for (int i = 0; i < 8; i++) {");
-
- fragBuilder->codeAppendf("float bit = %s(src.r, dst.r, op.r, modValue);", xorFuncName.c_str());
- fragBuilder->codeAppend("red += modValue * bit;");
- fragBuilder->codeAppend("src.r = mod(src.r, modValue);");
- fragBuilder->codeAppend("dst.r = mod(dst.r, modValue);");
- fragBuilder->codeAppend("op.r = mod(op.r, modValue);");
-
- fragBuilder->codeAppendf("bit = %s(src.g, dst.g, op.g, modValue);", xorFuncName.c_str());
- fragBuilder->codeAppend("green += modValue * bit;");
- fragBuilder->codeAppend("src.g = mod(src.g, modValue);");
- fragBuilder->codeAppend("dst.g = mod(dst.g, modValue);");
- fragBuilder->codeAppend("op.g = mod(op.g, modValue);");
-
- fragBuilder->codeAppendf("bit = %s(src.b, dst.b, op.b, modValue);", xorFuncName.c_str());
- fragBuilder->codeAppend("blue += modValue * bit;");
- fragBuilder->codeAppend("src.b = mod(src.b, modValue);");
- fragBuilder->codeAppend("dst.b = mod(dst.b, modValue);");
- fragBuilder->codeAppend("op.b = mod(op.b, modValue);");
-
- fragBuilder->codeAppend("modValue /= 2.0;");
-
- fragBuilder->codeAppend("}");
-
- fragBuilder->codeAppendf("%s = vec4(red/255.0, green/255.0, blue/255.0, 1.0);", outputColor);
-}
-
-class GLPixelXorFP;
-
-class PixelXorFP : public GrFragmentProcessor {
-public:
- static const GrFragmentProcessor* Create(SkPMColor opColor, const GrFragmentProcessor* dst) {
- return new PixelXorFP(opColor, dst);
- }
-
- ~PixelXorFP() override {};
-
- const char* name() const override { return "PixelXor"; }
-
- SkString dumpInfo() const override {
- SkString str;
- str.appendf("Color: 0x%08x", fOpColor);
- return str;
- }
-
- SkPMColor opColor() const { return fOpColor; }
-
-private:
- GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
-
- void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override;
-
- bool onIsEqual(const GrFragmentProcessor& fpBase) const override {
- const PixelXorFP& fp = fpBase.cast<PixelXorFP>();
- return fOpColor == fp.fOpColor;
- }
-
- void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
- inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
- }
-
- PixelXorFP(SkPMColor opColor, const GrFragmentProcessor* dst)
- : fOpColor(opColor) {
- this->initClassID<PixelXorFP>();
-
- SkASSERT(dst);
- SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst);
- SkASSERT(0 == dstIndex);
- }
-
- SkPMColor fOpColor;
-
- GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
- typedef GrFragmentProcessor INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-class GLPixelXorFP : public GrGLSLFragmentProcessor {
-public:
- void emitCode(EmitArgs& args) override {
- GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString dstColor("dstColor");
- this->emitChild(0, nullptr, &dstColor, args);
-
- fOpColorUni = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
- kVec3f_GrSLType, kHigh_GrSLPrecision,
- "opColor");
- const char* kOpColorUni = args.fUniformHandler->getUniformCStr(fOpColorUni);
-
- add_pixelxor_code(fragBuilder, args.fInputColor, dstColor.c_str(),
- args.fOutputColor, kOpColorUni);
- }
-
- static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*) { }
-
-protected:
- void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {
- const PixelXorFP& pixXor = proc.cast<PixelXorFP>();
- pdman.set3f(fOpColorUni,
- SkGetPackedR32(pixXor.opColor())/255.0f,
- SkGetPackedG32(pixXor.opColor())/255.0f,
- SkGetPackedB32(pixXor.opColor())/255.0f);
- }
-
-private:
- GrGLSLProgramDataManager::UniformHandle fOpColorUni;
-
- typedef GrGLSLFragmentProcessor INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-GrGLSLFragmentProcessor* PixelXorFP::onCreateGLSLInstance() const {
- return new GLPixelXorFP;
-}
-
-void PixelXorFP::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const {
- GLPixelXorFP::GenKey(*this, caps, b);
-}
-
-const GrFragmentProcessor* PixelXorFP::TestCreate(GrProcessorTestData* d) {
- SkColor color = d->fRandom->nextU();
-
- SkAutoTUnref<const GrFragmentProcessor> dst(GrProcessorUnitTest::CreateChildFP(d));
- return new PixelXorFP(SkPreMultiplyColor(color), dst);
-}
-
-GR_DEFINE_FRAGMENT_PROCESSOR_TEST(PixelXorFP);
-
-///////////////////////////////////////////////////////////////////////////////
-// Xfer Processor
-///////////////////////////////////////////////////////////////////////////////
-
-class PixelXorXP : public GrXferProcessor {
-public:
- PixelXorXP(const DstTexture* dstTexture, bool hasMixedSamples, SkPMColor opColor)
- : INHERITED(dstTexture, true, hasMixedSamples)
- , fOpColor(opColor) {
- this->initClassID<PixelXorXP>();
- }
-
- const char* name() const override { return "PixelXor"; }
-
- GrGLSLXferProcessor* createGLSLInstance() const override;
-
- SkPMColor opColor() const { return fOpColor; }
-
-private:
- GrXferProcessor::OptFlags onGetOptimizations(const GrPipelineOptimizations& optimizations,
- bool doesStencilWrite,
- GrColor* overrideColor,
- const GrCaps& caps) const override {
- return GrXferProcessor::kNone_OptFlags;
- }
-
- void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override;
-
- bool onIsEqual(const GrXferProcessor& xpBase) const override {
- const PixelXorXP& xp = xpBase.cast<PixelXorXP>();
-
- return fOpColor == xp.fOpColor;
- }
-
- SkPMColor fOpColor;
-
- typedef GrXferProcessor INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-class GLPixelXorXP : public GrGLSLXferProcessor {
-public:
- GLPixelXorXP(const PixelXorXP& pixelXorXP) { }
-
- ~GLPixelXorXP() override {}
-
- static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*) { }
-
-private:
- void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder* fragBuilder,
- GrGLSLUniformHandler* uniformHandler,
- const char* srcColor,
- const char* srcCoverage,
- const char* dstColor,
- const char* outColor,
- const char* outColorSecondary,
- const GrXferProcessor& proc) override {
- fOpColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
- kVec3f_GrSLType, kHigh_GrSLPrecision,
- "opColor");
- const char* kOpColorUni = uniformHandler->getUniformCStr(fOpColorUni);
-
- add_pixelxor_code(fragBuilder, srcColor, dstColor, outColor, kOpColorUni);
-
- // Apply coverage.
- INHERITED::DefaultCoverageModulation(fragBuilder, srcCoverage, dstColor, outColor,
- outColorSecondary, proc);
- }
-
- void onSetData(const GrGLSLProgramDataManager& pdman,
- const GrXferProcessor& processor) override {
- const PixelXorXP& pixelXor = processor.cast<PixelXorXP>();
- pdman.set3f(fOpColorUni,
- SkGetPackedR32(pixelXor.opColor())/255.0f,
- SkGetPackedG32(pixelXor.opColor())/255.0f,
- SkGetPackedB32(pixelXor.opColor())/255.0f);
- };
-
- GrGLSLProgramDataManager::UniformHandle fOpColorUni;
-
- typedef GrGLSLXferProcessor INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-void PixelXorXP::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const {
- GLPixelXorXP::GenKey(*this, caps, b);
-}
-
-GrGLSLXferProcessor* PixelXorXP::createGLSLInstance() const { return new GLPixelXorXP(*this); }
-
-///////////////////////////////////////////////////////////////////////////////
-
-class GrPixelXorXPFactory : public GrXPFactory {
-public:
- static GrXPFactory* Create(SkPMColor opColor) {
- return new GrPixelXorXPFactory(opColor);
- }
-
- void getInvariantBlendedColor(const GrProcOptInfo& colorPOI,
- GrXPFactory::InvariantBlendedColor* blendedColor) const override {
- blendedColor->fWillBlendWithDst = true;
- blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags;
- }
-
-private:
- GrPixelXorXPFactory(SkPMColor opColor)
- : fOpColor(opColor) {
- this->initClassID<GrPixelXorXPFactory>();
- }
-
- GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
- const GrPipelineOptimizations& optimizations,
- bool hasMixedSamples,
- const DstTexture* dstTexture) const override {
- return new PixelXorXP(dstTexture, hasMixedSamples, fOpColor);
- }
-
- bool onWillReadDstColor(const GrCaps& caps,
- const GrPipelineOptimizations& optimizations,
- bool hasMixedSamples) const override {
- return true;
- }
-
- bool onIsEqual(const GrXPFactory& xpfBase) const override {
- const GrPixelXorXPFactory& xpf = xpfBase.cast<GrPixelXorXPFactory>();
- return fOpColor == xpf.fOpColor;
- }
-
- GR_DECLARE_XP_FACTORY_TEST;
-
- SkPMColor fOpColor;
-
- typedef GrXPFactory INHERITED;
-};
-
-GR_DEFINE_XP_FACTORY_TEST(GrPixelXorXPFactory);
-
-const GrXPFactory* GrPixelXorXPFactory::TestCreate(GrProcessorTestData* d) {
- SkColor color = d->fRandom->nextU();
-
- return GrPixelXorXPFactory::Create(SkPreMultiplyColor(color));
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-const GrFragmentProcessor* SkPixelXorXfermode::getFragmentProcessorForImageFilter(
- const GrFragmentProcessor* dst) const {
- return PixelXorFP::Create(fOpColor, dst);
-}
-
-GrXPFactory* SkPixelXorXfermode::asXPFactory() const {
- return GrPixelXorXPFactory::Create(fOpColor);
-}
-
-#endif
* we verify the count is as expected. If a new factory is added, then these numbers must be
* manually adjusted.
*/
-static const int kFPFactoryCount = 41;
+static const int kFPFactoryCount = 39;
static const int kGPFactoryCount = 14;
-static const int kXPFactoryCount = 8;
+static const int kXPFactoryCount = 6;
template<>
void GrProcessorTestFactory<GrFragmentProcessor>::VerifyFactoryCount() {
#include "SkAlphaThresholdFilter.h"
#include "SkArithmeticMode.h"
#include "SkArcToPathEffect.h"
-#include "SkAvoidXfermode.h"
#include "SkBitmapSourceDeserializer.h"
#include "SkBlurDrawLooper.h"
#include "SkBlurImageFilter.h"
#include "SkPaintImageFilter.h"
#include "SkPerlinNoiseShader.h"
#include "SkPictureImageFilter.h"
-#include "SkPixelXorXfermode.h"
#include "SkTableColorFilter.h"
#include "SkTestImageFilters.h"
#include "SkTileImageFilter.h"
SkGradientShader::InitializeFlattenables();
SkLightingShader::InitializeFlattenables();
- // Xfermode
- SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPixelXorXfermode)
- SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkAvoidXfermode)
-
// PathEffect
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArcToPathEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkCornerPathEffect)