wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "effects/GrXfermodeFragmentProcessor.h" |
| 9 | |
| 10 | #include "GrFragmentProcessor.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 11 | #include "GrInvariantOutput.h" |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 12 | #include "effects/GrConstColorProcessor.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 13 | #include "glsl/GrGLSLFragmentProcessor.h" |
| 14 | #include "glsl/GrGLSLBlend.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 15 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 16 | #include "SkGrPriv.h" |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 17 | |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 18 | class ComposeTwoFragmentProcessor : public GrFragmentProcessor { |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 19 | public: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 20 | ComposeTwoFragmentProcessor(sk_sp<GrFragmentProcessor> src, sk_sp<GrFragmentProcessor> dst, |
| 21 | SkXfermode::Mode mode) |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 22 | : fMode(mode) { |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 23 | this->initClassID<ComposeTwoFragmentProcessor>(); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 24 | SkDEBUGCODE(int shaderAChildIndex = )this->registerChildProcessor(std::move(src)); |
| 25 | SkDEBUGCODE(int shaderBChildIndex = )this->registerChildProcessor(std::move(dst)); |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 26 | SkASSERT(0 == shaderAChildIndex); |
| 27 | SkASSERT(1 == shaderBChildIndex); |
| 28 | } |
| 29 | |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 30 | const char* name() const override { return "ComposeTwo"; } |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 31 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 32 | void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 33 | b->add32(fMode); |
| 34 | } |
| 35 | |
| 36 | SkXfermode::Mode getMode() const { return fMode; } |
| 37 | |
| 38 | protected: |
| 39 | bool onIsEqual(const GrFragmentProcessor& other) const override { |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 40 | const ComposeTwoFragmentProcessor& cs = other.cast<ComposeTwoFragmentProcessor>(); |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 41 | return fMode == cs.fMode; |
| 42 | } |
| 43 | |
| 44 | void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 45 | inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); |
| 46 | } |
| 47 | |
| 48 | private: |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 49 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 50 | |
| 51 | SkXfermode::Mode fMode; |
| 52 | |
| 53 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 54 | |
| 55 | typedef GrFragmentProcessor INHERITED; |
| 56 | }; |
| 57 | |
| 58 | ///////////////////////////////////////////////////////////////////// |
| 59 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 60 | class GLComposeTwoFragmentProcessor : public GrGLSLFragmentProcessor { |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 61 | public: |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 62 | void emitCode(EmitArgs&) override; |
| 63 | |
| 64 | private: |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 65 | typedef GrGLSLFragmentProcessor INHERITED; |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | ///////////////////////////////////////////////////////////////////// |
| 69 | |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 70 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ComposeTwoFragmentProcessor); |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 71 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 72 | sk_sp<GrFragmentProcessor> ComposeTwoFragmentProcessor::TestCreate(GrProcessorTestData* d) { |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 73 | // Create two random frag procs. |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 74 | sk_sp<GrFragmentProcessor> fpA(GrProcessorUnitTest::MakeChildFP(d)); |
| 75 | sk_sp<GrFragmentProcessor> fpB(GrProcessorUnitTest::MakeChildFP(d)); |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 76 | |
| 77 | SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 78 | d->fRandom->nextRangeU(0, SkXfermode::kLastMode)); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 79 | return sk_sp<GrFragmentProcessor>( |
| 80 | new ComposeTwoFragmentProcessor(std::move(fpA), std::move(fpB), mode)); |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 81 | } |
| 82 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 83 | GrGLSLFragmentProcessor* ComposeTwoFragmentProcessor::onCreateGLSLInstance() const{ |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 84 | return new GLComposeTwoFragmentProcessor; |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | ///////////////////////////////////////////////////////////////////// |
| 88 | |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 89 | void GLComposeTwoFragmentProcessor::emitCode(EmitArgs& args) { |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 90 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 91 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 92 | const ComposeTwoFragmentProcessor& cs = args.fFp.cast<ComposeTwoFragmentProcessor>(); |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 93 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 94 | const char* inputColor = nullptr; |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 95 | if (args.fInputColor) { |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 96 | inputColor = "inputColor"; |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 97 | fragBuilder->codeAppendf("vec4 inputColor = vec4(%s.rgb, 1.0);", args.fInputColor); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 98 | } |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 99 | |
| 100 | // declare outputColor and emit the code for each of the two children |
bsalomon | 38ddbad | 2015-09-24 06:00:00 -0700 | [diff] [blame] | 101 | SkString srcColor("src"); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 102 | this->emitChild(0, inputColor, &srcColor, args); |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 103 | |
bsalomon | 38ddbad | 2015-09-24 06:00:00 -0700 | [diff] [blame] | 104 | SkString dstColor("dst"); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 105 | this->emitChild(1, inputColor, &dstColor, args); |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 106 | |
| 107 | // emit blend code |
| 108 | SkXfermode::Mode mode = cs.getMode(); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 109 | fragBuilder->codeAppendf("// Compose Xfer Mode: %s\n", SkXfermode::ModeName(mode)); |
| 110 | GrGLSLBlend::AppendMode(fragBuilder, |
| 111 | srcColor.c_str(), |
| 112 | dstColor.c_str(), |
| 113 | args.fOutputColor, |
| 114 | mode); |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 115 | |
| 116 | // re-multiply the output color by the input color's alpha |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 117 | if (args.fInputColor) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 118 | fragBuilder->codeAppendf("%s *= %s.a;", args.fOutputColor, args.fInputColor); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 119 | } |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 120 | } |
| 121 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 122 | sk_sp<GrFragmentProcessor> GrXfermodeFragmentProcessor::MakeFromTwoProcessors( |
| 123 | sk_sp<GrFragmentProcessor> src, sk_sp<GrFragmentProcessor> dst, SkXfermode::Mode mode) { |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 124 | switch (mode) { |
| 125 | case SkXfermode::kClear_Mode: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 126 | return GrConstColorProcessor::Make(GrColor_TRANSPARENT_BLACK, |
| 127 | GrConstColorProcessor::kIgnore_InputMode); |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 128 | case SkXfermode::kSrc_Mode: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 129 | return src; |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 130 | case SkXfermode::kDst_Mode: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 131 | return dst; |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 132 | default: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 133 | return sk_sp<GrFragmentProcessor>( |
| 134 | new ComposeTwoFragmentProcessor(std::move(src), std::move(dst), mode)); |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | ////////////////////////////////////////////////////////////////////////////// |
| 139 | |
| 140 | class ComposeOneFragmentProcessor : public GrFragmentProcessor { |
| 141 | public: |
| 142 | enum Child { |
| 143 | kDst_Child, |
| 144 | kSrc_Child, |
| 145 | }; |
| 146 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 147 | ComposeOneFragmentProcessor(sk_sp<GrFragmentProcessor> dst, SkXfermode::Mode mode, Child child) |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 148 | : fMode(mode) |
| 149 | , fChild(child) { |
| 150 | this->initClassID<ComposeOneFragmentProcessor>(); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 151 | SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(std::move(dst)); |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 152 | SkASSERT(0 == dstIndex); |
| 153 | } |
| 154 | |
| 155 | const char* name() const override { return "ComposeOne"; } |
| 156 | |
robertphillips | 783a4da | 2015-11-19 14:00:02 -0800 | [diff] [blame] | 157 | SkString dumpInfo() const override { |
| 158 | SkString str; |
| 159 | |
| 160 | for (int i = 0; i < this->numChildProcessors(); ++i) { |
| 161 | str.append(this->childProcessor(i).dumpInfo()); |
| 162 | } |
| 163 | return str; |
| 164 | } |
| 165 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 166 | void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 167 | GR_STATIC_ASSERT((SkXfermode::kLastMode & SK_MaxU16) == SkXfermode::kLastMode); |
| 168 | b->add32(fMode | (fChild << 16)); |
| 169 | } |
| 170 | |
| 171 | SkXfermode::Mode mode() const { return fMode; } |
| 172 | |
| 173 | Child child() const { return fChild; } |
| 174 | |
| 175 | protected: |
| 176 | bool onIsEqual(const GrFragmentProcessor& that) const override { |
| 177 | return fMode == that.cast<ComposeOneFragmentProcessor>().fMode; |
| 178 | } |
| 179 | |
| 180 | void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 181 | SkXfermode::Coeff skSrcCoeff, skDstCoeff; |
| 182 | if (SkXfermode::ModeAsCoeff(fMode, &skSrcCoeff, &skDstCoeff)) { |
| 183 | GrBlendCoeff srcCoeff = SkXfermodeCoeffToGrBlendCoeff(skSrcCoeff); |
| 184 | GrBlendCoeff dstCoeff = SkXfermodeCoeffToGrBlendCoeff(skDstCoeff); |
| 185 | GrInvariantOutput childOutput(0xFFFFFFFF, kRGBA_GrColorComponentFlags, false); |
| 186 | this->childProcessor(0).computeInvariantOutput(&childOutput); |
| 187 | GrColor blendColor; |
| 188 | GrColorComponentFlags blendFlags; |
| 189 | if (kDst_Child == fChild) { |
| 190 | GrGetCoeffBlendKnownComponents(srcCoeff, dstCoeff, |
| 191 | inout->color(), inout->validFlags(), |
| 192 | childOutput.color(), childOutput.validFlags(), |
| 193 | &blendColor, &blendFlags); |
| 194 | } else { |
| 195 | GrGetCoeffBlendKnownComponents(srcCoeff, dstCoeff, |
| 196 | childOutput.color(), childOutput.validFlags(), |
| 197 | inout->color(), inout->validFlags(), |
| 198 | &blendColor, &blendFlags); |
| 199 | } |
| 200 | // will the shader code reference the input color? |
| 201 | GrInvariantOutput::ReadInput readsInput = GrInvariantOutput::kWillNot_ReadInput; |
| 202 | if (kDst_Child == fChild) { |
| 203 | if (kZero_GrBlendCoeff != srcCoeff || GrBlendCoeffRefsSrc(dstCoeff)) { |
| 204 | readsInput = GrInvariantOutput::kWill_ReadInput; |
| 205 | } |
| 206 | } else { |
| 207 | if (kZero_GrBlendCoeff != dstCoeff || GrBlendCoeffRefsDst(srcCoeff)) { |
| 208 | readsInput = GrInvariantOutput::kWill_ReadInput; |
| 209 | } |
| 210 | } |
| 211 | inout->setToOther(blendFlags, blendColor, readsInput); |
| 212 | } else { |
| 213 | inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | private: |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 218 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 219 | |
| 220 | SkXfermode::Mode fMode; |
| 221 | Child fChild; |
| 222 | |
| 223 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 224 | |
| 225 | typedef GrFragmentProcessor INHERITED; |
| 226 | }; |
| 227 | |
| 228 | ////////////////////////////////////////////////////////////////////////////// |
| 229 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 230 | class GLComposeOneFragmentProcessor : public GrGLSLFragmentProcessor { |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 231 | public: |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 232 | void emitCode(EmitArgs& args) override { |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 233 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 234 | SkXfermode::Mode mode = args.fFp.cast<ComposeOneFragmentProcessor>().mode(); |
| 235 | ComposeOneFragmentProcessor::Child child = |
| 236 | args.fFp.cast<ComposeOneFragmentProcessor>().child(); |
bsalomon | 38ddbad | 2015-09-24 06:00:00 -0700 | [diff] [blame] | 237 | SkString childColor("child"); |
| 238 | this->emitChild(0, nullptr, &childColor, args); |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 239 | |
| 240 | const char* inputColor = args.fInputColor; |
| 241 | // We don't try to optimize for this case at all |
| 242 | if (!inputColor) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 243 | fragBuilder->codeAppendf("const vec4 ones = vec4(1);"); |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 244 | inputColor = "ones"; |
| 245 | } |
| 246 | |
| 247 | // emit blend code |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 248 | fragBuilder->codeAppendf("// Compose Xfer Mode: %s\n", SkXfermode::ModeName(mode)); |
bsalomon | 38ddbad | 2015-09-24 06:00:00 -0700 | [diff] [blame] | 249 | const char* childStr = childColor.c_str(); |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 250 | if (ComposeOneFragmentProcessor::kDst_Child == child) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 251 | GrGLSLBlend::AppendMode(fragBuilder, inputColor, childStr, args.fOutputColor, mode); |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 252 | } else { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 253 | GrGLSLBlend::AppendMode(fragBuilder, childStr, inputColor, args.fOutputColor, mode); |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 254 | } |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | private: |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 258 | typedef GrGLSLFragmentProcessor INHERITED; |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 259 | }; |
| 260 | |
| 261 | ///////////////////////////////////////////////////////////////////// |
| 262 | |
| 263 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ComposeOneFragmentProcessor); |
| 264 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 265 | sk_sp<GrFragmentProcessor> ComposeOneFragmentProcessor::TestCreate(GrProcessorTestData* d) { |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 266 | // Create one random frag procs. |
| 267 | // For now, we'll prevent either children from being a shader with children to prevent the |
| 268 | // possibility of an arbitrarily large tree of procs. |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 269 | sk_sp<GrFragmentProcessor> dst(GrProcessorUnitTest::MakeChildFP(d)); |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 270 | SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( |
| 271 | d->fRandom->nextRangeU(0, SkXfermode::kLastMode)); |
| 272 | ComposeOneFragmentProcessor::Child child = d->fRandom->nextBool() ? |
| 273 | ComposeOneFragmentProcessor::kDst_Child : |
| 274 | ComposeOneFragmentProcessor::kSrc_Child; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 275 | return sk_sp<GrFragmentProcessor>(new ComposeOneFragmentProcessor(std::move(dst), mode, child)); |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 276 | } |
| 277 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 278 | GrGLSLFragmentProcessor* ComposeOneFragmentProcessor::onCreateGLSLInstance() const { |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 279 | return new GLComposeOneFragmentProcessor; |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | ////////////////////////////////////////////////////////////////////////////// |
| 283 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 284 | sk_sp<GrFragmentProcessor> GrXfermodeFragmentProcessor::MakeFromDstProcessor( |
| 285 | sk_sp<GrFragmentProcessor> dst, SkXfermode::Mode mode) { |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 286 | switch (mode) { |
| 287 | case SkXfermode::kClear_Mode: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 288 | return GrConstColorProcessor::Make(GrColor_TRANSPARENT_BLACK, |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 289 | GrConstColorProcessor::kIgnore_InputMode); |
| 290 | case SkXfermode::kSrc_Mode: |
| 291 | return nullptr; |
| 292 | default: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 293 | return sk_sp<GrFragmentProcessor>( |
| 294 | new ComposeOneFragmentProcessor(std::move(dst), mode, |
| 295 | ComposeOneFragmentProcessor::kDst_Child)); |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 299 | sk_sp<GrFragmentProcessor> GrXfermodeFragmentProcessor::MakeFromSrcProcessor( |
| 300 | sk_sp<GrFragmentProcessor> src, SkXfermode::Mode mode) { |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 301 | switch (mode) { |
| 302 | case SkXfermode::kClear_Mode: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 303 | return GrConstColorProcessor::Make(GrColor_TRANSPARENT_BLACK, |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 304 | GrConstColorProcessor::kIgnore_InputMode); |
| 305 | case SkXfermode::kDst_Mode: |
| 306 | return nullptr; |
| 307 | default: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame^] | 308 | return sk_sp<GrFragmentProcessor>( |
| 309 | new ComposeOneFragmentProcessor(src, mode, |
| 310 | ComposeOneFragmentProcessor::kSrc_Child)); |
wangyix | 809e5af | 2015-09-09 12:58:32 -0700 | [diff] [blame] | 311 | } |
| 312 | } |