| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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(src); |
| 25 SkDEBUGCODE(int shaderBChildIndex = )this->registerChildProcessor(dst); | 25 SkDEBUGCODE(int shaderBChildIndex = )this->registerChildProcessor(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 onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override { | 32 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override { |
| 33 b->add32(fMode); | 33 b->add32(fMode); |
| 34 } | 34 } |
| 35 | 35 |
| 36 SkXfermode::Mode getMode() const { return fMode; } | 36 SkXfermode::Mode getMode() const { return fMode; } |
| 37 | 37 |
| 38 protected: | 38 protected: |
| 39 bool onIsEqual(const GrFragmentProcessor& other) const override { | 39 bool onIsEqual(const GrFragmentProcessor& other) const override { |
| 40 const ComposeTwoFragmentProcessor& cs = other.cast<ComposeTwoFragmentPro
cessor>(); | 40 const ComposeTwoFragmentProcessor& cs = other.cast<ComposeTwoFragmentPro
cessor>(); |
| 41 return fMode == cs.fMode; | 41 return fMode == cs.fMode; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 44 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 45 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); | 45 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); |
| 46 } | 46 } |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 GrGLSLFragmentProcessor* onCreateGLInstance() const override; | 49 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 50 | 50 |
| 51 SkXfermode::Mode fMode; | 51 SkXfermode::Mode fMode; |
| 52 | 52 |
| 53 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 53 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 54 | 54 |
| 55 typedef GrFragmentProcessor INHERITED; | 55 typedef GrFragmentProcessor INHERITED; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 ///////////////////////////////////////////////////////////////////// | 58 ///////////////////////////////////////////////////////////////////// |
| 59 | 59 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 74 const GrFragmentProcessor* ComposeTwoFragmentProcessor::TestCreate(GrProcessorTe
stData* d) { | 74 const GrFragmentProcessor* ComposeTwoFragmentProcessor::TestCreate(GrProcessorTe
stData* d) { |
| 75 // Create two random frag procs. | 75 // Create two random frag procs. |
| 76 SkAutoTUnref<const GrFragmentProcessor> fpA(GrProcessorUnitTest::CreateChild
FP(d)); | 76 SkAutoTUnref<const GrFragmentProcessor> fpA(GrProcessorUnitTest::CreateChild
FP(d)); |
| 77 SkAutoTUnref<const GrFragmentProcessor> fpB(GrProcessorUnitTest::CreateChild
FP(d)); | 77 SkAutoTUnref<const GrFragmentProcessor> fpB(GrProcessorUnitTest::CreateChild
FP(d)); |
| 78 | 78 |
| 79 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( | 79 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( |
| 80 d->fRandom->nextRangeU(0, SkXfermode::kLastMode)); | 80 d->fRandom->nextRangeU(0, SkXfermode::kLastMode)); |
| 81 return new ComposeTwoFragmentProcessor(fpA, fpB, mode); | 81 return new ComposeTwoFragmentProcessor(fpA, fpB, mode); |
| 82 } | 82 } |
| 83 | 83 |
| 84 GrGLSLFragmentProcessor* ComposeTwoFragmentProcessor::onCreateGLInstance() const
{ | 84 GrGLSLFragmentProcessor* ComposeTwoFragmentProcessor::onCreateGLSLInstance() con
st{ |
| 85 return new GLComposeTwoFragmentProcessor(*this); | 85 return new GLComposeTwoFragmentProcessor(*this); |
| 86 } | 86 } |
| 87 | 87 |
| 88 ///////////////////////////////////////////////////////////////////// | 88 ///////////////////////////////////////////////////////////////////// |
| 89 | 89 |
| 90 void GLComposeTwoFragmentProcessor::emitCode(EmitArgs& args) { | 90 void GLComposeTwoFragmentProcessor::emitCode(EmitArgs& args) { |
| 91 | 91 |
| 92 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; | 92 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
| 93 const ComposeTwoFragmentProcessor& cs = args.fFp.cast<ComposeTwoFragmentProc
essor>(); | 93 const ComposeTwoFragmentProcessor& cs = args.fFp.cast<ComposeTwoFragmentProc
essor>(); |
| 94 | 94 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 ComposeOneFragmentProcessor(const GrFragmentProcessor* dst, SkXfermode::Mode
mode, Child child) | 143 ComposeOneFragmentProcessor(const GrFragmentProcessor* dst, SkXfermode::Mode
mode, Child child) |
| 144 : fMode(mode) | 144 : fMode(mode) |
| 145 , fChild(child) { | 145 , fChild(child) { |
| 146 this->initClassID<ComposeOneFragmentProcessor>(); | 146 this->initClassID<ComposeOneFragmentProcessor>(); |
| 147 SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst); | 147 SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst); |
| 148 SkASSERT(0 == dstIndex); | 148 SkASSERT(0 == dstIndex); |
| 149 } | 149 } |
| 150 | 150 |
| 151 const char* name() const override { return "ComposeOne"; } | 151 const char* name() const override { return "ComposeOne"; } |
| 152 | 152 |
| 153 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override { | 153 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override { |
| 154 GR_STATIC_ASSERT((SkXfermode::kLastMode & SK_MaxU16) == SkXfermode::kLas
tMode); | 154 GR_STATIC_ASSERT((SkXfermode::kLastMode & SK_MaxU16) == SkXfermode::kLas
tMode); |
| 155 b->add32(fMode | (fChild << 16)); | 155 b->add32(fMode | (fChild << 16)); |
| 156 } | 156 } |
| 157 | 157 |
| 158 SkXfermode::Mode mode() const { return fMode; } | 158 SkXfermode::Mode mode() const { return fMode; } |
| 159 | 159 |
| 160 Child child() const { return fChild; } | 160 Child child() const { return fChild; } |
| 161 | 161 |
| 162 protected: | 162 protected: |
| 163 bool onIsEqual(const GrFragmentProcessor& that) const override { | 163 bool onIsEqual(const GrFragmentProcessor& that) const override { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 readsInput = GrInvariantOutput::kWill_ReadInput; | 195 readsInput = GrInvariantOutput::kWill_ReadInput; |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 inout->setToOther(blendFlags, blendColor, readsInput); | 198 inout->setToOther(blendFlags, blendColor, readsInput); |
| 199 } else { | 199 } else { |
| 200 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); | 200 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 private: | 204 private: |
| 205 GrGLSLFragmentProcessor* onCreateGLInstance() const override; | 205 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 206 | 206 |
| 207 SkXfermode::Mode fMode; | 207 SkXfermode::Mode fMode; |
| 208 Child fChild; | 208 Child fChild; |
| 209 | 209 |
| 210 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 210 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 211 | 211 |
| 212 typedef GrFragmentProcessor INHERITED; | 212 typedef GrFragmentProcessor INHERITED; |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 ////////////////////////////////////////////////////////////////////////////// | 215 ////////////////////////////////////////////////////////////////////////////// |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 // possibility of an arbitrarily large tree of procs. | 257 // possibility of an arbitrarily large tree of procs. |
| 258 SkAutoTUnref<const GrFragmentProcessor> dst(GrProcessorUnitTest::CreateChild
FP(d)); | 258 SkAutoTUnref<const GrFragmentProcessor> dst(GrProcessorUnitTest::CreateChild
FP(d)); |
| 259 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( | 259 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>( |
| 260 d->fRandom->nextRangeU(0, SkXfermode::kLastMode)); | 260 d->fRandom->nextRangeU(0, SkXfermode::kLastMode)); |
| 261 ComposeOneFragmentProcessor::Child child = d->fRandom->nextBool() ? | 261 ComposeOneFragmentProcessor::Child child = d->fRandom->nextBool() ? |
| 262 ComposeOneFragmentProcessor::kDst_Child : | 262 ComposeOneFragmentProcessor::kDst_Child : |
| 263 ComposeOneFragmentProcessor::kSrc_Child; | 263 ComposeOneFragmentProcessor::kSrc_Child; |
| 264 return new ComposeOneFragmentProcessor(dst, mode, child); | 264 return new ComposeOneFragmentProcessor(dst, mode, child); |
| 265 } | 265 } |
| 266 | 266 |
| 267 GrGLSLFragmentProcessor* ComposeOneFragmentProcessor::onCreateGLInstance() const
{ | 267 GrGLSLFragmentProcessor* ComposeOneFragmentProcessor::onCreateGLSLInstance() con
st { |
| 268 return new GLComposeOneFragmentProcessor(*this); | 268 return new GLComposeOneFragmentProcessor(*this); |
| 269 } | 269 } |
| 270 | 270 |
| 271 ////////////////////////////////////////////////////////////////////////////// | 271 ////////////////////////////////////////////////////////////////////////////// |
| 272 | 272 |
| 273 const GrFragmentProcessor* GrXfermodeFragmentProcessor::CreateFromDstProcessor( | 273 const GrFragmentProcessor* GrXfermodeFragmentProcessor::CreateFromDstProcessor( |
| 274 const GrFragmentProcessor* dst, SkXfermode::Mode mode) { | 274 const GrFragmentProcessor* dst, SkXfermode::Mode mode) { |
| 275 switch (mode) { | 275 switch (mode) { |
| 276 case SkXfermode::kClear_Mode: | 276 case SkXfermode::kClear_Mode: |
| 277 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, | 277 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 290 case SkXfermode::kClear_Mode: | 290 case SkXfermode::kClear_Mode: |
| 291 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, | 291 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, |
| 292 GrConstColorProcessor::kIgnore_
InputMode); | 292 GrConstColorProcessor::kIgnore_
InputMode); |
| 293 case SkXfermode::kDst_Mode: | 293 case SkXfermode::kDst_Mode: |
| 294 return nullptr; | 294 return nullptr; |
| 295 default: | 295 default: |
| 296 return new ComposeOneFragmentProcessor(src, mode, | 296 return new ComposeOneFragmentProcessor(src, mode, |
| 297 ComposeOneFragmentProcessor::
kSrc_Child); | 297 ComposeOneFragmentProcessor::
kSrc_Child); |
| 298 } | 298 } |
| 299 } | 299 } |
| OLD | NEW |