| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "effects/GrXfermodeFragmentProcessor.h" | 8 #include "effects/GrXfermodeFragmentProcessor.h" |
| 9 | 9 |
| 10 #include "GrFragmentProcessor.h" | 10 #include "GrFragmentProcessor.h" |
| 11 #include "GrInvariantOutput.h" | 11 #include "GrInvariantOutput.h" |
| 12 #include "effects/GrConstColorProcessor.h" | 12 #include "effects/GrConstColorProcessor.h" |
| 13 #include "glsl/GrGLSLFragmentProcessor.h" | 13 #include "glsl/GrGLSLFragmentProcessor.h" |
| 14 #include "glsl/GrGLSLBlend.h" | 14 #include "glsl/GrGLSLBlend.h" |
| 15 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 15 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 16 #include "SkGrPriv.h" | 16 #include "SkGrPriv.h" |
| 17 | 17 |
| 18 class ComposeTwoFragmentProcessor : public GrFragmentProcessor { | 18 class ComposeTwoFragmentProcessor : public GrFragmentProcessor { |
| 19 public: | 19 public: |
| 20 ComposeTwoFragmentProcessor(const GrFragmentProcessor* src, const GrFragment
Processor* dst, | 20 ComposeTwoFragmentProcessor(sk_sp<GrFragmentProcessor> src, sk_sp<GrFragment
Processor> dst, |
| 21 SkXfermode::Mode mode) | 21 SkXfermode::Mode mode) |
| 22 : fMode(mode) { | 22 : fMode(mode) { |
| 23 this->initClassID<ComposeTwoFragmentProcessor>(); | 23 this->initClassID<ComposeTwoFragmentProcessor>(); |
| 24 SkDEBUGCODE(int shaderAChildIndex = )this->registerChildProcessor(src); | 24 SkDEBUGCODE(int shaderAChildIndex = )this->registerChildProcessor(std::m
ove(src)); |
| 25 SkDEBUGCODE(int shaderBChildIndex = )this->registerChildProcessor(dst); | 25 SkDEBUGCODE(int shaderBChildIndex = )this->registerChildProcessor(std::m
ove(dst)); |
| 26 SkASSERT(0 == shaderAChildIndex); | 26 SkASSERT(0 == shaderAChildIndex); |
| 27 SkASSERT(1 == shaderBChildIndex); | 27 SkASSERT(1 == shaderBChildIndex); |
| 28 } | 28 } |
| 29 | 29 |
| 30 const char* name() const override { return "ComposeTwo"; } | 30 const char* name() const override { return "ComposeTwo"; } |
| 31 | 31 |
| 32 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override { | 32 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override { |
| 33 b->add32(fMode); | 33 b->add32(fMode); |
| 34 } | 34 } |
| 35 | 35 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 62 void emitCode(EmitArgs&) override; | 62 void emitCode(EmitArgs&) override; |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 typedef GrGLSLFragmentProcessor INHERITED; | 65 typedef GrGLSLFragmentProcessor INHERITED; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 ///////////////////////////////////////////////////////////////////// | 68 ///////////////////////////////////////////////////////////////////// |
| 69 | 69 |
| 70 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ComposeTwoFragmentProcessor); | 70 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ComposeTwoFragmentProcessor); |
| 71 | 71 |
| 72 const GrFragmentProcessor* ComposeTwoFragmentProcessor::TestCreate(GrProcessorTe
stData* d) { | 72 sk_sp<GrFragmentProcessor> ComposeTwoFragmentProcessor::TestCreate(GrProcessorTe
stData* d) { |
| 73 // Create two random frag procs. | 73 // Create two random frag procs. |
| 74 SkAutoTUnref<const GrFragmentProcessor> fpA(GrProcessorUnitTest::CreateChild
FP(d)); | 74 sk_sp<GrFragmentProcessor> fpA(GrProcessorUnitTest::MakeChildFP(d)); |
| 75 SkAutoTUnref<const GrFragmentProcessor> fpB(GrProcessorUnitTest::CreateChild
FP(d)); | 75 sk_sp<GrFragmentProcessor> fpB(GrProcessorUnitTest::MakeChildFP(d)); |
| 76 | 76 |
| 77 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( | 77 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( |
| 78 d->fRandom->nextRangeU(0, SkXfermode::kLastMode)); | 78 d->fRandom->nextRangeU(0, SkXfermode::kLastMode)); |
| 79 return new ComposeTwoFragmentProcessor(fpA, fpB, mode); | 79 return sk_sp<GrFragmentProcessor>( |
| 80 new ComposeTwoFragmentProcessor(std::move(fpA), std::move(fpB), mode)); |
| 80 } | 81 } |
| 81 | 82 |
| 82 GrGLSLFragmentProcessor* ComposeTwoFragmentProcessor::onCreateGLSLInstance() con
st{ | 83 GrGLSLFragmentProcessor* ComposeTwoFragmentProcessor::onCreateGLSLInstance() con
st{ |
| 83 return new GLComposeTwoFragmentProcessor; | 84 return new GLComposeTwoFragmentProcessor; |
| 84 } | 85 } |
| 85 | 86 |
| 86 ///////////////////////////////////////////////////////////////////// | 87 ///////////////////////////////////////////////////////////////////// |
| 87 | 88 |
| 88 void GLComposeTwoFragmentProcessor::emitCode(EmitArgs& args) { | 89 void GLComposeTwoFragmentProcessor::emitCode(EmitArgs& args) { |
| 89 | 90 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 111 dstColor.c_str(), | 112 dstColor.c_str(), |
| 112 args.fOutputColor, | 113 args.fOutputColor, |
| 113 mode); | 114 mode); |
| 114 | 115 |
| 115 // re-multiply the output color by the input color's alpha | 116 // re-multiply the output color by the input color's alpha |
| 116 if (args.fInputColor) { | 117 if (args.fInputColor) { |
| 117 fragBuilder->codeAppendf("%s *= %s.a;", args.fOutputColor, args.fInputCo
lor); | 118 fragBuilder->codeAppendf("%s *= %s.a;", args.fOutputColor, args.fInputCo
lor); |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 | 121 |
| 121 const GrFragmentProcessor* GrXfermodeFragmentProcessor::CreateFromTwoProcessors( | 122 sk_sp<GrFragmentProcessor> GrXfermodeFragmentProcessor::MakeFromTwoProcessors( |
| 122 const GrFragmentProcessor* src, const GrFragmentProcessor* dst, SkXferm
ode::Mode mode) { | 123 sk_sp<GrFragmentProcessor> src, sk_sp<GrFragmentProcessor> dst, SkXferm
ode::Mode mode) { |
| 123 switch (mode) { | 124 switch (mode) { |
| 124 case SkXfermode::kClear_Mode: | 125 case SkXfermode::kClear_Mode: |
| 125 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, | 126 return GrConstColorProcessor::Make(GrColor_TRANSPARENT_BLACK, |
| 126 GrConstColorProcessor::kIgnore_
InputMode); | 127 GrConstColorProcessor::kIgnore_In
putMode); |
| 127 case SkXfermode::kSrc_Mode: | 128 case SkXfermode::kSrc_Mode: |
| 128 return SkRef(src); | 129 return src; |
| 129 case SkXfermode::kDst_Mode: | 130 case SkXfermode::kDst_Mode: |
| 130 return SkRef(dst); | 131 return dst; |
| 131 default: | 132 default: |
| 132 return new ComposeTwoFragmentProcessor(src, dst, mode); | 133 return sk_sp<GrFragmentProcessor>( |
| 134 new ComposeTwoFragmentProcessor(std::move(src), std::move(dst),
mode)); |
| 133 } | 135 } |
| 134 } | 136 } |
| 135 | 137 |
| 136 ////////////////////////////////////////////////////////////////////////////// | 138 ////////////////////////////////////////////////////////////////////////////// |
| 137 | 139 |
| 138 class ComposeOneFragmentProcessor : public GrFragmentProcessor { | 140 class ComposeOneFragmentProcessor : public GrFragmentProcessor { |
| 139 public: | 141 public: |
| 140 enum Child { | 142 enum Child { |
| 141 kDst_Child, | 143 kDst_Child, |
| 142 kSrc_Child, | 144 kSrc_Child, |
| 143 }; | 145 }; |
| 144 | 146 |
| 145 ComposeOneFragmentProcessor(const GrFragmentProcessor* dst, SkXfermode::Mode
mode, Child child) | 147 ComposeOneFragmentProcessor(sk_sp<GrFragmentProcessor> dst, SkXfermode::Mode
mode, Child child) |
| 146 : fMode(mode) | 148 : fMode(mode) |
| 147 , fChild(child) { | 149 , fChild(child) { |
| 148 this->initClassID<ComposeOneFragmentProcessor>(); | 150 this->initClassID<ComposeOneFragmentProcessor>(); |
| 149 SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst); | 151 SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(std::move(dst))
; |
| 150 SkASSERT(0 == dstIndex); | 152 SkASSERT(0 == dstIndex); |
| 151 } | 153 } |
| 152 | 154 |
| 153 const char* name() const override { return "ComposeOne"; } | 155 const char* name() const override { return "ComposeOne"; } |
| 154 | 156 |
| 155 SkString dumpInfo() const override { | 157 SkString dumpInfo() const override { |
| 156 SkString str; | 158 SkString str; |
| 157 | 159 |
| 158 for (int i = 0; i < this->numChildProcessors(); ++i) { | 160 for (int i = 0; i < this->numChildProcessors(); ++i) { |
| 159 str.append(this->childProcessor(i).dumpInfo()); | 161 str.append(this->childProcessor(i).dumpInfo()); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 } | 255 } |
| 254 | 256 |
| 255 private: | 257 private: |
| 256 typedef GrGLSLFragmentProcessor INHERITED; | 258 typedef GrGLSLFragmentProcessor INHERITED; |
| 257 }; | 259 }; |
| 258 | 260 |
| 259 ///////////////////////////////////////////////////////////////////// | 261 ///////////////////////////////////////////////////////////////////// |
| 260 | 262 |
| 261 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ComposeOneFragmentProcessor); | 263 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ComposeOneFragmentProcessor); |
| 262 | 264 |
| 263 const GrFragmentProcessor* ComposeOneFragmentProcessor::TestCreate(GrProcessorTe
stData* d) { | 265 sk_sp<GrFragmentProcessor> ComposeOneFragmentProcessor::TestCreate(GrProcessorTe
stData* d) { |
| 264 // Create one random frag procs. | 266 // Create one random frag procs. |
| 265 // For now, we'll prevent either children from being a shader with children
to prevent the | 267 // For now, we'll prevent either children from being a shader with children
to prevent the |
| 266 // possibility of an arbitrarily large tree of procs. | 268 // possibility of an arbitrarily large tree of procs. |
| 267 SkAutoTUnref<const GrFragmentProcessor> dst(GrProcessorUnitTest::CreateChild
FP(d)); | 269 sk_sp<GrFragmentProcessor> dst(GrProcessorUnitTest::MakeChildFP(d)); |
| 268 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( | 270 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( |
| 269 d->fRandom->nextRangeU(0, SkXfermode::kLastMode)); | 271 d->fRandom->nextRangeU(0, SkXfermode::kLastMode)); |
| 270 ComposeOneFragmentProcessor::Child child = d->fRandom->nextBool() ? | 272 ComposeOneFragmentProcessor::Child child = d->fRandom->nextBool() ? |
| 271 ComposeOneFragmentProcessor::kDst_Child : | 273 ComposeOneFragmentProcessor::kDst_Child : |
| 272 ComposeOneFragmentProcessor::kSrc_Child; | 274 ComposeOneFragmentProcessor::kSrc_Child; |
| 273 return new ComposeOneFragmentProcessor(dst, mode, child); | 275 return sk_sp<GrFragmentProcessor>(new ComposeOneFragmentProcessor(std::move(
dst), mode, child)); |
| 274 } | 276 } |
| 275 | 277 |
| 276 GrGLSLFragmentProcessor* ComposeOneFragmentProcessor::onCreateGLSLInstance() con
st { | 278 GrGLSLFragmentProcessor* ComposeOneFragmentProcessor::onCreateGLSLInstance() con
st { |
| 277 return new GLComposeOneFragmentProcessor; | 279 return new GLComposeOneFragmentProcessor; |
| 278 } | 280 } |
| 279 | 281 |
| 280 ////////////////////////////////////////////////////////////////////////////// | 282 ////////////////////////////////////////////////////////////////////////////// |
| 281 | 283 |
| 282 const GrFragmentProcessor* GrXfermodeFragmentProcessor::CreateFromDstProcessor( | 284 sk_sp<GrFragmentProcessor> GrXfermodeFragmentProcessor::MakeFromDstProcessor( |
| 283 const GrFragmentProcessor* dst, SkXfermode::Mode mode) { | 285 sk_sp<GrFragmentProcessor> dst, SkXfermode::Mode mode) { |
| 284 switch (mode) { | 286 switch (mode) { |
| 285 case SkXfermode::kClear_Mode: | 287 case SkXfermode::kClear_Mode: |
| 286 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, | 288 return GrConstColorProcessor::Make(GrColor_TRANSPARENT_BLACK, |
| 287 GrConstColorProcessor::kIgnore_
InputMode); | 289 GrConstColorProcessor::kIgnore_
InputMode); |
| 288 case SkXfermode::kSrc_Mode: | 290 case SkXfermode::kSrc_Mode: |
| 289 return nullptr; | 291 return nullptr; |
| 290 default: | 292 default: |
| 291 return new ComposeOneFragmentProcessor(dst, mode, | 293 return sk_sp<GrFragmentProcessor>( |
| 292 ComposeOneFragmentProcessor::
kDst_Child); | 294 new ComposeOneFragmentProcessor(std::move(dst), mode, |
| 295 ComposeOneFragmentProcessor::kDs
t_Child)); |
| 293 } | 296 } |
| 294 } | 297 } |
| 295 | 298 |
| 296 const GrFragmentProcessor* GrXfermodeFragmentProcessor::CreateFromSrcProcessor( | 299 sk_sp<GrFragmentProcessor> GrXfermodeFragmentProcessor::MakeFromSrcProcessor( |
| 297 const GrFragmentProcessor* src, SkXfermode::Mode mode) { | 300 sk_sp<GrFragmentProcessor> src, SkXfermode::Mode mode) { |
| 298 switch (mode) { | 301 switch (mode) { |
| 299 case SkXfermode::kClear_Mode: | 302 case SkXfermode::kClear_Mode: |
| 300 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, | 303 return GrConstColorProcessor::Make(GrColor_TRANSPARENT_BLACK, |
| 301 GrConstColorProcessor::kIgnore_
InputMode); | 304 GrConstColorProcessor::kIgnore_
InputMode); |
| 302 case SkXfermode::kDst_Mode: | 305 case SkXfermode::kDst_Mode: |
| 303 return nullptr; | 306 return nullptr; |
| 304 default: | 307 default: |
| 305 return new ComposeOneFragmentProcessor(src, mode, | 308 return sk_sp<GrFragmentProcessor>( |
| 306 ComposeOneFragmentProcessor::
kSrc_Child); | 309 new ComposeOneFragmentProcessor(src, mode, |
| 310 ComposeOneFragmentProcessor::kSr
c_Child)); |
| 307 } | 311 } |
| 308 } | 312 } |
| OLD | NEW |